Skip to content

Commit 3d06300

Browse files
committed
[Distributed] remove duped lookupProp func, we have it in swift::
1 parent 3319bc0 commit 3d06300

File tree

2 files changed

+12
-45
lines changed

2 files changed

+12
-45
lines changed

lib/AST/DistributedDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ using namespace swift;
6565
/********************** Distributed Actor Properties **************************/
6666
/******************************************************************************/
6767

68-
VarDecl* swift::lookupDistributedActorProperty(NominalTypeDecl *decl, DeclName name) {
68+
VarDecl*
69+
swift::lookupDistributedActorProperty(NominalTypeDecl *decl, DeclName name) {
6970
assert(decl && "decl was null");
7071
auto &C = decl->getASTContext();
7172

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,47 +33,10 @@
3333

3434
using namespace swift;
3535

36-
3736
/******************************************************************************/
3837
/************************ PROPERTY SYNTHESIS **********************************/
3938
/******************************************************************************/
4039

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-
7740
// Note: This would be nice to implement in DerivedConformanceDistributedActor,
7841
// but we can't since those are lazily triggered and an implementation exists
7942
// for the 'id' property because 'Identifiable.id' has an extension that impls
@@ -142,7 +105,7 @@ static VarDecl *addImplicitDistributedActorActorSystemProperty(
142105

143106
auto &C = nominal->getASTContext();
144107

145-
// ==== Synthesize and add 'id' property to the actor decl
108+
// ==== Synthesize and add 'actorSystem' property to the actor decl
146109
Type propertyType = getDistributedActorSystemType(nominal);
147110

148111
auto *propDecl = new (C)
@@ -166,19 +129,22 @@ static VarDecl *addImplicitDistributedActorActorSystemProperty(
166129
// mark as nonisolated, allowing access to it from everywhere
167130
propDecl->getAttrs().add(
168131
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));
173132

174133
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+
175141
// IMPORTANT: The `id` MUST be the first field of any distributed actor.
176142
// So we find the property and add the system AFTER it using the hint.
177143
//
178144
// If the `id` was not synthesized yet, we'll end up inserting at head,
179145
// 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);
182148
return propDecl;
183149
}
184150

0 commit comments

Comments
 (0)