Skip to content

Commit 9401062

Browse files
committed
[Distributed] Sema: Add a new distributed-thunk attribute
The attribute comes handy during solution application to determine whether the call is using a distributed thunk.
1 parent 3a0c8ce commit 9401062

File tree

9 files changed

+34
-1
lines changed

9 files changed

+34
-1
lines changed

include/swift/AST/Attr.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,12 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(_local, KnownToBeLocal,
735735
APIBreakingToAdd | APIBreakingToRemove,
736736
130)
737737

738+
SIMPLE_DECL_ATTR(_distributed_thunk, DistributedThunk,
739+
OnFunc | UserInaccessible |
740+
ABIBreakingToAdd | ABIBreakingToRemove |
741+
APIBreakingToAdd | APIBreakingToRemove,
742+
131)
743+
738744
// If you're adding a new underscored attribute here, please document it in
739745
// docs/ReferenceGuides/UnderscoredAttributes.md.
740746

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6433,6 +6433,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64336433
/// Returns 'true' if the function is distributed.
64346434
bool isDistributed() const;
64356435

6436+
/// Is this a thunk function used to access a distributed method
6437+
/// or computed property outside of its actor isolation context?
6438+
bool isDistributedThunk() const;
6439+
64366440
/// For a 'distributed' target (func or computed property),
64376441
/// get the 'thunk' responsible for performing the 'remoteCall'.
64386442
///

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4607,6 +4607,9 @@ ERROR(distributed_actor_isolated_method,none,
46074607
ERROR(distributed_local_cannot_be_used,none,
46084608
"'local' cannot be used in user-defined code currently",
46094609
())
4610+
ERROR(distributed_thunk_cannot_be_used,none,
4611+
"'distributed_thunk' cannot be used in user-defined code",
4612+
())
46104613
ERROR(distributed_actor_func_param_not_codable,none,
46114614
"parameter '%0' of type %1 in %2 does not conform to serialization requirement '%3'",
46124615
(StringRef, Type, DescriptiveDeclKind, StringRef))

lib/AST/ASTDumper.cpp

Lines changed: 7 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=";
@@ -1351,6 +1354,10 @@ void ValueDecl::dumpRef(raw_ostream &os) const {
13511354
os << " known-to-be-local";
13521355
}
13531356

1357+
if (getAttrs().hasAttribute<DistributedThunkAttr>()) {
1358+
os << " distributed-thunk";
1359+
}
1360+
13541361
// Print location.
13551362
auto &srcMgr = getASTContext().SourceMgr;
13561363
if (getLoc().isValid()) {

lib/AST/DistributedDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,10 @@ bool AbstractFunctionDecl::isDistributed() const {
12901290
return getAttrs().hasAttribute<DistributedActorAttr>();
12911291
}
12921292

1293+
bool AbstractFunctionDecl::isDistributedThunk() const {
1294+
return getAttrs().hasAttribute<DistributedThunkAttr>();
1295+
}
1296+
12931297
ConstructorDecl *
12941298
NominalTypeDecl::getDistributedRemoteCallTargetInitFunction() const {
12951299
auto mutableThis = const_cast<NominalTypeDecl *>(this);

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ static FuncDecl *createDistributedThunkFunction(FuncDecl *func) {
736736
if (isa<ClassDecl>(DC))
737737
thunk->getAttrs().add(new (C) FinalAttr(/*isImplicit=*/true));
738738

739+
thunk->getAttrs().add(new (C) DistributedThunkAttr(/*isImplicit=*/true));
739740
thunk->setGenericSignature(baseSignature);
740741
thunk->copyFormalAccessFrom(func, /*sourceIsParentContext=*/false);
741742
thunk->setBodySynthesizer(deriveBodyDistributed_thunk, func);

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
322322
void visitKnownToBeLocalAttr(KnownToBeLocalAttr *attr);
323323

324324
void visitSendableAttr(SendableAttr *attr);
325+
326+
void visitDistributedThunkAttr(DistributedThunkAttr *attr);
325327
};
326328

327329
} // end anonymous namespace
@@ -5934,6 +5936,11 @@ void AttributeChecker::visitSendableAttr(SendableAttr *attr) {
59345936
}
59355937
}
59365938

5939+
void AttributeChecker::visitDistributedThunkAttr(DistributedThunkAttr *attr) {
5940+
if (!D->isImplicit())
5941+
diagnoseAndRemoveAttr(attr, diag::distributed_thunk_cannot_be_used);
5942+
}
5943+
59375944
void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
59385945
// 'nonisolated' can be applied to global and static/class variables
59395946
// that do not have storage.

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,7 @@ namespace {
16131613
UNINTERESTING_ATTR(UnsafeInheritExecutor)
16141614
UNINTERESTING_ATTR(CompilerInitialized)
16151615

1616+
UNINTERESTING_ATTR(DistributedThunk)
16161617
#undef UNINTERESTING_ATTR
16171618

16181619
void visitAvailableAttr(AvailableAttr *attr) {

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 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 attribute
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

0 commit comments

Comments
 (0)