33
33
34
34
using namespace swift ;
35
35
36
-
37
36
/* *****************************************************************************/
38
37
/* *********************** PROPERTY SYNTHESIS **********************************/
39
38
/* *****************************************************************************/
40
39
41
- static VarDecl*
42
- lookupDistributedActorProperty (NominalTypeDecl *decl, DeclName name) {
43
- assert (decl && " decl was null" );
44
- auto &C = decl->getASTContext ();
45
-
46
- auto clazz = dyn_cast<ClassDecl>(decl);
47
- if (!clazz)
48
- return nullptr ;
49
-
50
- auto refs = decl->lookupDirect (name);
51
- if (refs.size () != 1 )
52
- return nullptr ;
53
-
54
- auto var = dyn_cast<VarDecl>(refs.front ());
55
- if (!var)
56
- return nullptr ;
57
-
58
- Type expectedType = Type ();
59
- if (name == C.Id_id ) {
60
- expectedType = getDistributedActorIDType (decl);
61
- } else if (name == C.Id_actorSystem ) {
62
- expectedType = getDistributedActorSystemType (decl);
63
- } else {
64
- llvm_unreachable (" Unexpected distributed actor property lookup!" );
65
- }
66
- if (!expectedType)
67
- return nullptr ;
68
-
69
- if (!var->getInterfaceType ()->isEqual (expectedType))
70
- return nullptr ;
71
-
72
- assert (var->isSynthesized () && " Expected compiler synthesized property" );
73
- return var;
74
- }
75
-
76
-
77
40
// Note: This would be nice to implement in DerivedConformanceDistributedActor,
78
41
// but we can't since those are lazily triggered and an implementation exists
79
42
// for the 'id' property because 'Identifiable.id' has an extension that impls
@@ -142,7 +105,7 @@ static VarDecl *addImplicitDistributedActorActorSystemProperty(
142
105
143
106
auto &C = nominal->getASTContext ();
144
107
145
- // ==== Synthesize and add 'id ' property to the actor decl
108
+ // ==== Synthesize and add 'actorSystem ' property to the actor decl
146
109
Type propertyType = getDistributedActorSystemType (nominal);
147
110
148
111
auto *propDecl = new (C)
@@ -166,19 +129,22 @@ static VarDecl *addImplicitDistributedActorActorSystemProperty(
166
129
// mark as nonisolated, allowing access to it from everywhere
167
130
propDecl->getAttrs ().add (
168
131
new (C) NonisolatedAttr (/* IsImplicit=*/ true ));
169
- // mark as @_compilerInitialized, since we synthesize the initializing
170
- // assignment during SILGen.
171
- propDecl->getAttrs ().add (
172
- new (C) CompilerInitializedAttr (/* IsImplicit=*/ true ));
173
132
174
133
auto idProperty = nominal->getDistributedActorIDProperty ();
134
+ // If the id was not yet synthesized, we need to ensure that eventually
135
+ // the order of fields will be: id, actorSystem (because IRGen needs the
136
+ // layouts to match with the AST we produce). We do this by inserting FIRST,
137
+ // and then as the ID gets synthesized, it'll also force FIRST and therefore
138
+ // the order will be okey -- ID and then system.
139
+ auto insertAtHead = idProperty == nullptr ;
140
+
175
141
// IMPORTANT: The `id` MUST be the first field of any distributed actor.
176
142
// So we find the property and add the system AFTER it using the hint.
177
143
//
178
144
// If the `id` was not synthesized yet, we'll end up inserting at head,
179
145
// but the id synthesis will force itself to be FIRST anyway, so it works out.
180
- nominal->addMember (propDecl, /* hint=*/ idProperty);
181
- nominal->addMember (pbDecl, /* hint=*/ idProperty);
146
+ nominal->addMember (propDecl, /* hint=*/ idProperty, /* insertAtHead= */ insertAtHead );
147
+ nominal->addMember (pbDecl, /* hint=*/ idProperty, /* insertAtHead= */ insertAtHead );
182
148
return propDecl;
183
149
}
184
150
0 commit comments