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

Tracking Issue for generic Atomic #130539

Open
1 of 7 tasks
CAD97 opened this issue Sep 19, 2024 · 4 comments
Open
1 of 7 tasks

Tracking Issue for generic Atomic #130539

CAD97 opened this issue Sep 19, 2024 · 4 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@CAD97
Copy link
Contributor

CAD97 commented Sep 19, 2024

Feature gate: #![feature(generic_atomic)]

This is a tracking issue for replacing the distinct Atomic* types with a generic Atomic<T> type. This allows using Atomic with FFI type aliases and helps clean up some API surface. Only types with existing AtomicT are usable in Atomic<T>.

Public API

// core::sync::atomic

pub struct Atomic<T: AtomicPrimitive>(/* private fields*/);

pub type AtomicI32 = Atomic<i32>; // etc

Steps / History

Unresolved Questions

  • Atomic<T> is soft-blocked on 128-bit atomics, because since trait implementations cannot be unstable, gating Atomic<i128> separately from Atomic<i32> isn't possible.
    • If necessary, AtomicI128 could instead name Atomic<Wrapper<i128>> for some unstable name Wrapper until 128-bit atomics are stable, to prevent Atomic<i128> from being usable from stable earlier than intended.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@CAD97 CAD97 added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 19, 2024
@cynecx
Copy link
Contributor

cynecx commented Sep 19, 2024

Would/could this allow Atomic<(*const (), u64)>?

@CAD97
Copy link
Contributor Author

CAD97 commented Sep 19, 2024

Not in the initial implementation tracked here, which does not aim to extend the set of types usable atomically yet. In the future, yes, this moves us into the direction of being able to support additional atomic types in the API.

workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 19, 2024
Create `Atomic<T>` type alias

and use it in core/alloc/std where possible, ignoring test files for now.

This is step one, creating the alias from `Atomic<T>` to `AtomicT`. The next step of flipping this and aliasing `AtomicT` to `Atomic<T>` will have a bigger impact, since `AtomicT` imports can be dropped once `Atomic::new` is a usable name.

First commit is the true change. Second commit is mostly mechanical replacement of `AtomicT` type names with `Atomic<T>`.

See [how this was done for `NonZero`](rust-lang#120257) for the rough blueprint I'm following.

- ACP: rust-lang/libs-team#443 (comment)
- Tracking issue: rust-lang#130539
@RalfJung
Copy link
Member

RalfJung commented Sep 19, 2024

From the ACP

impl<T> Unpin for Atomic<T> {}

This is surprising to me, why does this not propagate the Unpinness of T?

@CAD97
Copy link
Contributor Author

CAD97 commented Sep 19, 2024

Why not propagate Unpin

In this case, because I was overly terse laying out the API in the ACP, apparently. Both the NonZero code I was basing general structure off of and my local sketch do actually bound the autotrait impls on T: AutoTrait.

But also,

  • The initial set of allowed types are all Unpin.
  • It seems fundamentally impossible to use the atomic load/store/swap API with pinned data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants