Skip to content

Commit a6edf4f

Browse files
committed
[rbi] Convert all rbi tests to run also in NonisolatedNonsendingByDefault.
Going to update the tests in the next commit. This just makes it easier to review.
1 parent c12c99f commit a6edf4f

27 files changed

+177
-85
lines changed

test/ClangImporter/regionbasedisolation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: %target-swift-frontend %s -import-objc-header %S/Inputs/regionbasedisolation.h -emit-silgen -swift-version 6 | %FileCheck %s
44

55
// REQUIRES: objc_interop
6+
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
67

78
extension ObjCObject {
89
// CHECK-LABEL: sil hidden [ossa] @$sSo10ObjCObjectC20regionbasedisolationE11sendObjectsSaySo8NSObjectCGyYaKF : $@convention(method) @async (@guaranteed ObjCObject) -> (@sil_sending @owned Array<NSObject>, @error any Error) {

test/Concurrency/concurrent_value_checking.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify -DALLOW_TYPECHECKER_ERRORS -verify-additional-prefix typechecker- -verify-additional-prefix tns-allow-typechecker-
22

3-
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify -verify-additional-prefix tns-
3+
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify -verify-additional-prefix tns-ni- -verify-additional-prefix tns-
4+
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify -verify-additional-prefix tns-ni-ns- -verify-additional-prefix tns- -enable-upcoming-feature NonisolatedNonsendingByDefault
45

56
// REQUIRES: concurrency
67
// REQUIRES: asserts
8+
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
79

810
class NotConcurrent { } // expected-note 12{{class 'NotConcurrent' does not conform to the 'Sendable' protocol}}
911
// expected-tns-allow-typechecker-note @-1 {{class 'NotConcurrent' does not conform to the 'Sendable' protocol}}

test/Concurrency/concurrent_value_checking_objc.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -strict-concurrency=complete %s -emit-sil -o /dev/null -verify
1+
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -strict-concurrency=complete %s -emit-sil -o /dev/null -verify -verify-additional-prefix ni-
2+
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -strict-concurrency=complete %s -emit-sil -o /dev/null -verify -verify-additional-prefix ni-ns- -enable-upcoming-feature NonisolatedNonsendingByDefault
23

34
// REQUIRES: concurrency
45
// REQUIRES: objc_interop
56
// REQUIRES: asserts
7+
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
68

79
import Foundation
810

test/Concurrency/sendable_checking.swift

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// RUN: %target-swift-frontend -target %target-swift-5.0-abi-triple -verify -strict-concurrency=targeted -verify-additional-prefix targeted- -emit-sil -o /dev/null %s
2-
// RUN: %target-swift-frontend -target %target-swift-5.0-abi-triple -verify -strict-concurrency=complete -verify-additional-prefix tns- -verify-additional-prefix complete-and-tns- -emit-sil -o /dev/null %s
1+
// RUN: %target-swift-frontend -target %target-swift-5.0-abi-triple -verify -verify-additional-prefix targeted-and-ni- -strict-concurrency=targeted -verify-additional-prefix targeted- -emit-sil -o /dev/null %s
2+
// RUN: %target-swift-frontend -target %target-swift-5.0-abi-triple -verify -strict-concurrency=complete -verify-additional-prefix tns-ni- -verify-additional-prefix tns- -emit-sil -o /dev/null %s -swift-version 5 -verify-additional-prefix targeted-and-ni-
3+
// RUN: %target-swift-frontend -target %target-swift-5.0-abi-triple -verify -strict-concurrency=complete -verify-additional-prefix tns-ni-ns- -verify-additional-prefix tns- -emit-sil -o /dev/null %s -enable-upcoming-feature NonisolatedNonsendingByDefault -swift-version 5 -DNONISOLATEDNONSENDING
34

45
// REQUIRES: concurrency
56
// REQUIRES: asserts
67
// REQUIRES: OS=macosx
8+
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
79

810
@available(SwiftStdlib 5.1, *)
911
struct NS1 { }
@@ -15,7 +17,7 @@ extension NS1: Sendable { }
1517

1618
@available(SwiftStdlib 5.1, *)
1719
struct NS2 { // expected-note {{consider making struct 'NS2' conform to the 'Sendable' protocol}}
18-
// expected-complete-and-tns-note @-1 {{consider making struct 'NS2' conform to the 'Sendable' protocol}}
20+
// expected-tns-note @-1 {{consider making struct 'NS2' conform to the 'Sendable' protocol}}
1921
var ns1: NS1
2022
}
2123

@@ -27,7 +29,7 @@ extension NS3: Sendable { }
2729

2830
@available(SwiftStdlib 5.1, *)
2931
class NS4 { } // expected-note {{class 'NS4' does not conform to the 'Sendable' protocol}}
30-
// expected-complete-and-tns-note @-1 {{class 'NS4' does not conform to the 'Sendable' protocol}}
32+
// expected-tns-note @-1 {{class 'NS4' does not conform to the 'Sendable' protocol}}
3133

3234
@available(SwiftStdlib 5.1, *)
3335
func acceptCV<T: Sendable>(_: T) { }
@@ -44,15 +46,15 @@ func testCV(
4446

4547
acceptCV(ns1array) // expected-warning {{conformance of 'NS1' to 'Sendable' is unavailable}}
4648

47-
acceptCV(ns2) // expected-complete-and-tns-warning {{type 'NS2' does not conform to the 'Sendable' protocol}}
49+
acceptCV(ns2) // expected-tns-warning {{type 'NS2' does not conform to the 'Sendable' protocol}}
4850

4951
acceptCV(ns3) // expected-warning {{conformance of 'NS3' to 'Sendable' is only available in macOS 11.0 or newer}}
5052
// expected-note @-1 {{add 'if #available' version check}}
5153

52-
acceptCV(ns4) // expected-complete-and-tns-warning {{type 'NS4' does not conform to the 'Sendable' protocol}}
54+
acceptCV(ns4) // expected-tns-warning {{type 'NS4' does not conform to the 'Sendable' protocol}}
5355

54-
acceptCV(fn) // expected-complete-and-tns-warning {{type '() -> Void' does not conform to the 'Sendable' protocol}}
55-
// expected-complete-and-tns-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
56+
acceptCV(fn) // expected-tns-warning {{type '() -> Void' does not conform to the 'Sendable' protocol}}
57+
// expected-tns-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
5658

5759
acceptSendableFn(fn) // expected-warning{{passing non-Sendable parameter 'fn' to function expecting a '@Sendable' closure}}
5860
}
@@ -93,8 +95,8 @@ public actor MyActor: MyProto {
9395

9496
func g(ns1: NS1) async {
9597
await nonisolatedAsyncFunc1(ns1)
96-
// expected-tns-warning @-1 {{sending 'ns1' risks causing data races}}
97-
// expected-tns-note @-2 {{sending 'self'-isolated 'ns1' to nonisolated global function 'nonisolatedAsyncFunc1' risks causing data races between nonisolated and 'self'-isolated uses}}
98+
// expected-tns-ni-warning @-1 {{sending 'ns1' risks causing data races}}
99+
// expected-tns-ni-note @-2 {{sending 'self'-isolated 'ns1' to nonisolated global function 'nonisolatedAsyncFunc1' risks causing data races between nonisolated and 'self'-isolated uses}}
98100
_ = await nonisolatedAsyncFunc2()
99101
}
100102
}
@@ -162,18 +164,18 @@ class Super {
162164

163165
@MainActor
164166
func bar (x : () -> ()) async {}
165-
// expected-note@-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
167+
// expected-targeted-and-ni-note @-1 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
166168

167169
@MainActor
168170
func foo2<T : Sendable>(x: T) async {}
169171

170172
@MainActor
171173
func bar2<T>(x: T) async {}
172-
// expected-note@-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}} {{14-14=: Sendable}}
174+
// expected-targeted-and-ni-note @-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}} {{14-14=: Sendable}}
173175

174176
@MainActor
175177
func bar3<T: Equatable>(x: T) async {}
176-
// expected-note@-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}} {{25-25= & Sendable}}
178+
// expected-targeted-and-ni-note @-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}} {{25-25= & Sendable}}
177179
}
178180

179181
// Make sure isolation crossing overrides check sendability
@@ -182,16 +184,25 @@ class Super {
182184
class Sub : Super {
183185
override nonisolated func foo(x : () -> ()) async {}
184186

187+
// We do not emit an error for the override with
188+
// NonisolatedNonsendingByDefault since the vtable thunk passes in MainActor
189+
// so we are still in the main actor even though we are nonisolated. In the
190+
// case of that being disabled, we cannot do this since we will hop off the
191+
// actor.
185192
override nonisolated func bar(x : () -> ()) async {}
186-
// expected-warning@-1 {{non-Sendable parameter type '() -> ()' cannot be sent from caller of superclass instance method 'bar(x:)' into nonisolated override}}
193+
// expected-targeted-and-ni-warning@-1 {{non-Sendable parameter type '() -> ()' cannot be sent from caller of superclass instance method 'bar(x:)' into nonisolated override}}
187194

188195
override nonisolated func foo2<T>(x: T) async {}
189196

197+
// See comment above about why nonisolated overrides of superclass are allowed
198+
// when is enabled NonisolatedNonsendingByDefault.
190199
override nonisolated func bar2<T>(x: T) async {}
191-
// expected-warning@-1 {{non-Sendable parameter type 'T' cannot be sent from caller of superclass instance method 'bar2(x:)' into nonisolated override}}
200+
// expected-targeted-and-ni-warning @-1 {{non-Sendable parameter type 'T' cannot be sent from caller of superclass instance method 'bar2(x:)' into nonisolated override}}
192201

202+
// See comment above about why nonisolated overrides of superclass are allowed
203+
// when is enabled NonisolatedNonsendingByDefault.
193204
override nonisolated func bar3<T>(x: T) async {}
194-
// expected-warning@-1 {{non-Sendable parameter type 'T' cannot be sent from caller of superclass instance method 'bar3(x:)' into nonisolated override}}
205+
// expected-targeted-and-ni-warning @-1 {{non-Sendable parameter type 'T' cannot be sent from caller of superclass instance method 'bar3(x:)' into nonisolated override}}
195206
}
196207

197208
@available(SwiftStdlib 5.1, *)
@@ -217,7 +228,8 @@ class SubWSafeSubscript : SuperWSafeSubscript {
217228
class SuperWUnsafeSubscript {
218229
@MainActor
219230
subscript<T>(x : T) -> Int {
220-
// expected-note@-1 2{{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
231+
// expected-targeted-and-ni-note @-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
232+
// expected-targeted-and-ni-note @-2 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
221233
get async {
222234
return 0
223235
}
@@ -226,10 +238,15 @@ class SuperWUnsafeSubscript {
226238

227239
@available(SwiftStdlib 5.1, *)
228240
class SubWUnsafeSubscript : SuperWUnsafeSubscript {
241+
// We do not emit an error for the override with
242+
// NonisolatedNonsendingByDefault since the vtable thunk passes in MainActor
243+
// so we are still in the main actor even though we are nonisolated. In the
244+
// case of that being disabled, we cannot do this since we will hop off the
245+
// actor.
229246
override nonisolated subscript<T>(x : T) -> Int {
230247
get async {
231-
// expected-warning@-2{{non-Sendable parameter type 'T' cannot be sent from caller of superclass subscript 'subscript(_:)' into nonisolated override}}
232-
// expected-warning@-2{{non-Sendable parameter type 'T' cannot be sent from caller of superclass getter for subscript 'subscript(_:)' into nonisolated override}}
248+
// expected-targeted-and-ni-warning@-2{{non-Sendable parameter type 'T' cannot be sent from caller of superclass subscript 'subscript(_:)' into nonisolated override}}
249+
// expected-targeted-and-ni-warning@-2{{non-Sendable parameter type 'T' cannot be sent from caller of superclass getter for subscript 'subscript(_:)' into nonisolated override}}
233250
// there really shouldn't be two warnings produced here, see rdar://110846040 (Sendable diagnostics reported twice for subscript getters)
234251
return 0
235252
}
@@ -263,7 +280,7 @@ struct CustomActor {
263280
final class NonSendable {
264281
// expected-note @-1 5 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
265282
// TransferNonSendable emits 3 fewer errors here.
266-
// expected-complete-and-tns-note @-3 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
283+
// expected-tns-note @-3 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
267284
var value = ""
268285

269286
@MainActor
@@ -341,21 +358,23 @@ func testNonSendableBaseArg3() async {
341358
@Sendable
342359
func globalSendable(_ ns: NonSendable) async {}
343360

361+
#if !NONISOLATEDNONSENDING
344362
@available(SwiftStdlib 5.1, *)
345363
@MainActor
346364
func callNonisolatedAsyncClosure(
347365
ns: NonSendable,
348366
g: (NonSendable) async -> Void
349367
) async {
350368
await g(ns)
351-
// expected-tns-warning @-1 {{sending 'ns' risks causing data races}}
352-
// expected-tns-note @-2 {{sending main actor-isolated 'ns' to nonisolated callee risks causing data races between nonisolated and main actor-isolated uses}}
369+
// expected-tns-ni-warning @-1 {{sending 'ns' risks causing data races}}
370+
// expected-tns-ni-note @-2 {{sending main actor-isolated 'ns' to nonisolated callee risks causing data races between nonisolated and main actor-isolated uses}}
353371

354372
let f: (NonSendable) async -> () = globalSendable // okay
355373
await f(ns)
356-
// expected-tns-warning @-1 {{sending 'ns' risks causing data races}}
357-
// expected-tns-note @-2 {{sending main actor-isolated 'ns' to nonisolated callee risks causing data races between nonisolated and main actor-isolated uses}}
374+
// expected-tns-ni-warning @-1 {{sending 'ns' risks causing data races}}
375+
// expected-tns-ni-note @-2 {{sending main actor-isolated 'ns' to nonisolated callee risks causing data races between nonisolated and main actor-isolated uses}}
358376
}
377+
#endif
359378

360379
@available(SwiftStdlib 5.1, *)
361380
func testLocalCaptures() {
@@ -364,7 +383,7 @@ func testLocalCaptures() {
364383
@Sendable
365384
func a2() -> NonSendable {
366385
return ns
367-
// expected-complete-and-tns-warning @-1 {{capture of 'ns' with non-Sendable type 'NonSendable' in a '@Sendable' local function}}
386+
// expected-tns-warning @-1 {{capture of 'ns' with non-Sendable type 'NonSendable' in a '@Sendable' local function}}
368387
}
369388
}
370389

0 commit comments

Comments
 (0)