Skip to content

Commit e01bcc4

Browse files
committed
[Distributed] SILGen must consistently use prop get requests
1 parent 1b5c3d7 commit e01bcc4

File tree

4 files changed

+43
-49
lines changed

4 files changed

+43
-49
lines changed

include/swift/AST/DistributedDecl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class DeclContext;
3131
class FuncDecl;
3232
class NominalTypeDecl;
3333

34-
/// Obtain a distributed actor's well-known property by name.
35-
VarDecl* lookupDistributedActorProperty(NominalTypeDecl *decl, DeclName name);
36-
3734
/// Determine the concrete type of 'ActorSystem' as seen from the member.
3835
/// E.g. when in a protocol, and trying to determine what the actor system was
3936
/// constrained to.

lib/AST/DistributedDecl.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,45 +61,6 @@
6161

6262
using namespace swift;
6363

64-
/******************************************************************************/
65-
/********************** Distributed Actor Properties **************************/
66-
/******************************************************************************/
67-
68-
VarDecl* swift::lookupDistributedActorProperty(NominalTypeDecl *decl, DeclName name) {
69-
assert(decl && "decl was null");
70-
auto &C = decl->getASTContext();
71-
72-
auto clazz = dyn_cast<ClassDecl>(decl);
73-
if (!clazz)
74-
return nullptr;
75-
76-
auto refs = decl->lookupDirect(name);
77-
if (refs.size() != 1)
78-
return nullptr;
79-
80-
auto var = dyn_cast<VarDecl>(refs.front());
81-
if (!var)
82-
return nullptr;
83-
84-
Type expectedType = Type();
85-
if (name == C.Id_id) {
86-
expectedType = getDistributedActorIDType(decl);
87-
} else if (name == C.Id_actorSystem) {
88-
expectedType = getDistributedActorSystemType(decl);
89-
} else {
90-
llvm_unreachable("Unexpected distributed actor property lookup!");
91-
}
92-
if (!expectedType)
93-
return nullptr;
94-
95-
if (!var->getInterfaceType()->isEqual(expectedType))
96-
return nullptr;
97-
98-
assert(var->isSynthesized() && "Expected compiler synthesized property");
99-
return var;
100-
}
101-
102-
10364
/******************************************************************************/
10465
/************** Distributed Actor System Associated Types *********************/
10566
/******************************************************************************/

lib/SILGen/SILGenDistributed.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void emitActorSystemInit(SILGenFunction &SGF,
171171
// By construction, automatically generated distributed actor ctors have
172172
// exactly one ActorSystem-conforming argument to the constructor,
173173
// so we grab the first one from the params.
174-
VarDecl *var = lookupDistributedActorProperty(classDecl, C.Id_actorSystem);
174+
VarDecl *var = classDecl->getDistributedActorSystemProperty();
175175
assert(var);
176176

177177
initializeProperty(SGF, loc, actorSelf.getValue(), var, systemValue);
@@ -204,7 +204,7 @@ void SILGenFunction::emitDistActorIdentityInit(ConstructorDecl *ctor,
204204

205205
// --- create a temporary storage for the result of the call
206206
// it will be deallocated automatically as we exit this scope
207-
VarDecl *var = lookupDistributedActorProperty(classDecl, C.Id_id);
207+
VarDecl *var = classDecl->getDistributedActorIDProperty();
208208
auto resultTy = getLoweredType(F.mapTypeIntoContext(var->getInterfaceType()));
209209
auto temp = emitTemporaryAllocation(loc, resultTy);
210210

@@ -317,7 +317,7 @@ void SILGenFunction::emitDistributedActorReady(
317317
ManagedValue actorSystem;
318318
SGFContext sgfCxt;
319319
{
320-
VarDecl *property = lookupDistributedActorProperty(classDecl, C.Id_actorSystem);
320+
VarDecl *property = classDecl->getDistributedActorSystemProperty();
321321
Type formalType = F.mapTypeIntoContext(property->getInterfaceType());
322322
SILType loweredType = getLoweredType(formalType).getAddressType();
323323
SILValue actorSystemRef = emitActorPropertyReference(
@@ -451,11 +451,11 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) { // TODO(distrib
451451
auto classDecl = dc->getSelfClassDecl();
452452

453453
initializeProperty(*this, loc, remote,
454-
lookupDistributedActorProperty(classDecl, C.Id_id),
454+
classDecl->getDistributedActorIDProperty(),
455455
idArg);
456456

457457
initializeProperty(*this, loc, remote,
458-
lookupDistributedActorProperty(classDecl, C.Id_actorSystem),
458+
classDecl->getDistributedActorSystemProperty(),
459459
actorSystemArg);
460460

461461
// ==== Branch to return the fully initialized remote instance
@@ -498,12 +498,12 @@ void SILGenFunction::emitDistributedActorSystemResignIDCall(
498498

499499
// ==== locate: self.id
500500
auto idRef = emitActorPropertyReference(
501-
*this, loc, actorSelf.getValue(), lookupDistributedActorProperty(actorDecl, ctx.Id_id));
501+
*this, loc, actorSelf.getValue(), actorDecl->getDistributedActorIDProperty());
502502

503503
// ==== locate: self.actorSystem
504504
auto systemRef = emitActorPropertyReference(
505505
*this, loc, actorSelf.getValue(),
506-
lookupDistributedActorProperty(actorDecl, ctx.Id_actorSystem));
506+
actorDecl->getDistributedActorSystemProperty());
507507

508508
// Perform the call.
509509
emitDistributedActorSystemWitnessCall(

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,42 @@ using namespace swift;
3838
/************************ PROPERTY SYNTHESIS **********************************/
3939
/******************************************************************************/
4040

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+
4177
// Note: This would be nice to implement in DerivedConformanceDistributedActor,
4278
// but we can't since those are lazily triggered and an implementation exists
4379
// for the 'id' property because 'Identifiable.id' has an extension that impls

0 commit comments

Comments
 (0)