Skip to content

Avoid C atomic operations in Swift 5.9+ #90

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

Merged
merged 5 commits into from
Jul 10, 2023

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Jul 8, 2023

Importing _AtomicsShims with C++ interoperability enabled uncovers some issues with double-wide atomics as currently implemented in C.

It's time to stop tweaking these C definitions -- instead, disable C atomics, and switch to using native Swift atomic operations from Swift 5.9 onward.

(For now, we'll still need _AtomicsShims for its swift_retain_n/swift_release_n wrappers. I'm planning to get rid of the need for those, too, but that'll need some compiler tweaks that aren't targeted for 5.9.)

Resolves #88.

Checklist

  • I've read the Contribution Guidelines
  • My contributions are licensed under the Swift license.
  • I've followed the coding style of the rest of the project.
  • I've added tests covering all new code paths my change adds to the project (if appropriate).
  • I've verified that my change does not break any existing tests.
  • I've updated the documentation if necessary.

lorentey added 4 commits July 7, 2023 18:21
…mpiled as C++

`_Atomic(_sa_dword)` trips up C++. This is likely due to real issues, but it seems pointless to try to fix it — rather than heroically trying to keep this header working, we can simply force the use of native builtins on Swift 5.9 and later. (I planned to do that anyway, as a major step towards deleting `_AtomicsShims` altogether.)
Switch from the classic `-parse-stdlib` option to the new `BuiltinModule` experimental feature.
@lorentey
Copy link
Member Author

lorentey commented Jul 8, 2023

@swift-ci test

@lorentey lorentey requested review from glessard and Azoy July 8, 2023 02:14
Copy link
Member

@Azoy Azoy left a comment

Choose a reason for hiding this comment

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

looks good to me!

@lorentey
Copy link
Member Author

lorentey commented Jul 8, 2023

@swift-ci test

@lorentey lorentey merged commit 1c2c004 into apple:main Jul 10, 2023
@finagolfin
Copy link

This pull breaks building the latest trunk of this package with Swift 5.8, as can be seen on my daily Android CI, and presumably 5.7 too.

Maybe this can be reconfigured in such a way that #if compiler(>5.8) or similar checks are used in the Package manifest instead, to choose whether native builtins are used or not?

@lorentey lorentey added this to the 1.2.0 milestone Sep 22, 2023
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.

Cannot build when C++ interoperability is used
3 participants