Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBI allows duplicate sending in top-level code #76868

Open
sebastian-rtr98 opened this issue Oct 4, 2024 · 0 comments
Open

RBI allows duplicate sending in top-level code #76868

sebastian-rtr98 opened this issue Oct 4, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@sebastian-rtr98
Copy link

sebastian-rtr98 commented Oct 4, 2024

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 6a5ae8d)).

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.

@sebastian-rtr98 sebastian-rtr98 added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant