@@ -426,32 +426,6 @@ static FuncDecl *deriveDistributedActorSystem_invokeHandlerOnReturn(
426426/* ****************************** PROPERTIES ***********************************/
427427/* *****************************************************************************/
428428
429- // TODO(distributed): make use of this after all, but FORCE it?
430- static ValueDecl *deriveDistributedActor_id (DerivedConformance &derived) {
431- assert (derived.Nominal ->isDistributedActor ());
432- auto &C = derived.Context ;
433-
434- // ```
435- // nonisolated
436- // let id: Self.ID // Self.ActorSystem.ActorID
437- // ```
438- auto propertyType = getDistributedActorIDType (derived.Nominal );
439-
440- VarDecl *propDecl;
441- PatternBindingDecl *pbDecl;
442- std::tie (propDecl, pbDecl) = derived.declareDerivedProperty (
443- DerivedConformance::SynthesizedIntroducer::Let, C.Id_id , propertyType,
444- propertyType,
445- /* isStatic=*/ false , /* isFinal=*/ true );
446-
447- // mark as nonisolated, allowing access to it from everywhere
448- propDecl->getAttrs ().add (
449- new (C) NonisolatedAttr (/* IsImplicit=*/ true ));
450-
451- derived.addMembersToConformanceContext ({ propDecl, pbDecl });
452- return propDecl;
453- }
454-
455429static ValueDecl *deriveDistributedActor_actorSystem (
456430 DerivedConformance &derived) {
457431 auto &C = derived.Context ;
@@ -460,8 +434,7 @@ static ValueDecl *deriveDistributedActor_actorSystem(
460434 assert (classDecl && derived.Nominal ->isDistributedActor ());
461435
462436 // ```
463- // nonisolated
464- // let actorSystem: ActorSystem
437+ // nonisolated let actorSystem: ActorSystem
465438 // ```
466439 // (no need for @actorIndependent because it is an immutable let)
467440 auto propertyType = getDistributedActorSystemType (classDecl);
@@ -477,7 +450,14 @@ static ValueDecl *deriveDistributedActor_actorSystem(
477450 propDecl->getAttrs ().add (
478451 new (C) NonisolatedAttr (/* IsImplicit=*/ true ));
479452
480- derived.addMembersToConformanceContext ({ propDecl, pbDecl });
453+ // IMPORTANT: `id` MUST be the first field of a distributed actor, and
454+ // `actorSystem` MUST be the second field, because for a remote instance
455+ // we don't allocate memory after those two fields, so their order is very
456+ // important. The `hint` below makes sure the system is inserted right after.
457+ auto id = derived.Nominal ->getDistributedActorIDProperty ();
458+ derived.addMemberToConformanceContext (pbDecl, /* hint=*/ id);
459+ derived.addMemberToConformanceContext (propDecl, /* hint=*/ id);
460+
481461 return propDecl;
482462}
483463
@@ -571,11 +551,14 @@ deriveDistributedActorType_SerializationRequirement(
571551
572552ValueDecl *DerivedConformance::deriveDistributedActor (ValueDecl *requirement) {
573553 if (auto var = dyn_cast<VarDecl>(requirement)) {
574- if (var->getName () == Context.Id_id )
575- return deriveDistributedActor_id (*this );
576-
577554 if (var->getName () == Context.Id_actorSystem )
578555 return deriveDistributedActor_actorSystem (*this );
556+
557+ if (var->getName () == Context.Id_id )
558+ llvm_unreachable (" DistributedActor.id MUST be synthesized earlier, "
559+ " because it is forced by the Identifiable conformance. "
560+ " If we attempted to do synthesis here, the earlier phase "
561+ " failed and something is wrong: please report a bug." );
579562 }
580563
581564 if (auto func = dyn_cast<FuncDecl>(requirement)) {
0 commit comments