Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore): Use Native swift Atomics #1969

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mustiikhalil
Copy link
Contributor

The following PR addresses the following:

  • Replaces the usage of CAtomics with the native Atomics from the swift library
  • Bumps the development platform to macOS 15
  • Removes all references to CAtomics from the library since its out of commission

Closes #1949

@mustiikhalil mustiikhalil requested a review from ahoppen as a code owner February 5, 2025 18:18
Copy link
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.

Thank you @mustiikhalil 🙏🏽

Sources/SwiftExtensions/Atomics.swift Outdated Show resolved Hide resolved
Copy link
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.

Thanks for the update. I have two high-level comments:

  • Should we just use sequentiallyConsistent as the ordering? As far as I can tell, the current releasing and acquiring produce the same semantics and I find sequentiallyConsistent easier to reason about. Or am I missing something.
  • I think some of the Atomic<Int32> and Atomic<UInt32> can now become Atomic<Int> if that simplified their usage. They were only Int32 and UInt32 because of C interop.

Sources/SourceKitLSP/SourceKitIndexDelegate.swift Outdated Show resolved Hide resolved
Copy link
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. I noticed one small mistake while looking through again, otherwise everything is great!

@@ -216,7 +217,7 @@ package final class TestSourceKitLSPClient: MessageHandler, Sendable {
// It's really unfortunate that there are no async deinits. If we had async
// deinits, we could await the sending of a ShutdownRequest.
let sema = DispatchSemaphore(value: 0)
server.handle(ShutdownRequest(), id: .number(Int(nextRequestID.fetchAndIncrement()))) { result in
server.handle(ShutdownRequest(), id: .number(Int(nextRequestID.add(1, ordering: .sequentiallyConsistent).newValue))) { result in
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
server.handle(ShutdownRequest(), id: .number(Int(nextRequestID.add(1, ordering: .sequentiallyConsistent).newValue))) { result in
server.handle(ShutdownRequest(), id: .number(Int(nextRequestID.add(1, ordering: .sequentiallyConsistent).oldValue))) { result in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and I am assuming that when subtracting or adding in the following places its the new value that we need and not the old one.

let count = bytesCollected.add(bytes.count, ordering: .sequentiallyConsistent).newValue
var progress = Double(count) / Double(expectedLogSize)
let count = pendingUnitCount.subtract(count, ordering: .sequentiallyConsistent).newValue
if count == 0 {

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that’s correct. It’s just this case where we want to use the oldValue because nextRequestID is the next request ID that hasn’t been used yet. We use nextRequestID with oldValue in other places as well.

@mustiikhalil mustiikhalil force-pushed the issue-1949-refactor-atomic branch 2 times, most recently from d53797e to 7fb0adb Compare February 6, 2025 14:52
@mustiikhalil mustiikhalil changed the title Uses Native swift Atomics (chore): Use Native swift Atomics Feb 6, 2025
@ahoppen
Copy link
Member

ahoppen commented Feb 6, 2025

@swift-ci Please test

Replaces the usage of CAtomics with the native
Atomics from the swift library and bumps the development platform
to macOS 15
Replacing the usage of Int32, and UInt32 with Int since the previous was only used because of c bridging

Uses .sequentiallyConsistent for all loading and storing methods
@mustiikhalil mustiikhalil force-pushed the issue-1949-refactor-atomic branch from 7fb0adb to df47d38 Compare February 6, 2025 20:44
@mustiikhalil
Copy link
Contributor Author

The Ci failed because of a newly merged commit that uses the AtomicUint32

@ahoppen
Copy link
Member

ahoppen commented Feb 6, 2025

Thanks for the update @mustiikhalil

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented Feb 6, 2025

@swift-ci Please test Windows

@ahoppen
Copy link
Member

ahoppen commented Feb 8, 2025

@swift-ci Please test

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.

Replace implementation of AtomicBool etc. by atomic from the standard library
2 participants