Commit Graph

521 Commits

Author SHA1 Message Date
Doug Gregor
ad90116da9 [Serialization] Wire up archetype generic environments eagerly.
Teach the serialized form of ArchetypeType about its owning generic
environment, so we can wire up the generic environment of (primary)
archetypes eagerly (at the point of deserialization) rather than when
we form the generic environment. This ensures that there is no point
at which we have a (non-opened-existential) archetype without a
generic environment.

... except that the type reconstruction code creates such archetypes.
2017-01-06 11:16:42 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Doug Gregor
69cc9f4b54 [Serialization] Unique SIL generic environments when serializing.
Teach the serialization of SIL generic environments, which used to be
a trailing record following the SIL function definition, to use the
same uniqued "generic environment IDs" that are used for the AST
generic environments. Many of them overlap anyway, and SIL functions
tend to have AST generic environments anyway.

This approach guarantees that the AST + SIL deserialization provide
the same uniqueness of generic environments present prior to
serialization.
2017-01-05 18:24:55 -08:00
Doug Gregor
8c886fd974 [Serialization] Serialize SILBoxType substitutions directly.
Deserialization shouldn't be looking up conformances.
2017-01-04 15:13:26 -08:00
Doug Gregor
a9a8defe10 [Serialization] Make serialization of witnesses deterministic.
Serialization of the requirement-to-synthetic-environment map was
walking in DenseMap order. However, the keys to this map are
known---they're always the generic parameters of the requirement. So,
walk those generic parameters to make it deterministic, and don't
bother serializing them because they're known to the deserializer
already.

Fixes rdar://problem/29689811.
2016-12-16 10:35:43 -08:00
Doug Gregor
821965dee4 [Serialization] Give generic environments identitity.
Serialize generic environments via a generic environment ID with a
separte offset table, so we have identity for the generic environments
and will share generic environments on deserialization.
2016-12-16 08:41:43 -08:00
Michael Gottesman
6213550239 [semantic-sil] Create copy_unowned_value.
This was in the first high level ARC instruction proposal, but I have not needed
it until now. The use case for this is to ahandle strong_retain_unowned (which
takes in an unowned value, asserts it is still alive, performs a strong_retain,
and returns the @owned value). This @owned value needs a destroy_value.

rdar://29671437
2016-12-14 19:22:24 -08:00
Michael Gottesman
66cff7e37e [semantic-arc] Add StoreBorrowInst and BeginBorrowInst. 2016-12-12 13:06:18 -08:00
Doug Gregor
5cb04f4635 [Serialization] Serialize a typealias' underlying type as an interface type.
We'll lazily map the interface type to a contextual type when requested.
2016-12-10 15:35:09 -08:00
Doug Gregor
380bc68512 [Serialization] Remove serialization for 'isa' patterns.
Refutable patterns are never serialized, and there was no
corresponding deserialization code besides. NFC
2016-12-09 20:48:41 -08:00
Doug Gregor
d4fca2cc8b [Serialization] Lazily form context types for deserialized patterns.
When a pattern within a type context is serialized, serialize its
interface type (not its contextual type). When deserializing, record
the interface type and keep a side table of the associated
DeclContext, so that we can lazily map to the contextual type on first
access. This is designed to break recursion when we change the way
archetypes and generic environments are serialized.
2016-12-09 20:48:41 -08:00
Doug Gregor
7e40806ae4 [Serialization] Don’t serialize context types for variables.
We will lazily recreate the context types from the generic environment and interface types when requested.
2016-12-09 20:48:40 -08:00
Doug Gregor
1f89886ffa [Serialization] Stop serializing the contextual types of parameter declarations.
Only serialize the interface types of parameter declarations into the
module file, then lazily build the contextual types when
requested. This saves a small amount of space in the Swift module
files (~64k for the Swift standard library) and some effort on load.
2016-12-09 20:48:40 -08:00
Joe Groff
0308ecf89f Serialize SILBoxTypes using their layout. 2016-12-08 15:59:34 -08:00
Slava Pestov
f3c72d8941 AST: Remove SubstitutedType 2016-12-07 17:03:07 -08:00
Doug Gregor
ea067c0346 [AST] Eliminate ArchetypeType::NestedType.
Now that we no longer distinguish outer archetypes from inner
archetypes, we can replace NestedType with just Type.
2016-12-07 14:27:49 -08:00
Slava Pestov
52b91ad910 AST: Remove AssociatedTypeType 2016-12-01 14:53:31 -08:00
Slava Pestov
8bdbe774e0 AST: Don't call hasType()/getType()/setType() on SubscriptDecls 2016-12-01 13:00:17 -08:00
Slava Pestov
835472b14f AST: Remove PolymorphicFunctionType 2016-11-29 03:05:35 -07:00
Slava Pestov
e71979ea1a Serialization: Don't serialize contextual type of AbstractFunctionDecls and EnumElementDecls
These can contain PolymorphicFunctionTypes, and should no longer be
accessed.
2016-11-29 03:05:29 -07:00
Doug Gregor
2030349d2f [Serialization] Simplify serialized representation of archetype types.
We don't need to store the associated type declaration and name
separately in the module file, either.
2016-11-28 11:39:38 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
2294e33604 AST: Remove ArchetypeType::getSelfProtocol()
Now that the last usages have been removed, we no longer need
special handling for the 'Self' archetype of a protocol.
2016-11-19 00:28:17 -08:00
Doug Gregor
84d70a2284 Eliminate witness markers. NFC 2016-11-09 19:22:51 -08:00
Slava Pestov
4780b0bcdf AST: Introduce @_inlineable attribute
This attribute causes a function's body to be serialized, but unlike
@_transparent and @inline(__always), does not force it to be inlined.
2016-11-01 21:14:35 -07:00
Doug Gregor
b5511bd3ea [Serialization] (De-)serialize witnesses completely.
The witnesses in a NormalProtocolConformance have never been
completely serialized, because their substitutions involved a weird
mix of archetypes that blew up the deserialization code. So, only the
witness declarations themselves got serialized. Many clients (the type
checker, SourceKit, etc.) didn't need the extra information, but some
clients (e.g., the SIL optimizers) would end up recomputing this
information. Ick.

Now, serialize the complete Witness structure along with the AST,
including information about the synthetic environment, complete
substitutions, etc. This should obsolete some redundant code paths in
the SIL optimization infrastructure.

This (de-)serialization code takes a new-ish approach to serializing
the synthetic environment in that it avoids serializing any
archetypes. Rather, it maps everything back to interface types during
serialization, and deserialization forms a new generic environment
(with new archetypes!) on-the-fly, mapping deserialized types back
into that environment (and to those archetypes). This way, we don't
have to maintain identity of archetypes in the deserialization code,
and might get some better re-use of the archetypes.

More of rdar://problem/24079818.
2016-11-01 17:14:17 -07:00
Michael Gottesman
68e1940083 [semantic-arc] Instead of using the parsing heuristic for determining ownership when serializing, just serialize a bit.
The reason we are using the parsing heuristic is to ensure that we do
not need to update a ton of test cases. This makes sense since in
general, when parsing we are creating new code that is running for the
first time through the compiler. On the other hand, in
serialization/deserialization we expect to get back exactly the
SILFunction that we serialized. So it makes sense to explicitly
preserve whether we have ownership qualification or not.

rdar://28851920
2016-10-25 00:01:48 -07:00
Michael Gottesman
6f751498e6 [semantic-arc] Bump module format number.
I had several versions of the copy value, destroy value patch and in one of them
I bumped the module file version number. The one I committed was not one of
those = /.

Sorry Jordan!
2016-10-24 10:36:40 -07:00
Michael Gottesman
c41ead0b72 [semantic-arc] Add support for the load_borrow and end_borrow instructions to SIL, Serialization, Printing/Parsing.
I did not add it to the ownership verifier or to IRGen yet.

