apple/swift-atomics
59.6
Adequate · 1 October 2026
3.7k
lines of production code
Swift
with Python
2
measurements over time
What this system is
This system is the Swift Atomics library, providing low-level atomic operations for Swift types such as integers, booleans, pointers, and references. It implements these primitives using native compiler builtins to ensure correct memory alignment and performance, while supporting weak compare-exchange operations for efficient retry loops. The project includes a comprehensive test suite covering these atomic behaviors across multiple platforms and build systems, including CMake and Xcode.
How it got here
2020 — CMake migration and Swift 5.10 support
9 changes.
This period focused on modernizing the build infrastructure by introducing CMake support for the Atomics and \_AtomicsShims libraries, replacing legacy Xcode and manual test registration approaches. The work also involved upgrading the toolchain requirements to Swift 5.10 to leverage native compiler builtins for atomic operations and migrating internal utilities to Python 3.
2023 — Native atomics and Xcode support
7 changes.
The project refactored its atomic primitives to leverage native Builtin types, introducing custom storage structs to fix alignment issues and adding weak compare-exchange operations. This period also established a comprehensive Xcode project configuration and significantly expanded test coverage by splitting the suite into type-specific files.
Features
Add CMake build support for the Atomics library
The Atomics library now includes a CMake build system (Sources/Atomics/CMakeLists.txt), allowing it to be built and installed via CMake in addition to the existing Xcode project. The configuration defines the library target, links against the \_AtomicsShims library, and applies platform-specific compiler flags (such as -mcx16 for x86\_64).
Sources/Atomics · high confidence
New Xcode project configuration for Swift Atomics
The Xcode directory now contains a complete project structure (Atomics.xcodeproj) with shared xcconfig files to build the Swift Atomics library as a single framework bundle. This configuration sets deployment targets to macOS 12.0, iOS 15.0, watchOS 8.0, and tvOS 15.0, uses Swift 5.5, and enables the BuiltinModule experimental feature. It also includes a test plan (Atomics.xctestplan) supporting default and Thread Sanitizer runs, and configures code signing identities for iOS, watchOS, and tvOS platforms.
Xcode · high confidence
New Xcode project for Atomics with native builtin support
Developers can now open and build the Atomics library directly in Xcode using a newly added project configuration. This setup exercises native builtins in a monomodule configuration and includes a comprehensive test suite covering atomic integers, pointers, references, and other types, along with utility scripts for source generation.
Xcode/Atomics.xcodeproj · high confidence
Behavioural changes
Add CMake build support and Darwin-specific linking for AtomicsShims
The \_AtomicsShims module now includes a CMake build configuration (CMakeLists.txt) to facilitate building the static library, and on Darwin platforms, it explicitly ensures linking against libswiftCore via assembly linker options to resolve dependency issues when built as a standalone module.
_Sources/\AtomicsShims · high confidence
Native atomic primitives restructured with custom storage types to fix alignment
The native atomic primitives implementation has been reorganized to use custom storage types (such as \\_AtomicInt8Storage\) for internal atomic operations. This change addresses alignment issues by ensuring proper memory alignment for atomic types, which improves reliability and correctness of atomic operations on native platforms. The autogenerated primitive definitions now explicitly manage alignment through dedicated storage structs rather than relying on implicit type alignment.
Sources/Atomics/Primitives · high confidence
Refactored atomic conformances to use dedicated storage types and native atomics
The atomic conformances for Bool, integers, pointers, and RawRepresentable types have been restructured to use specific internal storage types (such as \_AtomicInt8Storage and \_AtomicIntStorage) instead of generic or indirect wrappers. This change replaces the previous switch-based dispatch to C shim functions with direct calls to native atomic operations, simplifying the implementation and improving code clarity. Additionally, source files have been reorganized into the Conformances directory, and the Bool atomic representation now explicitly uses an 8-bit integer storage to ensure correct alignment and behavior.
Sources/Atomics/Conformances · high confidence
Refactored atomic protocol hierarchy and added weak compare-exchange support
The atomic protocol structure has been reorganized to improve type safety and clarity. The \AtomicValue\ protocol is now a base requirement, while \AtomicInteger\ and \AtomicOptionalWrappable\ have stricter constraints on their associated storage types to ensure the value type matches the representation. \AtomicStrongReference\ has been renamed to \AtomicReference\ and now uses a \\_AtomicBase\ associated type to better support non-final classes, with updated documentation clarifying subclass limitations. Additionally, the \AtomicStorage\ protocol now includes a new \atomicWeakCompareExchange\ method, allowing for more efficient atomic updates in loops where spurious failures are acceptable, along with a default implementation for the strong \atomicCompareExchange\ variant.
Sources/Atomics/Protocols · high confidence
Refactored atomic types into dedicated module and added weak compare-exchange operations
The atomic types have been reorganized into the Sources/Atomics/Types module, with source files moved and gyb templates de-templated into concrete Swift files. This change introduces a new weakCompareExchange method on UnsafeAtomic, allowing atomic updates that may spuriously fail and are designed for use in retry loops. Additionally, the DoubleWord type has been rewritten to use native Builtin types instead of shim functions, with its high/low properties deprecated in favor of first/second, and the library now requires Swift 5.10 or later, dropping support for versions 5.7–5.9.
Sources/Atomics/Types · high confidence
Regenerated atomic implementation sources
The autogenerated source files in Sources/Atomics/autogenerated, including AtomicLazyReference.swift and IntegerConformances.swift, have been regenerated. This update refreshes the underlying atomic operations and type conformances to align with the latest toolchain requirements and internal optimizations, ensuring correct behavior for atomic lazy references and integer atomic representations.
Sources/Atomics/autogenerated · medium confidence
Simplified atomic shim implementation and updated copyright
The \_AtomicsShims header has been significantly reduced in size by removing the extensive C preprocessor macros that previously generated atomic operations for all standard integer types, Bool, and double-word integers. The file now primarily includes standard headers and defines basic inline attributes, indicating a shift away from the previous complex macro-based stamping mechanism. Additionally, the copyright notice has been updated to include the year 2025.
_Sources/\AtomicsShims/include · medium confidence
Utilities: Upgrade gyb to Python 3 and expand test coverage
The \Utilities/gyb\ tool and its supporting scripts (\gyb.py\, \gyb\_utils.py\) have been migrated from Python 2.7 to Python 3, updating syntax for modern compatibility (e.g., \io.StringIO\, \list()\ iteration). Additionally, the \Utilities/run-full-tests.sh\ script was introduced to automate building and testing the package across multiple configurations (SPM, CMake, Xcode) and platforms, including long-running and ThreadSanitizer tests. The \generate-sources.sh\ script was also updated to use \find\ for robust source discovery and to remove obsolete autogenerated files.
Utilities · high confidence
Test coverage
Expanded and refactored atomic reference tests; Expanded test coverage for Swift Atomics basics; Migrate test execution to CMake; Refactor autogenerated atomic tests into separate files.
Dependencies
Swift 5.10 toolchain support and native builtin atomics
The package now requires Swift 5.10, enabling the use of native Swift compiler builtins for atomic operations instead of relying on C atomics. This change updates the minimum supported toolchain version and configures the build settings to leverage the new BuiltinModule experimental feature for improved performance and integration with modern Swift compilers.
(dependencies) · high confidence
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 66 → 60 (-6.4)
- Rubric changed (rubric-2026.09.11 → rubric-2026.09.18) — scores are not directly comparable.
Lenses
- Code Health 93 → 93 (+0.0)
- Architecture 89 → 97 (+8.2)
- Maturity 59 → 59 (+0.0)
- Readiness 54 → 41 (-13.2)
- Security 92 → 92 (+0.0)
Resolved (2)
- Dependency hygiene PARTLY measured — SwiftPM pinning read, dependency currency NOT established
- Documentation: no installation or build instructions (README.md)
New (2)
- Coverage not measured — Swift suite
- While the signatures are identical, the naming convention for the 'ordering' parameter differs in intent between the two types. ManagedAtomic uses a single ordering for both success and failure (implying a specific default or combined behavior), whereas UnsafeAtomic provides overloads that explicitly separate successOrdering and failureOrdering. This creates a cognitive dissonance where the same method name on similar types requires different mental models for memory ordering control (single vs. dual ordering).
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
apple/swift-atomics was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 1 October 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit bc30c67cf0c4479633621ad7950d71494a07390f — the exact code this score is about.
- Scored under rubric-2026.09.18 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-e569280dd5e2.