Skip to content

Commit 89e5559

Browse files
committed
Teach witness thunks to hop to the actor when needed.
When a synchronous, actor-isolated declaration witnesses an asynchronous, not-similarly-isolated requirement, emit an actor hop within the witness thunk to ensure that we properly enter the context of the actor. Fixes #58517 / rdar://92881539. (cherry picked from commit 25a7988)
1 parent a918648 commit 89e5559

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4505,6 +4505,25 @@ void SILGenFunction::emitProtocolWitness(
45054505
witnessUnsubstTy->getSelfParameter());
45064506
}
45074507

4508+
// If we are supposed to hop to the actor, do so now.
4509+
if (enterIsolation) {
4510+
Optional<ManagedValue> actorSelf;
4511+
if (*enterIsolation == ActorIsolation::ActorInstance) {
4512+
auto actorSelfVal = origParams.back();
4513+
4514+
if (actorSelfVal.getType().isAddress()) {
4515+
auto &actorSelfTL = getTypeLowering(actorSelfVal.getType());
4516+
if (!actorSelfTL.isAddressOnly()) {
4517+
actorSelfVal = emitManagedLoad(*this, loc, actorSelfVal, actorSelfTL);
4518+
}
4519+
}
4520+
4521+
actorSelf = actorSelfVal;
4522+
}
4523+
4524+
emitHopToTargetActor(loc, enterIsolation, actorSelf);
4525+
}
4526+
45084527
// For static C++ methods and constructors, we need to drop the (metatype)
45094528
// "self" param. The "native" SIL representation will look like this:
45104529
// @convention(method) (@thin Foo.Type) -> () but the "actual" SIL function

0 commit comments

Comments
 (0)