Closed jasonbobier closed 1 month ago
I think this is because ?? operator is using @autoclosure
for it’s right-hand side parameter.
Interesting. So @autoclosure
probably needs some more smarts in a strict concurrency world.
As reduced as I could get it:
class Class {}
func takeClosure(_: () -> Void) {}
actor Actor {
var x: Int = 0
func test() {
let _: (Class) -> Void = { c in
takeClosure {
_ = c
_ = self.x
}
// OK:
// let closure: () -> Void = {
// _ = c
// _ = self.x
// }
// takeClosure(closure)
}
}
}
326 | let _: (Class) -> Void = { c in
327 | takeClosure {
328 | _ = c
| |- error: sending 'c' risks causing data races [regionbasedisolation_named_transfer_yields_race]
| `- note: 'self'-isolated 'c' is captured by a actor-isolated closure. actor-isolated uses in closure may race against later nonisolated uses [regionbasedisolation_named_isolated_closure_yields_race]
329 | _ = self.x
330 | }
This appears to be about closures in general, not specifically autoclosures. I am not familiar with region-based isolation semantics yet, but I at least do not see any isolation crossings to diagnose or watch out for here. Both the method and the closures are isolated to the parent actor.
I am bringing back ‘type checker’ label because that’s where the isolation is determined. This might not be a SIL issue because it’s a consumer of that information. cc @gottesmm
I fixed this some time ago I think. It doesn't reproduce with swift-DEVELOPMENT-SNAPSHOT-2024-07-27-a. Thank you for the test case!
Description
I have a case where I can use an if/else block, but can't use ?? without a data race warning
Reproduction
Expected behavior
The ?? case would not cause a data race warning.
Environment
Xcode Version 16.0 beta 2 (16A5171r) in Swift 6 language mode
Additional information
No response