-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
implement ptr.addr() via transmute #97710
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @thomcc (rust-highfive has picked a reviewer for you, use r? to override) |
Seems reasonable. I'm going to mark it as rollup=never out of an over-abundance of caution around the difference between a transmute and a cast in terms of performance, since this is a pretty fundamental thing that gets done in a lot of code (or maybe not as much as I think?) @bors r+ rollup=never |
📌 Commit 4291332 has been approved by |
☀️ Test successful - checks-actions |
Tested on commit rust-lang/rust@760237f. Direct link to PR: <rust-lang/rust#97710> 💔 miri on linux: test-pass → test-fail (cc @RalfJung @eddyb @oli-obk).
Finished benchmarking commit (760237f): comparison url. Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
As per the discussion in rust-lang/unsafe-code-guidelines#286, the semantics for ptr-to-int transmutes that we are going with for now is to make them strip provenance without exposing it. That's exactly what
ptr.addr()
does! So we can implementptr.addr()
viatransmute
. This also means that once #97684 lands, Miri can distinguishptr.addr()
fromptr.expose_addr()
, and the following code will correctly be called out as having UB (if permissive provenance mode is enabled, which will become the default once the implementation is complete):This completes the Miri implementation of the new distinctions introduced by strict provenance. :)
Cc @Gankra -- for now I left in your
FIXME(strict_provenance_magic)
saying these should be intrinsics, but I do not necessarily agree that they should be. Or if we have an intrinsic, I think it should behave exactly like thetransmute
does, which makes one wonder why the intrinsic should be needed.