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 1 commit 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 🙏🏽

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.

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

@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

@mustiikhalil
Copy link
Contributor Author

I'm assuming this will never pass on macOS since the Ci has is OS as 13.6 instead of 15.0

Replaces the usage of CAtomics with the native
Atomics from the swift library and bumps the development platform
to macOS 15

Removes all references to CAtomics from the library

Removes atomic wrappers infavor of using them directly

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 22425e9 to d788e44 Compare February 9, 2025 21:50
@ahoppen
Copy link
Member

ahoppen commented Feb 10, 2025

Oh no, I completely forgot about that 😢. Thank you for the PR anyway. This will be great once we can update the deployment target.

@mustiikhalil
Copy link
Contributor Author

No worries! Always happy to help, I guess we can make it a draft until all of that is done

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