91 Commits
Author SHA1 Message Date
Pavel Yaskevich 85633139bf Rename internal passRetained helper to _passRetained
This avoids ambiguity with a public version of the same API
that is part of a Swift standard library and returns a non-optional
result.
2026-06-23 13:34:45 -07:00
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
Mishal Shah 81d30f50be Update the swift-evolution urls 2025-03-04 23:35:49 -08:00
Karoy LorenteyandGuillaume Lessard 074c8c8fea Update link to compiler issue
Co-authored-by: Guillaume Lessard <glessard@users.noreply.github.com>
2023-12-13 15:04:52 -08:00
Karoy Lorentey a3ac36c96d [native] Stop using @_implementationOnly import in package configs
@_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.
2023-12-12 12:05:41 -08: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 3431b8543f Fix CMake configuration 2023-09-27 16:12:25 -07:00
Karoy Lorentey f26da16e6e On 5.9, hide the _AtomicsShims import from the public interface
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. 🤞
2023-09-27 14:46:50 -07:00
Karoy Lorentey fe0fc8b76c Avoid confusing Swift 5.7 with _pointerBitWidth conditionals
#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.
2023-09-27 14:19:36 -07: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 d976dd29ad Protect _pointerBitWidth conditionals from misparsing on older Swifts 2023-09-25 19:42:22 -07:00
Karoy Lorentey 8189a83f1c [DocC] Fix some missing items 2023-09-22 17:04:54 -07:00
Karoy Lorentey 6ed54fa0d3 [CMake] Do not list .gyb files as sources 2023-09-22 11:24:11 -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 9351ce080d DoubleWord.AtomicRepresentation: Use DoubleWord storage on all platforms
We used to use Int64 on 32-bit architectures, but the inconsistency is bothering me. (Even ignoring alignment issues on SysV-derived ABIs on i386.)
2023-09-20 19:27:45 -07:00
Karoy Lorentey 9db6c56d8d Update CMake and Xcode build configs 2023-09-20 19:08:41 -07:00
Karoy Lorentey 4166cff711 Move definition of DoubleWord into DoubleWord.swift 2023-09-20 18:49:02 -07:00
Karoy Lorentey b1b74cb512 Reorganize source folder 2023-09-20 18:39:37 -07:00
Karoy Lorentey c39a7eff8d De-gyb HighLevelTypes.swift and AtomicLazyReference.swift 2023-09-20 18:34:02 -07:00
Karoy Lorentey 1f6a86f726 Start using _pointerBitWidth in 5.9+ 2023-09-18 16:08:16 -07:00
Karoy Lorentey d75ef1b060 [NFC] Move protocol AtomicStorage into its own source file 2023-09-18 16:05:17 -07:00
Karoy Lorentey 5603f612d2 [_AtomicShims] Don’t try to extend the library path using .linker_option
This emits a warning and it seems to be unnecessary.
2023-08-14 15:58:00 -07:00
Karoy Lorentey 673864b809 [_AtomicShims] On Darwin, ensure we link against libswiftCore using assembly shenanigans
This avoids a linker failure when the build system decides to build this module as a standalone library.

Hopefully this will all go away soon, when swift_retain_n/swift_release_n will become primitives exposed by the stdlib.
2023-08-11 15:39:22 -07:00
Karoy Lorentey 41382923ad Regenerate sources 2023-07-10 12:34:34 -07:00
Karoy Lorentey 1c2c004dd0 Merge pull request #90 from lorentey/fix-c++-interop
Avoid C atomic operations in Swift 5.9+
2023-07-10 12:33:23 -07:00
Karoy Lorentey 1698b26243 Don’t import Builtin unless we actually need it 2023-07-07 19:35:10 -07:00
Karoy Lorentey ca9d5816a6 Adjust ATOMICS_NATIVE_BUILTINS imports to adapt to the BuiltinModule mechanism 2023-07-07 18:52:13 -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
R Olson cbd73b1967 Update AtomicLazyReference.swift.gyb
Fix reference doc variable references
2023-07-06 16:16:42 -06: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 bbee754adc ManagedAtomic[LazyReference]: Always access ivar through pointer
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.
2023-03-31 15:19:02 -07:00
Karoy Lorentey 378fb4947f Also fix compatibility with 5.6 when ATOMICS_NATIVE_BUILTINS is enabled 2023-03-31 13:14:42 -07:00
Karoy Lorentey e53eff6f17 Update file headers 2023-03-30 14:58:57 -07:00
Karoy Lorentey 58a95f7984 Fix compatibility with Swift 5.6 2023-03-30 14:05:45 -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 11a0547baa Update CMake configuration 2023-03-24 17:12:13 -07:00
Karoy Lorentey 0f07d9dcf8 Add a weakCompareExchange variant that only takes a single ordering
Resolves https://github.com/apple/swift-atomics/issues/75
2023-03-24 16:30:49 -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 ca8a8fcc38 Merge pull request #58 from lorentey/fix-non-final-class-warnings
Fix support for non-final classes in AtomicReference
2023-03-20 16:41:41 -07:00
Karoy Lorentey 79718d92d3 Prepare for the protocol refactoring in #58 2023-03-19 20:42:55 -07:00
Karoy Lorentey 07ceb40fe1 AtomicOptionalRawRepresentableStorage.Storage → _Storage 2023-03-19 20:42:33 -07:00
Karoy Lorentey 907ce2a79e Remove remaining references to _AtomicValue 2023-03-19 20:41:37 -07:00
Karoy Lorentey e876381f7d Red tape for our lovely build systems 2023-03-19 20:15:06 -07:00
Karoy Lorentey f482c3098d Update AtomicOptionalWrappable support for RawRepresentable types
Also add some basic tests exercising these.
2023-03-19 19:59:46 -07:00
Karoy Lorentey 9088deb8db Merge pull request #42 from glessard/optional-rawrepresentable-atomic
implement AtomicStorage for Optionals of RawRepresentable types
2023-03-19 19:33:26 -07:00
Karoy Lorentey 3d0a97769f [nfc] Reflow 2023-03-19 19:27:10 -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