rdar://28685236
2016-10-20 10:53:44 -07:00
Joe Groff
aac85cb93f SIL: Introduce a 'closure' convention for unapplied invocation functions.
We don't want the machine calling conventions for closure invocation functions to necessarily be tied to the convention for normal thin functions or methods. NFC yet; for now, 'closure' follows the same behavior as the 'method' convention, but as part of partial_apply simplification it will be a requirement that partial_apply takes a @convention(closure) function and a box and produces a @convention(thick) function from them.
2016-10-17 15:55:04 -07:00
Michael Gottesman
e0bea5f9bb [semantic-arc] Implement SIL serialization support for ownership qualified store and load.
rdar://28685236
2016-10-15 18:10:52 -07:00
Slava Pestov
092a9318ee Serialization: Remove some unused code
Previous refactorings introducing GenericEnvironment left
behind some lint.
2016-10-12 18:56:37 -07:00
Slava Pestov
5ab94a6ef0 AST: Add "re-sugaring" to GenericEnvironment
Sugared GenericTypeParamTypes point to GenericTypeParamDecls,
allowing the name of the parameter as written by the user to be
recovered. Canonical GenericTypeParamTypes on the other hand
only store a depth and index, without referencing the original
declaration.

When printing SIL, we wish to output the original generic parameter
names, even though SIL only uses canonical types. Previously,
we used to accomplish this by mapping the generic parameter to an
archetype and printing the name of the archetype. This was not
adequate if multiple generic parameters mapped to the same
archetype, or if a generic parameter was mapped to a concrete type.

The new approach preserves the original sugared types in the
GenericEnvironment, adding a new GenericEnvironment::getSugaredType()
method.

There are also some other assorted simplifications made possible
by this.

Unfortunately this makes GenericEnvironments use a bit more memory,
however I have more improvements coming that will offset the gains,
in addition to making substitution lists smaller also.
2016-10-12 18:56:16 -07:00
Joe Groff
664390ace3 SIL: Add the ability for partial_apply instructions to control the ownership of the produced closure.
This lets us get to the goal of +0 guaranteed closure contexts. NFC yet, just add the under-the-hood ability for partial_apply instructions producing callee-guaranteed closures to be parsed, printed, and serialized.
2016-10-06 15:38:04 -07:00
Erik Eckstein
db00c5e924 SIL: allow alloc_ref_dynamic to allocate tail elements.
It's the same thing as for alloc_ref: the optional [tail_elems ...] attribute specify the tail elements to allocate.
For details see docs/SIL.rst

This feature is needed so that we can allocate a MangedBuffer with alloc_ref_dynamic.
The ManagedBuffer.create() function uses the dynamic self type to create the buffer instance.
2016-10-06 08:46:23 -07:00
Slava Pestov
408d745df8 Serialization: Don't serialize RequirementReprs
RequirementReprs stored serialized references to archetypes,
which do not have enough information to reconstruct same-type
requirements.

For this reason, we would serialize the 'as written' requirement
string as well as the actual types, which is a horrible hack.

Now that the ASTPrinter and SourceKit use GenericSignatures,
none of this is needed anymore.
2016-10-03 00:39:49 -04:00
Slava Pestov
a9c68c0736 AST: Remove archetype from AbstractTypeParamDecl
There's a bit of a hack to deal with generic typealiases, but
overall this makes things more logical.

This is the last big refactoring before we can allow constrained
extensions to make generic parameters concrete. All that remains
is a small set of changes to SIL type lowering, and retooling
some diagnostics in Sema.
2016-09-22 19:48:30 -07:00
Michael Ilseman
0bb868a539 [ParameterTypeFlags] Incorporate review feedback 2016-09-22 12:24:37 -07:00
Michael Ilseman
ed2522b384 [AST] Create ParameterTypeFlags and put them on function params
Long term, we want to refactor the AST to reflect the current
programming model in Swift. This would include refactoring
FunctionType to take a list of ParameterTypeElt, or something with a
better name, that can contain both the type and flags/bits that are
only specific to types in parameter position, such as @autoclosure and
@escaping. At the same time, noescape-by-default has severely hurt our
ability to print types without significant context, as we either have
to choose to too aggressively print @escaping or not print it in every
situation it occurs, or both.

