I'm not sure RBI can entirely fix this issue. E.g. you have a sort of worse problem than the fully synchronous case if you involve multiple tasks, even if they are all serialized with the same isolation:
// run this with ASAN on and you see use after frees and no dynamic exclusivity trap
@MainActor
func testSpan() async throws {
var array: [Double] = [1, 2, 3]
let span = array.span
await Task { @MainActor in
array.append(4)
}.value
for i in span.indices {
print(span[i])
}
}
try await testSpan()