Skip to content

Commit cd97415

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 b7d9f0f commit cd97415

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
@@ -8513,40 +8513,47 @@ GROUPED_ERROR(isolated_conformance_wrong_domain,IsolatedConformances,none,
85138513
// MARK: @execution Attribute
85148514
//===----------------------------------------------------------------------===//
85158515
8516-
ERROR(attr_execution_only_on_async,none,
8517-
"cannot use '@execution' on non-async %kind0",
8518-
(ValueDecl *))
8516+
ERROR(execution_behavior_only_on_async,none,
8517+
"cannot use '%0' on non-async %kind1",
8518+
(DeclAttribute, ValueDecl *))
85198519
8520-
ERROR(attr_execution_only_on_async_closure,none,
8521-
"cannot use '@execution' on non-async closure",
8522-
())
8520+
ERROR(execution_behavior_only_on_async_closure,none,
8521+
"cannot use '%0' on non-async closure",
8522+
(DeclAttribute))
85238523
8524-
ERROR(attr_execution_type_attr_only_on_async,none,
8525-
"cannot use '@execution' on non-async function type",
8526-
())
8524+
ERROR(execution_behavior_type_attr_only_on_async,none,
8525+
"cannot use '@%0' on non-async function type",
8526+
(StringRef))
85278527
8528-
ERROR(attr_execution_incompatible_isolated_parameter,none,
8529-
"cannot use '@execution' on %kind0 because it has "
8530-
"an isolated parameter: %1",
8531-
(ValueDecl *, ValueDecl *))
8528+
ERROR(execution_behavior_incompatible_isolated_parameter,none,
8529+
"cannot use '%0' on %kind1 because it has "
8530+
"an isolated parameter: %2",
8531+
(DeclAttribute, ValueDecl *, ValueDecl *))
85328532
8533-
ERROR(attr_execution_incompatible_dynamically_isolated_parameter,none,
8534-
"cannot use '@execution' on %kind0 because it has "
8535-
"a dynamically isolated parameter: %1",
8536-
(ValueDecl *, ValueDecl *))
8533+
ERROR(execution_behavior_incompatible_dynamically_isolated_parameter,none,
8534+
"cannot use '%0' on %kind1 because it has "
8535+
"a dynamically isolated parameter: %2",
8536+
(DeclAttribute, ValueDecl *, ValueDecl *))
85378537
8538-
ERROR(attr_execution_type_attr_incompatible_with_global_isolation,none,
8539-
"cannot use '@execution' because function type is "
8540-
"isolated to a global actor %0",
8541-
(Type))
8538+
ERROR(execution_behavior_attr_incompatible_with_global_isolation,none,
8539+
"cannot use '%0' because function type is isolated to a global actor %1",
8540+
(DeclAttribute, Type))
85428541
8543-
ERROR(attr_execution_type_attr_incompatible_with_isolated_param,none,
8544-
"cannot use '@execution' together with an isolated parameter",
8545-
())
8542+
ERROR(execution_behavior_attr_incompatible_with_isolated_param,none,
8543+
"cannot use '%0' together with an isolated parameter",
8544+
(DeclAttribute))
85468545
8547-
ERROR(attr_execution_type_attr_incompatible_with_isolated_any,none,
8548-
"cannot use '@execution' together with @isolated(any)",
8549-
())
8546+
ERROR(execution_behavior_type_attr_incompatible_with_global_isolation,none,
8547+
"cannot use '@%0' because function type is isolated to a global actor %1",
8548+
(StringRef, Type))
8549+
8550+
ERROR(execution_behavior_type_attr_incompatible_with_isolated_param,none,
8551+
"cannot use '@%0' together with an isolated parameter",
8552+
(StringRef))
8553+
8554+
ERROR(execution_behavior_type_attr_incompatible_with_isolated_any,none,
8555+
"cannot use '@%0' together with @isolated(any)",
8556+
(StringRef))
85508557

85518558
ERROR(invalid_function_conversion_with_non_sendable,none,
85528559
"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
}
@@ -8161,7 +8163,7 @@ class ClosureAttributeChecker
81618163
closure->getAsyncLoc().isInvalid()) {
81628164
ctx.Diags
81638165
.diagnose(attr->getLocation(),
8164-
diag::attr_execution_only_on_async_closure)
8166+
diag::execution_behavior_only_on_async_closure, attr)
81658167
.fixItRemove(attr->getRangeWithAt());
81668168
attr->setInvalid();
81678169
}
@@ -8170,8 +8172,8 @@ class ClosureAttributeChecker
81708172
ctx.Diags
81718173
.diagnose(
81728174
attr->getLocation(),
8173-
diag::attr_execution_type_attr_incompatible_with_global_isolation,
8174-
actorType)
8175+
diag::execution_behavior_attr_incompatible_with_global_isolation,
8176+
attr, actorType)
81758177
.fixItRemove(attr->getRangeWithAt());
81768178
attr->setInvalid();
81778179
}
@@ -8181,7 +8183,8 @@ class ClosureAttributeChecker
81818183
ctx.Diags
81828184
.diagnose(
81838185
attr->getLocation(),
8184-
diag::attr_execution_type_attr_incompatible_with_isolated_param)
8186+
diag::execution_behavior_attr_incompatible_with_isolated_param,
8187+
attr)
81858188
.fixItRemove(attr->getRangeWithAt());
81868189
attr->setInvalid();
81878190
}

lib/Sema/TypeCheckType.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4204,7 +4204,8 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42044204
if (auto executionAttr = claim<ExecutionTypeAttr>(attrs)) {
42054205
if (!repr->isAsync()) {
42064206
diagnoseInvalid(repr, executionAttr->getAtLoc(),
4207-
diag::attr_execution_type_attr_only_on_async);
4207+
diag::execution_behavior_type_attr_only_on_async,
4208+
executionAttr->getAttrName());
42084209
}
42094210

42104211
switch (isolation.getKind()) {
@@ -4214,20 +4215,22 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42144215
case FunctionTypeIsolation::Kind::GlobalActor:
42154216
diagnoseInvalid(
42164217
repr, executionAttr->getAtLoc(),
4217-
diag::attr_execution_type_attr_incompatible_with_global_isolation,
4218-
isolation.getGlobalActorType());
4218+
diag::execution_behavior_type_attr_incompatible_with_global_isolation,
4219+
executionAttr->getAttrName(), isolation.getGlobalActorType());
42194220
break;
42204221

42214222
case FunctionTypeIsolation::Kind::Parameter:
42224223
diagnoseInvalid(
42234224
repr, executionAttr->getAtLoc(),
4224-
diag::attr_execution_type_attr_incompatible_with_isolated_param);
4225+
diag::execution_behavior_type_attr_incompatible_with_isolated_param,
4226+
executionAttr->getAttrName());
42254227
break;
42264228

42274229
case FunctionTypeIsolation::Kind::Erased:
42284230
diagnoseInvalid(
42294231
repr, executionAttr->getAtLoc(),
4230-
diag::attr_execution_type_attr_incompatible_with_isolated_any);
4232+
diag::execution_behavior_type_attr_incompatible_with_isolated_any,
4233+
executionAttr->getAttrName());
42314234
break;
42324235

42334236
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)