Commit Graph

179 Commits

Author SHA1 Message Date
Holly Borla
6d65c11b4a [GenericEnvironment] Model opened pack element signatures as a complete clone
of the outer context signature, with an additional set of element type parameters
at depth + 1.
2022-11-23 11:16:27 -05:00
Holly Borla
d09ea98ba6 [GenericEnvironment] Add helper methods to map pack interface types to
element archetypes, and element interface types to pack archetypes.
2022-10-26 00:04:56 -07:00
Holly Borla
cf38d55e3a [AST] Plumb reduced shape types through local requirements into pack archetypes. 2022-10-23 11:42:46 -07:00
Slava Pestov
68514b10b5 AST: Introduce ElementArchetypeType 2022-10-21 21:55:35 -04:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
9bb837a241 [AST] Rename SequenceArchetype to PackArchetype. 2022-10-10 16:25:26 -07:00
Slava Pestov
b36f37cc72 Serialization: Preserve identity of opened generic environments
We used to create a new environment for each opened archetype, which is
incorrect when deserializing a nested type of another opened archetype.
2022-08-15 13:59:12 -04:00
Slava Pestov
7a970367fd AST: Rename GenericEnvironment::Kind::Normal to ::Primary, ::getIncomplete() to ::forPrimary() 2022-08-15 13:59:12 -04:00
Slava Pestov
87eb2cac31 AST: Don't strip bound dependent member types when forming keys in a generic environment 2022-08-15 13:59:12 -04:00
John McCall
5519749ade [NFC] Collect protocol decls, not type, in ExistentialLayout
Another thing that will be necessary for correctness with
compositions of parameterized protocols.
2022-04-11 22:15:16 -04:00
Doug Gregor
bd6f27bd55 Stop mapping opened archetypes "out of context".
These opened archetypes need to be bound within their context, so any mapping out of
the context will need to be explicit and map to newly-created generic parameters.
2022-03-11 09:27:48 -08:00
Anthony Latsis
b3ee4b0718 AST, Sema: Use the opened archetype's generic signature to determine existential member availability 2022-02-02 02:09:59 +03:00
Anthony Latsis
756bf30eeb GenericEnvironment: Don't use the existential layout's protocols to build "nested" opened archetypes 2022-02-01 23:00:55 +03:00
Doug Gregor
2bf7f36542 Don't build opaque archetypes referencing the outer environment.
When there are same-type constraints involving opaque archetype
parameters and generic parameters of the enclosing environment, a
nested type of an opaque type archetype might in fact refer to
something in the outer environment of the opaque type. Recognize this
case and perform substitutions on such types using the opaque type's
substitutions.
2022-01-19 16:26:28 -08:00
Doug Gregor
452eccab83 Remove NestedArchetypeType.
Nested archetypes are represented by their base archetype kinds (primary,
opened, or opaque type) with an interface type that is a nested type,
as represented by a DependentMemberType. This provides a more uniform
representation of archetypes throughout the frontend.
2022-01-14 21:28:21 -08:00
Doug Gregor
96fdbe18ea Check root archetypes in a few more places.
This makes more code agnostic to the presence of NestedArchetypeType.
2022-01-14 21:28:02 -08:00
Doug Gregor
34506bf316 Rework OpenedArchetypeType to generalize over interface types.
Form opened archetype types based on an interface type and existential
type, rather than assuming all OpenedArchetypeType instances only
represent the root. Sink the UUID, existential type, and actual creation
of the opened archetype into the opened generic environment, so we
consistently only create new archetype instances from the generic
environment. This slims down OpenedArchetypeType and makes it work
similarly to the other archetype kinds, as well as generalizing it
to support nested types.
Sink the existential type and UUID of an
2022-01-14 21:27:14 -08:00
Doug Gregor
ac4d26d711 Generalize (Primary|Sequence)ArchetypeType to arbitrary interface types.
As another step toward eliminating NestedArchetypeType, generalize the
representation, construction, and serialization of primary and sequence
archetypes to interface types, rather than generic parameter types.
2022-01-14 21:26:28 -08:00
Doug Gregor
590331d59f Moving nested archetype storage into the generic environment.
Instead of storing nested archetypes hierarchically in `ArchetypeType`,
store them in a map (indexed by dependent member type) on the generic
environment itself. With this, we no longer need to create archetypes
for every type along the path, because archetypes are findable via
generic environment + interface type.
2022-01-14 21:25:31 -08:00
Doug Gregor
2974f548be Reimplement ArchetypeType::getParent() in terms of interface type + environment
Rather that requiring parent archetypes to be stored at the time of
construction, map the base of the interface type through the
generic environment.
2022-01-14 21:25:31 -08:00
Doug Gregor
c8b71819d4 Always store a generic environment in a nested archetype. 2022-01-14 21:25:31 -08:00
Doug Gregor
bd0fa0bd0f Eliminate the notion of a "bound signature" for opaque type archetypes.
The refactoring that moved the substitution of the outer environment
into an opaque type archeptype into the generic environment eliminated
the need for the bound signature entirely, so remove it.
2022-01-06 10:06:12 -08:00
Doug Gregor
9dcb5a58aa Properly substitute outer generic parameters in an opaque type environment.
When forming the generic signature of a generic environment for opaque
types, substitute for the outer generic parameters based on the provided
substitution map. We weren't able to do this before because the
substitution cannot be performed when there are interface types or
type variables involved. However, the lazy construction of this
generic signature and use of other queries on opaque type archetypes
ensures that we don't form new generic signatures until we have
concrete types to work with.

