mirror of
https://github.com/apple/swift-atomics
synced 2026-11-25 04:37:47 +00:00
Fix UnsafeAtomic's Sendable conformance
In Swift 5.5, `UnsafeAtomic` has gained an implicit, unconditional `Sendable` conformance, because it is a `@frozen public struct` whose sole stored property (an `UnsafeMutablePointer` is also `Sendable`. This is not correct -- we only want `UnsafeAtomic` to conform to `Sendable` if its `Value` does. Explicitly declare the conformance on 5.5 to disable the bogus inference.
This commit is contained in:
1 parent
de1a62250e
commit
44bf6b59dc
4 files changed
+18
No files matched your search
@@ -47,6 +47,11 @@ public struct UnsafeAtomicLazyReference<Instance: AnyObject> {
|
||||
}
|
||||
}
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
extension UnsafeAtomicLazyReference: @unchecked Sendable
|
||||
where Instance: Sendable {}
|
||||
#endif
|
||||
|
||||
extension UnsafeAtomicLazyReference {
|
||||
/// The storage representation for an atomic lazy reference value.
|
||||
@frozen
|
||||
|
||||
@@ -71,6 +71,10 @@ public struct UnsafeAtomic<Value: AtomicValue> {
|
||||
}
|
||||
}
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
extension UnsafeAtomic: @unchecked Sendable where Value: Sendable {}
|
||||
#endif
|
||||
|
||||
/// A reference type holding an atomic value, with automatic memory management.
|
||||
@_fixed_layout
|
||||
public class ManagedAtomic<Value: AtomicValue> {
|
||||
|
||||
@@ -50,6 +50,11 @@ public struct UnsafeAtomicLazyReference<Instance: AnyObject> {
|
||||
}
|
||||
}
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
extension UnsafeAtomicLazyReference: @unchecked Sendable
|
||||
where Instance: Sendable {}
|
||||
#endif
|
||||
|
||||
extension UnsafeAtomicLazyReference {
|
||||
/// The storage representation for an atomic lazy reference value.
|
||||
@frozen
|
||||
|
||||
@@ -73,6 +73,10 @@ public struct UnsafeAtomic<Value: AtomicValue> {
|
||||
}
|
||||
}
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
extension UnsafeAtomic: @unchecked Sendable where Value: Sendable {}
|
||||
#endif
|
||||
|
||||
/// A reference type holding an atomic value, with automatic memory management.
|
||||
@_fixed_layout
|
||||
public class ManagedAtomic<Value: AtomicValue> {
|
||||
|
||||
Reference in new issue
Block a user