Skip to content

Commit c89ba5f

Browse files
committed
[Sema] Diagnose clash between inferred global actor isolation and @execution(concurrent)
1 parent b1e30b2 commit c89ba5f

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8220,7 +8220,7 @@ ERROR(attr_execution_concurrent_only_on_async,none,
82208220

82218221
ERROR(attr_execution_concurrent_incompatible_with_global_actor,none,
82228222
"cannot use '@execution(concurrent)' on %kind0 isolated to global actor %1",
8223-
(ValueDecl *, ValueDecl *))
8223+
(ValueDecl *, Type))
82248224

82258225
ERROR(attr_execution_concurrent_incompatible_isolated_parameter,none,
82268226
"cannot use '@execution(concurrent)' on %kind0 because it has "

lib/Sema/TypeCheckAttr.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
264264
return;
265265
}
266266

267-
// Checks based on explicit attributes, inferred ones would
268-
// have to be handled during actor isolation inference.
269-
270267
switch (attr->getBehavior()) {
271268
case ExecutionKind::Concurrent: {
272269
// 'concurrent' doesn't work with explicit `nonisolated`
@@ -277,14 +274,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
277274
diag::attr_execution_concurrent_incompatible_with_nonisolated, F);
278275
return;
279276
}
280-
281-
if (auto globalActor = F->getGlobalActorAttr()) {
282-
diagnoseAndRemoveAttr(
283-
attr,
284-
diag::attr_execution_concurrent_incompatible_with_global_actor, F,
285-
globalActor->second);
286-
return;
287-
}
288277
}
289278

290279
auto parameters = F->getParameters();
@@ -317,6 +306,18 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
317306
}
318307
}
319308

309+
// We need isolation check here because global actor isolation
310+
// could be inferred.
311+
312+
auto isolation = getActorIsolation(F);
313+
if (isolation.isGlobalActor()) {
314+
diagnoseAndRemoveAttr(
315+
attr,
316+
diag::attr_execution_concurrent_incompatible_with_global_actor, F,
317+
isolation.getGlobalActor());
318+
return;
319+
}
320+
320321
break;
321322
}
322323

test/attr/attr_execution.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,19 @@ struct TestAttributeCollisions {
5555

5656
@execution(concurrent) @Sendable func test(_: @Sendable () -> Void, _: sending Int) async {} // Ok
5757
}
58+
59+
@MainActor
60+
protocol P {
61+
func test() async
62+
}
63+
64+
struct InfersMainActor : P {
65+
@execution(concurrent) func test() async {}
66+
// expected-error@-1 {{cannot use '@execution(concurrent)' on instance method 'test()' isolated to global actor 'MainActor'}}
67+
}
68+
69+
@MainActor
70+
struct IsolatedType {
71+
@execution(concurrent) func test() async {}
72+
// expected-error@-1 {{cannot use '@execution(concurrent)' on instance method 'test()' isolated to global actor 'MainActor'}}
73+
}

0 commit comments

Comments
 (0)