Skip to content

Commit b2b1efd

Browse files
committed
[Distributed] Decl: Add a new distributed-thunk bit
The flag is used to distinguish between regular functions/accessors and synthesized distributed thunks.
1 parent 59ec5ab commit b2b1efd

File tree

7 files changed

+31
-4
lines changed

7 files changed

+31
-4
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,
@@ -6335,6 +6339,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
63356339
Bits.AbstractFunctionDecl.Throws = Throws;
63366340
Bits.AbstractFunctionDecl.HasSingleExpressionBody = false;
63376341
Bits.AbstractFunctionDecl.HasNestedTypeDeclarations = false;
6342+
Bits.AbstractFunctionDecl.DistributedThunk = false;
63386343
}
63396344

63406345
void setBodyKind(BodyKind K) {
@@ -6433,6 +6438,16 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64336438
/// Returns 'true' if the function is distributed.
64346439
bool isDistributed() const;
64356440

6441+
/// Is this a thunk function used to access a distributed method
6442+
/// or computed property outside of its actor isolation context?
6443+
bool isDistributedThunk() const {
6444+
return Bits.AbstractFunctionDecl.DistributedThunk;
6445+
}
6446+
6447+
void setDistributedThunk(bool isThunk) {
6448+
Bits.AbstractFunctionDecl.DistributedThunk = isThunk;
6449+
}
6450+
64366451
/// For a 'distributed' target (func or computed property),
64376452
/// get the 'thunk' responsible for performing the 'remoteCall'.
64386453
///

lib/AST/ASTDumper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,9 @@ namespace {
878878
if (D->isDistributed()) {
879879
PrintWithColorRAII(OS, ExprModifierColor) << " distributed";
880880
}
881+
if (D->isDistributedThunk()) {
882+
PrintWithColorRAII(OS, ExprModifierColor) << " distributed-thunk";
883+
}
881884

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

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
731731
genericParamList, params,
732732
func->getResultInterfaceType(), DC);
733733
thunk->setSynthesized(true);
734+
thunk->setDistributedThunk(true);
734735
thunk->getAttrs().add(new (C) NonisolatedAttr(/*isImplicit=*/true));
735736

736737
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
@@ -3320,6 +3320,7 @@ class DeclDeserializer {
33203320
bool overriddenAffectsABI, needsNewVTableEntry, isTransparent;
33213321
DeclID opaqueReturnTypeID;
33223322
bool isUserAccessible;
3323+
bool isDistributedThunk;
33233324
ArrayRef<uint64_t> nameAndDependencyIDs;
33243325

33253326
if (!isAccessor) {
@@ -3338,6 +3339,7 @@ class DeclDeserializer {
33383339
needsNewVTableEntry,
33393340
opaqueReturnTypeID,
33403341
isUserAccessible,
3342+
isDistributedThunk,
33413343
nameAndDependencyIDs);
33423344
} else {
33433345
decls_block::AccessorLayout::readRecord(scratch, contextID, isImplicit,
@@ -3355,6 +3357,7 @@ class DeclDeserializer {
33553357
rawAccessLevel,
33563358
needsNewVTableEntry,
33573359
isTransparent,
3360+
isDistributedThunk,
33583361
nameAndDependencyIDs);
33593362
}
33603363

@@ -3531,6 +3534,8 @@ class DeclDeserializer {
35313534
if (!isAccessor)
35323535
fn->setUserAccessible(isUserAccessible);
35333536

3537+
fn->setDistributedThunk(isDistributedThunk);
3538+
35343539
return fn;
35353540
}
35363541

lib/Serialization/ModuleFormat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 695; // existential Any and AnyObject
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 696; // `distributed thunk` bit on `AbstractFunctionDecl`
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -1451,6 +1451,7 @@ namespace decls_block {
14511451
BCFixed<1>, // requires a new vtable slot
14521452
DeclIDField, // opaque result type decl
14531453
BCFixed<1>, // isUserAccessible?
1454+
BCFixed<1>, // is distributed thunk
14541455
BCArray<IdentifierIDField> // name components,
14551456
// followed by TypeID dependencies
14561457
// The record is trailed by:
@@ -1502,6 +1503,7 @@ namespace decls_block {
15021503
AccessLevelField, // access level
15031504
BCFixed<1>, // requires a new vtable slot
15041505
BCFixed<1>, // is transparent
1506+
BCFixed<1>, // is distributed thunk
15051507
BCArray<IdentifierIDField> // name components,
15061508
// followed by TypeID dependencies
15071509
// The record is trailed by:

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3891,6 +3891,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
38913891
fn->needsNewVTableEntry(),
38923892
S.addDeclRef(fn->getOpaqueResultTypeDecl()),
38933893
fn->isUserAccessible(),
3894+
fn->isDistributedThunk(),
38943895
nameComponentsAndDependencies);
38953896

38963897
writeGenericParams(fn->getGenericParams());
@@ -4002,6 +4003,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
40024003
rawAccessLevel,
40034004
fn->needsNewVTableEntry(),
40044005
fn->isTransparent(),
4006+
fn->isDistributedThunk(),
40054007
dependencies);
40064008

40074009
writeGenericParams(fn->getGenericParams());

0 commit comments

Comments
 (0)