Swift Atomics Versions Save

Low-level atomic operations for Swift

1.2.0

8 months ago

This minor release adds support for Swift 5.9.

This release contains no API-level additions nor any other visible changes to stable interfaces; the version number bump is simply acknowledging that this release ships a full rewrite of package internals -- it isn't just a regular bug fix release.

Changes

  • This release requires Swift 5.7 or later. (Clients on older toolchains will automatically remain on the 1.0 or 1.1 releases.)
  • The package now supports being used as a dependency in projects that have C++ interoperability enabled in Swift 5.9.
  • On Swift 5.9+, atomic operations are now implemented using native Swift compiler builtins. The package no longer forwards to C atomics when built on newer toolchains.

Fixes

  • Minor documentation fixes.

Pull Requests

New Contributors

Full Changelog: https://github.com/apple/swift-atomics/compare/1.1.0...1.2.0

Thank you very much to everyone who contributed to this release!

1.1.0

1 year ago

This minor release improves support for recent Swift releases, adds new functionality and resolves some known issues.

Changes

  • This release requires Swift 5.6 or better. (Clients on older toolchains will automatically remain on the 1.0 releases.) (#67)

  • AtomicReference is now unconditionally available on all supported platforms. (#65 by @kelvin13)

  • ManagedAtomic now conforms to Sendable when its Value is Sendable. (#45)

  • RawRepresentable types can now opt into support for atomic operations on their optional values as long as their underlying RawValue also supports it. (#42 by @glessard)

    struct SomeValue: RawRepresentable, AtomicOptionalWrappable {
      var rawValue: UnsafeRawPointer
    
      init(rawValue: UnsafeRawPointer) {
        self.rawValue = rawValue
      }
    }
    
    let atomic: ManagedAtomic<SomeValue> // OK
    let atomic2: ManagedAtomic<SomeValue?> // Also OK!
    
  • The weakCompareExchange operation now comes with a variant that takes a single ordering (#75). This makes it less verbose to use it in the common case where the same ordering is needed on both the success and the failure paths.

    let atomic = ManagedAtomic<Int>(42)
    
    var original = 0
    var exchanged = false
    repeat {
      (exchanged, original) = atomic.weakCompareExchange(
        expected: original,
        desired: 23,
        ordering: .relaxed) // no need to specify a separate failureOrdering!
    } while !exchanged
    
  • DoubleWord.low and DoubleWord.high are now deprecated (#70). Use first and second instead.

  • This release lays the groundwork for replacing the use of C atomics with native Swift compiler intrinsics (#74). When it eventually becomes stable, this change will allow swift-atomics to support Windows (#56), and it will resolve a multitude of build problems on other platforms (e.g., #54, #55, #62, #8). Version 1.1 ships with experimental support for building the package in this mode; however, this mode is not enabled by default, and it is subject to arbitrarily change in any future release.

Fixes

  • ManagedAtomicLazyReference no longer leaks its value when it is deinitialized (#66).

  • AtomicReference conformances on non-final classes no longer emit a compiler warning in Swift 5.7 and later (#53). Atomic references now fully support class hierarchies, but only the superclass that introduced the AtomicReference conformance can be used as the type argument to ManagedAtomic or UnsafeAtomic. This turns a previously undiagnosed type safety violation into an unconditional compile-time error:

    class Base: AtomicReference {}
    // 1.0: warning: Non-final class 'Base' cannot safely conform to protocol
    //    'AtomicValue', which requires that 'Self.AtomicRepresentation.Value'
    //    is exactly equal to 'Self'; this is an error in Swift 6
    // 1.1: OK
    
    class Derived: Base {} 
    
    let ref1: ManagedAtomic<Base> = .init(Derived()) // OK
    let ref2: ManagedAtomic<Derived> = .init(Derived())
    // 1.0:
    //    no error, silent type safety violation
    // 1.1+: 
    //    error: 'ManagedAtomic' requires the types 'Derived' 
    //    and 'Base' be equivalent
    
  • All atomic operations are now implemented in terms of Int8, Int16, Int32, Int64, Int, or DoubleWord. The package no longer uses non-standard C to implement atomic operations on Bool (#37).

  • Building the package tests is now far less resource-intensive, considerably speeding up builds on some memory-constrained systems (#71).

Pull Requests

  • #42 Implement AtomicStorage for Optionals of RawRepresentable types (by @glessard)
  • #58 Fix support for non-final classes in AtomicReference (by @lorentey)
  • #65 enable AtomicReference everywhere (by @kelvin13)
  • #67 Bump minimum required toolchain to Swift 5.6 (by @lorentey)
  • #68 Remove obsolete workarounds for older toolchains (by @lorentey)
  • #69 ManagedAtomicLazyReference: Properly dispose object on deinit (by @lorentey)
  • #70 Simplify shims (by @lorentey)
  • #71 Resolve some test issues (by @lorentey)
  • #72 [test] Fix basic tests to to actually cover weakCompareExchange (by @lorentey)
  • #73 Update AtomicOptionalWrappable support for RawRepresentable types (by @lorentey)
  • #74 Add support for using LLVM intrinsics instead of C atomics (by @lorentey)
  • #76 Add a weakCompareExchange variant that only takes a single ordering (by @lorentey)
  • #77 Add an Xcode project exercising native builtins in a monomodule configuration (by @lorentey)
  • #78 Fix compatibility with Swift 5.6 (by @lorentey)
  • #80 Update file headers (by @lorentey)
  • #81 Fix some edge cases under 5.6 (by @lorentey)
  • #82 1.1 release preparations (by @lorentey)
  • #83 Utilities/run-full-tests.sh: Use a different derived data path when building the Xcode project (by @lorentey)

Full diffs: https://github.com/apple/swift-atomics/compare/1.0.3...1.1.0

Thank you very much to everyone who contributed to this release!

1.0.3

1 year ago

This is a documentation update, including the addition of basic DocC documentation bundles. The only other change is a fix to the CMake build configuration.

Changes

The package now contains documentation bundles, enabling nicer presentation of API documentation in DocC.

Pull Requests

New Contributors

Full Changelog: https://github.com/apple/swift-atomics/compare/1.0.2...1.0.3

1.0.2

2 years ago

This is a patch release that introduces initial support for building this package with the Swift 5.5 compiler.

(More fully-featured support with additional Sendable conformances will come in a future minor release.)

Fixes

  • The package now has a workaround for an arm64 code generation issue for double wide atomics in the version of LLVM that ships in Swift 5.5. (#41)
  • When building with Swift 5.5, UnsafeAtomic and UnsafeAtomicLazyReference now only conform to Sendable when their value is. Swift 5.5 implicitly adds unconditional conformances to these types in 1.0.1, which isn't right. (#47)
  • The package now has better support for building with CMake. (#39) (Note that the CMake build configuration is intended only to enable the use of this package within Swift toolchain builds. It isn't part of the package's public API, so it is subject to change in any release.)

Pull Requests

  • #38 [shims] Only define atomic shims in Swift's Clang Importer (by @lorentey)
  • #39 [cmake] Fix building with CMake (by @lorentey)
  • #40 Add support test script (by @lorentey)
  • #43 Implement double-wide loads with compare-exchange on arm64 in debug builds with the Swift 5.5 compiler (by @lorentey)
  • #44 Update utility scripts (by @lorentey)
  • #48 Fix UnsafeAtomic's Sendable conformance (by @lorentey)

Thank you to everyone who contributed to this release!

1.0.1

2 years ago

This is a patch release containing several bug fixes.

Fixes

  • The package now builds successfully on 32-bit architectures (i386, armv7) (#33)
  • The package manifest was adjusted to prevent SwiftPM warnings about unknown files in source directories.
  • Several types are now @frozen to match their @inlinable initializers. (This package isn't ABI stable, so this change is a no-op in all supported configurations.)

Pull Requests

  • #34 [shims] Fix i386/armv7 regression introduced in #26 (by @lorentey)
  • #35 [manifest] Fix warnings in 5.3 toolchains (by @lorentey)
  • #36 Fix build errors with library evolution enabled (by @lorentey)

Thank you to everyone who contributed to this release!

1.0.0

2 years ago

This release marks an important milestone for this package -- the advent of source stability!

Changes

  • The public API of Swift Atomics is now considered source stable. The README defines what we consider public API.
  • Swift Atomics now requires a Swift 5.3 or later toolchain.
  • The low-level (pointer-based) atomic boolean operations are now public. (They were accidentally omitted from previous releases.)
  • The package now includes a CMake-based build method for bootstrapping purposes. This isn't considered stable; it may be removed or arbitrarily changed in any new release, including patch releases.

Pull requests

  • #20 DoubleWord._readersBitWidth: Switch to using Int.bitWidth (by @lorentey)
  • #24 Mark the additional Bool methods as public (by @dfunckt)
  • #25 build: add a CMake based build for Atomics (by @compnerd)
  • #26 _AtomicShims: simplify double word setup (by @compnerd)
  • #28 gitignore: ignore vim swap files (by @compnerd)
  • #29 Tests: add XCTest manifest for non-SPM based builds (by @compnerd)
  • #30 Bump required toolchain version to 5.3 (by @lorentey)
  • #31 Declare Atomics source stable and describe what we consider public API (by @lorentey)
  • #32 [NFC] Update copyright notices (by @lorentey)

Thank you to everyone who contributed to this release!

0.0.3

3 years ago

Fixes

  • Adds basic support for building with the Swift 5.2 toolchains.
  • Resolves a warning about the arm64_32 architecture emitted by swift.org compiler builds.

0.0.2

3 years ago

Changes

  • On Linux only, support for double-wide atomics is unavailable by default on x86_64 CPUs. To enable double-wide atomic functionality, you have to manually switch on support for the cmpxchg16b instruction:

    $ swift build -Xcc -mcx16 -Xswiftc -DENABLE_DOUBLEWIDE_ATOMICS -c release
    

    Code containing cmpxchg16b will run on all but the earliest AMD x86_64 CPUs. (You can verify your target CPU supports it by checking that the cx16 flag is present in /proc/cpuinfo.)

  • The Swift Atomics test suite now requires --enable-test-discovery on non-Apple platforms.

0.0.1

3 years ago

Initial release.