Skip to content

Commit 2dfbceb

Browse files
authored
Merge pull request #73071 from rjmccall/map-fully-specialized-isolation
Map the isolated variable type into context correctly
2 parents 412fb93 + e7765ad commit 2dfbceb

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

lib/SILGen/SILGenConcurrency.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,7 @@ static ManagedValue emitLoadOfCaptureIsolation(SILGenFunction &SGF,
463463
auto &TC = SGF.SGM.Types;
464464
auto captureInfo = TC.getLoweredLocalCaptures(constant);
465465

466-
auto isolatedVarType = SGF.F.mapTypeIntoContext(
467-
isolatedCapture->getInterfaceType())->getCanonicalType();
466+
auto isolatedVarType = isolatedCapture->getTypeInContext()->getCanonicalType();
468467

469468
// Capture arguments are 1-1 with the lowered capture info.
470469
auto captures = captureInfo.getCaptures();

test/SILGen/isolated_any.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,52 @@ extension MyActor {
451451
}
452452
}
453453

454+
/*-- Generic actors --*/
455+
456+
actor GenericActor<T> {
457+
func asyncAction() async {}
458+
}
459+
460+
// CHECK-LABEL: sil hidden [ossa] @$s4test12GenericActorC0a5ErasebC0yyF
461+
// CHECK: // function_ref closure #1
462+
// CHECK-NEXT: [[CLOSURE_FN:%.*]] = function_ref @$s4test12GenericActorC0a5ErasebC0yyFyyYaYbcfU_ : $@convention(thin) @Sendable @async <τ_0_0> (@guaranteed Optional<any Actor>, @sil_isolated @guaranteed GenericActor<τ_0_0>) -> ()
463+
// CHECK-NEXT: [[CAPTURE:%.*]] = copy_value %0 : $GenericActor<T>
464+
// CHECK-NEXT: [[CAPTURE_FOR_ISOLATION:%.*]] = copy_value [[CAPTURE]] : $GenericActor<T>
465+
// CHECK-NEXT: [[ISOLATION_OBJECT:%.*]] = init_existential_ref [[CAPTURE_FOR_ISOLATION]] : $GenericActor<T> : $GenericActor<T>, $any Actor
466+
// CHECK-NEXT: [[ISOLATION:%.*]] = enum $Optional<any Actor>, #Optional.some!enumelt, [[ISOLATION_OBJECT]] : $any Actor
467+
// CHECK-NEXT: [[CLOSURE:%.*]] = partial_apply [callee_guaranteed] [isolated_any] [[CLOSURE_FN]]<T>([[ISOLATION]], [[CAPTURE]])
468+
// CHECK-NEXT: // function_ref
469+
// CHECK-NEXT: [[TAKE_FN:%.*]] = function_ref @$s4test30takeInheritingAsyncIsolatedAny2fnyyyYaYbYAc_tF
470+
// CHECK-NEXT: apply [[TAKE_FN]]([[CLOSURE]])
471+
// CHECK-NEXT: destroy_value [[CLOSURE]]
472+
extension GenericActor {
473+
func testEraseGenericActor() {
474+
takeInheritingAsyncIsolatedAny {
475+
await self.asyncAction()
476+
}
477+
}
478+
}
479+
480+
// CHECK-LABEL: sil hidden [ossa] @$s4test12GenericActorCAASiRszlE0a16EraseSpecializedbC0yyF
481+
// CHECK: // function_ref closure #1
482+
// CHECK-NEXT: [[CLOSURE_FN:%.*]] = function_ref @$s4test12GenericActorCAASiRszlE0a16EraseSpecializedbC0yyFyyYaYbcfU_ : $@convention(thin) @Sendable @async (@guaranteed Optional<any Actor>, @sil_isolated @guaranteed GenericActor<Int>) -> ()
483+
// CHECK-NEXT: [[CAPTURE:%.*]] = copy_value %0 : $GenericActor<Int>
484+
// CHECK-NEXT: [[CAPTURE_FOR_ISOLATION:%.*]] = copy_value [[CAPTURE]] : $GenericActor<Int>
485+
// CHECK-NEXT: [[ISOLATION_OBJECT:%.*]] = init_existential_ref [[CAPTURE_FOR_ISOLATION]] : $GenericActor<Int> : $GenericActor<Int>, $any Actor
486+
// CHECK-NEXT: [[ISOLATION:%.*]] = enum $Optional<any Actor>, #Optional.some!enumelt, [[ISOLATION_OBJECT]] : $any Actor
487+
// CHECK-NEXT: [[CLOSURE:%.*]] = partial_apply [callee_guaranteed] [isolated_any] [[CLOSURE_FN]]([[ISOLATION]], [[CAPTURE]])
488+
// CHECK-NEXT: // function_ref
489+
// CHECK-NEXT: [[TAKE_FN:%.*]] = function_ref @$s4test30takeInheritingAsyncIsolatedAny2fnyyyYaYbYAc_tF
490+
// CHECK-NEXT: apply [[TAKE_FN]]([[CLOSURE]])
491+
// CHECK-NEXT: destroy_value [[CLOSURE]]
492+
extension GenericActor where T == Int {
493+
func testEraseSpecializedGenericActor() {
494+
takeInheritingAsyncIsolatedAny {
495+
await self.asyncAction()
496+
}
497+
}
498+
}
499+
454500
/*-- Partial applications --*/
455501

456502
// FIXME: this is wrong; we need to capture the actor value

0 commit comments

Comments
 (0)