-
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
move Option::as_slice to intrinsic #109179
Conversation
r? @scottmcm (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
No, rustbot, this is not for the libs team (although it touches on libs). r? @rust-lang/compiler |
@scottmcm thanks for the help. I'll push the changes you proposed shortly once I have the test run complete. |
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 think this should be done, a niche optimization doesn't justify a compiler intrinsic with all of its maintenance cost imo.
We should instead implement offset_of
support for enums (btw is someone working on that? I could take a look if nobody is currently implementing this)
e552c50
to
70da052
Compare
This comment has been minimized.
This comment has been minimized.
I'm fine with extending |
to unblock the LLVM upgrade we could simply change the body to match self {
None => &[],
Some(x) => std::slice::from_ref(x),
} Less efficient, but obviously correct |
1e7f303
to
50846d5
Compare
This comment has been minimized.
This comment has been minimized.
Idk, an intrinsic that gets lowered in mir doesn't really have a lot of maintenance cost imo. Especially with something like this, which we'll reliably be able to support between changes to mir |
The only reason not to do this and pick my inefficient version instead is that it serves as motivation to work on offset_of to support enum variants. |
50846d5
to
a2d33d4
Compare
Don't worry about that, @oli-obk, I'll extend |
I should however replace the old implementation with @oli-obk's proposal to ensure that the LLVM build is actually unblocked. |
FYI: @drmeepster (author of #106934) had plans on doing this after the PR merges, don't forget to communicate with him, so the work is not duplicated :)
I still don't love the idea of adding an intrinsic, but I won't object to merging this in the meantime. |
a2d33d4
to
6fa28de
Compare
@eholk do you have time to r+ this? Or should we ask for another reviewer? |
The code looks pretty good to me. Is the main reason to do this to unblock the LLVM upgrade, or are there further benefits for it? |
6fa28de
to
27e9ee9
Compare
That and the previous implementation was a hack that could result in suboptimal codegen if the type layout algorithm changed in a way that led to a different payload offset between Again, this is only a stop-gap until we can get the same effect via |
@eholk do you need any further information to decide how to proceed? |
Looks good to me! @bors r+ |
…ce, r=eholk move Option::as_slice to intrinsic `@scottmcm` suggested on rust-lang#109095 I use a direct approach of unpacking the operation in MIR lowering, so here's the implementation. cc `@nikic` as this should hopefully unblock rust-lang#107224 (though perhaps other changes to the prior implementation, which I left for bootstrapping, are needed).
…ce, r=eholk move Option::as_slice to intrinsic ``@scottmcm`` suggested on rust-lang#109095 I use a direct approach of unpacking the operation in MIR lowering, so here's the implementation. cc ``@nikic`` as this should hopefully unblock rust-lang#107224 (though perhaps other changes to the prior implementation, which I left for bootstrapping, are needed).
…ce, r=eholk move Option::as_slice to intrinsic ```@scottmcm``` suggested on rust-lang#109095 I use a direct approach of unpacking the operation in MIR lowering, so here's the implementation. cc ```@nikic``` as this should hopefully unblock rust-lang#107224 (though perhaps other changes to the prior implementation, which I left for bootstrapping, are needed).
Rollup of 11 pull requests Successful merges: - rust-lang#100311 (Fix handling of trailing bare CR in str::lines) - rust-lang#108997 (Change text -> rust highlighting in sanitizer.md) - rust-lang#109179 (move Option::as_slice to intrinsic) - rust-lang#109187 (Render source page layout with Askama) - rust-lang#109280 (Remove `VecMap`) - rust-lang#109295 (refactor `fn bootstrap::builder::Builder::compiler_for` logic) - rust-lang#109312 (rustdoc: Cleanup parent module tracking for doc links) - rust-lang#109317 (Update links for custom discriminants.) - rust-lang#109405 (RPITITs are `DefKind::Opaque` with new lowering strategy) - rust-lang#109414 (Do not consider synthesized RPITITs on missing items checks) - rust-lang#109435 (Detect uninhabited types early in const eval) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
@scottmcm suggested on #109095 I use a direct approach of unpacking the operation in MIR lowering, so here's the implementation.
cc @nikic as this should hopefully unblock #107224 (though perhaps other changes to the prior implementation, which I left for bootstrapping, are needed).