Skip to content

Commit 1a3af5c

Browse files
committed
[Diagnostics] Adjust @execution(...) diagnostic to take DeclAttribute or StringRef
It has been decided to split the attribute into `@concurrent` and `nonisolated(nonsending`. Adjusting diagnostics to accept the attribute makes the transition easier.
1 parent 90387c9 commit 1a3af5c

File tree

4 files changed

+69
-56
lines changed

4 files changed

+69
-56
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8553,40 +8553,47 @@ GROUPED_ERROR(isolated_conformance_wrong_domain,IsolatedConformances,none,
85538553
// MARK: @execution Attribute
85548554
//===----------------------------------------------------------------------===//
85558555
8556-
ERROR(attr_execution_only_on_async,none,
8557-
"cannot use '@execution' on non-async %kind0",
8558-
(ValueDecl *))
8556+
ERROR(execution_behavior_only_on_async,none,
8557+
"cannot use '%0' on non-async %kind1",
8558+
(DeclAttribute, ValueDecl *))
85598559
8560-
ERROR(attr_execution_only_on_async_closure,none,
8561-
"cannot use '@execution' on non-async closure",
8562-
())
8560+
ERROR(execution_behavior_only_on_async_closure,none,
8561+
"cannot use '%0' on non-async closure",
8562+
(DeclAttribute))
85638563
8564-
ERROR(attr_execution_type_attr_only_on_async,none,
8565-
"cannot use '@execution' on non-async function type",
8566-
())
8564+
ERROR(execution_behavior_type_attr_only_on_async,none,
8565+
"cannot use '@%0' on non-async function type",
8566+
(StringRef))
85678567
8568-
ERROR(attr_execution_incompatible_isolated_parameter,none,
8569-
"cannot use '@execution' on %kind0 because it has "
8570-
"an isolated parameter: %1",
8571-
(ValueDecl *, ValueDecl *))
8568+
ERROR(execution_behavior_incompatible_isolated_parameter,none,
8569+
"cannot use '%0' on %kind1 because it has "
8570+
"an isolated parameter: %2",
8571+
(DeclAttribute, ValueDecl *, ValueDecl *))
85728572
8573-
ERROR(attr_execution_incompatible_dynamically_isolated_parameter,none,
8574-
"cannot use '@execution' on %kind0 because it has "
8575-
"a dynamically isolated parameter: %1",
8576-
(ValueDecl *, ValueDecl *))
8573+
ERROR(execution_behavior_incompatible_dynamically_isolated_parameter,none,
8574+
"cannot use '%0' on %kind1 because it has "
8575+
"a dynamically isolated parameter: %2",
8576+
(DeclAttribute, ValueDecl *, ValueDecl *))
85778577
8578-
ERROR(attr_execution_type_attr_incompatible_with_global_isolation,none,
8579-
"cannot use '@execution' because function type is "
8580-
"isolated to a global actor %0",
8581-
(Type))
8578+
ERROR(execution_behavior_attr_incompatible_with_global_isolation,none,
8579+
"cannot use '%0' because function type is isolated to a global actor %1",
8580+
(DeclAttribute, Type))
85828581
8583-
ERROR(attr_execution_type_attr_incompatible_with_isolated_param,none,
8584-
"cannot use '@execution' together with an isolated parameter",
8585-
())
8582+
ERROR(execution_behavior_attr_incompatible_with_isolated_param,none,
8583+
"cannot use '%0' together with an isolated parameter",
8584+
(DeclAttribute))
85868585
8587-
ERROR(attr_execution_type_attr_incompatible_with_isolated_any,none,
8588-
"cannot use '@execution' together with @isolated(any)",
8589-
())
8586+
ERROR(execution_behavior_type_attr_incompatible_with_global_isolation,none,
8587+
"cannot use '@%0' because function type is isolated to a global actor %1",
8588+
(StringRef, Type))
8589+
8590+
ERROR(execution_behavior_type_attr_incompatible_with_isolated_param,none,
8591+
"cannot use '@%0' together with an isolated parameter",
8592+
(StringRef))
8593+
8594+
ERROR(execution_behavior_type_attr_incompatible_with_isolated_any,none,
8595+
"cannot use '@%0' together with @isolated(any)",
8596+
(StringRef))
85908597

85918598
ERROR(invalid_function_conversion_with_non_sendable,none,
85928599
"cannot convert %0 to %1 because crossing of an isolation boundary "

lib/Sema/TypeCheckAttr.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
208208
}
209209

210210
if (!decl->isAsync()) {
211-
diagnoseAndRemoveAttr(attr, diag::attr_execution_only_on_async, decl);
211+
diagnoseAndRemoveAttr(attr, diag::execution_behavior_only_on_async, attr,
212+
decl);
212213
return;
213214
}
214215

@@ -224,17 +225,18 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
224225
// isolated parameters affect isolation of the function itself
225226
if (isa<IsolatedTypeRepr>(repr)) {
226227
diagnoseAndRemoveAttr(
227-
attr, diag::attr_execution_incompatible_isolated_parameter, decl,
228-
P);
228+
attr, diag::execution_behavior_incompatible_isolated_parameter,
229+
attr, decl, P);
229230
return;
230231
}
231232

