@@ -4440,6 +4440,34 @@ void SILGenFunction::emitProtocolWitness(
4440
4440
SmallVector<ManagedValue, 8 > origParams;
4441
4441
collectThunkParams (loc, origParams);
4442
4442
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
+
4443
4471
// Get the type of the witness.
4444
4472
auto witnessInfo = getConstantInfo (getTypeExpansionContext (), witness);
4445
4473
CanAnyFunctionType witnessSubstTy = witnessInfo.LoweredType ;
@@ -4481,25 +4509,6 @@ void SILGenFunction::emitProtocolWitness(
4481
4509
witnessUnsubstTy->getSelfParameter ());
4482
4510
}
4483
4511
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
-
4503
4512
// For static C++ methods and constructors, we need to drop the (metatype)
4504
4513
// "self" param. The "native" SIL representation will look like this:
4505
4514
// @convention(method) (@thin Foo.Type) -> () but the "actual" SIL function
0 commit comments