Skip to content

GAIT instance is modified simultaneously from different isolations #85719

@rayx

Description

@rayx

Description

I did experiments to verify my understanding that a GAIT instance might be accessed from either current isolation or global actor but not both simultaneously. I tried a lot of setup and compiler has caught data races in all of them except this one:

@MainActor
struct S {
    var value = 0

    mutating func modify() {
        value += 1
    }
}

actor A {
    @concurrent func transferToGlobalExecutor(_ s: inout S) async {
        s.value += 1
    }

    func test() async {
        var s = S()
        Task {
            await transferToGlobalExecutor(&s)
        }
        await s.modify()
    }
}

await A().test()

The code compiles, but IIUC s is modified simultaneously by transferToGlobalExecutor() and s.modify(), which runs in different isolations.

Reproduction

See above

Expected behavior

The code shouldn't compile.

Environment

x86-64 swiftc nightly on godbolt

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions