1717#include " swift/Basic/LLVM.h"
1818#include " swift/Basic/OptionSet.h"
1919#include " swift/Basic/SourceLoc.h"
20+ #include " swift/AST/Type.h"
2021#include " swift/AST/TypeAlignments.h"
2122#include " llvm/ADT/ArrayRef.h"
2223#include " llvm/ADT/PointerIntPair.h"
@@ -129,6 +130,18 @@ class CapturedValue {
129130 unsigned getFlags () const { return Value.getInt (); }
130131};
131132
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+
132145} // end swift namespace
133146
134147namespace swift {
@@ -140,26 +153,32 @@ class CaptureInfo {
140153 class CaptureInfoStorage final
141154 : public llvm::TrailingObjects<CaptureInfoStorage,
142155 CapturedValue,
143- GenericEnvironment *> {
156+ GenericEnvironment *,
157+ CapturedType> {
144158
145159 DynamicSelfType *DynamicSelf;
146160 OpaqueValueExpr *OpaqueValue;
147161 unsigned NumCapturedValues;
148162 unsigned NumGenericEnvironments;
163+ unsigned NumCapturedTypes;
149164
150165 public:
151166 explicit CaptureInfoStorage (DynamicSelfType *dynamicSelf,
152167 OpaqueValueExpr *opaqueValue,
153168 unsigned numCapturedValues,
154- unsigned numGenericEnvironments)
169+ unsigned numGenericEnvironments,
170+ unsigned numCapturedTypes)
155171 : DynamicSelf(dynamicSelf), OpaqueValue(opaqueValue),
156172 NumCapturedValues(numCapturedValues),
157- NumGenericEnvironments(numGenericEnvironments) { }
173+ NumGenericEnvironments(numGenericEnvironments),
174+ NumCapturedTypes(numCapturedTypes) { }
158175
159176 ArrayRef<CapturedValue> getCaptures () const ;
160177
161178 ArrayRef<GenericEnvironment *> getGenericEnvironments () const ;
162179
180+ ArrayRef<CapturedType> getCapturedTypes () const ;
181+
163182 DynamicSelfType *getDynamicSelfType () const {
164183 return DynamicSelf;
165184 }
@@ -171,6 +190,14 @@ class CaptureInfo {
171190 unsigned numTrailingObjects (OverloadToken<CapturedValue>) const {
172191 return NumCapturedValues;
173192 }
193+
194+ unsigned numTrailingObjects (OverloadToken<GenericEnvironment *>) const {
195+ return NumGenericEnvironments;
196+ }
197+
198+ unsigned numTrailingObjects (OverloadToken<CapturedType>) const {
199+ return NumCapturedTypes;
200+ }
174201 };
175202
176203 enum class Flags : unsigned {
@@ -187,7 +214,8 @@ class CaptureInfo {
187214 ArrayRef<CapturedValue> captures,
188215 DynamicSelfType *dynamicSelf, OpaqueValueExpr *opaqueValue,
189216 bool genericParamCaptures,
190- ArrayRef<GenericEnvironment *> genericEnv=ArrayRef<GenericEnvironment*>());
217+ ArrayRef<GenericEnvironment *> genericEnv=ArrayRef<GenericEnvironment*>(),
218+ ArrayRef<CapturedType> capturedTypes = ArrayRef<CapturedType>());
191219
192220 // / A CaptureInfo representing no captures at all.
193221 static CaptureInfo empty ();
@@ -196,11 +224,7 @@ class CaptureInfo {
196224 return StorageAndFlags.getPointer ();
197225 }
198226
199- bool isTrivial () const {
200- assert (hasBeenComputed ());
201- return getCaptures ().empty () && !hasGenericParamCaptures () &&
202- !hasDynamicSelfCapture () && !hasOpaqueValueCapture ();
203- }
227+ bool isTrivial () const ;
204228
205229 // / Returns all captured values and opaque expressions.
206230 ArrayRef<CapturedValue> getCaptures () const {
@@ -214,6 +238,12 @@ class CaptureInfo {
214238 return StorageAndFlags.getPointer ()->getGenericEnvironments ();
215239 }
216240
241+ // / Returns all captured values and opaque expressions.
242+ ArrayRef<CapturedType> getCapturedTypes () const {
243+ assert (hasBeenComputed ());
244+ return StorageAndFlags.getPointer ()->getCapturedTypes ();
245+ }
246+
217247 // / \returns true if the function captures the primary generic environment
218248 // / from its innermost declaration context.
219249 bool hasGenericParamCaptures () const {
0 commit comments