232233
if (auto *attrType = dyn_cast<AttributedTypeRepr>(repr)) {
233234
if (attrType->has(TypeAttrKind::Isolated)) {
234235
diagnoseAndRemoveAttr(
235236
attr,
236-
diag::attr_execution_incompatible_dynamically_isolated_parameter,
237-
decl, P);
237+
diag::
238+
execution_behavior_incompatible_dynamically_isolated_parameter,
239+
attr, decl, P);
238240
return;
239241
}
240242
}
@@ -8154,7 +8156,7 @@ class ClosureAttributeChecker
81548156
closure->getAsyncLoc().isInvalid()) {
81558157
ctx.Diags
81568158
.diagnose(attr->getLocation(),
8157-
diag::attr_execution_only_on_async_closure)
8159+
diag::execution_behavior_only_on_async_closure, attr)
81588160
.fixItRemove(attr->getRangeWithAt());
81598161
attr->setInvalid();
81608162
}
@@ -8163,8 +8165,8 @@ class ClosureAttributeChecker
81638165
ctx.Diags
81648166
.diagnose(
81658167
attr->getLocation(),
8166-
diag::attr_execution_type_attr_incompatible_with_global_isolation,
8167-
actorType)
8168+
diag::execution_behavior_attr_incompatible_with_global_isolation,
8169+
attr, actorType)
81688170
.fixItRemove(attr->getRangeWithAt());
81698171
attr->setInvalid();
81708172
}
@@ -8174,7 +8176,8 @@ class ClosureAttributeChecker
81748176
ctx.Diags
81758177
.diagnose(
81768178
attr->getLocation(),
8177-
diag::attr_execution_type_attr_incompatible_with_isolated_param)
8179+
diag::execution_behavior_attr_incompatible_with_isolated_param,
8180+
attr)
81788181
.fixItRemove(attr->getRangeWithAt());
81798182
attr->setInvalid();
81808183
}

