Skip to content

Commit 5563748

Browse files
committed
Update diagnostic text to address code review feedback
1 parent 90fb57e commit 5563748

19 files changed

+53
-52
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,7 @@ WARNING(add_predates_concurrency_import,none,
26452645
WARNING(remove_predates_concurrency_import,none,
26462646
"'@preconcurrency' attribute on module %0 has no effect", (Identifier))
26472647
NOTE(add_preconcurrency_to_conformance,none,
2648-
"add '@preconcurrency' to the %0 conformance to suppress isolation-related diagnostics", (DeclName))
2648+
"add '@preconcurrency' to the %0 conformance to defer isolation checking to run time", (DeclName))
26492649
WARNING(remove_public_import,none,
26502650
"public import of %0 was not used in public declarations or inlinable code",
26512651
(const ModuleDecl *))
@@ -5578,12 +5578,12 @@ ERROR(shared_immutable_state_decl,none,
55785578
"shared mutable state",
55795579
(Type, const ValueDecl *))
55805580
NOTE(shared_state_make_immutable,none,
5581-
"convert %0 to a 'let' constant to make the shared state immutable",
5581+
"convert %0 to a 'let' constant to make 'Sendable' shared state immutable",
55825582
(const ValueDecl *))
55835583
NOTE(shared_state_main_actor_node,none,
5584-
"restrict %0 to the main actor if it will only be accessed from the main thread", (const ValueDecl *))
5584+
"annotate %0 with '@MainActor' if property should only be accessed from the main actor", (const ValueDecl *))
55855585
NOTE(shared_state_nonisolated_unsafe,none,
5586-
"unsafely mark %0 as concurrency-safe if all accesses are protected by an external synchronization mechanism", (const ValueDecl *))
5586+
"disable concurrency-safety checks if accesses are protected by an external synchronization mechanism", (const ValueDecl *))
55875587
ERROR(actor_isolated_witness,none,
55885588
"%select{|distributed }0%1 %kind2 cannot be used to satisfy %3 protocol "
55895589
"requirement",

include/swift/AST/ProtocolConformance.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ class NormalProtocolConformance : public RootProtocolConformance,
573573
Context(dc) {
574574
assert(!conformingType->hasArchetype() &&
575575
"ProtocolConformances should store interface types");
576+
assert((preconcurrencyLoc.isInvalid() || isPreconcurrency) &&
577+
"Cannot have a @preconcurrency location without isPreconcurrency");
576578
setState(state);
577579
Bits.NormalProtocolConformance.IsInvalid = false;
578580
Bits.NormalProtocolConformance.IsUnchecked = isUnchecked;

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5141,9 +5141,8 @@ void ConformanceChecker::resolveValueWitnesses() {
51415141

51425142
SourceLoc preconcurrencyLoc = Conformance->getPreconcurrencyLoc();
51435143
if (preconcurrencyLoc.isValid()) {
5144-
SourceLoc endLoc =
5145-
preconcurrencyLoc.getAdvancedLoc(strlen("@preconcurrency "));
5146-
diag.fixItRemoveChars(preconcurrencyLoc, endLoc);
5144+
SourceLoc endLoc = preconcurrencyLoc.getAdvancedLoc(1);
5145+
diag.fixItRemove(SourceRange(preconcurrencyLoc, endLoc));
51475146
}
51485147
}
51495148

Lines changed: 2 additions & 2 deletions
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 {{restrict 'member' to the main actor if it will only be accessed from the main thread}}
4-
// expected-complete-note@-2{{unsafely mark 'member' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}
3+
// expected-complete-note@-1 {{annotate 'member' with '@MainActor' if property should only be accessed from the main actor}}
4+
// expected-complete-note@-2{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
55
}

test/Concurrency/actor_isolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ protocol NonisolatedProtocol {
15601560
}
15611561

15621562
actor ActorWithNonSendableLet: NonisolatedProtocol {
1563-
// expected-note@-1{{add '@preconcurrency' to the 'NonisolatedProtocol' conformance to suppress isolation-related diagnostics}}{{32-32=@preconcurrency }}
1563+
// expected-note@-1{{add '@preconcurrency' to the 'NonisolatedProtocol' conformance to defer isolation checking to run time}}{{32-32=@preconcurrency }}
15641564

15651565
// expected-warning@+1 {{actor-isolated property 'ns' cannot be used to satisfy nonisolated protocol requirement; this is an error in the Swift 6 language mode}}
15661566
let ns = NonSendable()

test/Concurrency/concurrency_warnings.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class GlobalCounter { // expected-note{{class 'GlobalCounter' does not conform t
1313
}
1414

1515
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}}
16-
// expected-note@-1 {{restrict 'rs' to the main actor if it will only be accessed from the main thread}}
17-
// expected-note@-2 {{unsafely mark 'rs' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}
16+
// expected-note@-1 {{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
17+
// expected-note@-2 {{annotate 'rs' with '@MainActor' if property should only be accessed from the main actor}}
1818

