Skip to content

Commit b2db4ad

Browse files
committed
[AST] Add new member access semantics - DistributedThunk
`DistributedThunk` is to be used while accessing 'distributed' computed property outside of its actor context.
1 parent 0303bed commit b2db4ad

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

include/swift/AST/Expr.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ enum class AccessSemantics : uint8_t {
124124
/// This is an ordinary access to a declaration, using whatever
125125
/// polymorphism is expected.
126126
Ordinary,
127+
128+
/// This is an access to the underlying storage through a distributed thunk.
129+
///
130+
/// The declaration must be a 'distributed' computed property used outside
131+
/// of its actor isolation context.
132+
DistributedThunk,
127133
};
128134

129135
/// Expr - Base class for all expressions in swift.
@@ -155,11 +161,10 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
155161

156162
SWIFT_INLINE_BITFIELD_EMPTY(LiteralExpr, Expr);
157163
SWIFT_INLINE_BITFIELD_EMPTY(IdentityExpr, Expr);
158-
SWIFT_INLINE_BITFIELD(LookupExpr, Expr, 1+1+1+1,
164+
SWIFT_INLINE_BITFIELD(LookupExpr, Expr, 1+1+1,
159165
IsSuper : 1,
160166
IsImplicitlyAsync : 1,
161-
IsImplicitlyThrows : 1,
162-
ShouldApplyDistributedThunk: 1
167+
IsImplicitlyThrows : 1
163168
);
164169
SWIFT_INLINE_BITFIELD_EMPTY(DynamicLookupExpr, LookupExpr);
165170

@@ -1656,18 +1661,6 @@ class LookupExpr : public Expr {
16561661
Bits.LookupExpr.IsImplicitlyThrows = isImplicitlyThrows;
16571662
}
16581663

1659-
/// Informs IRGen to that this expression should be applied as its distributed
1660-
/// thunk, rather than invoking the function directly.
1661-
///
1662-
/// Only intended to be set on distributed get-only computed properties.
1663-
bool shouldApplyLookupDistributedThunk() const {
1664-
return Bits.LookupExpr.ShouldApplyDistributedThunk;
1665-
}
1666-
1667-
void setShouldApplyLookupDistributedThunk(bool flag) {
1668-
Bits.LookupExpr.ShouldApplyDistributedThunk = flag;
1669-
}
1670-
16711664
static bool classof(const Expr *E) {
16721665
return E->getKind() >= ExprKind::First_LookupExpr &&
16731666
E->getKind() <= ExprKind::Last_LookupExpr;
@@ -1697,6 +1690,14 @@ class MemberRefExpr : public LookupExpr {
16971690
return (AccessSemantics) Bits.MemberRefExpr.Semantics;
16981691
}
16991692

1693+
/// Informs IRGen to that this member should be applied via its distributed
1694+
/// thunk, rather than invoking it directly.
1695+
///
1696+
/// Only intended to be set on distributed get-only computed properties.
1697+
void setAccessViaDistributedThunk() {
1698+
Bits.MemberRefExpr.Semantics = (unsigned)AccessSemantics::DistributedThunk;
1699+
}
1700+
17001701
SourceLoc getLoc() const { return NameLoc.getBaseNameLoc(); }
17011702
SourceLoc getStartLoc() const {
17021703
SourceLoc BaseStartLoc = getBase()->getStartLoc();

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ static StringRef getAccessSemanticsString(AccessSemantics value) {
255255
case AccessSemantics::Ordinary: return "ordinary";
256256
case AccessSemantics::DirectToStorage: return "direct_to_storage";
257257
case AccessSemantics::DirectToImplementation: return "direct_to_impl";
258+
case AccessSemantics::DistributedThunk: return "distributed_thunk";
258259
}
259260

260261
llvm_unreachable("Unhandled AccessSemantics in switch.");
@@ -2035,9 +2036,6 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
20352036

20362037
void visitMemberRefExpr(MemberRefExpr *E) {
20372038
printCommon(E, "member_ref_expr");
2038-
if (E->shouldApplyLookupDistributedThunk()) {
2039-
OS << " distributed";
2040-
}
20412039
PrintWithColorRAII(OS, DeclColor) << " decl=";
20422040
printDeclRef(E->getMember());
20432041
if (E->getAccessSemantics() != AccessSemantics::Ordinary)

lib/AST/Decl.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,11 @@ AbstractStorageDecl::getAccessStrategy(AccessSemantics semantics,
22832283
assert(hasStorage());
22842284
return AccessStrategy::getStorage();
22852285

2286+
// FIXME: For now `DistributedThunk` behaves just like `Ordinary` but it
2287+
// needs a new strategy to be useful.
2288+
case AccessSemantics::DistributedThunk:
2289+
LLVM_FALLTHROUGH;
2290+
22862291
case AccessSemantics::Ordinary:
22872292
// Skip these checks for local variables, both because they're unnecessary
22882293
// and because we won't necessarily have computed access.
@@ -2295,14 +2300,6 @@ AbstractStorageDecl::getAccessStrategy(AccessSemantics semantics,
22952300
if (shouldUseNativeDynamicDispatch())
22962301
return getOpaqueAccessStrategy(this, accessKind, /*dispatch*/ false);
22972302

2298-
// if (auto var = dyn_cast<VarDecl>(this)) {
2299-
// if (var->isDistributed()) {
2300-
// fprintf(stderr, "[%s:%d] (%s) DIST STRATEGY!!\n", __FILE__, __LINE__, __FUNCTION__);
2301-
// var->dump();
2302-
// return getDirectToDistributedThunkAccessorStrategy(this);
2303-
// }
2304-
// }
2305-
23062303
// If the storage is resilient from the given module and resilience
23072304
// expansion, we cannot use direct access.
23082305
//

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,27 +2363,20 @@ namespace {
23632363
// is it an access to a property?
23642364
if (isPropOrSubscript(decl)) {
23652365
// Cannot reference properties or subscripts of distributed actors.
2366-
fprintf(stderr, "[%s:%d] (%s) prop\n", __FILE__, __LINE__, __FUNCTION__);
23672366
if (isDistributed) {
2368-
fprintf(stderr, "[%s:%d] (%s) prop is dist\n", __FILE__, __LINE__, __FUNCTION__);
2369-
23702367
bool setThrows = false;
23712368
bool usesDistributedThunk = false;
23722369
if (auto access = checkDistributedAccess(declLoc, decl, context)) {
23732370
std::tie(setThrows, usesDistributedThunk) = *access;
23742371
} else {
2375-
fprintf(stderr, "[%s:%d] (%s) prop is dist -> NOPE \n", __FILE__, __LINE__, __FUNCTION__);
23762372
return AsyncMarkingResult::NotDistributed;
23772373
}
23782374

23792375
// distributed computed property access, mark it throws + async
23802376
if (auto lookupExpr = dyn_cast_or_null<LookupExpr>(context)) {
23812377
if (auto memberRef = dyn_cast<MemberRefExpr>(lookupExpr)) {
2382-
fprintf(stderr, "[%s:%d] (%s) SET DISTRIBUTED MEMBER REF\n", __FILE__, __LINE__, __FUNCTION__);
2383-
memberRef->dump();
2384-
23852378
memberRef->setImplicitlyThrows(true);
2386-
memberRef->setShouldApplyLookupDistributedThunk(true);
2379+
memberRef->setAccessViaDistributedThunk();
23872380
} else {
23882381
llvm_unreachable("expected distributed prop to be a MemberRef");
23892382
}

0 commit comments

Comments
 (0)