24
24
#include " swift/AST/NameLookup.h"
25
25
#include " swift/AST/ParameterList.h"
26
26
#include " swift/AST/Pattern.h"
27
+ #include " swift/AST/PrettyStackTrace.h"
27
28
#include " swift/AST/PropertyWrappers.h"
28
29
#include " swift/AST/Types.h"
29
30
#include " swift/ClangImporter/ClangModule.h"
31
+ #include " swift/SIL/PrettyStackTrace.h"
30
32
#include " swift/SIL/SILArgument.h"
31
33
#include " swift/SIL/SILBuilder.h"
32
34
#include " swift/SIL/SILModule.h"
@@ -2111,6 +2113,9 @@ TypeConverter::hasLoweredLocalCaptures(SILDeclRef fn) {
2111
2113
2112
2114
CaptureInfo
2113
2115
TypeConverter::getLoweredLocalCaptures (SILDeclRef fn) {
2116
+ PrettyStackTraceSILLocation stack (" getting lowered local captures" ,
2117
+ fn.getAsRegularLocation (), Context);
2118
+
2114
2119
fn.isForeign = 0 ;
2115
2120
fn.isCurried = 0 ;
2116
2121
fn.isDirectReference = 0 ;
@@ -2132,11 +2137,14 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
2132
2137
DynamicSelfType *capturesDynamicSelf = nullptr ;
2133
2138
OpaqueValueExpr *capturesOpaqueValue = nullptr ;
2134
2139
2135
- std::function<void (const CaptureInfo &captureInfo)> collectCaptures;
2140
+ std::function<void (const CaptureInfo &captureInfo, DeclContext *dc )> collectCaptures;
2136
2141
std::function<void (AnyFunctionRef)> collectFunctionCaptures;
2137
2142
std::function<void (SILDeclRef)> collectConstantCaptures;
2138
2143
2139
- collectCaptures = [&](const CaptureInfo &captureInfo) {
2144
+ collectCaptures = [&](const CaptureInfo &captureInfo, DeclContext *dc) {
2145
+ assert (captureInfo.hasBeenComputed () ||
2146
+ !TypeConverter::canCaptureFromParent (dc));
2147
+
2140
2148
if (captureInfo.hasGenericParamCaptures ())
2141
2149
capturesGenericParams = true ;
2142
2150
if (captureInfo.hasDynamicSelfCapture ())
@@ -2263,7 +2271,9 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
2263
2271
if (!visitedFunctions.insert (curFn).second )
2264
2272
return ;
2265
2273
2266
- collectCaptures (curFn.getCaptureInfo ());
2274
+ PrettyStackTraceAnyFunctionRef (" lowering local captures" , curFn);
2275
+ auto dc = curFn.getAsDeclContext ();
2276
+ collectCaptures (curFn.getCaptureInfo (), dc);
2267
2277
2268
2278
// A function's captures also include its default arguments, because
2269
2279
// when we reference a function we don't track which default arguments
@@ -2274,17 +2284,22 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
2274
2284
if (auto *AFD = curFn.getAbstractFunctionDecl ()) {
2275
2285
for (auto *P : *AFD->getParameters ()) {
2276
2286
if (P->getDefaultValue ())
2277
- collectCaptures (P->getDefaultArgumentCaptureInfo ());
2287
+ collectCaptures (P->getDefaultArgumentCaptureInfo (), dc );
2278
2288
}
2279
2289
}
2280
2290
};
2281
2291
2282
2292
collectConstantCaptures = [&](SILDeclRef curFn) {
2283
2293
if (curFn.isDefaultArgGenerator ()) {
2294
+ PrettyStackTraceSILLocation stack (" lowering local captures" ,
2295
+ fn.getAsRegularLocation (), Context);
2296
+
2284
2297
if (auto *afd = dyn_cast<AbstractFunctionDecl>(curFn.getDecl ())) {
2285
2298
auto *param = getParameterAt (afd, curFn.defaultArgIndex );
2286
- if (param->getDefaultValue ())
2287
- collectCaptures (param->getDefaultArgumentCaptureInfo ());
2299
+ if (param->getDefaultValue ()) {
2300
+ auto dc = afd->getInnermostDeclContext ();
2301
+ collectCaptures (param->getDefaultArgumentCaptureInfo (), dc);
2302
+ }
2288
2303
return ;
2289
2304
}
2290
2305
0 commit comments