2323#include " swift/AST/GenericSignature.h"
2424#include " swift/Basic/Compiler.h"
2525#include " swift/Basic/Debug.h"
26+ #include " swift/Basic/UUID.h"
2627#include " llvm/ADT/ArrayRef.h"
2728#include " llvm/Support/ErrorHandling.h"
2829#include " llvm/Support/TrailingObjects.h"
@@ -50,6 +51,12 @@ class QueryInterfaceTypeSubstitutions {
5051 Type operator ()(SubstitutableType *type) const ;
5152};
5253
54+ // / Extra data in a generic environment for an opened existentiak.
55+ struct OpenedGenericEnvironmentData {
56+ Type existential;
57+ UUID uuid;
58+ };
59+
5360// / Describes the mapping between archetypes and interface types for the
5461// / generic parameters of a DeclContext.
5562// /
@@ -60,7 +67,8 @@ class QueryInterfaceTypeSubstitutions {
6067// /
6168class alignas (1 << DeclAlignInBits) GenericEnvironment final
6269 : private llvm::TrailingObjects<
63- GenericEnvironment, OpaqueTypeDecl *, SubstitutionMap, Type> {
70+ GenericEnvironment, OpaqueTypeDecl *, SubstitutionMap,
71+ OpenedGenericEnvironmentData, Type> {
6472public:
6573 enum class Kind {
6674 // / A normal generic environment, determined only by its generic
@@ -72,16 +80,20 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
7280 Opaque,
7381 };
7482
83+ class NestedTypeStorage ;
84+
7585private:
7686 mutable llvm::PointerIntPair<GenericSignature, 2 , Kind> SignatureAndKind{
7787 GenericSignature (), Kind::Normal};
88+ NestedTypeStorage *nestedTypeStorage = nullptr ;
7889
7990 friend TrailingObjects;
8091 friend OpaqueTypeArchetypeType;
8192
8293 size_t numTrailingObjects (OverloadToken<OpaqueTypeDecl *>) const ;
8394 size_t numTrailingObjects (OverloadToken<SubstitutionMap>) const ;
8495 size_t numTrailingObjects (OverloadToken<Type>) const ;
96+ size_t numTrailingObjects (OverloadToken<OpenedGenericEnvironmentData>) const ;
8597
8698 // / Retrieve the array containing the context types associated with the
8799 // / generic parameters, stored in parallel with the generic parameters of the
@@ -93,7 +105,12 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
93105 // / generic signature.
94106 ArrayRef<Type> getContextTypes () const ;
95107
96- explicit GenericEnvironment (GenericSignature signature, Kind kind);
108+ // / Get the nested type storage, allocating it if required.
109+ NestedTypeStorage &getOrCreateNestedTypeStorage ();
110+
111+ explicit GenericEnvironment (GenericSignature signature);
112+ explicit GenericEnvironment (
113+ GenericSignature signature, Type existential, UUID uuid);
97114 explicit GenericEnvironment (
98115 GenericSignature signature, OpaqueTypeDecl *opaque, SubstitutionMap subs);
99116
@@ -102,6 +119,10 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
102119
103120 Type getOrCreateArchetypeFromInterfaceType (Type depType);
104121
122+ // / Add a mapping of a generic parameter to a specific type (which may be
123+ // / an archetype)
124+ void addMapping (GenericParamKey key, Type contextType);
125+
105126 // / Retrieve the mapping for the given generic parameter, if present.
106127 // /
107128 // / This is only useful when lazily populating a generic environment.
@@ -116,6 +137,12 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
116137
117138 TypeArrayView<GenericTypeParamType> getGenericParams () const ;
118139
140+ // / Retrieve the existential type for an opened existential environment.
141+ Type getOpenedExistentialType () const ;
142+
143+ // / Retrieve the UUID for an opened existential environment.
144+ UUID getOpenedExistentialUUID () const ;
145+
119146 // / Retrieve the opaque type declaration for a generic environment describing
120147 // / opaque types.
121148 OpaqueTypeDecl *getOpaqueTypeDecl () const ;
@@ -130,18 +157,13 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
130157 GenericEnvironment *getIncomplete (GenericSignature signature);
131158
132159 // / Create a new generic environment for an opened existential.
133- static GenericEnvironment *forOpenedExistential (
134- GenericSignature signature, const OpenedArchetypeType *type);
160+ static GenericEnvironment *forOpenedExistential (Type existential, UUID uuid);
135161
136162 // / Create a new generic environment for an opaque type with the given set of
137163 // / outer substitutions.
138164 static GenericEnvironment *forOpaqueType (
139165 OpaqueTypeDecl *opaque, SubstitutionMap subs, AllocationArena arena);
140166
141- // / Add a mapping of a generic parameter to a specific type (which may be
142- // / an archetype)
143- void addMapping (GenericParamKey key, Type contextType);
144-
145167 // / Make vanilla new/delete illegal.
146168 void *operator new (size_t Bytes) = delete ;
147169 void operator delete (void *Data) = delete ;
0 commit comments