Skip to content

Migrate atomics to Synchronization.Atomic, drop ToolsProtocolsCAtomics#51

Merged
rintaro merged 2 commits into
swiftlang:mainfrom
rintaro:migrate-atomics-to-synchronization
May 27, 2026
Merged

Migrate atomics to Synchronization.Atomic, drop ToolsProtocolsCAtomics#51
rintaro merged 2 commits into
swiftlang:mainfrom
rintaro:migrate-atomics-to-synchronization

Conversation

@rintaro
Copy link
Copy Markdown
Member

@rintaro rintaro commented May 21, 2026

Replace the AtomicBool/UInt8/UInt32/Int32 wrapper classes (backed by a small C atomics shim) with Synchronization.Atomic<T>. The ToolsProtocolsCAtomics target is removed from Package.swift and CMake.

Also relax atomic memory orderings to .relaxed. Every atomic in this package is either a unique-ID counter or a "once" flag whose result no other memory reads ride on. None of them synchronize with adjacent non-atomic state, so .relaxed is sufficient and avoids the SEQ_CST barriers.

Copy link
Copy Markdown
Contributor

@owenv owenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

Copy link
Copy Markdown
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. We should also be able to get rid of ThreadSafeBox in favor of Mutex.

Copy link
Copy Markdown

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread Sources/LanguageServerProtocolTransport/RequestAndReply.swift Outdated
@rintaro rintaro force-pushed the migrate-atomics-to-synchronization branch from 6115421 to a10b3db Compare May 22, 2026 18:31
rintaro added 2 commits May 22, 2026 11:33
Replace the AtomicBool/UInt8/UInt32/Int32 wrapper classes (backed by
a small C atomics shim) with Synchronization.Atomic<T>. All sites use
.sequentiallyConsistent ordering to match the prior shim's behavior;
relaxing per-site is left as a follow-up. The ToolsProtocolsCAtomics
target is removed from Package.swift and CMake.
The previous .sequentiallyConsistent ordering on every atomic
forced unnecessary barriers (notably dmb ish on ARM). Replace
with the minimum ordering each operation actually needs:

- ID counters (request/notification/signpost) → .relaxed.
  Operations only need uniqueness; ordering relative to other
  memory carries no information.
- LoggingScope's "fault logged" once-flag → .relaxed. No
  associated state rides on the flag.
- RequestAndReply.replied → .acquiring on load,
  .acquiringAndReleasing on exchange. ARC's refcount
  synchronization in deinit would make .relaxed functionally
  correct, but acquire/release expresses the operation's intent
  without leaning on that side-channel.
@rintaro rintaro merged commit d7a7203 into swiftlang:main May 27, 2026
52 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants