-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
When HIR auto-refs a comparison operator, clean it up in MIR #109292
Conversation
… MIR Today, if you're comparing `&&T`s, it ends up auto-reffing in HIR. So the MIR ends up calling `PartialEq/Cmp` with `&&&T`, and the MIR inliner can only get that down to `&T`: <https://rust.godbolt.org/z/hje6jd4Yf>. So this adds an always-run pass to look at `Call`s in MIR with `from_hir_call: false` to just call the correct `Partial{Eq,Cmp}` implementation directly, even if it's debug and we're not running the inliner, to avoid needing to ever monomorphize a bunch of useless forwarding impls. This hopes to avoid ever needing something like rust-lang#108372 where we'd tell people to manually dereference the sides of their comparisons.
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This could go either way, so let's see: |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 7b74759 with merge d8ac1e4bc289879ff692ef5472e1cebd5c3cc42b... |
This doesn't seem correct to me. Could you add something like this as a test: struct S;
struct T;
impl PartialEq<&&&T> for &&S {
fn eq(&self, _t: &&&&T) -> bool {
todo!()
}
}
fn main() {
let s = S;
let t = T;
dbg!(&&s == &&&t);
} That having been said, do we know why inlining doesn't cover this? I would very strongly prefer not having to add a special case for this. (I have more review comments but will leave those for later) |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Oh, right, that's coherent despite the blanket :( Guess that means this approach just can't work. |
Finished benchmarking commit (d8ac1e4bc289879ff692ef5472e1cebd5c3cc42b): comparison URL. Overall result: ❌✅ regressions and improvements - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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.
CyclesResultsThis 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.
|
Well, I like 4% on ripgrep opt-full, but this isn't nearly worth it. I'll try something else instead. |
Today, if you're comparing
&&T
s, it ends up auto-reffing in HIR. So the MIR ends up callingPartialEq/Cmp
with&&&T
, and the MIR inliner can only get that down to&T
: https://rust.godbolt.org/z/hje6jd4Yf.So this adds an always-run pass to look at
Call
s in MIR withfrom_hir_call: false
to just call the correctPartial{Eq,Cmp}
implementation directly, even if it's debug and we're not running the inliner, to avoid needing to ever monomorphize a bunch of useless forwarding impls.This hopes to avoid ever needing something like #108372 where we'd tell people to manually dereference the sides of their comparisons.
r? @ghost