50 Commits
Author SHA1 Message Date
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 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
Karoy Lorentey 5730529b7f Replace AtomicValue._AtomicValue with AtomicReference._AtomicBase 2023-03-17 22:08:36 -07:00
Karoy Lorentey cc86c556be Fix support for non-final classes in AtomicReference
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
```
2023-03-17 16:24:51 -07:00
Karoy Lorentey cb7a3b2d35 ManagedAtomicLazyReference: Properly dispose object on deinit 2023-03-17 15:11:58 -07:00
Karoy Lorentey 275fb6be61 Remove obsolete workarounds for older toolchains 2023-03-17 14:47:54 -07:00
Karoy Lorentey a79166d648 Merge pull request #46 from lorentey/sendable
Mark managed atomic constructs Sendable if their payloads are
2023-03-17 14:41:13 -07:00
Karoy Lorentey 72034b4908 Regenerate gybbed sources 2023-03-17 14:04:12 -07:00
Karoy Lorentey 363a18e010 Restore empty line separator in IntegerConformances test 2023-03-17 13:56:38 -07:00
taylorswift 58e5a13f1c enable AtomicReference everywhere, and add some type annotations to tests 2023-02-17 02:22:39 +00:00
Karoy Lorentey 6c8237adbd [AtomicValue] Document AtomicRepresentation 2022-12-08 16:06:15 -08:00
Karoy Lorentey 22b3e539a5 [docs] Add a documentation bundle 2022-12-08 16:05:53 -08:00
Karl f62b0d33b4 [Documentation] Add a note that TSan does not support fences. 2021-11-12 12:42:37 +01:00
Karoy Lorentey e220ff33c3 Mark managed atomic constructs Sendable if their payloads are 2021-09-30 13:08:00 -07:00
Karoy Lorentey 44bf6b59dc Fix UnsafeAtomic's Sendable conformance
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.
2021-09-24 14:51:07 -07:00
Karoly Lorentey fef04c75ae [Utilities] Upgrade gyb to Python 3 2021-09-22 19:25:08 -07:00
Karoy Lorentey 0e51be5d3a Unmanaged.retain(by:)/release(by:): Remove @inlinable
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.)
2021-09-22 14:53:32 -07:00
Karoy Lorentey 98a31b396d [cmake] Fix building with CMake
- Disable building tests on Darwin
- Fix test registration on Linux when double-wide atomics aren't available
- Unconditionally enable double-wide atomics
2021-09-22 14:53:32 -07:00
Karoy Lorentey 2468fa3eac Also use compare-exchange in dispose() 2021-09-22 13:33:39 -07:00
Karoy Lorentey e08ad97132 Implement double-wide loads with compare-exchange on arm64 in debug builds with the Swift 5.5 commpiler
Resolves https://github.com/apple/swift-atomics/issues/41.
2021-09-22 13:06:19 -07:00
Guillaume LessardandKaroy Lorentey e47d14acfb Update Sources/Atomics/AtomicOptionalRawRepresentable.swift
state the layout compatibility guarantee

Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2021-09-20 17:41:16 -06:00
Guillaume Lessard ae5e639014 add implementation for RawRepresentable where RawValue: AtomicOptionalWrappable 2021-09-17 17:56:31 -06:00
Karoy Lorentey 1d4afa40d7 Fix build errors with library evolution enabled
We do not support building this package with `-enable-library-evolution`, but I don't see a reason not to fix build errors with that configuration.
2021-08-30 12:54:20 -07:00
Karoy Lorentey 299d1251f1 Regenerate gybbed sources 2021-08-27 17:19:56 -07:00
Karoy Lorentey eb7e1335f8 [NFC] Update copyright notices 2021-08-27 17:13:03 -07:00
Saleem Abdulrasool 67bbf646d8 build: add a CMake based build for Atomics
This adds an initial implementation of a CMake based build system.
2021-04-30 08:32:45 -07:00
Akis Kesoglou 7e101a5653 Mark the additional Bool methods as public
…inline with the static methods on AtomicStorage and AtomicIntegerStorage.
2021-03-14 19:20:38 +02:00
Karoy Lorentey 09ddcdd88d DoubleWord._readersBitWidth: Switch to using Int.bitWidth
This fixes a spurious warning about `arch(arm64_32)` emitted by swift.org compiler builds.

Resolves #19
2021-01-26 17:38:10 -08:00
Karoy Lorentey 47c88d732f Work around some compiler issues in Swift 5.2
This allows the package to be built with the Swift 5.2.4 toolchain.

Resolves #15
2020-11-09 13:52:03 -08:00
JP Simard 55a062c4a8 Fix typo in AtomicMemoryOrderings.swift docstring 2020-10-22 06:03:22 -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
Daniel Jackson 42691f8636 Commit changes from running generate-sources 2020-10-02 16:29:09 -07:00
Daniel Jackson 778e62b8c6 Fix successOrdering typo in documentation, in the gyb file 2020-10-02 16:28:33 -07:00
Dan Jackson ad1fb15167 Update documentation typo: double ‘the’ 2020-10-02 09:28:57 -07:00
Karoy Lorentey b97750eb18 Initial commit. 2020-10-01 16:57:36 -07:00