Open jamieQ opened 2 months ago
the following code should produce a compile-time error disallowing the use of a non-sendable class across two isolation domains. running the code with TSAN enabled detects a data race at runtime.
class NonSendableClass { var data: Int = 0 } func f(_ ns: NonSendableClass) async { ns.data += 1 } @MainActor func main() async { let nonSendableObject = NonSendableClass() Task { await f(nonSendableObject) } await Task.yield() _ = nonSendableObject.data } await main()
the use of nonSendableObject in this way should produce a compiler error detecting a potential data race.
nonSendableObject
swift-driver version: 1.113 Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1) Target: arm64-apple-macosx14.0
(Xcode 16, beta 5)
originally reported via: https://forums.swift.org/t/a-non-sendable-class-can-bypass-swift6s-concurrency-check-and-cause-data-race.
notes:
Task.detached
@gottesmm I think this is a region based isolation issue, isn't it?
Description
the following code should produce a compile-time error disallowing the use of a non-sendable class across two isolation domains. running the code with TSAN enabled detects a data race at runtime.
Reproduction
Expected behavior
the use of
nonSendableObject
in this way should produce a compiler error detecting a potential data race.Environment
swift-driver version: 1.113 Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1) Target: arm64-apple-macosx14.0
(Xcode 16, beta 5)
Additional information
originally reported via: https://forums.swift.org/t/a-non-sendable-class-can-bypass-swift6s-concurrency-check-and-cause-data-race.
notes:
Task.detached
causes a compiler error to be produced