Skip to content

Commit 6a9afa5

Browse files
committed
[concurrency] Add back support for checking if we have a global actor/execution together.
1 parent 3415189 commit 6a9afa5

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5966,6 +5966,9 @@ ERROR(actor_isolation_multiple_attr_2,none,
59665966
ERROR(actor_isolation_multiple_attr_3,none,
59675967
"%0 %1 has multiple actor-isolation attributes ('%2', '%3' and '%4')",
59685968
(const Decl *, StringRef, StringRef, StringRef))
5969+
ERROR(actor_isolation_multiple_attr_4,none,
5970+
"%0 %1 has multiple actor-isolation attributes ('%2', '%3', '%4', and '%5')",
5971+
(const Decl *, StringRef, StringRef, StringRef, StringRef))
59695972
ERROR(actor_isolation_override_mismatch,none,
59705973
"%0 %kind1 has different actor isolation from %2 overridden declaration",
59715974
(ActorIsolation, const ValueDecl *, ActorIsolation))

lib/Sema/TypeCheckAttr.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4411,6 +4411,7 @@ static void checkGlobalActorAttr(
44114411
std::pair<CustomAttr *, NominalTypeDecl *> &globalActorAttr) {
44124412
auto isolatedAttr = decl->getAttrs().getAttribute<IsolatedAttr>();
44134413
auto nonisolatedAttr = decl->getAttrs().getAttribute<NonisolatedAttr>();
4414+
auto executionAttr = decl->getAttrs().getAttribute<ExecutionAttr>();
44144415
struct NameAndRange {
44154416
StringRef name;
44164417
SourceRange range;
@@ -4419,7 +4420,7 @@ static void checkGlobalActorAttr(
44194420
: name(_name), range(_range) {}
44204421
};
44214422

4422-
llvm::SmallVector<NameAndRange, 3> attributes;
4423+
llvm::SmallVector<NameAndRange, 4> attributes;
44234424

44244425
attributes.push_back(NameAndRange(globalActorAttr.second->getName().str(),
44254426
globalActorAttr.first->getRangeWithAt()));
@@ -4432,6 +4433,11 @@ static void checkGlobalActorAttr(
44324433
attributes.push_back(NameAndRange(nonisolatedAttr->getAttrName(),
44334434
nonisolatedAttr->getRangeWithAt()));
44344435
}
4436+
if (executionAttr) {
4437+
attributes.push_back(NameAndRange(executionAttr->getAttrName(),
4438+
executionAttr->getRangeWithAt()));
4439+
}
4440+
44354441
if (attributes.size() == 1)
44364442
return;
44374443

@@ -4442,9 +4448,10 @@ static void checkGlobalActorAttr(
44424448
.highlight(attributes[1].range)
44434449
.warnUntilSwiftVersion(6)
44444450
.fixItRemove(attributes[1].range);
4451+
return;
4452+
}
44454453

4446-
} else {
4447-
assert(attributes.size() == 3);
4454+
if (attributes.size() == 3) {
44484455
decl->diagnose(diag::actor_isolation_multiple_attr_3, decl,
44494456
attributes[0].name, attributes[1].name, attributes[2].name)
44504457
.highlight(attributes[0].range)
@@ -4453,7 +4460,21 @@ static void checkGlobalActorAttr(
44534460
.warnUntilSwiftVersion(6)
44544461
.fixItRemove(attributes[1].range)
44554462
.fixItRemove(attributes[2].range);
4463+
return;
44564464
}
4465+
4466+
assert(attributes.size() == 4);
4467+
decl->diagnose(diag::actor_isolation_multiple_attr_4, decl,
4468+
attributes[0].name, attributes[1].name, attributes[2].name,
4469+
attributes[3].name)
4470+
.highlight(attributes[0].range)
4471+
.highlight(attributes[1].range)
4472+
.highlight(attributes[2].range)
4473+
.highlight(attributes[3].range)
4474+
.warnUntilSwiftVersion(6)
4475+
.fixItRemove(attributes[1].range)
4476+
.fixItRemove(attributes[2].range)
4477+
.fixItRemove(attributes[3].range);
44574478
}
44584479

44594480
void AttributeChecker::visitCustomAttr(CustomAttr *attr) {

test/attr/attr_execution.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct TestAttributeCollisions {
5151
// expected-error@-1 {{cannot use '@execution(concurrent)' on instance method 'testIsolationAny(arg:)' because it has a dynamically isolated parameter: 'arg'}}
5252

5353
@MainActor @execution(concurrent) func testGlobalActor() async {}
54+
// expected-warning @-1 {{instance method 'testGlobalActor()' has multiple actor-isolation attributes ('MainActor' and 'execution(concurrent)')}}
5455

5556
@execution(concurrent) @Sendable func test(_: @Sendable () -> Void, _: sending Int) async {} // Ok
5657
}

0 commit comments

Comments
 (0)