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

Remove Session::one_time_diagnostic #95149

Merged
merged 4 commits into from
Mar 26, 2022
Merged

Remove Session::one_time_diagnostic #95149

merged 4 commits into from
Mar 26, 2022

Conversation

cjgillot
Copy link
Contributor

This is untracked mutable state, which modified the behaviour of queries.
It was used for 2 things: some full-blown errors, but mostly for lint declaration notes ("the lint level is defined here" notes).

It is replaced by the diagnostic deduplication infra which already exists in the diagnostic emitter.
A new diagnostic level OnceNote is introduced specifically for lint notes, to deduplicate subdiagnostics.

As a drive-by, diagnostic emission takes a &mut to allow dropping the SubDiagnostics.

Taking a Diagnostic by move would break the usual pattern
`diag.label(..).emit()`.
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 20, 2022
@rust-highfive
Copy link
Collaborator

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

Some changes occurred in src/tools/rustfmt.

cc @calebcartwright

@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 Mar 20, 2022
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Comment on lines 1014 to +1015
// FIXME(eddyb) this should ideally take `diagnostic` by value.
fn emit_diagnostic(&mut self, diagnostic: &Diagnostic) -> Option<ErrorGuaranteed> {
fn emit_diagnostic(&mut self, diagnostic: &mut Diagnostic) -> Option<ErrorGuaranteed> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would fixing the FIXME be possible as part of this PR, or are there big consequences that I'm failing to think of?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This requires to make the DiagnosticBuilder::emit method take self by move, which breaks struct_err(..).label(..).emit() chains.

Copy link
Member

Choose a reason for hiding this comment

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

Not exactly, I decided we can't make .emit() take &mut self for that reason, but once .emit() is called the DiagnosticBuilder state changes to ignore the Diagnostic on further .emit(), so we could be replacing the Diagnostic with a dummy one (or even having Option around it but that could slow down the Deref/DerefMut impl a bunch).

Comment on lines -86 to -90
note: the lint level is defined here
--> $DIR/lint-tool-test.rs:14:9
|
LL | #![deny(clippy_group)]
| ^^^^^^^^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be a small issue: for lints the current deduplication strategy is (lint_id, group_id), where the new deduplication strategy is only group_id. Fixing this might be "as simple" as changing the hashing to also account for the subdiagnostic's parent Diagnostic::code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! Wait, the note is still being emitted, but now we don't point at the group. That's perfectly fine.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

I'm r=me on the changes, but the tests are failing.

CC @eddyb, who was touching this code recently just in case (feel free to ignore).

@cjgillot
Copy link
Contributor Author

rustdoc-ui tests have been blessed, with the expected behaviour.
@bors r=estebank

@cjgillot
Copy link
Contributor Author

@bors r=estebank

@bors
Copy link
Contributor

bors commented Mar 25, 2022

📌 Commit f7d5b7a 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 Mar 25, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 26, 2022
Remove `Session::one_time_diagnostic`

This is untracked mutable state, which modified the behaviour of queries.
It was used for 2 things: some full-blown errors, but mostly for lint declaration notes ("the lint level is defined here" notes).

It is replaced by the diagnostic deduplication infra which already exists in the diagnostic emitter.
A new diagnostic level `OnceNote` is introduced specifically for lint notes, to deduplicate subdiagnostics.

As a drive-by, diagnostic emission takes a `&mut` to allow dropping the `SubDiagnostic`s.
@bors
Copy link
Contributor

bors commented Mar 26, 2022

⌛ Testing commit f7d5b7a with merge beeb270e17dcf0662d43128e69a07059d98374e0...

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 26, 2022
Remove `Session::one_time_diagnostic`

This is untracked mutable state, which modified the behaviour of queries.
It was used for 2 things: some full-blown errors, but mostly for lint declaration notes ("the lint level is defined here" notes).

It is replaced by the diagnostic deduplication infra which already exists in the diagnostic emitter.
A new diagnostic level `OnceNote` is introduced specifically for lint notes, to deduplicate subdiagnostics.

As a drive-by, diagnostic emission takes a `&mut` to allow dropping the `SubDiagnostic`s.
@Dylan-DPC
Copy link
Member

@bors retry (included in rollup so yielding)

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Mar 26, 2022

⌛ Testing commit f7d5b7a with merge c749254...

@bors
Copy link
Contributor

bors commented Mar 26, 2022

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 26, 2022
@bors bors merged commit c749254 into rust-lang:master Mar 26, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 26, 2022
@cjgillot cjgillot deleted the once-diag branch March 26, 2022 09:51
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c749254): comparison url.

Summary: This benchmark run did not return any relevant results. 13 results were found to be statistically significant but too small to be relevant.

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

@rustbot label: -perf-regression

flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 7, 2022
Remove `Session::one_time_diagnostic`

This is untracked mutable state, which modified the behaviour of queries.
It was used for 2 things: some full-blown errors, but mostly for lint declaration notes ("the lint level is defined here" notes).

It is replaced by the diagnostic deduplication infra which already exists in the diagnostic emitter.
A new diagnostic level `OnceNote` is introduced specifically for lint notes, to deduplicate subdiagnostics.

As a drive-by, diagnostic emission takes a `&mut` to allow dropping the `SubDiagnostic`s.
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. 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.

9 participants