-
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
Improve cause information for NLL higher-ranked errors #89249
Conversation
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
cc @estebank @lqd @matthewjasper @rust-lang/wg-compiler-nll |
@bors r+ |
📌 Commit ae4916bd3d0433eb2375068af42e0b4295279359 has been approved by |
This should probably have a perf run beforehand, now that I think about it. @bors r- |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit ae4916bd3d0433eb2375068af42e0b4295279359 with merge e155d2a2ad47d98b5b62f8b9fba9a9e7b4c6c2de... |
☀️ Try build successful - checks-actions |
Queued e155d2a2ad47d98b5b62f8b9fba9a9e7b4c6c2de with parent c09d637, future comparison URL. |
Finished benchmarking commit (e155d2a2ad47d98b5b62f8b9fba9a9e7b4c6c2de): 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 PR has several interconnected pieces: 1. In some of the NLL region error code, we now pass around an `ObligationCause`, instead of just a plain `Span`. This gets forwarded into `fulfill_cx.register_predicate_obligation` during error reporting. 2. The general InferCtxt error reporting code is extended to handle `ObligationCauseCode::BindingObligation` 3. A new enum variant `ConstraintCategory::Predicate` is added. We try to avoid using this as the 'best blame constraint' - instead, we use it to enhance the `ObligationCause` of the `BlameConstraint` that we do end up choosing. As a result, several NLL error messages now contain the same "the lifetime requirement is introduced here" message as non-NLL errors. Having an `ObligationCause` available will likely prove useful for future improvements to NLL error messages.
This shirnks the size of `ConstraintCategory`, hopefully fixing a performance regression.
ae4916b
to
41ad383
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 41ad383 with merge b13e7a00e877f93c9b85b09fddfef60e03d9d07b... |
☀️ Try build successful - checks-actions |
Queued b13e7a00e877f93c9b85b09fddfef60e03d9d07b with parent 3e8f32e, future comparison URL. |
Finished benchmarking commit (b13e7a00e877f93c9b85b09fddfef60e03d9d07b): comparison url. Summary: This change led to small 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 |
@estebank The regressions are now much smaller. Can you review the latest commit? |
// We currentl'y doesn't store the `DefId` in the `ConstraintCategory` | ||
// for perforamnce reasons. The error reporting code used by NLL only | ||
// uses the span, so this doesn't cause any problems at the moment. | ||
Some(ObligationCauseCode::BindingObligation( | ||
CRATE_DEF_ID.to_def_id(), | ||
predicate_span, | ||
)) |
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 should create a new ObligationCauseCode variant instead, but it's fine to do this I guess.
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 was trying to mimic the non-NLL code, which also uses ObligationCauseCode::BindingObligation
for this message:
rust/compiler/rustc_infer/src/infer/error_reporting/note.rs
Lines 396 to 405 in 2b6ed3b
if let ObligationCauseCode::BindingObligation(_, span) = | |
&trace.cause.code.peel_derives() | |
{ | |
let span = *span; | |
let mut err = self.report_concrete_failure(placeholder_origin, sub, sup); | |
err.span_note(span, "the lifetime requirement is introduced here"); | |
err | |
} else { | |
unreachable!() | |
} |
// Make sure this enum doesn't unintentionally grow | ||
rustc_data_structures::static_assert_size!(ConstraintCategory, 12); | ||
|
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.
👍
@bors r+ The performance impact seems small, but I'm sure the perf triage team can make a better determination about it. It seems to me that the majority of the impact is due to tracking extra metadata. It's a shame it doesn't impact "only" the NLL errors. |
📌 Commit 41ad383 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (8a12be7): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
This PR has several interconnected pieces:
around an
ObligationCause
, instead of just a plainSpan
.This gets forwarded into
fulfill_cx.register_predicate_obligation
during error reporting.
handle
ObligationCauseCode::BindingObligation
ConstraintCategory::Predicate
is added.We try to avoid using this as the 'best blame constraint' - instead,
we use it to enhance the
ObligationCause
of theBlameConstraint
that we do end up choosing.
As a result, several NLL error messages now contain the same
"the lifetime requirement is introduced here" message as non-NLL
errors.
Having an
ObligationCause
available will likely prove usefulfor future improvements to NLL error messages.