Skip to content

warn against using intrinsics that leave the scope of our memory model #118128

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 1 commit into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ extern "rust-intrinsic" {
/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::load`].
#[rustc_nounwind]
pub fn atomic_load_relaxed<T: Copy>(src: *const T) -> T;
/// Do NOT use this intrinsic; "unordered" operations do not exist in our memory model!
Copy link
Member

Choose a reason for hiding this comment

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

IIRC they were added for experimentation. Maybe the warning could be a bit more informative?

For whom is that warning anyway? std/compiler devs or for nightly users?
I.e. are you trying to convey that they shouldn't be exposed through stable std APIs or that nightly users are moving on thin ice when they experiment with this? Because the latter could be reasonable if they're doing that to experiment and demonstrate performance differences.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have clarified: in terms of the AM, I think the best that we can do is that these intrinsics act like regular non-atomic reads and writes.

Copy link
Member

Choose a reason for hiding this comment

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

Hrrm, I still think the language is a bit too unspecific. Then again, people who are just doing experiments are free to ignore any such warning anyway, so whatever.

/// In terms of the Rust Abstract Machine, this operation is equivalent to `src.read()`,
/// i.e., it performs a non-atomic read.
#[rustc_nounwind]
pub fn atomic_load_unordered<T: Copy>(src: *const T) -> T;

Expand All @@ -365,6 +368,9 @@ extern "rust-intrinsic" {
/// [`Ordering::Relaxed`] as the `order`. For example, [`AtomicBool::store`].
#[rustc_nounwind]
pub fn atomic_store_relaxed<T: Copy>(dst: *mut T, val: T);
/// Do NOT use this intrinsic; "unordered" operations do not exist in our memory model!
/// In terms of the Rust Abstract Machine, this operation is equivalent to `dst.write(val)`,
/// i.e., it performs a non-atomic write.
#[rustc_nounwind]
pub fn atomic_store_unordered<T: Copy>(dst: *mut T, val: T);

Expand Down Expand Up @@ -2312,6 +2318,10 @@ extern "rust-intrinsic" {

/// Emits a `!nontemporal` store according to LLVM (see their docs).
/// Probably will never become stable.
///
/// Do NOT use this intrinsic; "nontemporal" operations do not exist in our memory model!
/// It exists to support current stdarch, but the plan is to change stdarch and remove this intrinsic.
/// See <https://github.com/rust-lang/rust/issues/114582> for some more discussion.
#[rustc_nounwind]
pub fn nontemporal_store<T>(ptr: *mut T, val: T);

Expand Down