23
23
#include " swift/AST/GenericSignature.h"
24
24
#include " swift/Basic/Compiler.h"
25
25
#include " swift/Basic/Debug.h"
26
+ #include " swift/Basic/UUID.h"
26
27
#include " llvm/ADT/ArrayRef.h"
27
28
#include " llvm/Support/ErrorHandling.h"
28
29
#include " llvm/Support/TrailingObjects.h"
@@ -50,6 +51,12 @@ class QueryInterfaceTypeSubstitutions {
50
51
Type operator ()(SubstitutableType *type) const ;
51
52
};
52
53
54
+ // / Extra data in a generic environment for an opened existentiak.
55
+ struct OpenedGenericEnvironmentData {
56
+ Type existential;
57
+ UUID uuid;
58
+ };
59
+
53
60
// / Describes the mapping between archetypes and interface types for the
54
61
// / generic parameters of a DeclContext.
55
62
// /
@@ -60,7 +67,8 @@ class QueryInterfaceTypeSubstitutions {
60
67
// /
61
68
class alignas (1 << DeclAlignInBits) GenericEnvironment final
62
69
: private llvm::TrailingObjects<
63
- GenericEnvironment, OpaqueTypeDecl *, SubstitutionMap, Type> {
70
+ GenericEnvironment, OpaqueTypeDecl *, SubstitutionMap,
71
+ OpenedGenericEnvironmentData, Type> {
64
72
public:
65
73
enum class Kind {
66
74
// / A normal generic environment, determined only by its generic
@@ -72,16 +80,20 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
72
80
Opaque,
73
81
};
74
82
83
+ class NestedTypeStorage ;
84
+
75
85
private:
76
86
mutable llvm::PointerIntPair<GenericSignature, 2 , Kind> SignatureAndKind{
77
87
GenericSignature (), Kind::Normal};
88
+ NestedTypeStorage *nestedTypeStorage = nullptr ;
78
89
79
90
friend TrailingObjects;
80
91
friend OpaqueTypeArchetypeType;
81
92
82
93
size_t numTrailingObjects (OverloadToken<OpaqueTypeDecl *>) const ;
83
94
size_t numTrailingObjects (OverloadToken<SubstitutionMap>) const ;
84
95
size_t numTrailingObjects (OverloadToken<Type>) const ;
96
+ size_t numTrailingObjects (OverloadToken<OpenedGenericEnvironmentData>) const ;
85
97
86
98
// / Retrieve the array containing the context types associated with the
87
99
// / generic parameters, stored in parallel with the generic parameters of the
@@ -93,7 +105,12 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
93
105
// / generic signature.
94
106
ArrayRef<Type> getContextTypes () const ;
95
107
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);
97
114
explicit GenericEnvironment (
98
115
GenericSignature signature, OpaqueTypeDecl *opaque, SubstitutionMap subs);
99
116
@@ -102,6 +119,10 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
102
119
103
120
Type getOrCreateArchetypeFromInterfaceType (Type depType);
104
121
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
+
105
126
// / Retrieve the mapping for the given generic parameter, if present.
106
127
// /
107
128
// / This is only useful when lazily populating a generic environment.
@@ -116,6 +137,12 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
116
137
117
138
TypeArrayView<GenericTypeParamType> getGenericParams () const ;
118
139
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
+
119
146
// / Retrieve the opaque type declaration for a generic environment describing
120
147
// / opaque types.
121
148
OpaqueTypeDecl *getOpaqueTypeDecl () const ;
@@ -130,18 +157,13 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
130
157
GenericEnvironment *getIncomplete (GenericSignature signature);
131
158
132
159
// / 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);
135
161
136
162
// / Create a new generic environment for an opaque type with the given set of
137
163
// / outer substitutions.
138
164
static GenericEnvironment *forOpaqueType (
139
165
OpaqueTypeDecl *opaque, SubstitutionMap subs, AllocationArena arena);
140
166
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
-
145
167
// / Make vanilla new/delete illegal.
146
168
void *operator new (size_t Bytes) = delete ;
147
169
void operator delete (void *Data) = delete ;
0 commit comments