-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[Experiment] Replace unreachable_unchecked()
with uninit().assume_init()
in unwrap_unchecked()
#124737
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Nilstrieb (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
@alion02: 🔑 Insufficient privileges: not in try users |
This comment has been minimized.
This comment has been minimized.
@@ -1037,7 +1037,7 @@ impl<T> Option<T> { | |||
match self { | |||
Some(val) => val, | |||
// SAFETY: the safety contract must be upheld by the caller. | |||
None => unsafe { hint::unreachable_unchecked() }, | |||
None => unsafe { mem::MaybeUninit::uninit().assume_init() }, |
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.
is this really better? that's disappointing.. how about using offset_of and accessing the value with directly with a pointer offset, entirely removing the condition?
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 don't know if it's better in general - I just know it's better in at least one case. I think it's worth running a benchmark for it at least though. (which I can't do 🥺)
TIL about offset_of
. uninit
seems to be chucked pretty readily, but offset_of
might be better in low opt level builds etc.
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.
@Nilstrieb It doesn't seem to have the desired effect:
https://godbolt.org/z/z5fv4as4s
@alion02 Please make your new libcore compile.
Might as well try both suggested new impls of @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
[Experiment] Replace `unreachable_unchecked()` with `uninit().assume_init()` in `unwrap_unchecked()` [Relevant ACP.](rust-lang/libs-team#378) [Relevant godbolt.](https://godbolt.org/z/WqfcT7Ys9) Attempt to clean up the LLVM IR we generate based on the assumption that we usually don't want to `assume` the value of the discriminant (because it sticks around in the IR and randomly inhibits optimizations).
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
@bors r- |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@bors try |
[Experiment] Replace `unreachable_unchecked()` with `uninit().assume_init()` in `unwrap_unchecked()` [Relevant ACP.](rust-lang/libs-team#378) [Relevant godbolt.](https://godbolt.org/z/WqfcT7Ys9) Attempt to clean up the LLVM IR we generate based on the assumption that we usually don't want to `assume` the value of the discriminant (because it sticks around in the IR and randomly inhibits optimizations).
The job Click to see the possible cause of the failure (guessed by this bot)
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
When I tried #102151 it only lead to regressions. But a lot has changed since then and this isn't the same approach so maybe the results will be different this time. |
@bors try Generate a new try build, the old one is based on a broken master commit AFAICT. |
[Experiment] Replace `unreachable_unchecked()` with `uninit().assume_init()` in `unwrap_unchecked()` [Relevant ACP.](rust-lang/libs-team#378) [Relevant godbolt.](https://godbolt.org/z/WqfcT7Ys9) Attempt to clean up the LLVM IR we generate based on the assumption that we usually don't want to `assume` the value of the discriminant (because it sticks around in the IR and randomly inhibits optimizations).
@rust-timer queue |
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (4a9bbb3): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 675.885s -> 674.118s (-0.26%) |
Much smaller impact overall than I expected, but still vaguely interesting. By the way, I noticed that the x86 backend (which is presumably what these benchmarks are running on) is more resilient to |
We don't have the tools/facilities set up for benchmarking Arm, no. |
I assume running rustc-perf locally should work on an arm linux box. |
any improvements from this PR are LLVM bugs, but evidently the LLVM bugs exist. you should report them upstream, but I'd be ok with a bit of papering over them in the meantime. i would prefer the offset_of based approach over this. |
@rustbot author |
@alion02 FYI: when a PR is ready for review, send a message containing Or if you're not going to continue, please close it. Thank you! |
Pursuing other priorities. May return another time. Thanks for the reminder. |
Relevant ACP. Relevant godbolt.
Attempt to clean up the LLVM IR we generate based on the assumption that we usually don't want to
assume
the value of the discriminant (because it sticks around in the IR and randomly inhibits optimizations).