Skip to content

Commit 308b95a

Browse files
authored
Merge pull request #68990 from hborla/isolation-region-tests
[NFC][Concurrency] Separate out an error case to allow diagnostics from `SendNonSendable` in `sendable_checking.swift`.
2 parents d58943a + fb06817 commit 308b95a

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

test/Concurrency/sendable_checking.swift

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,6 @@ public actor MyActor: MyProto {
100100
}
101101
}
102102

103-
// rdar://82452688 - make sure sendable checking doesn't fire for a capture
104-
// of a value of error-type
105-
@available(SwiftStdlib 5.1, *)
106-
func f() async {
107-
let n = wobble() // expected-error{{cannot find 'wobble' in scope}}
108-
@Sendable func nested() {
109-
n.pointee += 1
110-
}
111-
}
112-
113103
// Make sure the generic signature doesn't minimize away Sendable requirements.
114104
@_nonSendable class NSClass { }
115105

@@ -242,7 +232,10 @@ extension MyActor {
242232
@available(SwiftStdlib 5.1, *)
243233
func testConversionsAndSendable(a: MyActor, s: any Sendable, f: @Sendable () -> Void) async {
244234
await a.f(s)
235+
236+
// FIXME: 'f' is Sendable
245237
await a.g(f)
238+
// expected-sns-warning@-1 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
246239
}
247240

248241
@available(SwiftStdlib 5.1, *)
@@ -261,15 +254,21 @@ final class NonSendable {
261254
func call() async {
262255
await update()
263256
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
257+
// expected-sns-warning@-2 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
258+
// expected-sns-warning@-3 {{passing argument of non-sendable type 'NonSendable' from nonisolated context to main actor-isolated context at this call site could yield a race with accesses later in this function (3 access sites displayed)}}
259+
264260

265261
await self.update()
266262
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
263+
// expected-sns-note@-2 {{access here could race}}
267264

268265
_ = await x
269266
// expected-warning@-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to main actor-isolated property 'x' cannot cross actor boundary}}
267+
// expected-sns-note@-2 {{access here could race}}
270268

271269
_ = await self.x
272270
// expected-warning@-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to main actor-isolated property 'x' cannot cross actor boundary}}
271+
// expected-sns-note@-2 {{access here could race}}
273272
}
274273

275274
@MainActor
@@ -281,9 +280,11 @@ func testNonSendableBaseArg() async {
281280
let t = NonSendable()
282281
await t.update()
283282
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
283+
// expected-sns-warning@-2 {{passing argument of non-sendable type 'NonSendable' from nonisolated context to main actor-isolated context at this call site could yield a race with accesses later in this function (1 access site displayed)}}
284284

285285
_ = await t.x
286286
// expected-warning @-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to main actor-isolated property 'x' cannot cross actor boundary}}
287+
// expected-sns-note@-2 {{access here could race}}
287288
}
288289

289290
@available(SwiftStdlib 5.1, *)
@@ -296,15 +297,16 @@ func callNonisolatedAsyncClosure(
296297
ns: NonSendable,
297298
g: (NonSendable) async -> Void
298299
) async {
299-
// FIXME: Both cases below should also produce a diagnostic with SendNonSendable,
300-
// because the 'ns' parameter should be merged into the MainActor's region.
301-
302300
await g(ns)
303301
// expected-targeted-and-complete-warning@-1 {{passing argument of non-sendable type 'NonSendable' outside of main actor-isolated context may introduce data races}}
302+
// expected-sns-warning@-2 {{call site passes `self` or a non-sendable argument of this function to another thread, potentially yielding a race with the caller}}
303+
// expected-sns-warning@-3 {{passing argument of non-sendable type 'NonSendable' from main actor-isolated context to nonisolated context at this call site could yield a race with accesses later in this function (1 access site displayed)}}
304304

305305
let f: (NonSendable) async -> () = globalSendable // okay
306306
await f(ns)
307307
// expected-targeted-and-complete-warning@-1 {{passing argument of non-sendable type 'NonSendable' outside of main actor-isolated context may introduce data races}}
308+
// expected-sns-note@-2 {{access here could race}}
309+
308310
}
309311

310312
@available(SwiftStdlib 5.1, *)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -typecheck -verify -strict-concurrency=complete %s
2+
3+
// Don't test SendNonSendable because this test will not make
4+
// it past Sema to the SIL pass.
5+
6+
// REQUIRES: concurrency
7+
8+
// rdar://82452688 - make sure sendable checking doesn't fire for a capture
9+
// of a value of error-type
10+
@available(SwiftStdlib 5.1, *)
11+
func f() async {
12+
let n = wobble() // expected-error{{cannot find 'wobble' in scope}}
13+
@Sendable func nested() {
14+
n.pointee += 1
15+
}
16+
}

0 commit comments

Comments
 (0)