Skip to content

Commit a28cba3

Browse files
authored
[Distributed] Bring back Derived id synthesis, as some cases still use it (#64452)
1 parent de56acc commit a28cba3

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

lib/Sema/DerivedConformanceDistributedActor.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,30 @@ static FuncDecl *deriveDistributedActorSystem_invokeHandlerOnReturn(
424424
/******************************* PROPERTIES ***********************************/
425425
/******************************************************************************/
426426

427-
// NOTE: There is no deriveDistributedActor_aid since it must be handled earlier
428-
// due to the Identifiable Conformance it must fulfil as well.
429-
// TODO(distributed): try to bring back `id` synthesis from addImplicitDistributedActorIDProperty to Derived infra
427+
static ValueDecl *deriveDistributedActor_id(DerivedConformance &derived) {
428+
assert(derived.Nominal->isDistributedActor());
429+
auto &C = derived.Context;
430+
431+
// ```
432+
// nonisolated let id: Self.ID // Self.ActorSystem.ActorID
433+
// ```
434+
auto propertyType = getDistributedActorIDType(derived.Nominal);
435+
436+
VarDecl *propDecl;
437+
PatternBindingDecl *pbDecl;
438+
std::tie(propDecl, pbDecl) = derived.declareDerivedProperty(
439+
DerivedConformance::SynthesizedIntroducer::Let, C.Id_id, propertyType,
440+
propertyType,
441+
/*isStatic=*/false, /*isFinal=*/true);
442+
443+
// mark as nonisolated, allowing access to it from everywhere
444+
propDecl->getAttrs().add(
445+
new (C) NonisolatedAttr(/*IsImplicit=*/true));
446+
447+
derived.addMemberToConformanceContext(pbDecl, /*insertAtHead=*/true);
448+
derived.addMemberToConformanceContext(propDecl, /*insertAtHead=*/true);
449+
return propDecl;
450+
}
430451

431452
static ValueDecl *deriveDistributedActor_actorSystem(
432453
DerivedConformance &derived) {
@@ -761,7 +782,9 @@ static void assertRequiredSynthesizedPropertyOrder(DerivedConformance &derived,
761782
ValueDecl *DerivedConformance::deriveDistributedActor(ValueDecl *requirement) {
762783
if (auto var = dyn_cast<VarDecl>(requirement)) {
763784
ValueDecl *derivedValue = nullptr;
764-
if (var->getName() == Context.Id_actorSystem) {
785+
if (var->getName() == Context.Id_id) {
786+
derivedValue = deriveDistributedActor_id(*this);
787+
} else if (var->getName() == Context.Id_actorSystem) {
765788
derivedValue = deriveDistributedActor_actorSystem(*this);
766789
} else if (var->getName() == Context.Id_unownedExecutor) {
767790
derivedValue = deriveDistributedActor_unownedExecutor(*this);

0 commit comments

Comments
 (0)