Skip to content

Commit 4abb567

Browse files
committed
[Concurrency] correct some strict concurrency warnings to be errors in Swift 6
1 parent dd9fe56 commit 4abb567

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5518,18 +5518,18 @@ ERROR(distributed_actor_remote_func_must_not_be_distributed,none,
55185518
NOTE(actor_mutable_state,none,
55195519
"mutation of this %0 is only permitted within the actor",
55205520
(DescriptiveDeclKind))
5521-
WARNING(shared_mutable_state_access,none,
5522-
"reference to %kind0 is not concurrency-safe because it involves "
5523-
"shared mutable state", (const ValueDecl *))
5524-
WARNING(shared_mutable_state_decl,none,
5525-
"%kind0 is not concurrency-safe because it is non-isolated global "
5526-
"shared mutable state", (const ValueDecl *))
5521+
ERROR(shared_mutable_state_access,none,
5522+
"reference to %kind0 is not concurrency-safe because it involves shared "
5523+
"mutable state", (const ValueDecl *))
5524+
ERROR(shared_mutable_state_decl,none,
5525+
"%kind0 is not concurrency-safe because it is non-isolated global shared "
5526+
"mutable state", (const ValueDecl *))
55275527
NOTE(shared_mutable_state_decl_note,none,
55285528
"isolate %0 to a global actor, or convert it to a 'let' constant and "
55295529
"conform it to 'Sendable'", (const ValueDecl *))
5530-
WARNING(shared_immutable_state_decl,none,
5531-
"%kind0 is not concurrency-safe because it is not either conforming to "
5532-
"'Sendable' or isolated to a global actor", (const ValueDecl *))
5530+
ERROR(shared_immutable_state_decl,none,
5531+
"%kind0 is not concurrency-safe because it is not either conforming to "
5532+
"'Sendable' or isolated to a global actor", (const ValueDecl *))
55335533
ERROR(actor_isolated_witness,none,
55345534
"%select{|distributed }0%1 %kind2 cannot be used to satisfy %3 protocol "
55355535
"requirement",

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2962,7 +2962,8 @@ namespace {
29622962
return false;
29632963
}
29642964

2965-
ctx.Diags.diagnose(loc, diag::shared_mutable_state_access, value);
2965+
ctx.Diags.diagnose(loc, diag::shared_mutable_state_access, value)
2966+
.warnUntilSwiftVersion(6);
29662967
value->diagnose(diag::kind_declared_here, value->getDescriptiveKind());
29672968
return true;
29682969
}

test/Concurrency/experimental_feature_strictconcurrency.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency -enable-experimental-feature GlobalConcurrency -emit-sil -o /dev/null -verify %s
2-
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency=complete -enable-experimental-feature GlobalConcurrency -emit-sil -o /dev/null -verify %s
3-
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency=complete -enable-experimental-feature GlobalConcurrency -emit-sil -o /dev/null -verify -verify-additional-prefix region-isolation- -enable-experimental-feature RegionBasedIsolation %s
1+
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency -enable-experimental-feature GlobalConcurrency -swift-version 6 -emit-sil -o /dev/null -verify %s
2+
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency=complete -enable-experimental-feature GlobalConcurrency -swift-version 6 -emit-sil -o /dev/null -verify %s
3+
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency=complete -enable-experimental-feature GlobalConcurrency -swift-version 6 -emit-sil -o /dev/null -verify -verify-additional-prefix region-isolation- -enable-experimental-feature RegionBasedIsolation %s
44

55
// REQUIRES: concurrency
66
// REQUIRES: asserts
@@ -15,11 +15,11 @@ protocol TestProtocol {
1515
associatedtype Value: Sendable
1616
}
1717

18-
struct Test1: TestProtocol { // expected-warning{{type 'Test1.Value' (aka 'C1') does not conform to the 'Sendable' protocol}}
18+
struct Test1: TestProtocol { // expected-error{{type 'Test1.Value' (aka 'C1') does not conform to the 'Sendable' protocol}}
1919
typealias Value = C1
2020
}
2121

22-
struct Test2: TestProtocol { // expected-warning{{conformance of 'C2' to 'Sendable' is unavailable}}
22+
struct Test2: TestProtocol { // expected-error{{conformance of 'C2' to 'Sendable' is unavailable}}
2323
// expected-note@-1{{in associated type 'Self.Value' (inferred as 'C2')}}
2424
typealias Value = C2
2525
}
@@ -32,7 +32,7 @@ actor TestGlobalActor {
3232
@TestGlobalActor
3333
var mutableIsolatedGlobal = 1
3434

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

3838
let immutableGlobal = 1
@@ -57,23 +57,23 @@ public struct TestWrapper {
5757

5858
struct TestStatics {
5959
static let immutableExplicitSendable = TestSendable()
60-
static let immutableNonsendable = TestNonsendable() // expected-warning{{static property 'immutableNonsendable' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor}}
60+
static let immutableNonsendable = TestNonsendable() // expected-error{{static property 'immutableNonsendable' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor}}
6161
static nonisolated(unsafe) let immutableNonisolatedUnsafe = TestNonsendable()
62-
static nonisolated let immutableNonisolated = TestNonsendable() // expected-warning{{static property 'immutableNonisolated' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor}}
62+
static nonisolated let immutableNonisolated = TestNonsendable() // expected-error{{static property 'immutableNonisolated' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor}}
6363
static let immutableInferredSendable = 0
64-
static var mutable = 0 // expected-warning{{static property 'mutable' is not concurrency-safe because it is non-isolated global shared mutable state}}
64+
static var mutable = 0 // expected-error{{static property 'mutable' is not concurrency-safe because it is non-isolated global shared mutable state}}
6565
// expected-note@-1{{isolate 'mutable' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
6666
// expected-note@-2{{static property declared here}}
6767
static var computedProperty: Int { 0 } // computed property that, though static, has no storage so is not a global
68-
@TestWrapper static var wrapped: Int // expected-warning{{static property 'wrapped' is not concurrency-safe because it is non-isolated global shared mutable state}}
68+
@TestWrapper static var wrapped: Int // expected-error{{static property 'wrapped' is not concurrency-safe because it is non-isolated global shared mutable state}}
6969
// expected-note@-1{{isolate 'wrapped' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
7070
}
7171

7272
@TestGlobalActor
7373
func f() {
7474
print(TestStatics.immutableExplicitSendable)
7575
print(TestStatics.immutableInferredSendable)
76-
print(TestStatics.mutable) // expected-warning{{reference to static property 'mutable' is not concurrency-safe because it involves shared mutable state}}
76+
print(TestStatics.mutable) // expected-error{{reference to static property 'mutable' is not concurrency-safe because it involves shared mutable state}}
7777
}
7878

7979
func testLocalNonisolatedUnsafe() async {

0 commit comments

Comments
 (0)