diff --git a/Sources/Atomics/AtomicOptional.swift b/Sources/Atomics/AtomicOptional.swift index 37b9d06..d645e8d 100644 --- a/Sources/Atomics/AtomicOptional.swift +++ b/Sources/Atomics/AtomicOptional.swift @@ -17,9 +17,10 @@ public protocol AtomicOptionalWrappable: AtomicValue { /// The atomic storage representation for `Optional`. associatedtype AtomicOptionalRepresentation: AtomicStorage - where AtomicOptionalRepresentation.Value == Self? + where AtomicOptionalRepresentation.Value == _AtomicValue? } -extension Optional: AtomicValue where Wrapped: AtomicOptionalWrappable { +extension Optional: AtomicValue +where Wrapped: AtomicOptionalWrappable, Wrapped._AtomicValue == Wrapped { public typealias AtomicRepresentation = Wrapped.AtomicOptionalRepresentation } diff --git a/Sources/Atomics/AtomicRawRepresentable.swift b/Sources/Atomics/AtomicRawRepresentable.swift index 82ace1f..5bbf4e7 100644 --- a/Sources/Atomics/AtomicRawRepresentable.swift +++ b/Sources/Atomics/AtomicRawRepresentable.swift @@ -10,7 +10,13 @@ // //===----------------------------------------------------------------------===// -extension RawRepresentable where Self: AtomicValue, RawValue: AtomicValue { +extension RawRepresentable +where + Self: AtomicValue, + RawValue: AtomicValue, + RawValue._AtomicValue == RawValue +{ + public typealias _AtomicValue = Self public typealias AtomicRepresentation = AtomicRawRepresentableStorage } @@ -18,7 +24,11 @@ extension RawRepresentable where Self: AtomicValue, RawValue: AtomicValue { /// type whose `RawValue` conforms to `AtomicValue`. @frozen public struct AtomicRawRepresentableStorage: AtomicStorage -where Value: RawRepresentable, Value.RawValue: AtomicValue { +where + Value: RawRepresentable, + Value.RawValue: AtomicValue, + Value.RawValue._AtomicValue == Value.RawValue +{ @usableFromInline internal typealias Storage = Value.RawValue.AtomicRepresentation @usableFromInline internal var _storage: Storage diff --git a/Sources/Atomics/AtomicStrongReference.swift b/Sources/Atomics/AtomicStrongReference.swift index 8931435..f6ed94d 100644 --- a/Sources/Atomics/AtomicStrongReference.swift +++ b/Sources/Atomics/AtomicStrongReference.swift @@ -15,15 +15,10 @@ import _AtomicsShims /// A class type that supports atomic strong references. public protocol AtomicReference: AnyObject, AtomicOptionalWrappable where - AtomicRepresentation == AtomicReferenceStorage, - AtomicOptionalRepresentation == AtomicOptionalReferenceStorage + _AtomicValue: AnyObject, + AtomicRepresentation == AtomicReferenceStorage<_AtomicValue>, + AtomicOptionalRepresentation == AtomicOptionalReferenceStorage<_AtomicValue> { - // These were added as a workaround for https://bugs.swift.org/browse/SR-10251 - // FIXME: We should remove these once the package requires a - // compiler version that contains that fix. - override associatedtype AtomicRepresentation = AtomicReferenceStorage - override associatedtype AtomicOptionalRepresentation = - AtomicOptionalReferenceStorage } /// The maximum number of other threads that can start accessing a diff --git a/Sources/Atomics/AtomicValue.swift b/Sources/Atomics/AtomicValue.swift index 3ba83b3..bfb0523 100644 --- a/Sources/Atomics/AtomicValue.swift +++ b/Sources/Atomics/AtomicValue.swift @@ -13,9 +13,10 @@ /// A type that supports atomic operations through a separate atomic storage /// representation. public protocol AtomicValue { + associatedtype _AtomicValue = Self /// The atomic storage representation for this value. associatedtype AtomicRepresentation: AtomicStorage - where AtomicRepresentation.Value == Self + where AtomicRepresentation.Value == _AtomicValue } /// The storage representation for an atomic value, providing pointer-based diff --git a/Sources/Atomics/HighLevelTypes.swift.gyb b/Sources/Atomics/HighLevelTypes.swift.gyb index aef8e08..6935c63 100644 --- a/Sources/Atomics/HighLevelTypes.swift.gyb +++ b/Sources/Atomics/HighLevelTypes.swift.gyb @@ -18,7 +18,8 @@ ${autogenerated_warning()} /// An unsafe reference type holding an atomic value, requiring manual memory /// management of the underlying storage representation. @frozen -public struct UnsafeAtomic { +public struct UnsafeAtomic +where Value._AtomicValue == Value { public typealias Storage = Value.AtomicRepresentation @usableFromInline @@ -75,7 +76,8 @@ extension UnsafeAtomic: @unchecked Sendable where Value: Sendable {} /// A reference type holding an atomic value, with automatic memory management. @_fixed_layout -public class ManagedAtomic { +public class ManagedAtomic +where Value._AtomicValue == Value { @usableFromInline internal var _storage: Value.AtomicRepresentation diff --git a/Sources/Atomics/autogenerated/HighLevelTypes.swift b/Sources/Atomics/autogenerated/HighLevelTypes.swift index 654acdf..ff584b7 100644 --- a/Sources/Atomics/autogenerated/HighLevelTypes.swift +++ b/Sources/Atomics/autogenerated/HighLevelTypes.swift @@ -20,7 +20,8 @@ /// An unsafe reference type holding an atomic value, requiring manual memory /// management of the underlying storage representation. @frozen -public struct UnsafeAtomic { +public struct UnsafeAtomic +where Value._AtomicValue == Value { public typealias Storage = Value.AtomicRepresentation @usableFromInline @@ -77,7 +78,8 @@ extension UnsafeAtomic: @unchecked Sendable where Value: Sendable {} /// A reference type holding an atomic value, with automatic memory management. @_fixed_layout -public class ManagedAtomic { +public class ManagedAtomic +where Value._AtomicValue == Value { @usableFromInline internal var _storage: Value.AtomicRepresentation