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
Add ptr::read_move
#113066
Add ptr::read_move
#113066
Conversation
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
r? @scottmcm |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hmm, so I have no problem with this experimentally, but while I mentioned it in IRLO, I don't actually know it'll actually be useful right now. Could you try it out with custom MIR on your end and report whether it actually helps you? You can write this on nightly: #![feature(core_intrinsics)]
#![feature(custom_mir)]
use std::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn experimental_read_via_move<T>(p: *const T) -> T {
mir!({
RET = Move(*p);
Return()
})
} I figure there's probably some complicated opsem questions about what |
/// | ||
/// * `src` must point to a properly initialized value of type `T`. | ||
/// | ||
/// * `src` must not be read or written while the return value exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ignorant about MIR move semantics.
Does it apply to T: Copy
too? How does that interact with freeing the allocation from which the value has been read?
The job Click to see the possible cause of the failure (guessed by this bot)
|
@scottmcm Unfortunately, it looks like the feature will need much deeper compiler changes. |
I think there's an opsem question here first, even. Because it's unclear to me whether the place is even allowed to be reused, because I don't know if you're allowed to keep that pointer to the place and read it later, despite having moved out of it already. (And, more importantly, if that's not allowed, what it's doing that doesn't break moving out of the inside of a nice-optimized |
Moving or reading a pointer may not be a good abstraction in the end. Something like |
Experimental support for reading from pointer by moving from it. It's necessary to allow compiler to reuse memory behind the "read" pointer. See this discussion for more context: https://internals.rust-lang.org/t/19038
This implementation mirrors
ptr::read
, but with the small change in the intrinsic implementation.