File tree Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -2288,9 +2288,7 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
2288
2288
continue ;
2289
2289
2290
2290
// We can always capture the storage in these cases.
2291
- Type captureType = capturedVar->getType ();
2292
- if (auto *metatypeType = captureType->getAs <MetatypeType>())
2293
- captureType = metatypeType->getInstanceType ();
2291
+ Type captureType = capturedVar->getType ()->getMetatypeInstanceType ();
2294
2292
2295
2293
if (auto *selfType = captureType->getAs <DynamicSelfType>()) {
2296
2294
captureType = selfType->getSelfType ();
@@ -2302,11 +2300,22 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
2302
2300
// mutable, we're going to be capturing a box or an address.
2303
2301
if (captureType->getClassOrBoundGenericClass () &&
2304
2302
capturedVar->isLet ()) {
2305
- if (selfCapture)
2303
+ // If we've already captured the same value already, just merge
2304
+ // flags.
2305
+ if (selfCapture && selfCapture->getDecl () == capture.getDecl ()) {
2306
2306
selfCapture = selfCapture->mergeFlags (capture);
2307
- else
2307
+ continue ;
2308
+
2309
+ // Otherwise, record the canonical self capture. It will appear
2310
+ // at the end of the capture list.
2311
+ } else if (!selfCapture) {
2308
2312
selfCapture = capture;
2309
- continue ;
2313
+ continue ;
2314
+ }
2315
+
2316
+ // If we end up here, we have multiple different captured values
2317
+ // with a dynamic 'Self' type. Handle this and any subsequent
2318
+ // captures via the normal code path below.
2310
2319
}
2311
2320
}
2312
2321
Original file line number Diff line number Diff line change @@ -442,6 +442,25 @@ public class FunctionConversionTest : EmptyProtocol {
442
442
}
443
443
}
444
444
445
+ public class CaptureTwoValuesTest {
446
+ public required init ( ) { }
447
+
448
+ // CHECK-LABEL: sil [ossa] @$s12dynamic_self20CaptureTwoValuesTestC08capturesdE0yyFZ : $@convention(method) (@thick CaptureTwoValuesTest.Type) -> () {
449
+ public static func capturesTwoValues( ) {
450
+ let a = Self ( )
451
+ let b = Self ( )
452
+
453
+ // CHECK: function_ref @$s12dynamic_self20CaptureTwoValuesTestC08capturesdE0yyFZyycfU_ : $@convention(thin) (@guaranteed CaptureTwoValuesTest, @guaranteed CaptureTwoValuesTest) -> ()
454
+ _ = {
455
+ _ = a
456
+ _ = b
457
+ _ = Self . self
458
+ }
459
+
460
+ // CHECK-LABEL: sil private [ossa] @$s12dynamic_self20CaptureTwoValuesTestC08capturesdE0yyFZyycfU_ : $@convention(thin) (@guaranteed CaptureTwoValuesTest, @guaranteed CaptureTwoValuesTest) -> () {
461
+ }
462
+ }
463
+
445
464
// CHECK-LABEL: sil_witness_table hidden X: P module dynamic_self {
446
465
// CHECK: method #P.f!1: {{.*}} : @$s12dynamic_self1XCAA1PA2aDP1f{{[_0-9a-zA-Z]*}}FTW
447
466
You can’t perform that action at this time.
0 commit comments