@@ -4434,41 +4434,45 @@ void SILGenFunction::emitProtocolWitness(
44344434 FullExpr scope (Cleanups, cleanupLoc);
44354435 FormalEvaluationScope formalEvalScope (*this );
44364436
4437- auto witnessKind = getWitnessDispatchKind (witness, isSelfConformance);
44384437 auto thunkTy = F.getLoweredFunctionType ();
44394438
44404439 SmallVector<ManagedValue, 8 > origParams;
44414440 collectThunkParams (loc, origParams);
44424441
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- }
4442+ // If the witness is isolated to a distributed actor, but the requirement is
4443+ // not, go through the distributed thunk.
4444+ if (witness.hasDecl () &&
4445+ getActorIsolation (witness.getDecl ()).isDistributedActor () &&
4446+ requirement.hasDecl () &&
4447+ !getActorIsolation (requirement.getDecl ()).isDistributedActor ()) {
4448+ witness = SILDeclRef (
4449+ cast<AbstractFunctionDecl>(witness.getDecl ())->getDistributedThunk ())
4450+ .asDistributed ();
4451+ } else if (enterIsolation) {
4452+ // If we are supposed to enter the actor, do so now by hopping to the
4453+ // actor.
4454+ Optional<ManagedValue> actorSelf;
4455+
4456+ // For an instance actor, get the actor 'self'.
4457+ if (*enterIsolation == ActorIsolation::ActorInstance) {
4458+ auto actorSelfVal = origParams.back ();
4459+
4460+ if (actorSelfVal.getType ().isAddress ()) {
4461+ auto &actorSelfTL = getTypeLowering (actorSelfVal.getType ());
4462+ if (!actorSelfTL.isAddressOnly ()) {
4463+ actorSelfVal = emitManagedLoad (
4464+ *this , loc, actorSelfVal, actorSelfTL);
44624465 }
4463-
4464- actorSelf = actorSelfVal;
44654466 }
44664467
4467- emitHopToTargetActor (loc, enterIsolation, actorSelf) ;
4468+ actorSelf = actorSelfVal ;
44684469 }
4470+
4471+ emitHopToTargetActor (loc, enterIsolation, actorSelf);
44694472 }
44704473
44714474 // Get the type of the witness.
4475+ auto witnessKind = getWitnessDispatchKind (witness, isSelfConformance);
44724476 auto witnessInfo = getConstantInfo (getTypeExpansionContext (), witness);
44734477 CanAnyFunctionType witnessSubstTy = witnessInfo.LoweredType ;
44744478 if (auto genericFnType = dyn_cast<GenericFunctionType>(witnessSubstTy)) {
0 commit comments