RBI allows duplicate sending in top-level code
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 70.4k
- Forks
- 10.8k
- PR merge metrics
- PR metrics pending
Description
Description
Region-based isolation in the Swift 6 language mode allows duplicate sending of a single non-Sendable value in top-level code, causing potential data races.
The issue does not occur in non-top-level code (e.g., within a function body).
Reproduction
class NonSendable { }
actor MyActor {
let nonSendable: NonSendable
init(_ nonSendable: NonSendable) {
self.nonSendable = nonSendable
}
}
func makeActor(_ nonSendable: sending NonSendable) -> MyActor {
MyActor(nonSendable)
}
let ns = NonSendable()
let _ = makeActor(ns)
let _ = makeActor(ns) // no data race detected
func f() {
let ns = NonSendable()
let _ = makeActor(ns)
// let _ = makeActor(ns) // when uncommenting this line, a data race is (correctly) detected
}
Expected behavior
The compiler should detect and diagnose a potential data race for the duplicate sending of ns in the top-level code.
Environment
The issue occurs when Swift 6 language mode is enabled in the latest relased version of Swift (Swift version 6.0.1 (swift-6.0.1-RELEASE)) and in the latest main development snapshot from 2024-09-25 (Swift version 6.1-dev (LLVM 89ccf4b8a46135a, Swift 6a5ae8d5df144dd)).
Additional information
This issue might be related to the behavior observed in this comment to issue #74820, where a similar problem with region-based isolation in top-level code is described.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Swift 6 reproduction from the issue and compare the duplicate sending at top level with the equivalent code inside f(). Trace the compiler's region-based isolation handling for top-level code; done means the second makeActor(ns) call is diagnosed as a potential data race without regressing the function-body behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100