Skip to content

make std::intrinsics functions actually be intrinsics #139916

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Apr 16, 2025

Most of the functions in std::intrinsics are actually intrinsics, but some are not: for historical reasons, std::intrinsics::{copy,copy_nonoverlapping,write_bytes} are accessible on stable, and the versions in std::ptr are just re-exports. These functions are not intrinsics, but wrappers around the intrinsic, because they add extra debug assertions.

This PR makes the functions in std::intrinsics actually be intrinsics.

  • The advantage is that we can now use it in tests that need to directly call the intrinsic, thus removing a footgun for compiler development. We also remove the extended user-facing doc comments of these functions out of a file that should be largely internal documentation.
  • The downside is that if users are using those functions directly, they will not get the debug assertions any more. Note however that those users are already ignoring a deprecation warning, so I think this is fine. Furthermore, if someone imports the intrinsic name of this function and turns that into a function pointer, that will no longer work, since only the wrapper functions can be turned into a function pointer. I would be rather surprised if anyone did this, though... and again, they must have already ignored a deprecation warning. Still, seems worth a crater run, if there's general agreement that we want to go ahead with this change.

(intrinsics::drop_in_place also remains not-an-intrinsic, which bugs me, but oh well, not much we can do about it; we can't remove it from the module as the path is accidentally-stable.)

Cc @rust-lang/libs-api @saethlin

@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2025

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

The Miri subtree was changed

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the intrinsic-wrappers branch from 0497c07 to 82d5e7a Compare April 16, 2025 13:39
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the intrinsic-wrappers branch from 82d5e7a to 5a7d62b Compare April 16, 2025 14:26
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the intrinsic-wrappers branch from 5a7d62b to 5d60226 Compare April 16, 2025 15:01
@jhpratt
Copy link
Member

jhpratt commented Apr 21, 2025

(intrinsics::drop_in_place also remains not-an-intrinsic, which bugs me, but oh well, not much we can do about it; we can't remove it from the module as the path is accidentally-stable.)

I'd be interested in seeing a crater run on that, to be honest. We've pulled the rug on things that were accidentally stabilized before, even long after the fact.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

r=me with test confirmed to be adjusted as expected

@@ -45,7 +45,7 @@
_9 = copy _10;
_8 = move _9 as *mut i32 (PtrToPtr);
StorageDead(_9);
- _3 = copy_nonoverlapping::<i32>(move _4, move _8, const 0_usize) -> [return: bb1, unwind unreachable];
- _3 = std::intrinsics::copy_nonoverlapping::<i32>(move _4, move _8, const 0_usize) -> [return: bb1, unwind unreachable];
+ copy_nonoverlapping(dst = move _8, src = move _4, count = const 0_usize);
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused why this changed - maybe I'm missing something but the test looks like it's supposed to already call the intrinsic? Is this change ok?

Copy link
Member Author

@RalfJung RalfJung Apr 28, 2025

Choose a reason for hiding this comment

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

Note that only the "old" line changed -- it is now using std::intrinsics::copy_nonoverlapping rather than the local copy_nonoverlapping, which is expected as that is exactly what changed in the rs file.

The "new" line, in both cases, is the MIR statement form of copy_nonoverlapping.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right, this is a diff of a diff. Okay, makes sense.

@RalfJung
Copy link
Member Author

RalfJung commented Apr 28, 2025

Since this is a slight breaking change (of accidentally-stable API surface), does it need an FCP of some sort -- from @rust-lang/libs-api, I assume?

@RalfJung RalfJung added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Apr 28, 2025
@Mark-Simulacrum Mark-Simulacrum added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 28, 2025
@Amanieu
Copy link
Member

Amanieu commented Apr 29, 2025

FCP since this is very slightly breaking, though unlikely to cause any issues in practice.

@rfcbot merge

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 29, 2025

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Apr 29, 2025
@RalfJung
Copy link
Member Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2025
make std::intrinsic functions actually be intrinsics

Most of the functions in `std::intrinsics` are actually intrinsics, but some are not: for historical reasons, `std::intrinsics::{copy,copy_nonoverlapping,write_bytes}` are accessible on stable, and the versions in `std::ptr` are just re-exports. These functions are not intrinsics, but wrappers around the intrinsic, because they add extra debug assertions.

This PR makes the functions in `std::intrinsics` actually be intrinsics.
- The advantage is that we can now use it in tests that need to directly call the intrinsic, thus removing a footgun for compiler development. We also remove the extended user-facing doc comments of these functions out of a file that should be largely internal documentation.
- The downside is that if users are using those functions directly, they will not get the debug assertions any more. Note however that those users are already ignoring a deprecation warning, so I think this is fine. Furthermore, if someone imports the `intrinsic` name of this function and turns that into a function pointer, that will no longer work, since only the wrapper functions can be turned into a function pointer. I would be rather surprised if anyone did this, though... and again, they must have already ignored a deprecation warning. Still, seems worth a crater run, if there's general agreement that we want to go ahead with this change.

(`intrinsics::drop_in_place` also remains not-an-intrinsic, which bugs me, but oh well, not much we can do about it; we can't remove it from the module as the path is accidentally-stable.)

Cc `@rust-lang/libs-api` `@saethlin`
@bors
Copy link
Collaborator

bors commented Apr 29, 2025

⌛ Trying commit 5d60226 with merge b8c67c6...

@RalfJung RalfJung added the relnotes Marks issues that should be documented in the release notes of the next release. label Apr 29, 2025
@RalfJung RalfJung changed the title make std::intrinsic functions actually be intrinsics make std::intrinsics functions actually be intrinsics Apr 29, 2025
@bors
Copy link
Collaborator

bors commented Apr 29, 2025

☀️ Try build successful - checks-actions
Build commit: b8c67c6 (b8c67c6e3233dac3bcd238e82e72152bf538d0fa)

@RalfJung
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-139916 created and queued.
🤖 Automatically detected try build b8c67c6
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2025
@RalfJung RalfJung added the S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). label Apr 29, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-139916 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-139916 is completed!
📊 6 regressed and 2 fixed (622899 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels May 1, 2025
@RalfJung
Copy link
Member Author

RalfJung commented May 1, 2025

These all look spurious :)

@scottmcm
Copy link
Member

scottmcm commented May 1, 2025

Big fan of letting tests just use the versions from core 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants