Skip to content

Commit dd0efd0

Browse files
committed
address review feedback and improve diagnostic detail
1 parent 137a6d8 commit dd0efd0

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5243,15 +5243,15 @@ NOTE(actor_mutable_state,none,
52435243
WARNING(shared_mutable_state_access,none,
52445244
"reference to %kind0 is not concurrency-safe because it involves "
52455245
"shared mutable state", (const ValueDecl *))
5246-
ERROR(shared_mutable_state_decl,none,
5247-
"%kind0 is not concurrency-safe because it is global shared mutable "
5248-
"state", (const ValueDecl *))
5246+
WARNING(shared_mutable_state_decl,none,
5247+
"%kind0 is not concurrency-safe because it is non-isolated global "
5248+
"shared mutable state", (const ValueDecl *))
52495249
NOTE(shared_mutable_state_decl_note,none,
5250-
"isolate %0 to a global actor, or convert it to a constant",
5251-
(const ValueDecl *))
5252-
ERROR(shared_non_sendable_decl,none,
5253-
"%kind0 is not concurrency-safe because it does not conform to "
5254-
"'Sendable'", (const ValueDecl *))
5250+
"isolate %0 to a global actor, or convert it to a 'let' constant and "
5251+
"conform it to 'Sendable'", (const ValueDecl *))
5252+
WARNING(shared_immutable_state_decl,none,
5253+
"%kind0 is not concurrency-safe because it is not either conforming to "
5254+
"'Sendable' or isolated to a global actor", (const ValueDecl *))
52555255
ERROR(actor_isolated_witness,none,
52565256
"%select{|distributed }0%1 %kind2 cannot be used to satisfy %3 protocol "
52575257
"requirement",

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4083,18 +4083,14 @@ ActorIsolation ActorIsolationRequest::evaluate(
40834083
auto *classDecl = var->getDeclContext()->getSelfClassDecl();
40844084
const bool isActorType = classDecl && classDecl->isAnyActor();
40854085
if (isGlobalState && !isActorType) {
4086-
auto &ctx = var->getASTContext();
40874086
if (var->isLet()) {
40884087
if (!isSendableType(var->getModuleContext(),
40894088
var->getInterfaceType())) {
4090-
ctx.Diags.diagnose(var->getLoc(), diag::shared_non_sendable_decl,
4091-
var);
4089+
var->diagnose(diag::shared_immutable_state_decl, var);
40924090
}
40934091
} else {
4094-
ctx.Diags.diagnose(var->getLoc(), diag::shared_mutable_state_decl,
4095-
var);
4096-
ctx.Diags.diagnose(var->getLoc(),
4097-
diag::shared_mutable_state_decl_note, var);
4092+
var->diagnose(diag::shared_mutable_state_decl, var);
4093+
var->diagnose(diag::shared_mutable_state_decl_note, var);
40984094
}
40994095
}
41004096
}

test/Concurrency/experimental_feature_strictconcurrency.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,25 @@ actor TestGlobalActor {
2929
@TestGlobalActor
3030
var mutableIsolatedGlobal = 1
3131

32-
var mutableNonisolatedGlobal = 1 // expected-error{{var 'mutableNonisolatedGlobal' is not concurrency-safe because it is global shared mutable state}}
33-
// expected-note@-1{{isolate 'mutableNonisolatedGlobal' to a global actor, or convert it to a constant}}
32+
var mutableNonisolatedGlobal = 1 // expected-warning{{var 'mutableNonisolatedGlobal' is not concurrency-safe because it is non-isolated global shared mutable state}}
33+
// expected-note@-1{{isolate 'mutableNonisolatedGlobal' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
3434

3535
let immutableGlobal = 1
3636

3737
final class TestSendable: Sendable {
3838
init() {}
3939
}
4040

41+
final class TestNonsendable {
42+
init() {}
43+
}
44+
4145
struct A {
4246
static let immutableExplicitSendable = TestSendable()
47+
static let immutableNonsendableGlobal = TestNonsendable() // expected-warning{{static property 'immutableNonsendableGlobal' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor}}
4348
static let immutableInferredSendable = 0
44-
static var mutable = 0 // expected-error{{static property 'mutable' is not concurrency-safe because it is global shared mutable state}}
45-
// expected-note@-1{{isolate 'mutable' to a global actor, or convert it to a constant}}
49+
static var mutable = 0 // expected-warning{{static property 'mutable' is not concurrency-safe because it is non-isolated global shared mutable state}}
50+
// expected-note@-1{{isolate 'mutable' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
4651
// expected-note@-2{{static property declared here}}
4752
}
4853

0 commit comments

Comments
 (0)