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. |
WaffleLapkin
left a comment
There was a problem hiding this comment.
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
…ix, r=scottmcm Option::as_slice: fix comment The implementation got changed in rust-lang#117525 without updating the comment. Now the comment makes no sense any more since there is no intrinsic that returns a pointer in this function any more. (It is also very strange to say "in the new version" in a comment -- what is that supposed to tell someone reading the code 2 years later? That wording was introduced even earlier, in rust-lang#109179.) Cc `@GKFX` `@petrochenkov` `@llogiq` `@scottmcm`
Rollup merge of #144230 - RalfJung:option-as-slice-comment-fix, r=scottmcm Option::as_slice: fix comment The implementation got changed in #117525 without updating the comment. Now the comment makes no sense any more since there is no intrinsic that returns a pointer in this function any more. (It is also very strange to say "in the new version" in a comment -- what is that supposed to tell someone reading the code 2 years later? That wording was introduced even earlier, in #109179.) Cc `@GKFX` `@petrochenkov` `@llogiq` `@scottmcm`
…ix, r=scottmcm Option::as_slice: fix comment The implementation got changed in rust-lang#117525 without updating the comment. Now the comment makes no sense any more since there is no intrinsic that returns a pointer in this function any more. (It is also very strange to say "in the new version" in a comment -- what is that supposed to tell someone reading the code 2 years later? That wording was introduced even earlier, in rust-lang#109179.) Cc `@GKFX` `@petrochenkov` `@llogiq` `@scottmcm`
…ttmcm Option::as_slice: fix comment The implementation got changed in rust-lang/rust#117525 without updating the comment. Now the comment makes no sense any more since there is no intrinsic that returns a pointer in this function any more. (It is also very strange to say "in the new version" in a comment -- what is that supposed to tell someone reading the code 2 years later? That wording was introduced even earlier, in rust-lang/rust#109179.) Cc `@GKFX` `@petrochenkov` `@llogiq` `@scottmcm`
@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).