Skip to content

Commit 1e36088

Browse files
authored
Merge pull request #73074 from rjmccall/map-fully-specialized-isolation-6.0
[6.0] Map the isolated variable type into context correctly.
2 parents 055888f + baa6606 commit 1e36088

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
@@ -428,6 +428,52 @@ extension MyActor {
428428
}
429429
}
430430

431+
/*-- Generic actors --*/
432+
433+
actor GenericActor<T> {
434+
func asyncAction() async {}
435+
}
436+
437+
// CHECK-LABEL: sil hidden [ossa] @$s4test12GenericActorC0a5ErasebC0yyF
438+
// CHECK: // function_ref closure #1
439+
// CHECK-NEXT: [[CLOSURE_FN:%.*]] = function_ref @$s4test12GenericActorC0a5ErasebC0yyFyyYaYbcfU_ : $@convention(thin) @Sendable @async <τ_0_0> (@guaranteed Optional<any Actor>, @sil_isolated @guaranteed GenericActor<τ_0_0>) -> ()
440+
// CHECK-NEXT: [[CAPTURE:%.*]] = copy_value %0 : $GenericActor<T>
441+
// CHECK-NEXT: [[CAPTURE_FOR_ISOLATION:%.*]] = copy_value [[CAPTURE]] : $GenericActor<T>
442+
// CHECK-NEXT: [[ISOLATION_OBJECT:%.*]] = init_existential_ref [[CAPTURE_FOR_ISOLATION]] : $GenericActor<T> : $GenericActor<T>, $any Actor
443+
// CHECK-NEXT: [[ISOLATION:%.*]] = enum $Optional<any Actor>, #Optional.some!enumelt, [[ISOLATION_OBJECT]] : $any Actor
444+
// CHECK-NEXT: [[CLOSURE:%.*]] = partial_apply [callee_guaranteed] [isolated_any] [[CLOSURE_FN]]<T>([[ISOLATION]], [[CAPTURE]])
445+
// CHECK-NEXT: // function_ref
446+
// CHECK-NEXT: [[TAKE_FN:%.*]] = function_ref @$s4test30takeInheritingAsyncIsolatedAny2fnyyyYaYbYAc_tF
447+
// CHECK-NEXT: apply [[TAKE_FN]]([[CLOSURE]])
448+
// CHECK-NEXT: destroy_value [[CLOSURE]]
449+
extension GenericActor {
450+
func testEraseGenericActor() {
451+
takeInheritingAsyncIsolatedAny {
452+
await self.asyncAction()
453+
}
454+
}
455+
}
456+
457+
// CHECK-LABEL: sil hidden [ossa] @$s4test12GenericActorCAASiRszlE0a16EraseSpecializedbC0yyF
458+
// CHECK: // function_ref closure #1
459+
// CHECK-NEXT: [[CLOSURE_FN:%.*]] = function_ref @$s4test12GenericActorCAASiRszlE0a16EraseSpecializedbC0yyFyyYaYbcfU_ : $@convention(thin) @Sendable @async (@guaranteed Optional<any Actor>, @sil_isolated @guaranteed GenericActor<Int>) -> ()
460+
// CHECK-NEXT: [[CAPTURE:%.*]] = copy_value %0 : $GenericActor<Int>
461+
// CHECK-NEXT: [[CAPTURE_FOR_ISOLATION:%.*]] = copy_value [[CAPTURE]] : $GenericActor<Int>
462+
// CHECK-NEXT: [[ISOLATION_OBJECT:%.*]] = init_existential_ref [[CAPTURE_FOR_ISOLATION]] : $GenericActor<Int> : $GenericActor<Int>, $any Actor
463+
// CHECK-NEXT: [[ISOLATION:%.*]] = enum $Optional<any Actor>, #Optional.some!enumelt, [[ISOLATION_OBJECT]] : $any Actor
464+
// CHECK-NEXT: [[CLOSURE:%.*]] = partial_apply [callee_guaranteed] [isolated_any] [[CLOSURE_FN]]([[ISOLATION]], [[CAPTURE]])
465+
// CHECK-NEXT: // function_ref
466+
// CHECK-NEXT: [[TAKE_FN:%.*]] = function_ref @$s4test30takeInheritingAsyncIsolatedAny2fnyyyYaYbYAc_tF
467+
// CHECK-NEXT: apply [[TAKE_FN]]([[CLOSURE]])
468+
// CHECK-NEXT: destroy_value [[CLOSURE]]
469+
extension GenericActor where T == Int {
470+
func testEraseSpecializedGenericActor() {
471+
takeInheritingAsyncIsolatedAny {
472+
await self.asyncAction()
473+
}
474+
}
475+
}
476+
431477
/*-- Partial applications --*/
432478

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

0 commit comments

Comments
 (0)