Skip to content

Commit e91be76

Browse files
committed
DistributedActors: Fix upcoming request cycle
1 parent 694aebb commit e91be76

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/Sema/DerivedConformance/DerivedConformanceDistributedActor.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/ExistentialLayout.h"
2525
#include "swift/AST/NameLookupRequests.h"
2626
#include "swift/AST/ParameterList.h"
27+
#include "swift/AST/ProtocolConformance.h"
2728
#include "swift/Basic/Assertions.h"
2829
#include "swift/Strings.h"
2930

@@ -552,14 +553,27 @@ deriveDistributedActorType_ActorSystem(
552553
return defaultDistributedActorSystemTypeDecl->getDeclaredInterfaceType();
553554
}
554555

556+
static Type getDistributedActorSystem(DerivedConformance &derived) {
557+
auto *assocType = derived.Protocol->getAssociatedType(
558+
derived.Context.Id_ActorSystem);
559+
560+
// This is called from inside associated type inference itself, so if we
561+
// haven't populate the type witness yet, it won't be found by name
562+
// lookup, and calling getTypeWitness() will trigger a request cycle.
563+
if (!derived.Conformance->hasTypeWitness(assocType))
564+
return Type();
565+
566+
return derived.Conformance->getTypeWitness(assocType);
567+
}
568+
555569
static Type
556570
deriveDistributedActorType_ID(
557571
DerivedConformance &derived) {
558572
if (!derived.Nominal->isDistributedActor())
559573
return nullptr;
560574

561575
// Look for a type DefaultDistributedActorSystem within the parent context.
562-
auto systemTy = getDistributedActorSystemType(derived.Nominal);
576+
auto systemTy = getDistributedActorSystem(derived);
563577

564578
// There is no known actor system type, so fail to synthesize.
565579
if (!systemTy || systemTy->hasError())
@@ -579,7 +593,7 @@ deriveDistributedActorType_SerializationRequirement(
579593
return nullptr;
580594

581595
// Look for a type DefaultDistributedActorSystem within the parent context.
582-
auto systemTy = getDistributedActorSystemType(derived.Nominal);
596+
auto systemTy = getDistributedActorSystem(derived);
583597

584598
// There is no known actor system type, so fail to synthesize.
585599
if (!systemTy || systemTy->hasError())

0 commit comments

Comments
 (0)