Skip to content

Commit dd1be8f

Browse files
committed
[Frontend] Hide @execution attribute behind an experimental feature ExecutionAttribute
Since the proposal has not been approved yet we cannot expose `@execution` attribute.
1 parent e2ff330 commit dd1be8f

19 files changed

+144
-18
lines changed

include/swift/AST/DeclAttr.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ DECL_ATTR_FEATURE_REQUIREMENT(ABI, ABIAttribute)
545545
DECL_ATTR(execution, Execution,
546546
OnFunc | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
547547
166)
548+
DECL_ATTR_FEATURE_REQUIREMENT(Execution, ExecutionAttribute)
548549

549550
LAST_DECL_ATTR(Execution)
550551

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ struct PrintOptions {
397397
/// Suppress modify/read accessors.
398398
bool SuppressCoroutineAccessors = false;
399399

400+
/// Suppress the @execution attribute
401+
bool SuppressExecutionAttribute = false;
402+
400403
/// List of attribute kinds that should not be printed.
401404
std::vector<AnyAttrKind> ExcludeAttrList = {
402405
DeclAttrKind::Transparent, DeclAttrKind::Effects,

include/swift/Basic/Features.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ SUPPRESSIBLE_EXPERIMENTAL_FEATURE(AddressableTypes, true)
436436
/// Allow the @abi attribute.
437437
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ABIAttribute, true)
438438

439+
/// Allow the @execution attribute. This is also connected to
440+
/// AsyncCallerExecution feature.
441+
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ExecutionAttribute, false)
442+
439443
/// Functions with nonisolated isolation inherit their isolation from the
440444
/// calling context.
441445
EXPERIMENTAL_FEATURE(AsyncCallerExecution, false)

lib/AST/ASTPrinter.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3251,6 +3251,14 @@ suppressingFeatureCustomAvailability(PrintOptions &options,
32513251
action();
32523252
}
32533253

3254+
static void
3255+
suppressingFeatureExecutionAttribute(PrintOptions &options,
3256+
llvm::function_ref<void()> action) {
3257+
llvm::SaveAndRestore<bool> scope1(options.SuppressExecutionAttribute, true);
3258+
ExcludeAttrRAII scope2(options.ExcludeAttrList, DeclAttrKind::Execution);
3259+
action();
3260+
}
3261+
32543262
/// Suppress the printing of a particular feature.
32553263
static void suppressingFeature(PrintOptions &options, Feature feature,
32563264
llvm::function_ref<void()> action) {
@@ -6423,7 +6431,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
64236431
break;
64246432

64256433
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
6426-
Printer << "@execution(caller) ";
6434+
if (!Options.SuppressExecutionAttribute)
6435+
Printer << "@execution(caller) ";
64276436
break;
64286437
}
64296438

