Skip to content

Commit b17b5ee

Browse files
xedinktoso
authored andcommitted
[Distributed] Decl: Add a new distributed-thunk bit
The flag is used to distinguish between regular functions/accessors and synthesized distributed thunks.
1 parent b2c6635 commit b17b5ee

File tree

7 files changed

+193
-116
lines changed

7 files changed

+193
-116
lines changed

include/swift/AST/Decl.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
412412
SWIFT_INLINE_BITFIELD(SubscriptDecl, VarDecl, 2,
413413
StaticSpelling : 2
414414
);
415-
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+2+8+1+1+1+1+1+1,
415+
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+2+8+1+1+1+1+1+1+1,
416416
/// \see AbstractFunctionDecl::BodyKind
417417
BodyKind : 3,
418418

@@ -439,7 +439,11 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
439439

440440
/// Whether peeking into this function detected nested type declarations.
441441
/// This is set when skipping over the decl at parsing.
442-
HasNestedTypeDeclarations : 1
442+
HasNestedTypeDeclarations : 1,
443+
444+
/// Whether this function is a distributed thunk for a distributed
445+
/// function or computed property.
446+
DistributedThunk: 1
443447
);
444448

445449
SWIFT_INLINE_BITFIELD(FuncDecl, AbstractFunctionDecl, 1+1+2+1+1+2+1,
@@ -6318,6 +6322,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
63186322
Bits.AbstractFunctionDecl.Throws = Throws;
63196323
Bits.AbstractFunctionDecl.HasSingleExpressionBody = false;
63206324
Bits.AbstractFunctionDecl.HasNestedTypeDeclarations = false;
6325+
Bits.AbstractFunctionDecl.DistributedThunk = false;
63216326
}
63226327

63236328
void setBodyKind(BodyKind K) {
@@ -6419,6 +6424,16 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64196424
/// Returns 'true' if the function is distributed.
64206425
bool isDistributed() const;
64216426

6427+
/// Is this a thunk function used to access a distributed method
6428+
/// or computed property outside of its actor isolation context?
6429+
bool isDistributedThunk() const {
6430+
return Bits.AbstractFunctionDecl.DistributedThunk;
6431+
}
6432+
6433+
void setDistributedThunk(bool isThunk) {
6434+
Bits.AbstractFunctionDecl.DistributedThunk = isThunk;
6435+
}
6436+
64226437
/// For a 'distributed' target (func or computed property),
64236438
/// get the 'thunk' responsible for performing the 'remoteCall'.
64246439
///

lib/AST/ASTDumper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,9 @@ namespace {
875875
if (D->isDistributed()) {
876876
PrintWithColorRAII(OS, ExprModifierColor) << " distributed";
877877
}
878+
if (D->isDistributedThunk()) {
879+
PrintWithColorRAII(OS, ExprModifierColor) << " distributed-thunk";
880+
}
878881

879882
if (auto fac = D->getForeignAsyncConvention()) {
880883
OS << " foreign_async=";

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
701701
genericParamList, params,
702702
func->getResultInterfaceType(), DC);
703703
thunk->setSynthesized(true);
704+
thunk->setDistributedThunk(true);
704705
thunk->getAttrs().add(new (C) NonisolatedAttr(/*isImplicit=*/true));
705706

706707
if (isa<ClassDecl>(DC))

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,6 @@ namespace {
16121612

16131613
UNINTERESTING_ATTR(UnsafeInheritExecutor)
16141614
UNINTERESTING_ATTR(CompilerInitialized)
1615-
16161615
#undef UNINTERESTING_ATTR
16171616

16181617
void visitAvailableAttr(AvailableAttr *attr) {

lib/Serialization/Deserialization.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,6 +3309,7 @@ class DeclDeserializer {
33093309
bool overriddenAffectsABI, needsNewVTableEntry, isTransparent;
33103310
DeclID opaqueReturnTypeID;
33113311
bool isUserAccessible;
3312+
bool isDistributedThunk;
33123313
ArrayRef<uint64_t> nameAndDependencyIDs;
33133314

33143315
if (!isAccessor) {
@@ -3327,6 +3328,7 @@ class DeclDeserializer {
33273328
needsNewVTableEntry,
33283329
opaqueReturnTypeID,
33293330
isUserAccessible,
3331+
isDistributedThunk,
33303332
nameAndDependencyIDs);
33313333
} else {
33323334
decls_block::AccessorLayout::readRecord(scratch, contextID, isImplicit,
@@ -3344,6 +3346,7 @@ class DeclDeserializer {
33443346
rawAccessLevel,
33453347
needsNewVTableEntry,
33463348
isTransparent,
3349+
isDistributedThunk,
33473350
nameAndDependencyIDs);
33483351
}
33493352

@@ -3520,6 +3523,8 @@ class DeclDeserializer {
35203523
if (!isAccessor)
35213524
fn->setUserAccessible(isUserAccessible);
35223525

3526+
fn->setDistributedThunk(isDistributedThunk);
3527+
35233528
return fn;
35243529
}
35253530

0 commit comments

Comments
 (0)