@@ -4139,11 +4139,21 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4139
4139
DynamicSelfType *capturesDynamicSelf = nullptr ;
4140
4140
OpaqueValueExpr *capturesOpaqueValue = nullptr ;
4141
4141
4142
- std::function<void (CaptureInfo captureInfo, DeclContext *dc )> collectCaptures;
4142
+ std::function<void (CaptureInfo captureInfo)> collectCaptures;
4143
4143
std::function<void (AnyFunctionRef)> collectFunctionCaptures;
4144
4144
std::function<void (SILDeclRef)> collectConstantCaptures;
4145
4145
4146
- collectCaptures = [&](CaptureInfo captureInfo, DeclContext *dc) {
4146
+ auto recordCapture = [&](CapturedValue capture) {
4147
+ ValueDecl *value = capture.getDecl ();
4148
+ auto existing = captures.find (value);
4149
+ if (existing != captures.end ()) {
4150
+ existing->second = existing->second .mergeFlags (capture);
4151
+ } else {
4152
+ captures.insert (std::pair<ValueDecl *, CapturedValue>(value, capture));
4153
+ }
4154
+ };
4155
+
4156
+ collectCaptures = [&](CaptureInfo captureInfo) {
4147
4157
assert (captureInfo.hasBeenComputed ());
4148
4158
4149
4159
if (captureInfo.hasGenericParamCaptures ())
@@ -4288,13 +4298,7 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4288
4298
}
4289
4299
4290
4300
// Collect non-function captures.
4291
- ValueDecl *value = capture.getDecl ();
4292
- auto existing = captures.find (value);
4293
- if (existing != captures.end ()) {
4294
- existing->second = existing->second .mergeFlags (capture);
4295
- } else {
4296
- captures.insert (std::pair<ValueDecl *, CapturedValue>(value, capture));
4297
- }
4301
+ recordCapture (capture);
4298
4302
}
4299
4303
};
4300
4304
@@ -4306,8 +4310,7 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4306
4310
return ;
4307
4311
4308
4312
PrettyStackTraceAnyFunctionRef (" lowering local captures" , curFn);
4309
- auto dc = curFn.getAsDeclContext ();
4310
- collectCaptures (curFn.getCaptureInfo (), dc);
4313
+ collectCaptures (curFn.getCaptureInfo ());
4311
4314
4312
4315
// A function's captures also include its default arguments, because
4313
4316
// when we reference a function we don't track which default arguments
@@ -4318,7 +4321,7 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4318
4321
if (auto *AFD = curFn.getAbstractFunctionDecl ()) {
4319
4322
for (auto *P : *AFD->getParameters ()) {
4320
4323
if (P->hasDefaultExpr ())
4321
- collectCaptures (P->getDefaultArgumentCaptureInfo (), dc );
4324
+ collectCaptures (P->getDefaultArgumentCaptureInfo ());
4322
4325
}
4323
4326
}
4324
4327
};
@@ -4331,10 +4334,8 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
4331
4334
if (auto *afd = dyn_cast<AbstractFunctionDecl>(curFn.getDecl ())) {
4332
4335
auto *param = getParameterAt (static_cast <ValueDecl *>(afd),
4333
4336
curFn.defaultArgIndex );
4334
- if (param->hasDefaultExpr ()) {
4335
- auto dc = afd->getInnermostDeclContext ();
4336
- collectCaptures (param->getDefaultArgumentCaptureInfo (), dc);
4337
- }
4337
+ if (param->hasDefaultExpr ())
4338
+ collectCaptures (param->getDefaultArgumentCaptureInfo ());
4338
4339
return ;
4339
4340
}
4340
4341
0 commit comments