diff --git a/lib/SILGen/SILGenProlog.cpp b/lib/SILGen/SILGenProlog.cpp index 3a5e75a963598..bf04fe3b9960d 100644 --- a/lib/SILGen/SILGenProlog.cpp +++ b/lib/SILGen/SILGenProlog.cpp @@ -843,6 +843,15 @@ SILValue SILGenFunction::emitLoadActorExecutor(SILLocation loc, else actorV = actor.borrow(*this, loc).getValue(); + // Open an existential actor type. + CanType actorType = actor.getType().getASTType(); + if (actorType->isExistentialType()) { + actorType = OpenedArchetypeType::get( + actorType, F.getGenericSignature())->getCanonicalType(); + SILType loweredActorType = getLoweredType(actorType); + actorV = B.createOpenExistentialRef(loc, actorV, loweredActorType); + } + // For now, we just want to emit a hop_to_executor directly to the // actor; LowerHopToActor will add the emission logic necessary later. return actorV; diff --git a/test/SILGen/isolated_parameters.swift b/test/SILGen/isolated_parameters.swift index dc63c2ae2c85c..7f15092f6bae6 100644 --- a/test/SILGen/isolated_parameters.swift +++ b/test/SILGen/isolated_parameters.swift @@ -24,3 +24,14 @@ public func takeClosureWithIsolatedParam(body: (isolated A) async -> Void) { } public func testClosureWithIsolatedParam() { takeClosureWithIsolatedParam { _ in } } + +// CHECK-LABEL: sil{{.*}} [ossa] @$s4test0A19IsolatedExistentialyyScA_pYiYaF +// CHECK: bb0([[ACTOR:%.*]] : @guaranteed $any Actor) +@available(SwiftStdlib 5.1, *) +public func testIsolatedExistential(_ a: isolated Actor) async { + // CHECK: [[ACTOR_COPY:%.*]] = copy_value [[ACTOR]] : $any Actor + // CHECK: [[ACTOR_BORROW:%.*]] = begin_borrow [[ACTOR_COPY]] : $any Actor + // CHECK: [[ACTOR_OPENED:%.*]] = open_existential_ref [[ACTOR_BORROW]] : $any Actor to $@opened("{{.*}}", any Actor) Self + // CHECK: hop_to_executor [[ACTOR_OPENED]] : $@opened("{{.*}}", any Actor) Self + // CHECK: return +}