-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
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
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels