Skip to content

Commit 359eeec

Browse files
committed
[region-isolation] Add a test showing that we do not infer nonisolated(unsafe) onto named closures.
The semantics we want is for nonisolated(unsafe) to be inferred onto anonymous closures. We already have that semantics since we do not look through move_value [var_decl] or begin_borrow [var_decl]. So even though the underlying partial_apply will be viewed as nonisolated(unsafe), we will not consider that when determining the nonisolated(unsafe) for the begin_borrow or move_value that defined the variable whose value is the partial_apply.
1 parent 4976be8 commit 359eeec

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/Concurrency/transfernonsendable_nonisolatedunsafe.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,4 +1026,18 @@ func closureTests() async {
10261026
// expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(priority:operation:)' risks causing races in between local and caller code}}
10271027
Task.detached { _ = x4a; _ = x4b } // expected-note {{access can happen concurrently}}
10281028
}
1029+
1030+
// The reason why this works is that we do not infer nonisolated(unsafe)
1031+
// passed the begin_borrow [var_decl] of y. So we think the closure is
1032+
// nonisolated(unsafe), but its uses via the begin_borrow [var_decl] is
1033+
// not.
1034+
func testNamedClosure() async {
1035+
nonisolated(unsafe) let x = NonSendableKlass()
1036+
let y = {
1037+
_ = x
1038+
}
1039+
sendingClosure(y) // expected-warning {{sending 'y' risks causing data races}}
1040+
// expected-note @-1 {{'y' used after being passed as a 'sending' parameter}}
1041+
sendingClosure(y) // expected-note {{access can happen concurrently}}
1042+
}
10291043
}

0 commit comments

Comments
 (0)