diff --git a/lib/Sema/DerivedConformanceDistributedActor.cpp b/lib/Sema/DerivedConformanceDistributedActor.cpp index 66f489df9bf46..31f856e7ad061 100644 --- a/lib/Sema/DerivedConformanceDistributedActor.cpp +++ b/lib/Sema/DerivedConformanceDistributedActor.cpp @@ -424,9 +424,30 @@ static FuncDecl *deriveDistributedActorSystem_invokeHandlerOnReturn( /******************************* PROPERTIES ***********************************/ /******************************************************************************/ -// NOTE: There is no deriveDistributedActor_aid since it must be handled earlier -// due to the Identifiable Conformance it must fulfil as well. -// TODO(distributed): try to bring back `id` synthesis from addImplicitDistributedActorIDProperty to Derived infra +static ValueDecl *deriveDistributedActor_id(DerivedConformance &derived) { + assert(derived.Nominal->isDistributedActor()); + auto &C = derived.Context; + + // ``` + // nonisolated let id: Self.ID // Self.ActorSystem.ActorID + // ``` + auto propertyType = getDistributedActorIDType(derived.Nominal); + + VarDecl *propDecl; + PatternBindingDecl *pbDecl; + std::tie(propDecl, pbDecl) = derived.declareDerivedProperty( + DerivedConformance::SynthesizedIntroducer::Let, C.Id_id, propertyType, + propertyType, + /*isStatic=*/false, /*isFinal=*/true); + + // mark as nonisolated, allowing access to it from everywhere + propDecl->getAttrs().add( + new (C) NonisolatedAttr(/*IsImplicit=*/true)); + + derived.addMemberToConformanceContext(pbDecl, /*insertAtHead=*/true); + derived.addMemberToConformanceContext(propDecl, /*insertAtHead=*/true); + return propDecl; +} static ValueDecl *deriveDistributedActor_actorSystem( DerivedConformance &derived) { @@ -761,7 +782,9 @@ static void assertRequiredSynthesizedPropertyOrder(DerivedConformance &derived, ValueDecl *DerivedConformance::deriveDistributedActor(ValueDecl *requirement) { if (auto var = dyn_cast(requirement)) { ValueDecl *derivedValue = nullptr; - if (var->getName() == Context.Id_actorSystem) { + if (var->getName() == Context.Id_id) { + derivedValue = deriveDistributedActor_id(*this); + } else if (var->getName() == Context.Id_actorSystem) { derivedValue = deriveDistributedActor_actorSystem(*this); } else if (var->getName() == Context.Id_unownedExecutor) { derivedValue = deriveDistributedActor_unownedExecutor(*this);