Skip to content

Commit 730be21

Browse files
committed
[Distributed] SILGen must consistently use prop get requests
1 parent 279e07b commit 730be21

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

lib/SILGen/SILGenDistributed.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@ using namespace Lowering;
3838

3939
// MARK: utility functions
4040

41-
/// Obtain a nominal type's member by name, as a VarDecl.
42-
/// \returns nullptr if the name lookup doesn't resolve to exactly one member,
43-
/// or the subsequent cast to VarDecl failed.
44-
static VarDecl* lookupProperty(NominalTypeDecl *decl, DeclName name) {
45-
assert(decl && "decl was null");
46-
if (auto clazz = dyn_cast<ClassDecl>(decl)) {
47-
auto refs = decl->lookupDirect(name);
48-
if (refs.size() != 1)
49-
return nullptr;
50-
return dyn_cast<VarDecl>(refs.front());
51-
}
52-
53-
return nullptr;
54-
}
55-
5641
/// Emit a reference to a specific stored property of the actor.
5742
static SILValue emitActorPropertyReference(
5843
SILGenFunction &SGF, SILLocation loc, SILValue actorSelf,
@@ -186,7 +171,7 @@ static void emitActorSystemInit(SILGenFunction &SGF,
186171
// By construction, automatically generated distributed actor ctors have
187172
// exactly one ActorSystem-conforming argument to the constructor,
188173
// so we grab the first one from the params.
189-
VarDecl *var = lookupProperty(classDecl, C.Id_actorSystem);
174+
VarDecl *var = classDecl->getDistributedActorSystemProperty();
190175
assert(var);
191176

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

220205
// --- create a temporary storage for the result of the call
221206
// it will be deallocated automatically as we exit this scope
222-
VarDecl *var = lookupProperty(classDecl, C.Id_id);
207+
VarDecl *var = classDecl->getDistributedActorIDProperty();
223208
auto resultTy = getLoweredType(F.mapTypeIntoContext(var->getInterfaceType()));
224209
auto temp = emitTemporaryAllocation(loc, resultTy);
225210

@@ -332,7 +317,7 @@ void SILGenFunction::emitDistributedActorReady(
332317
ManagedValue actorSystem;
333318
SGFContext sgfCxt;
334319
{
335-
VarDecl *property = lookupProperty(classDecl, C.Id_actorSystem);
320+
VarDecl *property = classDecl->getDistributedActorSystemProperty();
336321
Type formalType = F.mapTypeIntoContext(property->getInterfaceType());
337322
SILType loweredType = getLoweredType(formalType).getAddressType();
338323
SILValue actorSystemRef = emitActorPropertyReference(
@@ -466,11 +451,11 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) { // TODO(distrib
466451
auto classDecl = dc->getSelfClassDecl();
467452

468453
initializeProperty(*this, loc, remote,
469-
lookupProperty(classDecl, C.Id_id),
454+
classDecl->getDistributedActorIDProperty(),
470455
idArg);
471456

472457
initializeProperty(*this, loc, remote,
473-
lookupProperty(classDecl, C.Id_actorSystem),
458+
classDecl->getDistributedActorSystemProperty(),
474459
actorSystemArg);
475460

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

514499
// ==== locate: self.id
515500
auto idRef = emitActorPropertyReference(
516-
*this, loc, actorSelf.getValue(), lookupProperty(actorDecl, ctx.Id_id));
501+
*this, loc, actorSelf.getValue(), actorDecl->getDistributedActorIDProperty());
517502

518503
// ==== locate: self.actorSystem
519504
auto systemRef = emitActorPropertyReference(
520505
*this, loc, actorSelf.getValue(),
521-
lookupProperty(actorDecl, ctx.Id_actorSystem));
506+
actorDecl->getDistributedActorSystemProperty());
522507

523508
// Perform the call.
524509
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)