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.
This fixes linker errors such as
```
Undefined symbols for architecture arm64:
"_sa_retain_n(void*, unsigned int)", referenced from:
(extension in Atomics):Swift.Unmanaged.retain(by: Swift.Int) -> () in Unmanaged extensions.swift.o
NOTE: found '__sa_retain_n' in _AtomicsShims.c.o, declaration possibly missing 'extern "C"'
```
when building with Swift/C++ interoperability enabled.
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.
`_Atomic(_sa_dword)` trips up C++. This is likely due to real issues, but it seems pointless to try to fix it — rather than heroically trying to keep this header working, we can simply force the use of native builtins on Swift 5.9 and later. (I planned to do that anyway, as a major step towards deleting `_AtomicsShims` altogether.)
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
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.
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.
Linux on x86_64 unfortunately disables support for cmpxchg16 by default, making double-wide atomic operations fall back to using locks. We cannot currently override this on the package level, so stop providing double-wide atomics in this configuration by default.
To enable codegen support for double-wide atomics on Linux/x86_64, compile the package with `-Xcc -mcx16 -Xswiftc -DENABLE_DOUBLEWIDE_ATOMICS`.