Skip to content

Commit 879bf58

Browse files
xedinktoso
authored andcommitted
[Distributed] Allow requesting distributed thunks on AbstractStorageDecl
One step towards future distributed subscripts.
1 parent 2ed19c6 commit 879bf58

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
@@ -5113,6 +5113,13 @@ class AbstractStorageDecl : public ValueDecl {
51135113

51145114
bool hasAnyNativeDynamicAccessors() const;
51155115

5116+
/// Does this have a 'distributed' modifier?
5117+
bool isDistributed() const;
5118+
5119+
/// Return a distributed thunk if this computed property is marked as
5120+
/// 'distributed' and and nullptr otherwise.
5121+
FuncDecl *getDistributedThunk() const;
5122+
51165123
// Implement isa/cast/dyncast/etc.
51175124
static bool classof(const Decl *D) {
51185125
return D->getKind() >= DeclKind::First_AbstractStorageDecl &&
@@ -5346,13 +5353,6 @@ class VarDecl : public AbstractStorageDecl {
53465353
/// Is this an "async let" property?
53475354
bool isAsyncLet() const;
53485355

5349-
/// Does this have a 'distributed' modifier?
5350-
bool isDistributed() const;
5351-
5352-
/// Return a distributed thunk if this computed property is marked as
5353-
/// 'distributed' and and nullptr otherwise.
5354-
FuncDecl *getDistributedThunk() const;
5355-
53565356
/// Is this var known to be a "local" distributed actor,
53575357
/// if so the implicit throwing ans some isolation checks can be skipped.
53585358
bool isKnownToBeLocal() const;

include/swift/AST/TypeCheckRequests.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,11 +1280,13 @@ class GetDistributedRemoteCallArgumentInitFunctionRequest :
12801280
/// The thunk is responsible for invoking 'remoteCall' when invoked on a remote
12811281
/// 'distributed actor'.
12821282
class GetDistributedThunkRequest
1283-
: public SimpleRequest<
1284-
GetDistributedThunkRequest,
1285-
FuncDecl *(llvm::PointerUnion<VarDecl *, AbstractFunctionDecl *>),
1286-
RequestFlags::Cached> {
1287-
using Originator = llvm::PointerUnion<VarDecl *, AbstractFunctionDecl *>;
1283+
: public SimpleRequest<GetDistributedThunkRequest,
1284+
FuncDecl *(
1285+
llvm::PointerUnion<AbstractStorageDecl *,
1286+
AbstractFunctionDecl *>),
1287+
RequestFlags::Cached> {
1288+
using Originator =
1289+
llvm::PointerUnion<AbstractStorageDecl *, AbstractFunctionDecl *>;
12881290

12891291
public:
12901292
using SimpleRequest::SimpleRequest;

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ SWIFT_REQUEST(TypeChecker, GetDistributedTargetInvocationResultHandlerOnReturnFu
137137
AbstractFunctionDecl *(NominalTypeDecl *),
138138
Cached, NoLocationInfo)
139139
SWIFT_REQUEST(TypeChecker, GetDistributedThunkRequest,
140-
FuncDecl *(llvm::PointerUnion<VarDecl *, AbstractFunctionDecl *>),
140+
FuncDecl *(llvm::PointerUnion<AbstractStorageDecl *, AbstractFunctionDecl *>),
141141
Cached, NoLocationInfo)
142142
SWIFT_REQUEST(TypeChecker, GetDistributedActorIDPropertyRequest,
143143
VarDecl *(NominalTypeDecl *),

lib/AST/Decl.cpp

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

6423-
bool VarDecl::isDistributed() const {
6424-
return getAttrs().hasAttribute<DistributedActorAttr>();
6425-
}
6426-
64276423
bool VarDecl::isKnownToBeLocal() const {
64286424
return getAttrs().hasAttribute<KnownToBeLocalAttr>();
64296425
}

lib/AST/DistributedDecl.cpp

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

1364+
bool AbstractStorageDecl::isDistributed() const {
1365+
return getAttrs().hasAttribute<DistributedActorAttr>();
1366+
}
1367+
13641368
ConstructorDecl *
13651369
NominalTypeDecl::getDistributedRemoteCallTargetInitFunction() const {
13661370
auto mutableThis = const_cast<NominalTypeDecl *>(this);
@@ -1404,11 +1408,11 @@ AbstractFunctionDecl *ASTContext::getRemoteCallOnDistributedActorSystem(
14041408
/********************** Distributed Actor Properties **************************/
14051409
/******************************************************************************/
14061410

1407-
FuncDecl *VarDecl::getDistributedThunk() const {
1411+
FuncDecl *AbstractStorageDecl::getDistributedThunk() const {
14081412
if (!isDistributed())
14091413
return nullptr;
14101414

1411-
auto mutableThis = const_cast<VarDecl *>(this);
1415+
auto mutableThis = const_cast<AbstractStorageDecl *>(this);
14121416
return evaluateOrDefault(getASTContext().evaluator,
14131417
GetDistributedThunkRequest{mutableThis}, nullptr);
14141418
}

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -806,14 +806,18 @@ addDistributedActorCodableConformance(
806806
FuncDecl *GetDistributedThunkRequest::evaluate(Evaluator &evaluator,
807807
Originator originator) const {
808808
AbstractFunctionDecl *distributedTarget = nullptr;
809-
if (auto *var = originator.dyn_cast<VarDecl *>()) {
810-
if (!var->isDistributed())
809+
if (auto *storage = originator.dyn_cast<AbstractStorageDecl *>()) {
810+
if (!storage->isDistributed())
811811
return nullptr;
812812

813-
if (checkDistributedActorProperty(var, /*diagnose=*/false))
814-
return nullptr;
813+
if (auto *var = dyn_cast<VarDecl>(storage)) {
814+
if (checkDistributedActorProperty(var, /*diagnose=*/false))
815+
return nullptr;
815816

816-
distributedTarget = var->getAccessor(AccessorKind::Get);
817+
distributedTarget = var->getAccessor(AccessorKind::Get);
818+
} else {
819+
llvm_unreachable("unsupported storage kind");
820+
}
817821
} else {
818822
distributedTarget = originator.get<AbstractFunctionDecl *>();
819823
if (!distributedTarget->isDistributed())

0 commit comments

Comments
 (0)