@@ -426,32 +426,6 @@ static FuncDecl *deriveDistributedActorSystem_invokeHandlerOnReturn(
426
426
/* ****************************** PROPERTIES ***********************************/
427
427
/* *****************************************************************************/
428
428
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
-
455
429
static ValueDecl *deriveDistributedActor_actorSystem (
456
430
DerivedConformance &derived) {
457
431
auto &C = derived.Context ;
@@ -460,8 +434,7 @@ static ValueDecl *deriveDistributedActor_actorSystem(
460
434
assert (classDecl && derived.Nominal ->isDistributedActor ());
461
435
462
436
// ```
463
- // nonisolated
464
- // let actorSystem: ActorSystem
437
+ // nonisolated let actorSystem: ActorSystem
465
438
// ```
466
439
// (no need for @actorIndependent because it is an immutable let)
467
440
auto propertyType = getDistributedActorSystemType (classDecl);
@@ -477,7 +450,14 @@ static ValueDecl *deriveDistributedActor_actorSystem(
477
450
propDecl->getAttrs ().add (
478
451
new (C) NonisolatedAttr (/* IsImplicit=*/ true ));
479
452
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
+
481
461
return propDecl;
482
462
}
483
463
@@ -571,11 +551,14 @@ deriveDistributedActorType_SerializationRequirement(
571
551
572
552
ValueDecl *DerivedConformance::deriveDistributedActor (ValueDecl *requirement) {
573
553
if (auto var = dyn_cast<VarDecl>(requirement)) {
574
- if (var->getName () == Context.Id_id )
575
- return deriveDistributedActor_id (*this );
576
-
577
554
if (var->getName () == Context.Id_actorSystem )
578
555
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." );
579
562
}
580
563
581
564
if (auto func = dyn_cast<FuncDecl>(requirement)) {
0 commit comments