1919
import GlobalVariables
2020

test/Concurrency/concurrent_value_checking.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ typealias BadGenericCF<T> = @Sendable () -> T?
274274
typealias GoodGenericCF<T: Sendable> = @Sendable () -> T? // okay
275275

276276
var concurrentFuncVar: (@Sendable (NotConcurrent) -> Void)? = nil // expected-warning{{var 'concurrentFuncVar' is not concurrency-safe because it is non-isolated global shared mutable state; this is an error in the Swift 6 language mode}}
277-
// expected-note@-1 {{restrict 'concurrentFuncVar' to the main actor if it will only be accessed from the main thread}}
278-
// expected-note@-2 {{unsafely mark 'concurrentFuncVar' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}
279-
// expected-note@-3 {{convert 'concurrentFuncVar' to a 'let' constant to make the shared state immutable}}
277+
// expected-note@-1 {{annotate 'concurrentFuncVar' with '@MainActor' if property should only be accessed from the main actor}}
278+
// expected-note@-2 {{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
279+
// expected-note@-3 {{convert 'concurrentFuncVar' to a 'let' constant to make 'Sendable' shared state immutable}}
280280

281281
// ----------------------------------------------------------------------
282282
// Sendable restriction on @Sendable closures.

test/Concurrency/flow_isolation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ struct CardboardBox<T> {
520520

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

527527
@available(SwiftStdlib 5.1, *)
528528
actor EscapeArtist {

test/Concurrency/freestanding_top_level.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
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 non-isolated global shared mutable state; this is an error in the Swift 6 language mode}}
5-
// expected-complete-note@+3 {{restrict 'global' to the main actor if it will only be accessed from the main thread}}{{1-1=@MainActor }}
6-
// expected-complete-note@+2 {{unsafely mark 'global' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}{{1-1=nonisolated(unsafe) }}
7-
// expected-complete-note@+1 {{convert 'global' to a 'let' constant to make the shared state immutable}}{{1-4=let}}
5+
// expected-complete-note@+3 {{annotate 'global' with '@MainActor' if property should only be accessed from the main actor}}{{1-1=@MainActor }}
6+
// expected-complete-note@+2 {{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}{{1-1=nonisolated(unsafe) }}
7+
// expected-complete-note@+1 {{convert 'global' to a 'let' constant to make 'Sendable' shared state immutable}}{{1-4=let}}
88
var global = 10
99

1010
// No warning because we're in the same module.

test/Concurrency/global_actor_inference.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protocol Interface {
117117

118118
@MainActor
119119
class Object: Interface {
120-
// expected-note@-1{{add '@preconcurrency' to the 'Interface' conformance to suppress isolation-related diagnostics}}{{15-15=@preconcurrency }}
120+
// expected-note@-1{{add '@preconcurrency' to the 'Interface' conformance to defer isolation checking to run time}}{{15-15=@preconcurrency }}
121121

122122
var baz: Int = 42 // expected-warning{{main actor-isolated property 'baz' cannot be used to satisfy nonisolated protocol requirement}}
123123
}

test/Concurrency/global_variables.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ actor TestGlobalActor {
1515
var mutableIsolatedGlobal = 1
1616

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

2222
let immutableGlobal = 1
2323

@@ -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 {{restrict 'immutableNonsendable' to the main actor if it will only be accessed from the main thread}}
52-
// expected-note@-2 {{unsafely mark 'immutableNonsendable' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}
51+
// expected-note@-1 {{annotate 'immutableNonsendable' with '@MainActor' if property should only be accessed from the main actor}}
52+
// 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}}
55-
// expected-note@-1 {{restrict 'immutableNonisolated' to the main actor if it will only be accessed from the main thread}}
55+
// 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{{unsafely mark 'immutableNonisolated' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}
57+
// expected-note@-3{{annotate 'immutableNonisolated' with '@MainActor' if property should only be accessed from the main actor}}
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 non-isolated global shared mutable state}}
62-
// expected-note@-1{{convert 'mutable' to a 'let' constant to make the shared state immutable}}
63-
// expected-note@-2{{unsafely mark 'mutable' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}
64-
// expected-note@-3{{restrict 'mutable' to the main actor if it will only be accessed from the main thread}}
62+
// expected-note@-1{{convert 'mutable' to a 'let' constant to make 'Sendable' shared state immutable}}
63+
// 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}}
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 non-isolated global shared mutable state}}
67-
// expected-note@-1{{convert 'wrapped' to a 'let' constant to make the shared state immutable}}{{23-26=let}}
68-
// expected-note@-2{{unsafely mark 'wrapped' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}{{16-16=nonisolated(unsafe) }}
69-
// expected-note@-3{{restrict 'wrapped' to the main actor if it will only be accessed from the main thread}}{{3-3=@MainActor }}
67+
// expected-note@-1{{convert 'wrapped' to a 'let' constant to make 'Sendable' shared state immutable}}{{23-26=let}}
68+
// 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 }}
7070
}
7171