lib/AST/Attr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ void IsolatedTypeAttr::printImpl(ASTPrinter &printer,
305305

306306
void ExecutionTypeAttr::printImpl(ASTPrinter &printer,
307307
const PrintOptions &options) const {
308+
if (options.SuppressExecutionAttribute)
309+
return;
310+
308311
printer.callPrintStructurePre(PrintStructureKind::BuiltinAttribute);
309312
printer.printAttrName("@execution");
310313
printer << "(";

lib/AST/FeatureSet.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,45 @@ static bool usesFeatureBuiltinEmplaceTypedThrows(Decl *decl) {
416416
return false;
417417
}
418418

419+
static bool usesFeatureExecutionAttribute(Decl *decl) {
420+
if (decl->getAttrs().hasAttribute<ExecutionAttr>())
421+
return true;
422+
423+
auto VD = dyn_cast<ValueDecl>(decl);
424+
if (!VD)
425+
return false;
426+
427+
auto hasExecutionAttr = [](TypeRepr *R) {
428+
if (!R)
429+
return false;
430+
431+
return R->findIf([](TypeRepr *repr) {
432+
if (auto *AT = dyn_cast<AttributedTypeRepr>(repr)) {
433+
return llvm::any_of(AT->getAttrs(), [](TypeOrCustomAttr attr) {
434+
if (auto *TA = attr.dyn_cast<TypeAttribute *>()) {
435+
return isa<ExecutionTypeAttr>(TA);
436+
}
437+
return false;
438+
});
439+
}
440+
return false;
441+
});
442+
};
443+
444+
// Check if any parameters that have `@execution` attribute.
445+
if (auto *PL = getParameterList(VD)) {
446+
for (auto *P : *PL) {
447+
if (hasExecutionAttr(P->getTypeRepr()))
448+
return true;
449+
}
450+
}
451+
452+
if (hasExecutionAttr(VD->getResultTypeRepr()))
453+
return true;
454+
455+
return false;
456+
}
457+
419458
// ----------------------------------------------------------------------------
420459
// MARK: - FeatureSet
421460
// ----------------------------------------------------------------------------

lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4725,6 +4725,12 @@ ParserStatus Parser::parseTypeAttribute(TypeOrCustomAttr &result,
47254725
}
47264726

47274727
case TypeAttrKind::Execution: {
4728+
if (!Context.LangOpts.hasFeature(Feature::ExecutionAttribute)) {
4729+
diagnose(Tok, diag::requires_experimental_feature, "@execution", false,
4730+
getFeatureName(Feature::ExecutionAttribute));
4731+
return makeParserError();
4732+
}
4733+
47284734
SourceLoc lpLoc = Tok.getLoc(), behaviorLoc, rpLoc;
47294735
if (!consumeIfNotAtStartOfLine(tok::l_paren)) {
47304736
if (!justChecking) {

test/ASTGen/attrs.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// RUN: %target-swift-frontend-dump-parse \
44
// RUN: -enable-experimental-feature ABIAttribute \
5+
// RUN: -enable-experimental-feature ExecutionAttribute \
56
// RUN: -enable-experimental-feature Extern \
67
// RUN: -enable-experimental-feature LifetimeDependence \
78
// RUN: -enable-experimental-feature SymbolLinkageMarkers \
@@ -11,6 +12,7 @@
1112

1213
// RUN: %target-swift-frontend-dump-parse \
1314
// RUN: -enable-experimental-feature ABIAttribute \
15+
// RUN: -enable-experimental-feature ExecutionAttribute \
1416
// RUN: -enable-experimental-feature Extern \
1517
// RUN: -enable-experimental-feature LifetimeDependence \
1618
// RUN: -enable-experimental-feature SymbolLinkageMarkers \
@@ -23,6 +25,7 @@
2325
// RUN: -module-abi-name ASTGen \
2426
// RUN: -enable-experimental-feature ParserASTGen \
2527
// RUN: -enable-experimental-feature ABIAttribute \
28+
// RUN: -enable-experimental-feature ExecutionAttribute \
2629
// RUN: -enable-experimental-feature Extern \
2730
// RUN: -enable-experimental-feature LifetimeDependence \
2831
// RUN: -enable-experimental-feature SymbolLinkageMarkers \
@@ -32,6 +35,7 @@
3235
// REQUIRES: swift_swift_parser
3336
// REQUIRES: swift_feature_ParserASTGen
3437
// REQUIRES: swift_feature_ABIAttribute
38+
// REQUIRES: swift_feature_ExecutionAttribute
3539
// REQUIRES: swift_feature_Extern
3640
// REQUIRES: swift_feature_LifetimeDependence
3741
// REQUIRES: swift_feature_SymbolLinkageMarkers

test/Concurrency/Runtime/nonisolated_inherits_isolation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// RUN: %target-run-simple-swift( -swift-version 6 -g %import-libdispatch -import-objc-header %S/Inputs/RunOnMainActor.h -enable-experimental-feature AsyncCallerExecution )
1+
// RUN: %target-run-simple-swift( -swift-version 6 -g %import-libdispatch -import-objc-header %S/Inputs/RunOnMainActor.h -enable-experimental-feature ExecutionAttribute -enable-experimental-feature AsyncCallerExecution )
22

33
// REQUIRES: executable_test
44
// REQUIRES: concurrency
55
// REQUIRES: concurrency_runtime
66
// REQUIRES: libdispatch
77
// REQUIRES: asserts
88

9+
// REQUIRES: swift_feature_ExecutionAttribute
910
// REQUIRES: swift_feature_AsyncCallerExecution
1011

1112
// UNSUPPORTED: freestanding

test/Concurrency/attr_execution.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// RUN: %target-swift-emit-silgen -enable-experimental-feature AsyncCallerExecution %s | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen -enable-experimental-feature ExecutionAttribute -enable-experimental-feature AsyncCallerExecution %s | %FileCheck %s
22

33
// REQUIRES: asserts
4+
// REQUIRES: swift_feature_ExecutionAttribute
45
// REQUIRES: swift_feature_AsyncCallerExecution
56

67

0 commit comments

Comments
 (0)