17
17
#include " swift/Basic/LLVM.h"
18
18
#include " swift/Basic/OptionSet.h"
19
19
#include " swift/Basic/SourceLoc.h"
20
+ #include " swift/AST/Type.h"
20
21
#include " swift/AST/TypeAlignments.h"
21
22
#include " llvm/ADT/ArrayRef.h"
22
23
#include " llvm/ADT/PointerIntPair.h"
@@ -129,6 +130,18 @@ class CapturedValue {
129
130
unsigned getFlags () const { return Value.getInt (); }
130
131
};
131
132
133
+ // / Describes a type that has been captured by a closure or local function.
134
+ class CapturedType {
135
+ Type type;
136
+ SourceLoc loc;
137
+
138
+ public:
139
+ CapturedType (Type type, SourceLoc loc) : type(type), loc(loc) { }
140
+
141
+ Type getType () const { return type; }
142
+ SourceLoc getLoc () const { return loc; }
143
+ };
144
+
132
145
} // end swift namespace
133
146
134
147
namespace swift {
@@ -140,26 +153,32 @@ class CaptureInfo {
140
153
class CaptureInfoStorage final
141
154
: public llvm::TrailingObjects<CaptureInfoStorage,
142
155
CapturedValue,
143
- GenericEnvironment *> {
156
+ GenericEnvironment *,
157
+ CapturedType> {
144
158
145
159
DynamicSelfType *DynamicSelf;
146
160
OpaqueValueExpr *OpaqueValue;
147
161
unsigned NumCapturedValues;
148
162
unsigned NumGenericEnvironments;
163
+ unsigned NumCapturedTypes;
149
164
150
165
public:
151
166
explicit CaptureInfoStorage (DynamicSelfType *dynamicSelf,
152
167
OpaqueValueExpr *opaqueValue,
153
168
unsigned numCapturedValues,
154
- unsigned numGenericEnvironments)
169
+ unsigned numGenericEnvironments,
170
+ unsigned numCapturedTypes)
155
171
: DynamicSelf(dynamicSelf), OpaqueValue(opaqueValue),
156
172
NumCapturedValues(numCapturedValues),
157
- NumGenericEnvironments(numGenericEnvironments) { }
173
+ NumGenericEnvironments(numGenericEnvironments),
174
+ NumCapturedTypes(numCapturedTypes) { }
158
175
159
176
ArrayRef<CapturedValue> getCaptures () const ;
160
177
161
178
ArrayRef<GenericEnvironment *> getGenericEnvironments () const ;
162
179
180
+ ArrayRef<CapturedType> getCapturedTypes () const ;
181
+
163
182
DynamicSelfType *getDynamicSelfType () const {
164
183
return DynamicSelf;
165
184
}
@@ -171,6 +190,14 @@ class CaptureInfo {
171
190
unsigned numTrailingObjects (OverloadToken<CapturedValue>) const {
172
191
return NumCapturedValues;
173
192
}
193
+
194
+ unsigned numTrailingObjects (OverloadToken<GenericEnvironment *>) const {
195
+ return NumGenericEnvironments;
196
+ }
197
+
198
+ unsigned numTrailingObjects (OverloadToken<CapturedType>) const {
199
+ return NumCapturedTypes;
200
+ }
174
201
};
175
202
176
203
enum class Flags : unsigned {
@@ -187,7 +214,8 @@ class CaptureInfo {
187
214
ArrayRef<CapturedValue> captures,
188
215
DynamicSelfType *dynamicSelf, OpaqueValueExpr *opaqueValue,
189
216
bool genericParamCaptures,
190
- ArrayRef<GenericEnvironment *> genericEnv=ArrayRef<GenericEnvironment*>());
217
+ ArrayRef<GenericEnvironment *> genericEnv=ArrayRef<GenericEnvironment*>(),
218
+ ArrayRef<CapturedType> capturedTypes = ArrayRef<CapturedType>());
191
219
192
220
// / A CaptureInfo representing no captures at all.
193
221
static CaptureInfo empty ();
@@ -196,11 +224,7 @@ class CaptureInfo {
196
224
return StorageAndFlags.getPointer ();
197
225
}
198
226
199
- bool isTrivial () const {
200
- assert (hasBeenComputed ());
201
- return getCaptures ().empty () && !hasGenericParamCaptures () &&
202
- !hasDynamicSelfCapture () && !hasOpaqueValueCapture ();
203
- }
227
+ bool isTrivial () const ;
204
228
205
229
// / Returns all captured values and opaque expressions.
206
230
ArrayRef<CapturedValue> getCaptures () const {
@@ -214,6 +238,12 @@ class CaptureInfo {
214
238
return StorageAndFlags.getPointer ()->getGenericEnvironments ();
215
239
}
216
240
241
+ // / Returns all captured values and opaque expressions.
242
+ ArrayRef<CapturedType> getCapturedTypes () const {
243
+ assert (hasBeenComputed ());
244
+ return StorageAndFlags.getPointer ()->getCapturedTypes ();
245
+ }
246
+
217
247
// / \returns true if the function captures the primary generic environment
218
248
// / from its innermost declaration context.
219
249
bool hasGenericParamCaptures () const {
0 commit comments