lib/Sema/TypeCheckType.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,7 +4198,8 @@ NeverNullType TypeResolver::resolveASTFunctionType(
41984198
if (auto executionAttr = claim<ExecutionTypeAttr>(attrs)) {
41994199
if (!repr->isAsync()) {
42004200
diagnoseInvalid(repr, executionAttr->getAtLoc(),
4201-
diag::attr_execution_type_attr_only_on_async);
4201+
diag::execution_behavior_type_attr_only_on_async,
4202+
executionAttr->getAttrName());
42024203
}
42034204

42044205
switch (isolation.getKind()) {
@@ -4208,20 +4209,22 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42084209
case FunctionTypeIsolation::Kind::GlobalActor:
42094210
diagnoseInvalid(
42104211
repr, executionAttr->getAtLoc(),
4211-
diag::attr_execution_type_attr_incompatible_with_global_isolation,
4212-
isolation.getGlobalActorType());
4212+
diag::execution_behavior_type_attr_incompatible_with_global_isolation,
4213+
executionAttr->getAttrName(), isolation.getGlobalActorType());
42134214
break;
42144215

42154216
case FunctionTypeIsolation::Kind::Parameter:
42164217
diagnoseInvalid(
42174218
repr, executionAttr->getAtLoc(),
4218-
diag::attr_execution_type_attr_incompatible_with_isolated_param);
4219+
diag::execution_behavior_type_attr_incompatible_with_isolated_param,
4220+
executionAttr->getAttrName());
42194221
break;
42204222

42214223
case FunctionTypeIsolation::Kind::Erased:
42224224
diagnoseInvalid(
42234225
repr, executionAttr->getAtLoc(),
4224-
diag::attr_execution_type_attr_incompatible_with_isolated_any);
4226+
diag::execution_behavior_type_attr_incompatible_with_isolated_any,
4227+
executionAttr->getAttrName());
42254228
break;
42264229

42274230
case FunctionTypeIsolation::Kind::NonIsolatedCaller:

test/attr/attr_execution.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@ do {
1717
}
1818

1919
@execution(concurrent) func nonAsync1() {}
20-
// expected-error@-1 {{cannot use '@execution' on non-async global function 'nonAsync1()'}}
20+
// expected-error@-1 {{cannot use '@execution(concurrent)' on non-async global function 'nonAsync1()'}}
2121

2222
@execution(caller) func nonAsync2() {}
23-
// expected-error@-1 {{cannot use '@execution' on non-async global function 'nonAsync2()'}}
23+
// expected-error@-1 {{cannot use '@execution(caller)' on non-async global function 'nonAsync2()'}}
2424

2525
@execution(concurrent) func testGlobal() async {} // Ok
2626

