Skip to content

core: make some fundamental atomic functions generic#153407

Open
joboet wants to merge 2 commits intorust-lang:mainfrom
joboet:generic_atomic_fundamentals
Open

core: make some fundamental atomic functions generic#153407
joboet wants to merge 2 commits intorust-lang:mainfrom
joboet:generic_atomic_fundamentals

Conversation

@joboet
Copy link
Member

@joboet joboet commented Mar 4, 2026

CC #130539

This makes the basic Atomic creation/destructuring operations (new, into_inner, from_ptr, as_ptr, From<T>, Default) generic over T instead of defining them for each primitive. All other operations need a bit more design work, so I've left them out for now.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 4, 2026
@joboet
Copy link
Member Author

joboet commented Mar 4, 2026

@bors try jobs=i686-gnu-1,i686-gnu-2

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 4, 2026
core: make some fundamental atomic functions generic


try-job: i686-gnu-1
try-job: i686-gnu-2
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 4, 2026

💔 Test for a3a652d failed: CI. Failed jobs:

@joboet joboet force-pushed the generic_atomic_fundamentals branch from f804a05 to a6a05f8 Compare March 4, 2026 16:55
@joboet joboet marked this pull request as ready for review March 5, 2026 11:57
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 5, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 5, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2026

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, scottmcm

pub const fn new(v: T) -> Atomic<T> {
// SAFETY:
// `Atomic<T>` is essentially a transparent wrapper around `T`.
unsafe { transmute_unchecked(v) }
Copy link
Member

Choose a reason for hiding this comment

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

Do these really need to be transmutes? Feels like it at least needs better justification that "essentially" -- and to do this AtomicPrimitive should have a # Safety section listing what you can rely on from it in order to rely on that here.

Maybe AtomicPrimitive should have an into_storage or similar method on it instead? Because for lots of these things, new should just be the obvious Atomic { v: UnsafeCell::new(v) }. (Is it only bool that does anything different from that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe AtomicPrimitive should have an into_storage or similar method on it instead? Because for lots of these things, new should just be the obvious Atomic { v: UnsafeCell::new(v) }. (Is it only bool that does anything different from that?

T::Storage needs to be layout-compatible with T in any case since get_mut relies on that, too. Adding an into_storage without adding functions for references seems inconsistent to me. And in any case, this is a perma-unstable sealed API that will need design changes before becoming unsealed anyway.

I'm somewhat open to expand the safety section though...

pub const fn into_inner(self) -> T {
// SAFETY:
// * `Atomic<T>` is essentially a transparent wrapper around `T`.
unsafe { transmute_unchecked(self) }
Copy link
Member

Choose a reason for hiding this comment

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

...and from_inner too, I guess, on AtomicPrimitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants