Skip to content

Point at source of trait bound obligations in more places#89580

Merged
bors merged 11 commits into
rust-lang:masterfrom
estebank:trait-bounds-are-tricky
Nov 21, 2021
Merged

Point at source of trait bound obligations in more places#89580
bors merged 11 commits into
rust-lang:masterfrom
estebank:trait-bounds-are-tricky

Conversation

@estebank

@estebank estebank commented Oct 5, 2021

Copy link
Copy Markdown
Contributor

Be more thorough in using ItemObligation and BindingObligation when
evaluating obligations so that we can point at trait bounds that
introduced unfulfilled obligations. We no longer incorrectly point at
unrelated trait bounds (substs-ppaux.verbose.stderr).

In particular, we now point at trait bounds on method calls.

We no longer point at "obvious" obligation sources (we no longer have a
note pointing at Trait saying "required by a bound in Trait", like
in associated-types-no-suitable-supertrait*).

We no longer point at associated items (ImplObligation), as they didn't
add any user actionable information, they just added noise.

Address part of #89418.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @nagisa

(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 Oct 5, 2021
@rust-log-analyzer

This comment has been minimized.

@estebank

estebank commented Oct 5, 2021

Copy link
Copy Markdown
Contributor Author

I wonder if the error is because predicates_of now returns a DUMMY_SP for the trait's obligation. That would only affect this test if the span is the only thing being tracked in incremental, which would be a bug, right?

Edit: We can land this with extra verbosity pointing at traits, I can change the test to ignore predicates_of or I can rework the entire approach to try and signal that an obligation is coming from a trait in some other out of band way, instead of with DUMMY_SP (which arguably is the right thing to do, we just don't carry that kind of metadata today to tie the predicate to the ObligationCauseCode).

@cjgillot, I see that you touched this file. Do you know if there's any reliance on predicates_of changing when trait modifiers like pub and unsafe are changed? Currently they do because the change of the span, but with this PR's change, that's no longer true. Would it be reasonable to change the test to no longer look for that?

Another option would be to add an empty predicate type that represents pub and unsafe as a safeguard, but we likely don't want/need that.

Edit 2: I was halfway through atttempting the "signal origin in PredicateKind" approach when remembered that naïvely extending PredicateKind will cause fingerprinting issues, as I already tried to do something similar some time back and had to back off.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this test be performed around the hir.span(hir_id) call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but because it is in a nested match doing that would have meant making span mutable and reassign to it in that case. Doing this kind of rebinding feels to me like a better approach most of the time.

@cjgillot

cjgillot commented Oct 6, 2021

Copy link
Copy Markdown
Contributor

@cjgillot, I see that you touched this file. Do you know if there's any reliance on predicates_of changing when trait modifiers like pub and unsafe are changed? Currently they do because the change of the span, but with this PR's change, that's no longer true. Would it be reasonable to change the test to no longer look for that?

I don't know enough the trait solving algorithm to comment on the need for the value to change when pub and unsafe change. OTOH, I would consider that any incremental code that relies on span-related invalidation to work correctly would be a red flag. So IMHO, it's fine to update the test.

If you want confirmation, you'd need to ask to professional trait solvers like @jackh726.

@jackh726

jackh726 commented Oct 6, 2021

Copy link
Copy Markdown
Member

If you want confirmation, you'd need to ask to professional trait solvers like @jackh726.

😂❤you give me too much credit

Do you know if there's any reliance on predicates_of changing when trait modifiers like pub and unsafe are changed?

I would be extremely surprised if this were the case. I imagine for everything but diagnostics, we throw away the span anyways.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems… weird. Self::DIM is not a… bound, is it? Though it looks like this error itself is not quite correct in the first place.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Associated consts in array length position cause these. It's a preexisting problem that it's only exposed here because of better obligation tracking.

@nagisa nagisa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looked through the test changes for now, there seem to be some unfortunate regressions at least from my perspective.

Comment thread src/test/ui/error-codes/E0283.stderr Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a regression?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It kind of is, but I feel it is acceptable given how many other things improve by screwing this one up (by using DUMMY_SP for trait implicit obligations).

Comment thread src/test/ui/substs-ppaux.verbose.stderr Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a regression? Is it unavoidable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The previous note span was wrong :-|

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After the last change we no longer show this note (and arguably never should have).

@estebank estebank force-pushed the trait-bounds-are-tricky branch from aa1f6cf to 9b3dd9c Compare October 12, 2021 14:18
Comment thread compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs Outdated
@estebank estebank force-pushed the trait-bounds-are-tricky branch from d12ff11 to 0df3c8f Compare October 13, 2021 14:32
@rust-log-analyzer

This comment has been minimized.

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2021
@bors

This comment has been minimized.

@estebank estebank force-pushed the trait-bounds-are-tricky branch from dae3bdd to 0d4fdb2 Compare October 15, 2021 15:00

@nagisa nagisa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems very nice. r=me with one remaining nit.

Comment thread compiler/rustc_typeck/src/check/compare_method.rs Outdated
@bors

This comment has been minimized.

@jackh726 jackh726 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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 21, 2021
@estebank estebank force-pushed the trait-bounds-are-tricky branch from 0d4fdb2 to a62418a Compare October 25, 2021 22:18
@rust-log-analyzer

This comment has been minimized.

@bors

This comment has been minimized.

@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2021
@estebank estebank force-pushed the trait-bounds-are-tricky branch from a62418a to 1cadfe6 Compare November 18, 2021 01:32
@rust-log-analyzer

This comment has been minimized.

@estebank

Copy link
Copy Markdown
Contributor Author

@bors r=nagisa

@bors

bors commented Nov 18, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit a8dcc87 has been approved by nagisa

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (b8e5ab2): comparison url.

Summary: This change led to large relevant mixed results 🤷 in compiler performance.

  • Large improvement in instruction counts (up to -5.0% on incr-unchanged builds of inflate)
  • Small regression in instruction counts (up to 1.1% on incr-unchanged builds of wg-grammar)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

@rustbot rustbot added the perf-regression Performance regression. label Nov 21, 2021
@pnkfelix

Copy link
Copy Markdown
Contributor

Visiting for weekly performance triage.

Many other PR's over the past week have observed a similar delta to incr-unchanged builds of inflate, so I am dismissing that change as spurious. (The current hypothesis is that it is due to rust-lang/rustc-perf#1105.)

Other than that, there were a broad set of small regressions. Putting aside the ones tagged with ? ("noisy"), there are 19 benchmarks that regressed by 0.10% to 0.42%. This seems like an acceptable cost.

@rustbot label: +perf-regression-triaged

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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.