-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make lint diagnostics responsible for providing their primary span #125208
Conversation
@bors p=1 prone to bitrot |
44d8cb9
to
68763a5
Compare
cc @davidtwco, @compiler-errors, @TaKO8Ki Some changes occurred in exhaustiveness checking cc @Nadrieril Some changes occurred in match checking cc @Nadrieril Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
68763a5
to
b5bee8b
Compare
This comment has been minimized.
This comment has been minimized.
b5bee8b
to
5d6cff6
Compare
This comment has been minimized.
This comment has been minimized.
5d6cff6
to
ce91022
Compare
This comment has been minimized.
This comment has been minimized.
I foresee lots of merge conflicts with #124417 :/ |
ce91022
to
d8ce69b
Compare
@Xiretza Happy to block this PR on yours and do the rebasing myself here. |
☔ The latest upstream changes (presumably #125077) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
This looks good to me, r=me once you're ready to see this merged
aee03c5
to
b22eadf
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…r=<try> Make lint diagnostics responsible for providing their primary span ### Summary and Rustc-Dev-Facing Changes Instead of passing the primary span of lint diagnostics separately — namely to the functions `tcx.emit_span_lint` and `tcx.emit_node_span_lint` —, make lint diagnostics responsible for “storing” (providing) their span. I've removed the two aforementioned methods. You are now expected to use `tcx.emit_lint` and `tcx.emit_node_lint` respectively and to provide the primary span when deriving `LintDiagnostic` (via `#[primary_span]`) / implementing `LintDiagnostic` manually (via `LintDiagnostic::span`). ### Motivation Making the general format of `#[derive(LintDiagnostic)]` identical to `#[derive(Diagnostic)]`. I bet this has lead to slight confusion or annoyances before. Moreover, it enables deriving both traits at once (see rust-lang#125169 for the motivation). ### Approach As outlined in rust-lang#125169 (comment), the naïve approach of doing the same as `Diagnostic` doesn't work for `LintDiagnostic`, i.e., setting the primary span with `Diag::span` inside `decorate_lint` (that's `into_diag` for `Diagnostic`) because `lint_level` (`lint_level_impl`) needs access to the primary spans before decorating the `Diag` to be able to filter out some lints (namely if they come from an external macro) etc. Therefore, I had to introduce a new method to `LintDiagnostic`: `fn span(&self) -> Option<MultiSpan>` (similar to the existing method `LintDiagnostic::msg`). ### Commits 1. The 1st commit addresses [rust-lang#125169 (comment)](rust-lang#125169 (comment)). It contains the necessary changes to the linting APIs. It doesn't build on its own due to the removed APIs. Split out for easier reviewing. 2. The 2nd commit updates all existing lint diagnostics to use the new APIs. Most of them are mindless, monotonous, obvious changes. Some changes are *slightly* more involved out of necessity. I've verified (partly programmatically, partly manually) that all lint diags that used to have a primary span still have a primary span. 3. The 3rd commit updates the fulldeps UI tests that exercise the (lint) diagnostic API 4. The 4th commit fixes [rust-lang#125169](rust-lang#125169). I've only deduplicated the lint diagnostic structs mentioned in the issue and haven't gone looking for other structs that may benefit from deriving both `Diagnostic` and `LintDiagnostic` because I didn't have the time to do so yet. ### Meta Fixes rust-lang#125169. I'll submit a rustc-dev-guide PR later. I hope this doesn't need an MCP, it's pretty straight forward. cc `@davidtwco` r? `@nnethercote` or anyone on compiler who has the energy to review 82 files
b22eadf
to
775527e
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…r=<try> Make lint diagnostics responsible for providing their primary span ### Summary and Rustc-Dev-Facing Changes Instead of passing the primary span of lint diagnostics separately — namely to the functions `tcx.emit_span_lint` and `tcx.emit_node_span_lint` —, make lint diagnostics responsible for “storing” (providing) their span. I've removed the two aforementioned methods. You are now expected to use `tcx.emit_lint` and `tcx.emit_node_lint` respectively and to provide the primary span when deriving `LintDiagnostic` (via `#[primary_span]`) / implementing `LintDiagnostic` manually (via `LintDiagnostic::span`). > [!NOTE] > FIXME(fmease): Mention how early lints are handled. ### Motivation Making the general format of `#[derive(LintDiagnostic)]` identical to `#[derive(Diagnostic)]`. I bet this has lead to slight confusion or annoyances before. Moreover, it enables deriving both traits at once (see rust-lang#125169 for the motivation). ### Approach As outlined in rust-lang#125169 (comment), the naïve approach of doing the same as `Diagnostic` doesn't work for `LintDiagnostic`, i.e., setting the primary span with `Diag::span` inside `decorate_lint` (that's `into_diag` for `Diagnostic`) because `lint_level` (`lint_level_impl`) needs access to the primary spans before decorating the `Diag` to be able to filter out some lints (namely if they come from an external macro) etc. Therefore, I had to introduce a new method to `LintDiagnostic`: `fn span(&self) -> Option<MultiSpan>` (similar to the existing method `LintDiagnostic::msg`). ### Commits 1. The 1st commit addresses [rust-lang#125169 (comment)](rust-lang#125169 (comment)). It contains the necessary changes to the linting APIs. It doesn't build on its own due to the removed APIs. Split out for easier reviewing. 2. The 2nd commit updates all existing lint diagnostics to use the new APIs. Most of them are mindless, monotonous, obvious changes. Some changes are *slightly* more involved out of necessity. I've verified (partly programmatically, partly manually) that all lint diags that used to have a primary span still have a primary span. 3. The 3rd commit updates the fulldeps UI tests that exercise the (lint) diagnostic API 4. The 4th commit fixes [rust-lang#125169](rust-lang#125169). I've only deduplicated the lint diagnostic structs mentioned in the issue and haven't gone looking for other structs that may benefit from deriving both `Diagnostic` and `LintDiagnostic` because I didn't have the time to do so yet. ### Meta Fixes rust-lang#125169. I'll submit a rustc-dev-guide PR later. I hope this doesn't need an MCP, it's pretty straight forward. cc `@davidtwco` r? `@nnethercote` or anyone on compiler who has the energy to review 82 files
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (6932f95): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking 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 may lead to changes in compiler perf. @bors rollup=never Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 2.1%, secondary 3.2%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary -2.4%, secondary 3.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 785.158s -> 785.364s (0.03%) |
David gave a soft approval for an earlier version of this, so it makes sense to officially hand it over now that it seems close to being ready. r? @davidtwco |
Yesterday I coincidentally stumbled upon this Zulip post from 2024-09-25 which essentially declares the current diagnostic translation effort (#100717) unfruitful and unmaintained. While I only read this post yesterday, I have been aware of this fact for some time. Therefore I don't want to burden davidtwco with re-reviewing >1000 lines and I'm also fine with closing this PR. Of course, not a lot has changed. It's essentially a rebase from a 5 month old master. I stalled the rebase until now because I knew that this approach (of making lint diagnostics responsible or providing their primary span) does not scale to early (buffered) lints. I came to realize that when reviewing PR #124417 (which made early lints translatable) and implementing PR #125410 (which won back some of the perf regressions caused by the former). You say it doesn't scale to early (buffered) lints, so how did you succeed in rebasing then while keeping perf in check? Well, I've cheated a little bit. The statement "lints diagnostics are responsible for providing their primary span" now only holds for non-early lints. The early lint diagnostics don't provide a For perf reasons, we can't eagerly "lower" This creates a divide between early and late Footnotes
|
Summary and Rustc-Dev-Facing Changes
Instead of passing the primary span of lint diagnostics separately — namely to the functions
tcx.emit_span_lint
andtcx.emit_node_span_lint
—, make lint diagnostics responsible for “storing” (providing) their span. I've removed the two aforementioned methods. You are now expected to usetcx.emit_lint
andtcx.emit_node_lint
respectively and to provide the primary span when derivingLintDiagnostic
(via#[primary_span]
) / implementingLintDiagnostic
manually (viaLintDiagnostic::span
).Note
FIXME(fmease): Mention how early lints are handled.
Motivation
Making the general format of
#[derive(LintDiagnostic)]
identical to#[derive(Diagnostic)]
. I bet this has lead to slight confusion or annoyances before. Moreover, it enables deriving both traits at once (see #125169 for the motivation).Approach
As outlined in #125169 (comment), the naïve approach of doing the same as
Diagnostic
doesn't work forLintDiagnostic
, i.e., setting the primary span withDiag::span
insidedecorate_lint
(that'sinto_diag
forDiagnostic
) becauselint_level
(lint_level_impl
) needs access to the primary spans before decorating theDiag
to be able to filter out some lints (namely if they come from an external macro) etc.Therefore, I had to introduce a new method to
LintDiagnostic
:fn span(&self) -> Option<MultiSpan>
(similar to the existing methodLintDiagnostic::msg
).Commits
Diagnostic
andLintDiagnostic
because I didn't have the time to do so yet.Meta
Fixes #125169.
I'll submit a rustc-dev-guide PR later.
I hope this doesn't need an MCP, it's pretty straight forward.
cc @davidtwco
r? @nnethercote or anyone on compiler who has the energy to review 82 files