Skip to content

Commit 6dc1d0a

Browse files
committed
DistributedActors: Fix upcoming request cycle
1 parent 9671ab3 commit 6dc1d0a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/Sema/DerivedConformance/DerivedConformanceDistributedActor.cpp

Lines changed: 18 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,29 @@ 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+
if (!assocType)
560+
return Type();
561+
562+
// This is called from inside associated type inference itself, so if we
563+
// haven't populate the type witness yet, it won't be found by name
564+
// lookup, and calling getTypeWitness() will trigger a request cycle.
565+
if (!derived.Conformance->hasTypeWitness(assocType))
566+
return Type();
567+
568+
return derived.Conformance->getTypeWitness(assocType);
569+
}
570+
555571
static Type
556572
deriveDistributedActorType_ID(
557573
DerivedConformance &derived) {
558574
if (!derived.Nominal->isDistributedActor())
559575
return nullptr;
560576

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

564580
// There is no known actor system type, so fail to synthesize.
565581
if (!systemTy || systemTy->hasError())
@@ -579,7 +595,7 @@ deriveDistributedActorType_SerializationRequirement(
579595
return nullptr;
580596

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

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

0 commit comments

Comments
 (0)