This enables same-type constraints amongst different opaque result types
and their associated types.
2022-01-05 18:23:08 -08:00
Doug Gregor
2dd49a8565 Rework the relationship between generic environments and opaque archetypes.
Teach `GenericEnvironment` how to lazily create opaque type archetypes,
performing the contextual substitutions as required but without
building the "bound" generic signature until required. To get here,
augment `GenericEnvironment` with knowledge of the purpose of the
environment, whether it is for normal cases (any signature), an opened
existential type, or an opaque type. For opaque types, store the
opaque type declaration and substitution map, which we also use to
uniquely find the generic environment. Among other things, this
ensures that different opaque type archetypes within the same opaque
type declaration are properly sharing a generic environment, which
wasn't happening before.
2022-01-05 17:15:40 -08:00
Anthony Latsis
c55f54dbe0 GenericEnvironment: Allow 'mapTypeIntoContext' to accept types containing opened archetypes 2021-11-19 16:44:07 +03:00
Robert Widmann
e7e11df927 Model Sequence Archetypes 2021-11-16 11:38:57 -08:00
Slava Pestov
215fbf1d97 AST: GenericEnvironment::getOrCreateArchetypeFromInterfaceType() needs to handle case where parent of concrete anchor is concrete
This still doesn't handle the case where a non-concrete anchor has a
concrete parent; that requires switching the archetype representation
to be "flat".

Fixes <rdar://problem/84734584>.
2021-10-28 20:01:17 -04:00
Anthony Latsis
1cf9622f32 GenericEnvironment: Replace 'substDependentTypesWithErrorTypes' with an assertion 2021-10-25 05:11:34 +03:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07:00
Slava Pestov
c2a275ef0f AST: Factor out GenericSignature::getLocalRequirements() method
This encapsulates GenericEnvironment's usage of the GSB.
2021-07-17 00:05:05 -04:00
Slava Pestov
5570ed5f58 AST: Clean up recursion guards in GenericEnvironment
Instead of using the recursiveConcreteType and recursiveSuperclass bits in
EquivalenceClass, store an ErrorType to the cached value before we begin
archetype construction. If a recursive call attempts to get the archetype
for the same type re-entrantly, we will return an ErrorType.
2021-07-16 18:15:23 -04:00
Slava Pestov
7f5eea46a4 AST: Refactor GenericEnvironment::getOrCreateArchetypeFromInterfaceType() to take a Type 2021-07-16 18:15:23 -04:00
Slava Pestov
940ca1ea81 AST: Refactor GSB::EquivalenceClass::getTypeInContext() into GenericEnvironment::getOrCreateArchetypeFromInterfaceType() 2021-07-16 18:15:23 -04:00
Slava Pestov
a96682c34e AST: Move EquivalenceClass::getTypeInContext() to GenericEnvironment.cpp 2021-07-16 18:15:23 -04:00
Slava Pestov
9d07ff73dc AST: Move ArchetypeType::resolveNestedType() to GenericEnvironment.cpp 2021-07-16 18:15:23 -04:00
Slava Pestov
a65effed60 AST: Lazy construct GenericSignatureBuilder in a GenericEnvironment 2021-07-16 18:15:23 -04:00
Saleem Abdulrasool
d783b6add0 Revert "Begin untangling GenericEnvironment from GenericSignatureBuilder" 2021-07-15 16:05:05 -07:00
Slava Pestov
e43ead6141 AST: Clean up recursion guards in GenericEnvironment
Instead of using the recursiveConcreteType and recursiveSuperclass bits in
EquivalenceClass, store an ErrorType to the cached value before we begin
archetype construction. If a recursive call attempts to get the archetype
for the same type re-entrantly, we will return an ErrorType.
2021-07-14 18:25:24 -04:00
Slava Pestov
01a87bfdcb AST: Refactor GenericEnvironment::getOrCreateArchetypeFromInterfaceType() to take a Type 2021-07-14 17:18:16 -04:00
Slava Pestov
48fc69d52a AST: Refactor GSB::EquivalenceClass::getTypeInContext() into GenericEnvironment::getOrCreateArchetypeFromInterfaceType() 2021-07-14 17:18:16 -04:00
Slava Pestov
2f17416846 AST: Move EquivalenceClass::getTypeInContext() to GenericEnvironment.cpp 2021-07-14 17:18:16 -04:00
Slava Pestov
97c57b3972 AST: Move ArchetypeType::resolveNestedType() to GenericEnvironment.cpp 2021-07-14 17:18:16 -04:00
Slava Pestov
323e52e66a AST: Lazy construct GenericSignatureBuilder in a GenericEnvironment 2021-07-14 17:18:15 -04:00
Slava Pestov
b0208a134f AST: Move getSugaredType() from GenericEnvironment to GenericSignature
None of this actually involves archetypes, so it can just be an
operation on the GenericSignature itself.
2020-08-24 19:16:36 -04:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Slava Pestov
e9bcd00bc2 AST: Remove GenericEnvironment::OwningDC 2019-09-06 17:16:03 -04:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Joe Groff
6b2b4a01cb Followup fixes for stored opaque-type properties.
- TypedPatterns expect to have a contextual type in generic contexts.
- mapTypeOutOfContext failed for NestedArchetypes under opaque archetypes.
2019-07-10 21:24:21 -07:00
Joe Groff
a419754fe9 Support nested types on opaque archetypes (and maybe opened ones). 2019-04-17 14:43:32 -07:00
Joe Groff
0cfca9496a Give opened archetypes a generic environment.
And maybe allow nested types to live on them.
2019-02-20 12:52:48 -08:00