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

Introduce a noncopyable Atomic<T> construct #94

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Jul 27, 2023

Now that we have @_rawLayout, it is now possible to start drafting the move-only Atomic<Value> type we always wanted.

This is an early experiment that isn't ready for prime time yet:

  1. It requires a compiler with support for the experimental RawLayout feature. (It is currently experimentally available on swift's main branch, which still identifies itself as Swift 5.9.)
  2. The code is triggering compiler assertions all over the place. These need to be reported and fixed (or worked around).
  3. @_rawLayout(like:) currently does not support picking up the layout type from the type argument of the Atomic generic, so this PR unconditionally widens the type's layout to the maximum possible atomic width. (I.e., we use double-wide layout even if we only need to store a single byte's worth of data.) Support is now (almost?) working.
  4. It might be a good idea to have the atomic representations be themselves noncopyable. However, this would require waiting until such types can conform to protocols, which is likely a bad idea.

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
Copy link
Member Author

CI is going to fail, but just for fun:

@swift-ci test

@lorentey
Copy link
Member Author

lorentey commented Sep 22, 2023

This does work well, but I don't expect we'll land it in this form.

We are planning to radically streamline the AtomicValue protocol for the stdlib proposal, and I expect we'll want to land a "packagized" version of that as a brand new module (SynchronizationPackage), completely replacing the current API surface. (Perhaps the new module will ship in a new package, even.)

The nice thing is that most client code that isn't defining its own atomics from scratch will survive without any changes. (Other than changing the import statement and replacing Unsafe/ManagedAtomic with Atomic, of course.)

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.

1 participant