As a gentle step towards the final solution, without uprooting our
overall AST structure, and as a way towards fixing the @escaping
printing ails, put these bits on the TupleTypeElt and ParenType, which
will serve as a model for what ParameterTypeElt will be like in the
future. Re-use these flags on CallArgParam, to leverage shared
knowledge in the type system. It is a little painful to tack onto
these types, but it's minor and will be overhauled soon, which will
eventually result in size savings and less complexity overall.

This includes all the constraint system adjustments to make these
types work and influence type equality and overload resolution as
desired. They are encoded in the module format. Additional tests
added.
2016-09-22 12:24:02 -07:00
Erik Eckstein
34a4e6df0a SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-16 11:02:19 -07:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Erik Eckstein
b11b60e658 SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-14 14:54:18 -07:00
Doug Gregor
4eac3ea2e7 Always create initializer contexts for pattern binding entries in non-local scopes.
We were optimizing away unused pattern binding initializer contexts in
both the parser and in semantic analysis, which led to a
somewhat-unpredictable set of DeclContexts in the AST. Normalize
everything by always creating these contexts.
2016-09-02 10:39:19 -07:00
Doug Gregor
5e25d25c96 [AST] Separate the DeclContexts for different pattern binding entries in a pattern binding decl. 2016-09-02 10:39:19 -07:00
Slava Pestov
4bfaa47890 AST: Nuke GenericParamList::AllArchetypes
Now that SILFunctions no longer reference a GenericParamList, we
don't need to de-serialize cross-module references to archetypes
anymore.

This was the last remaining usage of AllArchetypes, so we can
finally rip it out.
2016-08-28 13:51:38 -07:00
Slava Pestov
ca0b548584 SIL: Replace SILFunction::ContextGenericParams with a GenericEnvironment
This patch is rather large, since it was hard to make this change
incrementally, but most of the changes are mechanical.

Now that we have a lighter-weight data structure in the AST for mapping
interface types to archetypes and vice versa, use that in SIL instead of
a GenericParamList.

This means that when serializing a SILFunction body, we no longer need to
serialize references to archetypes from other modules.

Several methods used for forming substitutions can now be moved from
GenericParamList to GenericEnvironment.

Also, GenericParamList::cloneWithOuterParameters() and
GenericParamList::getEmpty() can now go away, since they were only used
when SILGen-ing witness thunks.

Finally, when printing generic parameters with identical names, the
SIL printer used to number them from highest depth to lowest, by
walking generic parameter lists starting with the innermost one.
Now, ambiguous generic parameters are numbered from lowest depth
to highest, by walking the generic signature, which means test
output in one of the SILGen tests has changed.
2016-08-28 13:51:37 -07:00
Slava Pestov
1c1ab0b83a AST: Introduce new GenericEnvironment class
A GenericEnvironment stores the mapping between GenericTypeParamTypes
and context archetypes (or eventually, concrete types, once we allow
extensions to constrain a generic parameter to a concrete type).

The goals here are two-fold:

- Eliminate the GenericTypeParamDecl::getArchetype() method, and
  always use mapTypeIntoContext() instead

- Replace SILFunction::ContextGenericParams with a GenericEnvironment

This patch adds the new data type as well as serializer and AST
verifier support. but nothing else uses it yet.

Note that GenericSignature::get() now asserts if there are no
generic parameters, instead of returning null. This requires a
few tweaks here and there.
2016-08-28 13:51:36 -07:00
Slava Pestov
8d9ad273ba Serialization: Remove mechanism for serializing references to in-memory Decl's AllArchetypes
I don't see any tests failing with this code removed; I guess
either the duplicate archetype issue no longer occurs, or does
not matter since we use interface types almost everywhere
when talking about Decls from other modules.
2016-08-22 10:45:53 -07:00
Doug Gregor
eb3ba78d94 Remove the swift3_migration attribute.
This attribute was a (my) bad idea that we ended up not using. Kill it.
2016-08-19 14:04:06 -07:00
John McCall
afdda3d107 Implement SE-0117.
One minor revision: this lifts the proposed restriction against
overriding a non-open method with an open one.  On reflection,
that was inconsistent with the existing rule permitting non-public
methods to be overridden with public ones.  The restriction on
subclassing a non-open class with an open class remains, and is
in fact consistent with the existing access rule.
2016-08-02 07:46:38 -07:00