-
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
More accurate error for binop errors after identifying RHS type #90006
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue This is doing more work on the happy path (evaluating the binop twice, with a ty var and with a concrete ty). Let's see if I need to rework this for perf's sake. |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit c01107c2d7d7e2c47830a49fba5d724ba4ffe7ff with merge 393f6bcfbcbf8ba2089decd734dbf36b4081686c... |
☀️ Try build successful - checks-actions |
Queued 393f6bcfbcbf8ba2089decd734dbf36b4081686c with parent 5e02151, future comparison URL. |
Finished benchmarking commit (393f6bcfbcbf8ba2089decd734dbf36b4081686c): comparison url. Summary: This change led to very large relevant regressions 😿 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking 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 led 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 |
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 009cc3d96655794853c7f9fd34f7a3dd517a9e55 with merge 3125063ba74acf6044a7425b21bbfddead7736b5... |
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
Queued 6dbdb30db6f062a3181014360f5f679d7fb1132d with parent 5dab47d, future comparison URL. |
Finished benchmarking commit (6dbdb30db6f062a3181014360f5f679d7fb1132d): comparison url. Summary: This change led to moderate relevant mixed results 🤷 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking 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 led 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 |
lhs_ty | ||
) | ||
} else { | ||
format!("can't compare `{}` with `{}`", lhs_ty, rhs_ty,) |
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.
The "can't compare" wording is used for all comparison operations, so it's not always clear what trait should be implemented exactly, especially if the comparison happens in a macro.
I think it would be more useful to extend the old warning instead:
"binary operation `{op}` cannot be applied to types `{ty1}` and `{ty2}`"
| | ||
help: you can convert a `u16` to a `usize` | ||
| | ||
LL | a = c + (b * 5).into(); |
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.
usize::from(b * 5)
was a better suggestion, so if the suggestions are filtered, then from
should be given a higher priority.
@@ -1,4 +1,4 @@ | |||
error[E0369]: binary operation `==` cannot be applied to type `&[T]` | |||
error[E0369]: can't compare `&[T]` with `&[T]` |
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.
Why are these types considered different?
@@ -475,11 +553,54 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
} | |||
} | |||
err.emit(); | |||
self.tcx.ty_error() | |||
let ty = self.tcx.ty_error(); |
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.
let ty = self.tcx.ty_error(); | |
let err_ty = self.tcx.ty_error(); |
@@ -422,6 +484,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
"*".to_string(), | |||
rustc_errors::Applicability::MachineApplicable, | |||
); | |||
suggested = true; | |||
} else if let IsAssign::No = is_assign { |
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.
} else if let IsAssign::No = is_assign { | |
} else if is_assign == IsAssign::No { |
if let Ok(method) = result { | ||
errors.retain(|e| match e.obligation.predicate.kind().skip_binder() { | ||
ty::PredicateKind::Trait(predicate) => { | ||
// Skip the obligations coming from the binop, we want to emit E0369 instead |
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.
"Skip the errors coming from obligations related to the binop, we want to emit ..., these errors must be emitted by the code below."
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.
And the same wording change below.
And maybe factor out this common logic to a closure/function.
let trait_did = self.op_metadata(Op::Binary(op, is_assign), op.span).1.unwrap(); | ||
let (obligation, _) = | ||
self.obligation_for_method(op.span, trait_did, lhs_ty, Some(&[rhs_ty])); | ||
let mut fulfill = <dyn TraitEngine<'_>>::new(self.tcx); |
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.
Why do you need to create a new inference context?
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.
Using the current inference context incurs a huge cost on all binops. This change brought down the perf impact on keccak from ~5% to non-detectable on that crate, and the crates that are affected have under ~.5% impact.
let def_id = predicate.def_id(); | ||
// We also remove obligations for `PartialEq` because | ||
// `PartialOrd` introduces them and this way we don't get | ||
// duplicated output. |
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 is a good idea, too subtle and special-cased, and I don't see anything ensuring that PartialOrd
is involved at all.
I would also suggest splitting this into a few more focused PRs, the "running inference twice" part, the "consider (The "running inference twice" part should also get reviewed by someone from traits/inference WG, I'm not sure that it doesn't change the language behavior.) |
☔ The latest upstream changes (presumably #90067) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage: |
Ping for triage: |
@JohnCSimon yes, I tried rebasing and cleaning it up 2 months ago, but the divergence has gotten big enough that I need to relearn how to accomplish the same effect I had in this PR. I'll try to get back to it in the short term. |
I am closing this as it is bitrotted. |
Evaluate binops a second time with the resolved RHS type so we can provide suggestions for errors caused by trait predicates that didn't fail when looking for the binop with a type variable in the RHS.
Provide more casting and borrowing suggestions in binops.
Fix #44695, partially address #40660, partially address #57621 (we provide bad suggestion spans when
assert_eq!
is involved), doesn't account for #52544.Zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/Up.20to.20.255.20regression.20on.20kekkak.20with.20.2390006/near/258044068