[Distributed] Force the order of properties in AST

This commit is contained in:
Konrad `ktoso` Malawski
2022-05-08 17:40:51 +09:00
parent 361947275e
commit 1e489d6c0b
7 changed files with 106 additions and 99 deletions

View File

@@ -117,9 +117,17 @@ static VarDecl *addImplicitDistributedActorIDProperty(
propDecl->getAttrs().add(
new (C) CompilerInitializedAttr(/*IsImplicit=*/true));
nominal->addMember(propDecl);
nominal->addMember(pbDecl);
// IMPORTANT: The `id` MUST be the first field of any distributed actor,
// because when we allocate remote proxy instances, we don't allocate memory
// for anything except the first two fields: id and actorSystem, so they
// MUST be those fields.
//
// Their specific order also matters, because it is enforced this way in IRGen
// and how we emit them in AST MUST match what IRGen expects or cross-module
// things could be using wrong offsets and manifest as reading trash memory on
// id or system accesses.
nominal->addMember(propDecl, /*hint=*/nullptr, /*insertAtHead=*/true);
nominal->addMember(pbDecl, /*hint=*/nullptr, /*insertAtHead=*/true);
return propDecl;
}