@@ -4440,6 +4440,34 @@ void SILGenFunction::emitProtocolWitness(
44404440 SmallVector<ManagedValue, 8 > origParams;
44414441 collectThunkParams (loc, origParams);
44424442
4443+ // If we are supposed to enter the actor, do so now.
4444+ if (enterIsolation) {
4445+ if (enterIsolation->isDistributedActor ()) {
4446+ // For a distributed actor, call through the distributed thunk.
4447+ witness = witness.asDistributed ();
4448+ } else {
4449+ // For a non-distributed actor, hop to the actor.
4450+ Optional<ManagedValue> actorSelf;
4451+
4452+ // For an instance actor, get the actor 'self'.
4453+ if (*enterIsolation == ActorIsolation::ActorInstance) {
4454+ auto actorSelfVal = origParams.back ();
4455+
4456+ if (actorSelfVal.getType ().isAddress ()) {
4457+ auto &actorSelfTL = getTypeLowering (actorSelfVal.getType ());
4458+ if (!actorSelfTL.isAddressOnly ()) {
4459+ actorSelfVal = emitManagedLoad (
4460+ *this , loc, actorSelfVal, actorSelfTL);
4461+ }
4462+ }
4463+
4464+ actorSelf = actorSelfVal;
4465+ }
4466+
4467+ emitHopToTargetActor (loc, enterIsolation, actorSelf);
4468+ }
4469+ }
4470+
44434471 // Get the type of the witness.
44444472 auto witnessInfo = getConstantInfo (getTypeExpansionContext (), witness);
44454473 CanAnyFunctionType witnessSubstTy = witnessInfo.LoweredType ;
@@ -4481,25 +4509,6 @@ void SILGenFunction::emitProtocolWitness(
44814509 witnessUnsubstTy->getSelfParameter ());
44824510 }
44834511
4484- // If we are supposed to hop to the actor, do so now.
4485- if (enterIsolation) {
4486- Optional<ManagedValue> actorSelf;
4487- if (*enterIsolation == ActorIsolation::ActorInstance) {
4488- auto actorSelfVal = origParams.back ();
4489-
4490- if (actorSelfVal.getType ().isAddress ()) {
4491- auto &actorSelfTL = getTypeLowering (actorSelfVal.getType ());
4492- if (!actorSelfTL.isAddressOnly ()) {
4493- actorSelfVal = emitManagedLoad (*this , loc, actorSelfVal, actorSelfTL);
4494- }
4495- }
4496-
4497- actorSelf = actorSelfVal;
4498- }
4499-
4500- emitHopToTargetActor (loc, enterIsolation, actorSelf);
4501- }
4502-
45034512 // For static C++ methods and constructors, we need to drop the (metatype)
45044513 // "self" param. The "native" SIL representation will look like this:
45054514 // @convention(method) (@thin Foo.Type) -> () but the "actual" SIL function
0 commit comments