Skip to content

Commit 4910a6f

Browse files
committed
[send-non-sendable] Convert a few tests of sendable behavior to check for both strict and strict + sns behavior using the new diagnostic verifier multiple prefix option.
1 parent f3dcbbe commit 4910a6f

6 files changed

+57
-32
lines changed

test/Concurrency/async_tasks.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %target-swift-frontend -strict-concurrency=targeted -disable-availability-checking %s -o /dev/null -verify
1+
// RUN: %target-swift-frontend -strict-concurrency=targeted -disable-availability-checking %s -o /dev/null -verify -emit-sil
2+
// RUN: %target-swift-frontend -strict-concurrency=strict -disable-availability-checking %s -o /dev/null -verify -emit-sil
3+
// RUN: %target-swift-frontend -strict-concurrency=strict -disable-availability-checking %s -o /dev/null -verify -emit-sil -enable-experimental-feature SendNonSendable
24

35
// REQUIRES: concurrency
46

test/Concurrency/sendable_associated_type.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -strict-concurrency=complete -emit-sil -o /dev/null %s -verify
2+
// RUN: %target-swift-frontend -strict-concurrency=complete -enable-experimental-feature SendNonSendable -emit-sil -o /dev/null %s -verify
23

34
// REQUIRES: concurrency
45

test/Concurrency/sendable_checking.swift

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
// RUN: %target-swift-frontend -verify -strict-concurrency=targeted -emit-sil -o /dev/null %s
1+
// RUN: %target-swift-frontend -verify -strict-concurrency=targeted -verify-additional-prefix targeted-and-complete- -emit-sil -o /dev/null %s
2+
// RUN: %target-swift-frontend -verify -strict-concurrency=complete -verify-additional-prefix targeted-and-complete- -verify-additional-prefix complete-and-sns- -verify-additional-prefix complete- -emit-sil -o /dev/null %s
3+
// RUN: %target-swift-frontend -verify -strict-concurrency=complete -verify-additional-prefix sns- -verify-additional-prefix complete-and-sns- -emit-sil -o /dev/null %s -enable-experimental-feature SendNonSendable
24

35
// REQUIRES: concurrency
46
// REQUIRES: OS=macosx
57

68
@available(SwiftStdlib 5.1, *)
79
struct NS1 { }
8-
// expected-note@-1 2{{consider making struct 'NS1' conform to the 'Sendable' protocol}}
10+
// expected-note @-1 {{consider making struct 'NS1' conform to the 'Sendable' protocol}}
11+
// expected-targeted-and-complete-note @-2 {{consider making struct 'NS1' conform to the 'Sendable' protocol}}
912

1013
@available(SwiftStdlib 5.1, *)
1114
@available(*, unavailable)
1215
extension NS1: Sendable { }
1316
// expected-note@-1 4{{conformance of 'NS1' to 'Sendable' has been explicitly marked unavailable here}}
1417

