The deinit implementations used to access the ivar directly, but that can confuse the compiler into assuming the value never changes after its initialization, because it doesn’t see accesses that are done via the pointer.
Stop accessing the ivar directly once it has been initialized.
This is going to ship as is, with no promises about it remaining in future versions. It is going to be a load bearing component of the package, though — just not necessary a stable one.
Now that we can rely on https://reviews.llvm.org/D86218, we don’t need to tiptoe around the use of `_Atomic(struct dword)`.
Rip out the clumsy encode/decode mess and the use of __uint128_t.
Swift 5.6/7 generates new compiler warnings when non-final classes
conform to `AtomicReference`. The warnings are pointing out a real
design issue: Self is covariant in protocols, but we intend atomic
operations to always deal with the base class rather than individual
subclasses.
Add a new associated type requirement to AtomicValue to represent the
actual type that originally conformed to the protocol, and add
explicit same-type requirements to clients to ensure they aren’t
asked to return a subclass.
Unfortunately, this change is source breaking:
```
class Base: AtomicReference {}
class Derived: Base {}
let ref = ManagedAtomic<Derived?>(nil)
// before: OK
// after: 'ManagedAtomic' requires the types 'Derived' and 'Base' be equivalent
```
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.
These are only ever called from opaque function bodies, so there is no need to make them inlinable anyway.
This allows us to stop linking client code with _AtomicsShims. (Although I don't quite understand how it was necessary before.)
- Disable building tests on Darwin
- Fix test registration on Linux when double-wide atomics aren't available
- Unconditionally enable double-wide atomics
Per #37, we currently happen to use some non-standard C atomics that only work in Clang; to prevent issues when this module gets compiled using other compilers, `#ifdef` out all the actual shims, leaving only the definitions for `retain_n`/`release_n`.
(For example, CMake builds the shims module using the system C compiler by default, which is usually GCC on Linux.)
Unify the double word path by using a bit more macro expansion. The two
differences between 32-bit and 64-bit is:
- `__uint128_t` vs `uint64_t`
- 64-bit shifts vs 32-bit shifts
We can simply use a macro to expand out the underlying C type rather
than bifurcating the definitions. For the second difference, we can
simply use the `__INTPTR_WIDTH__` for the shifts. We explicitly use
macros for the type-definitions to hide the typedef from Swift.
Use the C11 aggregate constructor to further reduce the code.