Skip to content
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

Merged
merged 2 commits into from
Sep 28, 2021

Conversation

Aaron1011
Copy link
Member

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.

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2021
@Aaron1011
Copy link
Member Author

cc @estebank @lqd @matthewjasper @rust-lang/wg-compiler-nll

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 26, 2021

📌 Commit ae4916bd3d0433eb2375068af42e0b4295279359 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 26, 2021
@Aaron1011
Copy link
Member Author

This should probably have a perf run beforehand, now that I think about it.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 26, 2021
@Aaron1011
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 26, 2021
@bors
Copy link
Contributor

bors commented Sep 26, 2021

⌛ Trying commit ae4916bd3d0433eb2375068af42e0b4295279359 with merge e155d2a2ad47d98b5b62f8b9fba9a9e7b4c6c2de...

@bors
Copy link
Contributor

bors commented Sep 26, 2021

☀️ Try build successful - checks-actions
Build commit: e155d2a2ad47d98b5b62f8b9fba9a9e7b4c6c2de (e155d2a2ad47d98b5b62f8b9fba9a9e7b4c6c2de)

@rust-timer
Copy link
Collaborator

Queued e155d2a2ad47d98b5b62f8b9fba9a9e7b4c6c2de with parent c09d637, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e155d2a2ad47d98b5b62f8b9fba9a9e7b4c6c2de): comparison url.

Summary: This change led to very large relevant regressions 😿 in compiler performance.

  • Very large regression in instruction counts (up to 4.8% on full builds of wg-grammar)

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 @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

@rustbot rustbot added perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Sep 27, 2021
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.
@Aaron1011
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 27, 2021
@bors
Copy link
Contributor

bors commented Sep 27, 2021

⌛ Trying commit 41ad383 with merge b13e7a00e877f93c9b85b09fddfef60e03d9d07b...

@bors
Copy link
Contributor

bors commented Sep 27, 2021

☀️ Try build successful - checks-actions
Build commit: b13e7a00e877f93c9b85b09fddfef60e03d9d07b (b13e7a00e877f93c9b85b09fddfef60e03d9d07b)

@rust-timer
Copy link
Collaborator

Queued b13e7a00e877f93c9b85b09fddfef60e03d9d07b with parent 3e8f32e, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b13e7a00e877f93c9b85b09fddfef60e03d9d07b): comparison url.

Summary: This change led to small relevant regressions 😿 in compiler performance.

  • Small regression in instruction counts (up to 0.5% on incr-unchanged builds of helloworld)

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 @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 27, 2021
@Aaron1011
Copy link
Member Author

@estebank The regressions are now much smaller. Can you review the latest commit?

Comment on lines +2004 to +2010
// 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,
))
Copy link
Contributor

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.

Copy link
Member Author

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:

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!()
}

Comment on lines +312 to +314
// Make sure this enum doesn't unintentionally grow
rustc_data_structures::static_assert_size!(ConstraintCategory, 12);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@estebank
Copy link
Contributor

@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.

@bors
Copy link
Contributor

bors commented Sep 27, 2021

📌 Commit 41ad383 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 27, 2021
@bors
Copy link
Contributor

bors commented Sep 27, 2021

⌛ Testing commit 41ad383 with merge 8a12be7...

@bors
Copy link
Contributor

bors commented Sep 28, 2021

☀️ Test successful - checks-actions
Approved by: estebank
Pushing 8a12be7 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 28, 2021
@bors bors merged commit 8a12be7 into rust-lang:master Sep 28, 2021
@rustbot rustbot added this to the 1.57.0 milestone Sep 28, 2021
@rust-timer
Copy link
Collaborator

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

@rustbot rustbot removed the perf-regression Performance regression. label Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants