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
}

0 commit comments

Comments
 (0)