7272
public actor TestPublicActor {

test/Concurrency/preconcurrency_conformances.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ final class K : @preconcurrency Initializable {
101101

102102
@MainActor
103103
final class MainActorK: Initializable {
104-
// expected-note@-1{{add '@preconcurrency' to the 'Initializable' conformance to suppress isolation-related diagnostics}}{{25-25=@preconcurrency }}
104+
// expected-note@-1{{add '@preconcurrency' to the 'Initializable' conformance to defer isolation checking to run time}}{{25-25=@preconcurrency }}
105105
init() { } // expected-warning{{main actor-isolated initializer 'init()' cannot be used to satisfy nonisolated protocol requirement}}
106106
// expected-note@-1{{add 'nonisolated' to 'init()' to make this initializer not isolated to the actor}}
107107
}

test/Concurrency/predates_concurrency.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protocol NotIsolated {
231231

232232
extension MainActorPreconcurrency: NotIsolated {
233233
// expected-complete-note@-1{{add '@preconcurrency' to the 'NotIsolated' conformance to suppress isolation-related diagnostics}}{{36-36=@preconcurrency }}
234-
// expected-complete-tns-note@-2{{add '@preconcurrency' to the 'NotIsolated' conformance to suppress isolation-related diagnostics}}{{36-36=@preconcurrency }}
234+
// expected-complete-tns-note@-2{{add '@preconcurrency' to the 'NotIsolated' conformance to defer isolation checking to run time}}{{36-36=@preconcurrency }}
235235

236236
func requirement() {}
237237
// expected-complete-tns-warning@-1 {{main actor-isolated instance method 'requirement()' cannot be used to satisfy nonisolated protocol requirement}}

test/Concurrency/predates_concurrency_import.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func test(
4444
let nonStrictGlobal = NonStrictClass() // no warning
4545

4646
let strictGlobal = StrictStruct() // expected-warning{{let 'strictGlobal' is not concurrency-safe because non-'Sendable' type 'StrictStruct' may have shared mutable state}}
47-
// expected-note@-1{{restrict 'strictGlobal' to the main actor if it will only be accessed from the main thread}}
48-
// expected-note@-2{{unsafely mark 'strictGlobal' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}
47+
// expected-note@-1{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
48+
// expected-note@-2{{annotate 'strictGlobal' with '@MainActor' if property should only be accessed from the main actor}}
4949

5050
extension NonStrictClass {
5151
@Sendable func f() { }
@@ -62,8 +62,8 @@ struct HasStatics {
6262
nonisolated static let ss: StrictStruct = StrictStruct()
6363
// expected-warning@-1{{'nonisolated' can not be applied to variable with non-'Sendable' type 'StrictStruct'}}
6464
// expected-warning@-2{{static property 'ss' is not concurrency-safe because non-'Sendable' type 'StrictStruct' may have shared mutable state}}
65-
// expected-note@-3{{restrict 'ss' to the main actor if it will only be accessed from the main thread}}
66-
// expected-note@-4{{unsafely mark 'ss' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}
65+
// expected-note@-3{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
66+
// expected-note@-4{{annotate 'ss' with '@MainActor' if property should only be accessed from the main actor}}
6767
}
6868

6969
extension NonStrictClass2: @retroactive MySendableProto { }

test/Concurrency/predates_concurrency_import_swift6.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ 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{{restrict 'strictGlobal' to the main actor if it will only be accessed from the main thread}}
22-
// expected-note@-2{{unsafely mark 'strictGlobal' as concurrency-safe if all accesses are protected by an external synchronization mechanism}}
21+
// expected-note@-1{{annotate 'strictGlobal' with '@MainActor' if property should only be accessed from the main actor}}
22+
// expected-note@-2{{disable concurrency-safety checks if accesses are protected by an external synchronization mechanism}}
2323

2424
extension NonStrictClass {
2525
@Sendable func f() { }

test/Distributed/distributed_protocol_isolation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protocol StrictlyLocal {
106106
}
107107

108108
distributed actor Nope1_StrictlyLocal: StrictlyLocal {
109-
// expected-note@-1{{add '@preconcurrency' to the 'StrictlyLocal' conformance to suppress isolation-related diagnostics}}
109+
// expected-note@-1{{add '@preconcurrency' to the 'StrictlyLocal' conformance to defer isolation checking to run time}}
110110

111111
func local() {}
112112
// expected-error@-1{{distributed actor-isolated instance method 'local()' cannot be used to satisfy nonisolated protocol requirement}}
@@ -159,7 +159,7 @@ actor LocalOK_ImplicitlyThrowsAsync_AsyncThrowsAll: AsyncThrowsAll {
159159
}
160160

161161
distributed actor Nope1_AsyncThrowsAll: AsyncThrowsAll {
162-
// expected-note@-1{{add '@preconcurrency' to the 'AsyncThrowsAll' conformance to suppress isolation-related diagnostics}}
162+
// expected-note@-1{{add '@preconcurrency' to the 'AsyncThrowsAll' conformance to defer isolation checking to run time}}
163163

164164
func maybe(param: String, int: Int) async throws -> Int { 111 }
165165
// expected-error@-1{{distributed actor-isolated instance method 'maybe(param:int:)' cannot be used to satisfy nonisolated protocol requirement}}
@@ -206,7 +206,7 @@ func test_watching_A(a: A_TerminationWatchingA) async throws {
206206
}
207207

208208
distributed actor DA_TerminationWatchingA: TerminationWatchingA {
209-
// expected-note@-1{{add '@preconcurrency' to the 'TerminationWatchingA' conformance to suppress isolation-related diagnostics}}
209+
// expected-note@-1{{add '@preconcurrency' to the 'TerminationWatchingA' conformance to defer isolation checking to run time}}
210210

211211
func terminated(a: String) { }
212212
// expected-error@-1{{distributed actor-isolated instance method 'terminated(a:)' cannot be used to satisfy nonisolated protocol requirement}}

0 commit comments

Comments
 (0)