From 44bf6b59dc11d5cc2c29d796b382bcacaba42228 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 24 Sep 2021 14:51:07 -0700 Subject: [PATCH] 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. --- Sources/Atomics/AtomicLazyReference.swift.gyb | 5 +++++ Sources/Atomics/HighLevelTypes.swift.gyb | 4 ++++ Sources/Atomics/autogenerated/AtomicLazyReference.swift | 5 +++++ Sources/Atomics/autogenerated/HighLevelTypes.swift | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/Sources/Atomics/AtomicLazyReference.swift.gyb b/Sources/Atomics/AtomicLazyReference.swift.gyb index f7b448e..61d03c3 100644 --- a/Sources/Atomics/AtomicLazyReference.swift.gyb +++ b/Sources/Atomics/AtomicLazyReference.swift.gyb @@ -47,6 +47,11 @@ public struct UnsafeAtomicLazyReference { } } +#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 diff --git a/Sources/Atomics/HighLevelTypes.swift.gyb b/Sources/Atomics/HighLevelTypes.swift.gyb index b986f34..799a57e 100644 --- a/Sources/Atomics/HighLevelTypes.swift.gyb +++ b/Sources/Atomics/HighLevelTypes.swift.gyb @@ -71,6 +71,10 @@ public struct UnsafeAtomic { } } +#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 { diff --git a/Sources/Atomics/autogenerated/AtomicLazyReference.swift b/Sources/Atomics/autogenerated/AtomicLazyReference.swift index 1184a7e..fdef07d 100644 --- a/Sources/Atomics/autogenerated/AtomicLazyReference.swift +++ b/Sources/Atomics/autogenerated/AtomicLazyReference.swift @@ -50,6 +50,11 @@ public struct UnsafeAtomicLazyReference { } } +#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 diff --git a/Sources/Atomics/autogenerated/HighLevelTypes.swift b/Sources/Atomics/autogenerated/HighLevelTypes.swift index 6551cae..3b67afc 100644 --- a/Sources/Atomics/autogenerated/HighLevelTypes.swift +++ b/Sources/Atomics/autogenerated/HighLevelTypes.swift @@ -73,6 +73,10 @@ public struct UnsafeAtomic { } } +#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 {