22 Commits
Author SHA1 Message Date
Karoy Lorentey 040c295e86 Update copyrights 2025-06-04 11:31:02 -07:00
Karoy Lorentey 581fb9e875 Drop support for Swifts 5.7-5.9
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.
2025-06-03 19:23:53 -07:00
Egor Zhdan 14b0f18370 Make AtomicsShims compatible with C++ interop
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.
2025-05-30 16:43:33 +01:00
Karoy Lorentey bd8115e046 _sa_retain_n/_sa_release_n: Use C calling convention in package builds 2023-12-07 11:14:18 -08:00
Karoy Lorentey 48fad5a291 Let builtins & shims expose different primitive signatures
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.
2023-09-25 21:05:53 -07:00
Karoy Lorentey 8b703fe93c [native atomics] Fix alignment issues by reintroducing custom storage types
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.
2023-09-22 00:41:51 -07:00
Karoy Lorentey 15824c718b [_AtomicsShims] Don’t define atomic operations when this header is compiled as C++
`_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.)
2023-07-07 18:21:46 -07:00
Karoy Lorentey 55a158b620 [Xcode] Don’t use a bridging header in a framework target
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
2023-06-20 10:52:41 -07:00
Karoy Lorentey 5a9973dc1d Add an Xcode project exercising native builtins in a monomodule configuration
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.
2023-03-24 20:34:16 -07:00
Karoy Lorentey 7feb1c1791 Add support for using LLVM intrinsics instead of C atomics 2023-03-24 15:33:30 -07:00
Karoy Lorentey 0f2c36bf75 _AtomicsShims: Also delete encoder/decoder macro for bools 2023-03-18 13:13:56 -07:00
Karoy Lorentey f2c34f56f6 Simplify shims
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.
2023-03-18 13:10:31 -07:00
taylorswift 58e5a13f1c enable AtomicReference everywhere, and add some type annotations to tests 2023-02-17 02:22:39 +00:00
Karoy Lorentey 5d07eab6fe [shims] Only define atomic shims in Swift's Clang Importer
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.)
2021-09-08 18:11:06 -07:00
Karoy Lorentey d4a3aae83b [shims] Fix i386/armv7 regression introduced in #26 2021-08-30 12:28:45 -07:00
Karoy Lorentey eb7e1335f8 [NFC] Update copyright notices 2021-08-27 17:13:03 -07:00
Saleem Abdulrasool 7294d12edd _AtomicShims: simplify double word setup
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.
2021-04-23 08:24:29 -07:00
Karoy Lorentey 9ad914d118 Make double-wide atomics conditional on platform support
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`.
2020-10-09 14:52:33 -07:00
Karoy Lorentey 6e09389a3d Revert "[shims] Make retain_n/release_n shims header-only" 2020-10-07 23:57:38 -07:00
Karoy Lorentey 40bd3bac4f [shims] Force-inline new shims 2020-10-06 18:39:11 -07:00
Karoy Lorentey 45fa32a922 [shims] Make retain_n/release_n shims header-only.
Resolves issue #8.
2020-10-06 18:00:10 -07:00
Karoy Lorentey b97750eb18 Initial commit. 2020-10-01 16:57:36 -07:00