-
Notifications
You must be signed in to change notification settings - Fork 13k
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 encountering &SmallImplCopy < &SmallImplCopy
, suggest copying
#108372
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@bors try |
⌛ Trying commit f2e8be54b78532fa835749035d7eda460b85d459 with merge f696d008ac44f498f11e01e4370309aab53c5dcd... |
This lint might be more appropriate in clippy, but I wanted to see what the impact on crater would be. |
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -1875,7 +1875,7 @@ impl PartialEq<IpAddr> for Ipv6Addr { | |||
fn eq(&self, other: &IpAddr) -> bool { | |||
match other { | |||
IpAddr::V4(_) => false, | |||
IpAddr::V6(v6) => self == v6, | |||
IpAddr::V6(v6) => *self == *v6, |
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.
Hmm, suggesting changes like this doesn't fill me with joy.
When in the compiler does the important difference between the two codegens happen? Does it need to be in THIR->MIR lowering, or could a mir-opt notice these cases early enough to give the same benefits?
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.
Yeah, not suggesting this would be ideal. I wonder if the original problem is more with this happening in loops in particular. Having said that, I wanted to gauge how prevalent this is.
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.
Looking at the number of places where we are warning in rustc itself, I fear that 1) actually landing the suggestion should be gated on detecting the expression being part of a loop and 2) there might be real perf gains on fixing the underlining codegen optimization issue or cleaning up the ecosystem with the aid of this lint.
&& size <= 8 | ||
&& size_r <= 8 |
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.
Should we hard-code 8 here? Or get the usize-size from the compiler?
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.
We would then give different suggestions depending on what platform the developer happens to be in. That is a departure of what we've been doing so far.
f2e8be5
to
d61c6da
Compare
This comment was marked as resolved.
This comment was marked as resolved.
7e28982
to
f8f5b4b
Compare
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Unfortunately, I'm not sure it does. If I take the example from the issue and manually deref all the pub fn variant_X(input: &[(usize, usize, usize, usize)]) -> usize {
input
.iter()
- .filter(|(a, b, c, d)| a <= c && d <= b || c <= a && b <= d)
+ .filter(|(a, b, c, d)| *a <= *c && *d <= *b || *c <= *a && *b <= *d)
.count()
} Then I still get the same branchy code: https://rust.godbolt.org/z/8KEn563eY 🙁 |
This comment was marked as resolved.
This comment was marked as resolved.
5bcdc39
to
d62b097
Compare
This comment has been minimized.
This comment has been minimized.
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit f69f2e381683371996771d7c1c09536a98f3baa2 with merge 789cac255072eb4c1b81cf93275aee3003c63106... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
f69f2e3
to
9b45be0
Compare
This comment has been minimized.
This comment has been minimized.
9b45be0
to
fad3411
Compare
This comment has been minimized.
This comment has been minimized.
fad3411
to
938013b
Compare
This comment has been minimized.
This comment has been minimized.
Why does it matter if the type is |
@kadiwa4 It matters for primitives. Compare the MIR in https://rust.godbolt.org/z/MsWxfn6s8. |
☔ The latest upstream changes (presumably #108538) made this pull request unmergeable. Please resolve the merge conflicts. |
… 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.
When encountering a binary operation for two
T: Copy
whereT
is as small as a 64bit pointer, suggest dereferencing the expressions so the binary operation is inlined.Mitigate the effects of #105259, particularly when match ergonomics is involved.