2727
struct Test {
2828
@execution(concurrent) init() {}
29-
// expected-error@-1 {{cannot use '@execution' on non-async initializer 'init()'}}
29+
// expected-error@-1 {{cannot use '@execution(concurrent)' on non-async initializer 'init()'}}
3030

3131
@execution(concurrent) init(async: Void) async {}
3232

3333
@execution(concurrent) func member() {}
34-
// expected-error@-1 {{cannot use '@execution' on non-async instance method 'member()'}}
34+
// expected-error@-1 {{cannot use '@execution(concurrent)' on non-async instance method 'member()'}}
3535

3636
@execution(concurrent) func member() async {} // Ok
3737

3838
@execution(concurrent) var syncP: Int {
39-
// expected-error@-1 {{cannot use '@execution' on non-async property 'syncP'}}
39+
// expected-error@-1 {{cannot use '@execution(concurrent)' on non-async property 'syncP'}}
4040
get {}
4141
}
4242
@execution(concurrent) var asyncP: Int {
4343
get async {}
4444
}
4545

46-
// expected-error@+1 {{cannot use '@execution' on non-async subscript 'subscript(sync:)'}}
46+
// expected-error@+1 {{cannot use '@execution(caller)' on non-async subscript 'subscript(sync:)'}}
4747
@execution(caller) subscript(sync _: Int) -> Bool {
4848
@execution(concurrent) get { false }
4949
// expected-error@-1 {{@execution(concurrent)' attribute cannot be applied to this declaration}}
@@ -72,7 +72,7 @@ do {
7272

7373
protocol P {
7474
@execution(caller) var syncP: Int { get }
75-
// expected-error@-1 {{cannot use '@execution' on non-async property 'syncP'}}
75+
// expected-error@-1 {{cannot use '@execution(caller)' on non-async property 'syncP'}}
7676

7777
@execution(caller) var asyncP: Int { get async }
7878
}
@@ -82,16 +82,16 @@ struct TestAttributeCollisions {
8282
@execution(concurrent) nonisolated func testNonIsolated() async {}
8383

8484
@execution(concurrent) func test(arg: isolated MainActor) async {}
85-
// expected-error@-1 {{cannot use '@execution' on instance method 'test(arg:)' because it has an isolated parameter: 'arg'}}
85+
// expected-error@-1 {{cannot use '@execution(concurrent)' on instance method 'test(arg:)' because it has an isolated parameter: 'arg'}}
8686
@execution(concurrent) subscript(test arg: isolated MainActor) -> Int {
87-
// expected-error@-1 {{cannot use '@execution' on subscript 'subscript(test:)' because it has an isolated parameter: 'arg'}}
87+
// expected-error@-1 {{cannot use '@execution(concurrent)' on subscript 'subscript(test:)' because it has an isolated parameter: 'arg'}}
8888
get async {}
8989
}
9090

9191
@execution(concurrent) func testIsolationAny(arg: @isolated(any) () -> Void) async {}
92-
// expected-error@-1 {{cannot use '@execution' on instance method 'testIsolationAny(arg:)' because it has a dynamically isolated parameter: 'arg'}}
92+
// expected-error@-1 {{cannot use '@execution(concurrent)' on instance method 'testIsolationAny(arg:)' because it has a dynamically isolated parameter: 'arg'}}
9393
@execution(concurrent) subscript(testIsolationAny arg: @isolated(any) () -> Void) -> Int {
94-
// expected-error@-1 {{cannot use '@execution' on subscript 'subscript(testIsolationAny:)' because it has a dynamically isolated parameter: 'arg'}}
94+
// expected-error@-1 {{cannot use '@execution(concurrent)' on subscript 'subscript(testIsolationAny:)' because it has a dynamically isolated parameter: 'arg'}}
9595
get async {}
9696
}
9797

@@ -102,7 +102,7 @@ struct TestAttributeCollisions {
102102
@MainActor @execution(caller) func testGlobalActorCaller() async {}
103103
// expected-warning@-1 {{instance method 'testGlobalActorCaller()' has multiple actor-isolation attributes (@MainActor and @execution(caller))}}
104104
@execution(caller) func testCaller(arg: isolated MainActor) async {}
105-
// expected-error@-1 {{cannot use '@execution' on instance method 'testCaller(arg:)' because it has an isolated parameter: 'arg'}}
105+
// expected-error@-1 {{cannot use '@execution(caller)' on instance method 'testCaller(arg:)' because it has an isolated parameter: 'arg'}}
106106

107107
@execution(concurrent) @Sendable func test(_: @Sendable () -> Void, _: sending Int) async {} // Ok
108108
@execution(caller) @Sendable func testWithSendableCaller(_: @Sendable () -> Void, _: sending Int) async {} // Ok
@@ -129,13 +129,13 @@ _ = { @execution(concurrent) in // Ok
129129
}
130130

131131
_ = { @MainActor @execution(concurrent) in
132-
// expected-error@-1 {{cannot use '@execution' because function type is isolated to a global actor 'MainActor'}}
132+
// expected-error@-1 {{cannot use '@execution(concurrent)' because function type is isolated to a global actor 'MainActor'}}
133133
}
134134

135135
_ = { @execution(concurrent) () -> Int in
136-
// expected-error@-1 {{'@execution' on non-async closure}}
136+
// expected-error@-1 {{'@execution(concurrent)' on non-async closure}}
137137
}
138138

139139
_ = { @execution(caller) (x: isolated (any Actor)?) in
140-
// expected-error@-1 {{cannot use '@execution' together with an isolated parameter}}
140+
// expected-error@-1 {{cannot use '@execution(caller)' together with an isolated parameter}}
141141
}

0 commit comments

Comments
 (0)