Skip to content

Commit d73402a

Browse files
committed
AST: Restrict @execution to func and init declarations
1 parent 6512aa1 commit d73402a

File tree

4 files changed

+13
-59
lines changed

4 files changed

+13
-59
lines changed

include/swift/AST/DeclAttr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ DECL_ATTR(abi, ABI,
862862
DECL_ATTR_FEATURE_REQUIREMENT(ABI, ABIAttribute)
863863

864864
DECL_ATTR(execution, Execution,
865-
OnAbstractFunction,
865+
OnFunc | OnConstructor,
866866
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
867867
166)
868868
DECL_ATTR_FEATURE_REQUIREMENT(Execution, ExecutionAttribute)

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,6 @@ static bool usesFeatureBuiltinEmplaceTypedThrows(Decl *decl) {
466466
}
467467

468468
static bool usesFeatureExecutionAttribute(Decl *decl) {
469-
if (auto *ASD = dyn_cast<AbstractStorageDecl>(decl)) {
470-
if (auto *getter = ASD->getAccessor(AccessorKind::Get))
471-
return usesFeatureExecutionAttribute(getter);
472-
return false;
473-
}
474-
475469
if (decl->getAttrs().hasAttribute<ExecutionAttr>())
476470
return true;
477471

test/ModuleInterface/execution_attr.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,5 @@ public struct Test {
3030
// CHECK-NEXT: public func other(_: () async -> Swift.Void)
3131
// CHECK-NEXT: #endif
3232
public func other(_: @execution(caller) () async -> Void) {}
33-
34-
// CHECK: #if compiler(>=5.3) && $ExecutionAttribute
35-
// CHECK-NEXT: public var test: Swift.Int {
36-
// CHECK-NEXT: @execution(caller) get async
37-
// CHECK-NEXT: }
38-
// CHECK-NEXT: #else
39-
// CHECK-NEXT: public var test: Swift.Int {
40-
// CHECK-NEXT: get async
41-
// CHECK-NEXT: }
42-
// CHECK-NEXT: #endif
43-
public var test: Int {
44-
@execution(caller)
45-
get async {
46-
42
47-
}
48-
}
49-
50-
// CHECK: #if compiler(>=5.3) && $ExecutionAttribute
51-
// CHECK-NEXT: public subscript(x: Swift.Int) -> Swift.Bool {
52-
// CHECK-NEXT: @execution(caller) get async
53-
// CHECK-NEXT: }
54-
// CHECK-NEXT: #else
55-
// CHECK-NEXT: public subscript(x: Swift.Int) -> Swift.Bool {
56-
// CHECK-NEXT: get async
57-
// CHECK-NEXT: }
58-
// CHECK-NEXT: #endif
59-
public subscript(x: Int) -> Bool {
60-
@execution(caller)
61-
get async {
62-
false
63-
}
64-
}
6533
}
6634

test/attr/attr_execution.swift

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,32 @@ struct Test {
2020
@execution(concurrent) init() {}
2121
// expected-error@-1 {{cannot use '@execution' on non-async initializer 'init()'}}
2222

23+
@execution(concurrent) init(async: Void) async {}
24+
2325
@execution(concurrent) func member() {}
2426
// expected-error@-1 {{cannot use '@execution' on non-async instance method 'member()'}}
2527

2628
@execution(concurrent) func member() async {} // Ok
2729

2830
// expected-error@+1 {{'@execution(caller)' attribute cannot be applied to this declaration}}
2931
@execution(caller) subscript(a: Int) -> Bool {
30-
get { false }
32+
@execution(concurrent) get { false }
33+
// expected-error@-1 {{@execution(concurrent)' attribute cannot be applied to this declaration}}
3134
@execution(concurrent) set { }
32-
// expected-error@-1 {{cannot use '@execution' on non-async setter for subscript 'subscript(_:)'}}
35+
// expected-error@-1 {{@execution(concurrent)' attribute cannot be applied to this declaration}}
3336
}
3437

3538
@execution(caller) var x: Int
3639
// expected-error@-1 {{'@execution(caller)' attribute cannot be applied to this declaration}}
3740
}
3841

42+
do {
43+
class C {
44+
@execution(caller) deinit {}
45+
// expected-error@-1 {{'@execution(caller)' attribute cannot be applied to this declaration}}
46+
}
47+
}
48+
3949
do {
4050
@execution(caller) func local() async {} // Ok
4151
}
@@ -93,21 +103,3 @@ _ = { @execution(concurrent) () -> Int in
93103
_ = { @execution(caller) (x: isolated (any Actor)?) in
94104
// expected-error@-1 {{cannot use '@execution' together with an isolated parameter}}
95105
}
96-
97-
struct TestDifferentPositions {
98-
@execution(caller)
99-
init() async {
100-
}
101-
102-
var x: Int {
103-
@execution(concurrent)
104-
get async {
105-
}
106-
}
107-
108-
subscript(x: Int) -> Bool {
109-
@execution(concurrent)
110-
get async {
111-
}
112-
}
113-
}

0 commit comments

Comments
 (0)