1518
@available(SwiftStdlib 5.1, *)
16-
struct NS2 { // expected-note{{consider making struct 'NS2' conform to the 'Sendable' protocol}}
19+
struct NS2 { // expected-note {{consider making struct 'NS2' conform to the 'Sendable' protocol}}
20+
// expected-complete-and-sns-note @-1 {{consider making struct 'NS2' conform to the 'Sendable' protocol}}
1721
var ns1: NS1
1822
}
1923

@@ -24,7 +28,8 @@ struct NS3 { }
2428
extension NS3: Sendable { }
2529

2630
@available(SwiftStdlib 5.1, *)
27-
class NS4 { } // expected-note{{class 'NS4' does not conform to the 'Sendable' protocol}}
31+
class NS4 { } // expected-note {{class 'NS4' does not conform to the 'Sendable' protocol}}
32+
// expected-complete-and-sns-note @-1 {{class 'NS4' does not conform to the 'Sendable' protocol}}
2833

2934
@available(SwiftStdlib 5.1, *)
3035
func acceptCV<T: Sendable>(_: T) { }
@@ -35,15 +40,22 @@ func acceptSendableFn(_: @Sendable @escaping () -> Void) { }
3540
func testCV(
3641
ns1: NS1, ns1array: [NS1], ns2: NS2, ns3: NS3, ns4: NS4,
3742
fn: @escaping () -> Void
38-
// expected-note@-1{{parameter 'fn' is implicitly non-sendable}}
43+
// expected-note @-1 {{parameter 'fn' is implicitly non-sendable}}
3944
) {
40-
acceptCV(ns1) // expected-warning{{conformance of 'NS1' to 'Sendable' is unavailable}}
41-
acceptCV(ns1array) // expected-warning{{conformance of 'NS1' to 'Sendable' is unavailable}}
42-
acceptCV(ns2)
43-
acceptCV(ns3) // expected-warning{{conformance of 'NS3' to 'Sendable' is only available in macOS 11.0 or newer}}
44-
// expected-note@-1{{add 'if #available' version check}}
45-
acceptCV(ns4)
46-
acceptCV(fn)
45+
acceptCV(ns1) // expected-warning {{conformance of 'NS1' to 'Sendable' is unavailable}}
46+
47+
acceptCV(ns1array) // expected-warning {{conformance of 'NS1' to 'Sendable' is unavailable}}
48+
49+
acceptCV(ns2) // expected-complete-and-sns-warning {{type 'NS2' does not conform to the 'Sendable' protocol}}
50+
51+
acceptCV(ns3) // expected-warning {{conformance of 'NS3' to 'Sendable' is only available in macOS 11.0 or newer}}
52+
// expected-note @-1 {{add 'if #available' version check}}
53+
54+
acceptCV(ns4) // expected-complete-and-sns-warning {{type 'NS4' does not conform to the 'Sendable' protocol}}
55+
56+
acceptCV(fn) // expected-complete-and-sns-warning {{type '() -> Void' does not conform to the 'Sendable' protocol}}
57+
// expected-complete-and-sns-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
58+
4759
acceptSendableFn(fn) // expected-warning{{passing non-sendable parameter 'fn' to function expecting a @Sendable closure}}
4860
}
4961

@@ -82,7 +94,7 @@ public actor MyActor: MyProto {
8294
public func bar<B>(aBar: B) async where B: Sendable { }
8395

8496
func g(ns1: NS1) async {
85-
await nonisolatedAsyncFunc1(ns1) // expected-warning{{passing argument of non-sendable type 'NS1' outside of actor-isolated context may introduce data races}}
97+
await nonisolatedAsyncFunc1(ns1) // expected-targeted-and-complete-warning{{passing argument of non-sendable type 'NS1' outside of actor-isolated context may introduce data races}}
8698
_ = await nonisolatedAsyncFunc2() // expected-warning{{non-sendable type 'NS1' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary}}
8799
}
88100
}
@@ -234,7 +246,9 @@ func testConversionsAndSendable(a: MyActor, s: any Sendable, f: @Sendable () ->
234246

235247
@available(SwiftStdlib 5.1, *)
236248
final class NonSendable {
237-
// expected-note@-1 6 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
249+
// expected-note @-1 3 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
250+
// SendNonSendable emits 3 fewer errors here.
251+
// expected-targeted-and-complete-note @-3 3 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
238252
var value = ""
239253

240254
@MainActor
@@ -244,10 +258,10 @@ final class NonSendable {
244258

245259
func call() async {
246260
await update()
247-
// expected-warning@-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
261+
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
248262

249263
await self.update()
250-
// expected-warning@-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
264+
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
251265

252266
_ = await x
253267
// expected-warning@-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to main actor-isolated property 'x' cannot cross actor boundary}}
@@ -264,8 +278,8 @@ final class NonSendable {
264278
func testNonSendableBaseArg() async {
265279
let t = NonSendable()
266280
await t.update()
267-
// expected-warning@-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
281+
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
268282

269283
_ = await t.x
270-
// expected-warning@-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to main actor-isolated property 'x' cannot cross actor boundary}}
284+
// expected-warning @-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to main actor-isolated property 'x' cannot cross actor boundary}}
271285
}

test/Concurrency/sendable_existentials.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %target-swift-frontend -strict-concurrency=targeted -emit-sil -o /dev/null %s -verify
2+
// RUN: %target-swift-frontend -strict-concurrency=complete -verify-additional-prefix complete-and-sns- -verify-additional-prefix complete- -emit-sil -o /dev/null %s -verify
3+
// RUN: %target-swift-frontend -strict-concurrency=complete -verify-additional-prefix complete-and-sns- -emit-sil -o /dev/null %s -verify
24

35
// REQUIRES: concurrency
46
// REQUIRES: OS=macosx
@@ -34,22 +36,22 @@ func testE(a: Any, aOpt: Any?) async {
3436
}
3537

3638
func testESilently(a: Any, aOpt: Any?) {
37-
send(a)
38-
sendOpt(a)
39-
sendOpt(aOpt)
39+
send(a) // expected-complete-and-sns-warning {{'Any' does not conform to the 'Sendable' protocol}}
40+
sendOpt(a) // expected-complete-and-sns-warning {{'Any' does not conform to the 'Sendable' protocol}}
41+
sendOpt(aOpt) // expected-complete-and-sns-warning {{'Any' does not conform to the 'Sendable' protocol}}
4042

41-
let _: E = .something(a)
42-
_ = E.something(a)
43+
let _: E = .something(a) // expected-complete-and-sns-warning {{'Any' does not conform to the 'Sendable' protocol}}
44+
_ = E.something(a) // expected-complete-and-sns-warning {{'Any' does not conform to the 'Sendable' protocol}}
4345

4446
var sendable: Sendable
45-
sendable = a
47+
sendable = a // expected-complete-and-sns-warning {{'Any' does not conform to the 'Sendable' protocol}}
4648

4749
var arrayOfSendable: [Sendable]
48-
arrayOfSendable = [a, a]
50+
arrayOfSendable = [a, a] // expected-complete-and-sns-warning 2{{'Any' does not conform to the 'Sendable' protocol}}
4951

5052
func localFunc() { }
51-
sendable = localFunc
52-
53+
sendable = localFunc // expected-complete-and-sns-warning {{'() -> ()' does not conform to the 'Sendable' protocol}}
54+
// expected-complete-and-sns-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
5355
_ = sendable
5456
_ = arrayOfSendable
5557
}

test/Concurrency/sendable_without_preconcurrency.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/StrictModule.swiftmodule -module-name StrictModule -swift-version 6 %S/Inputs/StrictModule.swift
33
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/NonStrictModule.swiftmodule -module-name NonStrictModule %S/Inputs/NonStrictModule.swift
44
// RUN: %target-swift-frontend -strict-concurrency=targeted -disable-availability-checking -I %t -verify %s -o /dev/null -emit-sil
5+
// RUN: %target-swift-frontend -strict-concurrency=complete -disable-availability-checking -I %t -verify %s -o /dev/null -emit-sil -verify-additional-prefix complete-
6+
// RUN: %target-swift-frontend -strict-concurrency=complete -disable-availability-checking -I %t -verify %s -o /dev/null -emit-sil -verify-additional-prefix complete- -enable-experimental-feature SendNonSendable
57

68
// REQUIRES: concurrency
79
// REQUIRES: asserts
@@ -15,7 +17,7 @@ actor A {
1517

1618
class NS { } // expected-note{{class 'NS' does not conform to the 'Sendable' protocol}}
1719

18-
struct MyType {
20+
struct MyType { // expected-complete-note {{consider making struct 'MyType' conform to the 'Sendable' protocol}}
1921
var nsc: NonStrictClass
2022
}
2123

@@ -27,7 +29,8 @@ struct MyType2 { // expected-note{{consider making struct 'MyType2' conform to t
2729
func testA(ns: NS, mt: MyType, mt2: MyType2, sc: StrictClass, nsc: NonStrictClass) async {
2830
Task {
2931
print(ns) // expected-warning{{capture of 'ns' with non-sendable type 'NS' in a `@Sendable` closure}}
30-
print(mt) // no warning: MyType is Sendable because we suppressed NonStrictClass's warning
32+
print(mt) // no warning by default: MyType is Sendable because we suppressed NonStrictClass's warning
33+
// expected-complete-warning @-1 {{capture of 'mt' with non-sendable type 'MyType' in a `@Sendable` closure}}
3134
print(mt2) // expected-warning{{capture of 'mt2' with non-sendable type 'MyType2' in a `@Sendable` closure}}
3235
print(sc) // expected-warning{{capture of 'sc' with non-sendable type 'StrictClass' in a `@Sendable` closure}}
3336
}

test/Concurrency/sendable_without_preconcurrency_2.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/StrictModule.swiftmodule -module-name StrictModule -swift-version 6 %S/Inputs/StrictModule.swift
33
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/NonStrictModule.swiftmodule -module-name NonStrictModule %S/Inputs/NonStrictModule.swift
44
// RUN: %target-swift-frontend -strict-concurrency=targeted -disable-availability-checking -I %t %s -verify -emit-sil -o /dev/null
5+
// RUN: %target-swift-frontend -strict-concurrency=complete -verify-additional-prefix complete- -disable-availability-checking -I %t %s -verify -emit-sil -o /dev/null
6+
// RUN: %target-swift-frontend -strict-concurrency=complete -verify-additional-prefix complete- -disable-availability-checking -I %t %s -verify -emit-sil -o /dev/null -enable-experimental-feature SendNonSendable
57

68
// REQUIRES: concurrency
79
// REQUIRES: asserts
@@ -15,7 +17,7 @@ actor A {
1517

1618
class NS { } // expected-note 2{{class 'NS' does not conform to the 'Sendable' protocol}}
1719

18-
struct MyType {
20+
struct MyType { // expected-complete-note {{consider making struct 'MyType' conform to the 'Sendable' protocol}}
1921
var nsc: NonStrictClass
2022
}
2123

@@ -27,7 +29,8 @@ struct MyType2: Sendable {
2729
func testA(ns: NS, mt: MyType, mt2: MyType2, sc: StrictClass, nsc: NonStrictClass) async {
2830
Task {
2931
print(ns) // expected-warning{{capture of 'ns' with non-sendable type 'NS' in a `@Sendable` closure}}
30-
print(mt) // no warning: MyType is Sendable because we suppressed NonStrictClass's warning
32+
print(mt) // no warning with targeted: MyType is Sendable because we suppressed NonStrictClass's warning
33+
// expected-complete-warning @-1 {{capture of 'mt' with non-sendable type 'MyType' in a `@Sendable` closure}}
3134
print(mt2)
3235
print(sc) // expected-warning {{capture of 'sc' with non-sendable type 'StrictClass' in a `@Sendable` closure}}
3336
print(nsc) // expected-warning {{capture of 'nsc' with non-sendable type 'NonStrictClass' in a `@Sendable` closure}}

0 commit comments

Comments
 (0)