As usual, we support just the three latest Swift releases: 5.10, 6.0 and 6.1.
Also delete obsolete C atomics. Dropping Swifts <5.9 allows us to make ATOMICS_NATIVE_BUILTINS the unconditional default behavior.
@_implementationOnly does not work correctly unless Swift’s Library Evolution dialect is enabled — it leads to obscure module loading failures.
There seems to be no way to create a compile-time condition on whether library evolution is enabled, so we need to stop using @_implementationOnly imports in all package configurations.
This appears to resolve a build failure when library evolution is enabled. (This isn’t a fully supported configuration (this package is not ABI stable), but it should still be possible to build the package in that configuration.)
@_implementationOnly has bad failure modes when library evolution isn’t enabled, but I hope we’ll be avoiding those here, as on 5.9+, we’re only using it to import a couple of functions — we aren’t relying on imported things to set struct layouts or anything like that. 🤞
#if conditional parsing is evidently broken in 5.7, and it gets confused unless things are arranged just right. Things seem to work as long as the `compiler(>=5.9)` conditional is put on its own `#if` construct on the topmost level — so let’s do that for now.
For builtins, we want to emulate the stdlib’s solution where all atomic primitive operations take and return a (sort of) opaque atomic representation value.
For C shims, we do not want to atomic primitives to take and return _Atomic(T) values, so let’s revert to the original 1.1.x solution.
The SysV ABI defined uint64_t with 4 byte alignment on i386 — so we can’t just assume that the integer types will have the right alignment by default for atomics.
Emulate the original `_Atomic<Width>Storage` types in the C shims even in native atomics configuration, so that they can carry a custom `@_alignment` attribute.
Oops, that was not intended to work, and in fact it produces warnings in clients.
Instead, change _sa_retain_n and _sa_release_n to Swift calling convention and call them using _silgen_name trickery when in single-module configuration.
Resolves rdar://110860922
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
```