Skip to content

Commit 8d9962e

Browse files
committed
[Distributed] Allow requesting distributed thunks on AbstractStorageDecl
One step towards future distributed subscripts.
1 parent 3f3410d commit 8d9962e

File tree

6 files changed

+30
-24
lines changed

6 files changed

+30
-24
lines changed

include/swift/AST/Decl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5123,6 +5123,13 @@ class AbstractStorageDecl : public ValueDecl {
51235123

51245124
bool hasAnyNativeDynamicAccessors() const;
51255125

5126+
/// Does this have a 'distributed' modifier?
5127+
bool isDistributed() const;
5128+
5129+
/// Return a distributed thunk if this computed property is marked as
5130+
/// 'distributed' and and nullptr otherwise.
5131+
FuncDecl *getDistributedThunk() const;
5132+
51265133
// Implement isa/cast/dyncast/etc.
51275134
static bool classof(const Decl *D) {
51285135
return D->getKind() >= DeclKind::First_AbstractStorageDecl &&
@@ -5356,13 +5363,6 @@ class VarDecl : public AbstractStorageDecl {
53565363
/// Is this an "async let" property?
53575364
bool isAsyncLet() const;
53585365

5359-
/// Does this have a 'distributed' modifier?
5360-
bool isDistributed() const;
5361-
5362-
/// Return a distributed thunk if this computed property is marked as
5363-
/// 'distributed' and and nullptr otherwise.
5364-
FuncDecl *getDistributedThunk() const;
5365-
53665366
/// Is this var known to be a "local" distributed actor,
53675367
/// if so the implicit throwing ans some isolation checks can be skipped.
53685368
bool isKnownToBeLocal() const;

include/swift/AST/TypeCheckRequests.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,11 +1238,13 @@ class GetDistributedRemoteCallArgumentInitFunctionRequest :
12381238
/// The thunk is responsible for invoking 'remoteCall' when invoked on a remote
12391239
/// 'distributed actor'.
12401240
class GetDistributedThunkRequest
1241-
: public SimpleRequest<
1242-
GetDistributedThunkRequest,
1243-
FuncDecl *(llvm::PointerUnion<VarDecl *, AbstractFunctionDecl *>),
1244-
RequestFlags::Cached> {
1245-
using Originator = llvm::PointerUnion<VarDecl *, AbstractFunctionDecl *>;
1241+
: public SimpleRequest<GetDistributedThunkRequest,
1242+
FuncDecl *(
1243+
llvm::PointerUnion<AbstractStorageDecl *,
1244+
AbstractFunctionDecl *>),
1245+
RequestFlags::Cached> {
1246+
using Originator =
1247+
llvm::PointerUnion<AbstractStorageDecl *, AbstractFunctionDecl *>;
12461248

12471249
public:
12481250
using SimpleRequest::SimpleRequest;

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ SWIFT_REQUEST(TypeChecker, GetDistributedTargetInvocationResultHandlerOnReturnFu
127127
AbstractFunctionDecl *(NominalTypeDecl *),
128128
Cached, NoLocationInfo)
129129
SWIFT_REQUEST(TypeChecker, GetDistributedThunkRequest,
130-
FuncDecl *(llvm::PointerUnion<VarDecl *, AbstractFunctionDecl *>),
130+
FuncDecl *(llvm::PointerUnion<AbstractStorageDecl *, AbstractFunctionDecl *>),
131131
Cached, NoLocationInfo)
132132
SWIFT_REQUEST(TypeChecker, GetDistributedActorIDPropertyRequest,
133133
VarDecl *(NominalTypeDecl *),

lib/AST/Decl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6455,10 +6455,6 @@ bool VarDecl::isAsyncLet() const {
64556455
return getAttrs().hasAttribute<AsyncAttr>();
64566456
}
64576457

6458-
bool VarDecl::isDistributed() const {
6459-
return getAttrs().hasAttribute<DistributedActorAttr>();
6460-
}
6461-
64626458
bool VarDecl::isKnownToBeLocal() const {
64636459
return getAttrs().hasAttribute<KnownToBeLocalAttr>();
64646460
}

lib/AST/DistributedDecl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,10 @@ bool AbstractFunctionDecl::isDistributed() const {
12901290
return getAttrs().hasAttribute<DistributedActorAttr>();
12911291
}
12921292

1293+
bool AbstractStorageDecl::isDistributed() const {
1294+
return getAttrs().hasAttribute<DistributedActorAttr>();
1295+
}
1296+
12931297
ConstructorDecl *
12941298
NominalTypeDecl::getDistributedRemoteCallTargetInitFunction() const {
12951299
auto mutableThis = const_cast<NominalTypeDecl *>(this);
@@ -1333,11 +1337,11 @@ AbstractFunctionDecl *ASTContext::getRemoteCallOnDistributedActorSystem(
13331337
/********************** Distributed Actor Properties **************************/
13341338
/******************************************************************************/
13351339

1336-
FuncDecl *VarDecl::getDistributedThunk() const {
1340+
FuncDecl *AbstractStorageDecl::getDistributedThunk() const {
13371341
if (!isDistributed())
13381342
return nullptr;
13391343

1340-
auto mutableThis = const_cast<VarDecl *>(this);
1344+
auto mutableThis = const_cast<AbstractStorageDecl *>(this);
13411345
return evaluateOrDefault(getASTContext().evaluator,
13421346
GetDistributedThunkRequest{mutableThis}, nullptr);
13431347
}

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,18 @@ addDistributedActorCodableConformance(
836836
FuncDecl *GetDistributedThunkRequest::evaluate(Evaluator &evaluator,
837837
Originator originator) const {
838838
AbstractFunctionDecl *distributedTarget = nullptr;
839-
if (auto *var = originator.dyn_cast<VarDecl *>()) {
840-
if (!var->isDistributed())
839+
if (auto *storage = originator.dyn_cast<AbstractStorageDecl *>()) {
840+
if (!storage->isDistributed())
841841
return nullptr;
842842

843-
if (checkDistributedActorProperty(var, /*diagnose=*/false))
844-
return nullptr;
843+
if (auto *var = dyn_cast<VarDecl>(storage)) {
844+
if (checkDistributedActorProperty(var, /*diagnose=*/false))
845+
return nullptr;
845846

846-
distributedTarget = var->getAccessor(AccessorKind::Get);
847+
distributedTarget = var->getAccessor(AccessorKind::Get);
848+
} else {
849+
llvm_unreachable("unsupported storage kind");
850+
}
847851
} else {
848852
distributedTarget = originator.get<AbstractFunctionDecl *>();
849853
if (!distributedTarget->isDistributed())

0 commit comments

Comments
 (0)