Skip to content

Commit 36572d9

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 68ca6a2 commit 36572d9

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,11 @@ AbstractStorageDecl::getAccessStrategy(AccessSemantics semantics,
22722272
assert(hasStorage());
22732273
return AccessStrategy::getStorage();
22742274

2275+
// FIXME: For now `DistributedThunk` behaves just like `Ordinary` but it
2276+
// needs a new strategy to be useful.
2277+
case AccessSemantics::DistributedThunk:
2278+
LLVM_FALLTHROUGH;
2279+
22752280
case AccessSemantics::Ordinary:
22762281
// Skip these checks for local variables, both because they're unnecessary
22772282
// and because we won't necessarily have computed access.

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2379,7 +2379,7 @@ namespace {
23792379
if (auto lookupExpr = dyn_cast_or_null<LookupExpr>(context)) {
23802380
if (auto memberRef = dyn_cast<MemberRefExpr>(lookupExpr)) {
23812381
memberRef->setImplicitlyThrows(true);
2382-
memberRef->setShouldApplyLookupDistributedThunk(true);
2382+
memberRef->setAccessViaDistributedThunk();
23832383
} else {
23842384
llvm_unreachable("expected distributed prop to be a MemberRef");
23852385
}

0 commit comments

Comments
 (0)