Skip to content

Commit 2c1e45a

Browse files
committed
Changed note main actor variables
1 parent c11b301 commit 2c1e45a

10 files changed

+24
-22
lines changed

include/swift/AST/DiagnosticsSema.def

+1-3
Original file line numberDiff line numberDiff line change
@@ -5393,7 +5393,7 @@ NOTE(note_add_distributed_to_decl,none,
53935393
ERROR(invalid_isolated_calls_in_body,none,
53945394
"calls to '@%0'-isolated' code in %kind1",
53955395
(StringRef, const ValueDecl *))
5396-
NOTE(add_globalactor_to_function,none,
5396+
NOTE(add_globalactor_to_decl,none,
53975397
"add '@%0' to make %kind1 part of global actor %2",
53985398
(StringRef, const ValueDecl *, Type))
53995399
FIXIT(insert_globalactor_attr, "@%0 ", (Type))
@@ -5645,8 +5645,6 @@ ERROR(shared_immutable_state_decl,none,
56455645
NOTE(shared_state_make_immutable,none,
56465646
"convert %0 to a 'let' constant to make 'Sendable' shared state immutable",
56475647
(const ValueDecl *))
5648-
NOTE(shared_state_main_actor_node,none,
5649-
"annotate %0 with '@MainActor' if property should only be accessed from the main actor", (const ValueDecl *))
56505648
NOTE(shared_state_nonisolated_unsafe,none,
56515649
"disable concurrency-safety checks if accesses are protected by an external synchronization mechanism", (const ValueDecl *))
56525650
ERROR(actor_isolated_witness,none,

lib/Sema/TypeCheckConcurrency.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -2436,7 +2436,7 @@ namespace {
24362436
if (fn->getOverriddenDecl())
24372437
return false;
24382438

2439-
fn->diagnose(diag::add_globalactor_to_function,
2439+
fn->diagnose(diag::add_globalactor_to_decl,
24402440
globalActor->getWithoutParens().getString(),
24412441
fn, globalActor)
24422442
.fixItInsert(fn->getAttributeInsertionLoc(false),
@@ -5403,7 +5403,7 @@ ActorIsolation ActorIsolationRequest::evaluate(
54035403

54045404
// Diagnose global state that is not either immutable plus Sendable or
54055405
// isolated to a global actor.
5406-
auto checkGlobalIsolation = [var = dyn_cast<VarDecl>(value)](
5406+
auto checkGlobalIsolation = [var = dyn_cast<VarDecl>(value), &ctx](
54075407
ActorIsolation isolation) {
54085408
// Diagnose only declarations in the same module.
54095409
//
@@ -5447,10 +5447,14 @@ ActorIsolation ActorIsolationRequest::evaluate(
54475447
}
54485448
}
54495449

5450-
diagVar->diagnose(diag::shared_state_main_actor_node,
5451-
diagVar)
5452-
.fixItInsert(diagVar->getAttributeInsertionLoc(false),
5453-
"@MainActor ");
5450+
auto mainActor = ctx.getMainActorType();
5451+
if (mainActor) {
5452+
diagVar->diagnose(diag::add_globalactor_to_decl,
5453+
mainActor->getWithoutParens().getString(),
5454+
diagVar, mainActor)
5455+
.fixItInsert(diagVar->getAttributeInsertionLoc(false),
5456+
diag::insert_globalactor_attr, mainActor);
5457+
}
54545458
diagVar->diagnose(diag::shared_state_nonisolated_unsafe,
54555459
diagVar)
54565460
.fixItInsert(diagVar->getAttributeInsertionLoc(true),
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct Foo {
22
static let member = Bar() // expected-complete-warning {{static property 'member' is not concurrency-safe because non-'Sendable' type 'Bar' may have shared mutable state; this is an error in the Swift 6 language mode}}
3-
// expected-complete-note@-1 {{annotate 'member' with '@MainActor' if property should only be accessed from the main actor}}
3+
// expected-complete-note@-1 {{add '@MainActor' to make static property 'member' part of global actor 'MainActor'}}
44
// expected-complete-note@-2{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
55
}

test/Concurrency/concurrency_warnings.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GlobalCounter { // expected-note{{class 'GlobalCounter' does not conform t
1313

1414
let rs = GlobalCounter() // expected-warning {{let 'rs' is not concurrency-safe because non-'Sendable' type 'GlobalCounter' may have shared mutable state; this is an error in the Swift 6 language mode}}
1515
// expected-note@-1 {{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
16-
// expected-note@-2 {{annotate 'rs' with '@MainActor' if property should only be accessed from the main actor}}
16+
// expected-note@-2 {{add '@MainActor' to make let 'rs' part of global actor 'MainActor'}}
1717

1818
import GlobalVariables
1919

test/Concurrency/concurrent_value_checking.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ typealias BadGenericCF<T> = @Sendable () -> T?
295295
typealias GoodGenericCF<T: Sendable> = @Sendable () -> T? // okay
296296

297297
var concurrentFuncVar: (@Sendable (NotConcurrent) -> Void)? = nil // expected-warning{{var 'concurrentFuncVar' is not concurrency-safe because it is nonisolated global shared mutable state; this is an error in the Swift 6 language mode}}
298-
// expected-note@-1 {{annotate 'concurrentFuncVar' with '@MainActor' if property should only be accessed from the main actor}}
298+
// expected-note@-1 {{add '@MainActor' to make var 'concurrentFuncVar' part of global actor 'MainActor'}}
299299
// expected-note@-2 {{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
300300
// expected-note@-3 {{convert 'concurrentFuncVar' to a 'let' constant to make 'Sendable' shared state immutable}}
301301

test/Concurrency/flow_isolation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ struct CardboardBox<T> {
520520

521521
@available(SwiftStdlib 5.1, *)
522522
var globalVar: EscapeArtist? // expected-warning {{var 'globalVar' is not concurrency-safe because it is nonisolated global shared mutable state; this is an error in the Swift 6 language mode}}
523-
// expected-note@-1 {{annotate 'globalVar' with '@MainActor' if property should only be accessed from the main actor}}
523+
// expected-note@-1 {{add '@MainActor' to make var 'globalVar' part of global actor 'MainActor'}}
524524
// expected-note@-2 {{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
525525
// expected-note@-3 {{convert 'globalVar' to a 'let' constant to make 'Sendable' shared state immutable}}
526526

test/Concurrency/freestanding_top_level.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %target-swift-frontend -concurrency-model=task-to-thread -typecheck -verify -verify-additional-prefix complete- -strict-concurrency=complete %s
33

44
// expected-complete-warning@+4 {{var 'global' is not concurrency-safe because it is nonisolated global shared mutable state; this is an error in the Swift 6 language mode}}
5-
// expected-complete-note@+3 {{annotate 'global' with '@MainActor' if property should only be accessed from the main actor}}{{1-1=@MainActor }}
5+
// expected-complete-note@+3 {{add '@MainActor' to make var 'global' part of global actor 'MainActor'}}{{1-1=@MainActor }}
66
// expected-complete-note@+2 {{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}{{1-1=nonisolated(unsafe) }}
77
// expected-complete-note@+1 {{convert 'global' to a 'let' constant to make 'Sendable' shared state immutable}}{{1-4=let}}
88
var global = 10

test/Concurrency/global_variables.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ actor TestGlobalActor {
1515
var mutableIsolatedGlobal = 1
1616

1717
var mutableNonisolatedGlobal = 1 // expected-error{{var 'mutableNonisolatedGlobal' is not concurrency-safe because it is nonisolated global shared mutable state}}
18-
// expected-note@-1{{annotate 'mutableNonisolatedGlobal' with '@MainActor' if property should only be accessed from the main actor}}{{1-1=@MainActor }}
18+
// expected-note@-1{{add '@MainActor' to make var 'mutableNonisolatedGlobal' part of global actor 'MainActor'}}{{1-1=@MainActor }}
1919
// expected-note@-2{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}{{1-1=nonisolated(unsafe) }}
2020
// expected-note@-3{{convert 'mutableNonisolatedGlobal' to a 'let' constant to make 'Sendable' shared state immutable}}{{1-4=let}}
2121

@@ -48,25 +48,25 @@ actor TestActor {
4848
struct TestStatics {
4949
static let immutableExplicitSendable = TestSendable()
5050
static let immutableNonsendable = TestNonsendable() // expected-error{{static property 'immutableNonsendable' is not concurrency-safe because non-'Sendable' type 'TestNonsendable' may have shared mutable state}}
51-
// expected-note@-1 {{annotate 'immutableNonsendable' with '@MainActor' if property should only be accessed from the main actor}}
51+
// expected-note@-1 {{add '@MainActor' to make static property 'immutableNonsendable' part of global actor 'MainActor'}}
5252
// expected-note@-2 {{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
5353
static nonisolated(unsafe) let immutableNonisolatedUnsafe = TestNonsendable()
5454
static nonisolated let immutableNonisolated = TestNonsendable() // expected-error{{static property 'immutableNonisolated' is not concurrency-safe because non-'Sendable' type 'TestNonsendable' may have shared mutable state}}
5555
// expected-note@-1 {{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
5656
// expected-error@-2 {{'nonisolated' can not be applied to variable with non-'Sendable' type 'TestNonsendable'}}
57-
// expected-note@-3{{annotate 'immutableNonisolated' with '@MainActor' if property should only be accessed from the main actor}}
57+
// expected-note@-3{{add '@MainActor' to make static property 'immutableNonisolated' part of global actor 'MainActor'}}
5858
static nonisolated(unsafe) let immutableNonisolatedUnsafeSendable = TestSendable()
5959
// expected-warning@-1 {{'nonisolated(unsafe)' is unnecessary for a constant with 'Sendable' type 'TestSendable', consider removing it}} {{10-30=}}
6060
static let immutableInferredSendable = 0
6161
static var mutable = 0 // expected-error{{static property 'mutable' is not concurrency-safe because it is nonisolated global shared mutable state}}
6262
// expected-note@-1{{convert 'mutable' to a 'let' constant to make 'Sendable' shared state immutable}}
6363
// expected-note@-2{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
64-
// expected-note@-3{{annotate 'mutable' with '@MainActor' if property should only be accessed from the main actor}}
64+
// expected-note@-3{{add '@MainActor' to make static property 'mutable' part of global actor 'MainActor'}}
6565
static var computedProperty: Int { 0 } // computed property that, though static, has no storage so is not a global
6666
@TestWrapper static var wrapped: Int // expected-error{{static property 'wrapped' is not concurrency-safe because it is nonisolated global shared mutable state}}
6767
// expected-note@-1{{convert 'wrapped' to a 'let' constant to make 'Sendable' shared state immutable}}{{23-26=let}}
6868
// expected-note@-2{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}{{16-16=nonisolated(unsafe) }}
69-
// expected-note@-3{{annotate 'wrapped' with '@MainActor' if property should only be accessed from the main actor}}{{3-3=@MainActor }}
69+
// expected-note@-3{{add '@MainActor' to make static property 'wrapped' part of global actor 'MainActor'}}{{3-3=@MainActor }}
7070
}
7171

7272
public actor TestPublicActor {

test/Concurrency/predates_concurrency_import.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let nonStrictGlobal = NonStrictClass() // no warning
4444

4545
let strictGlobal = StrictStruct() // expected-warning{{let 'strictGlobal' is not concurrency-safe because non-'Sendable' type 'StrictStruct' may have shared mutable state}}
4646
// expected-note@-1{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
47-
// expected-note@-2{{annotate 'strictGlobal' with '@MainActor' if property should only be accessed from the main actor}}
47+
// expected-note@-2{{add '@MainActor' to make let 'strictGlobal' part of global actor 'MainActor'}}
4848

4949
extension NonStrictClass {
5050
@Sendable func f() { }
@@ -62,7 +62,7 @@ struct HasStatics {
6262
// expected-warning@-1{{'nonisolated' can not be applied to variable with non-'Sendable' type 'StrictStruct'}}
6363
// expected-warning@-2{{static property 'ss' is not concurrency-safe because non-'Sendable' type 'StrictStruct' may have shared mutable state}}
6464
// expected-note@-3{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
65-
// expected-note@-4{{annotate 'ss' with '@MainActor' if property should only be accessed from the main actor}}
65+
// expected-note@-4{{add '@MainActor' to make static property 'ss' part of global actor 'MainActor'}}
6666
}
6767

6868
extension NonStrictClass2: @retroactive MySendableProto { }

test/Concurrency/predates_concurrency_import_swift6.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func test(ss: StrictStruct, ns: NonStrictClass) {
1818

1919
let nonStrictGlobal = NonStrictClass()
2020
let strictGlobal = StrictStruct() // expected-warning{{let 'strictGlobal' is not concurrency-safe because non-'Sendable' type 'StrictStruct' may have shared mutable state}}
21-
// expected-note@-1{{annotate 'strictGlobal' with '@MainActor' if property should only be accessed from the main actor}}
21+
// expected-note@-1{{add '@MainActor' to make let 'strictGlobal' part of global actor 'MainActor'}}
2222
// expected-note@-2{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
2323

2424
extension NonStrictClass {

0 commit comments

Comments
 (0)