-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 DiagCtxt
API duplication
#119146
Remove DiagCtxt
API duplication
#119146
Conversation
Some changes occurred in need_type_info.rs cc @lcnr Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes might have occurred in exhaustiveness checking cc @Nadrieril Some changes occurred in src/tools/clippy cc @rust-lang/clippy Type relation code was changed Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor Some changes occurred in src/librustdoc/clean/types.rs cc @camelid Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in cc @BoxyUwU Some changes occurred in cc @BoxyUwU Some changes occurred in compiler/rustc_codegen_gcc Some changes might have occurred in exhaustiveness checking cc @Nadrieril Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri The Miri subtree was changed cc @rust-lang/miri |
Here's a table showing the full API and the existing duplication.
|
And here's a table showing all the possible chaining combinations.
The shortest chains are always preferred, of course. |
This comment has been minimized.
This comment has been minimized.
94075a8
to
4092152
Compare
This comment has been minimized.
This comment has been minimized.
4092152
to
a8bd180
Compare
a8bd180
to
8a1a0de
Compare
Not expected to affect perf, but let's check: @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…ion, r=<try> Remove `DiagCtxt` API duplication `DiagCtxt` defines the internal API for creating and emitting diagnostics: methods like `struct_err`, `struct_span_warn`, `note`, `create_fatal`, `emit_bug`. There are over 50 methods. Some of these methods are then duplicated across several other types: `Session`, `ParseSess`, `Parser`, `ExtCtxt`, and `MirBorrowckCtxt`. `Session` duplicates the most, though half the ones it does are unused. Each duplicated method just calls forward to the corresponding method in `DiagCtxt`. So this duplication exists to (in the best case) shorten chains like `ecx.tcx.sess.parse_sess.dcx.emit_err()` to `ecx.emit_err()`. This API duplication is ugly and has been bugging me for a while. And it's inconsistent: there's no real logic about which methods are duplicated, and the use of `#[rustc_lint_diagnostic]` and `#[track_caller]` attributes vary across the duplicates. This PR removes the duplicated API methods and makes all diagnostic creation and emission go through `DiagCtxt`. It also adds `dcx` getter methods to several types to shorten chains. This approach scales *much* better than API duplication; indeed, the PR adds `dcx()` to numerous types that didn't have API duplication: `TyCtxt`, `LoweringCtxt`, `ConstCx`, `FnCtxt`, `TypeErrCtxt`, `InferCtxt`, `CrateLoader`, `CheckAttrVisitor`, and `Resolver`. These result in a lot of changes from `foo.tcx.sess.emit_err()` to `foo.dcx().emit_err()`. (You could do this with more types, but it gets into diminishing returns territory for types that don't emit many diagnostics.) After all these changes, some call sites are more verbose, some are less verbose, and many are the same. The total number of lines is reduced, mostly because of the removed API duplication. And consistency is increased, because calls to `emit_err` and friends are always preceded with `.dcx()` or `.dcx`. r? `@compiler-errors`
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (917190f): comparison URL. Overall result: ❌ regressions - 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 a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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: 672.674s -> 672.581s (-0.01%) |
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #119190) made this pull request unmergeable. Please resolve the merge conflicts. |
ee2ef81
to
73653d7
Compare
I fixed the conflicts. |
☔ The latest upstream changes (presumably #119163) made this pull request unmergeable. Please resolve the merge conflicts. |
I figure I won't fix the conflicts again until/unless this gets r+, because it's so conflict-prone. The conflicts won't affect reviewing in any significant way. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (2271c26): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 669.724s -> 672.287s (0.38%) |
…ion, r=compiler-errors Remove `DiagCtxt` API duplication `DiagCtxt` defines the internal API for creating and emitting diagnostics: methods like `struct_err`, `struct_span_warn`, `note`, `create_fatal`, `emit_bug`. There are over 50 methods. Some of these methods are then duplicated across several other types: `Session`, `ParseSess`, `Parser`, `ExtCtxt`, and `MirBorrowckCtxt`. `Session` duplicates the most, though half the ones it does are unused. Each duplicated method just calls forward to the corresponding method in `DiagCtxt`. So this duplication exists to (in the best case) shorten chains like `ecx.tcx.sess.parse_sess.dcx.emit_err()` to `ecx.emit_err()`. This API duplication is ugly and has been bugging me for a while. And it's inconsistent: there's no real logic about which methods are duplicated, and the use of `#[rustc_lint_diagnostic]` and `#[track_caller]` attributes vary across the duplicates. This PR removes the duplicated API methods and makes all diagnostic creation and emission go through `DiagCtxt`. It also adds `dcx` getter methods to several types to shorten chains. This approach scales *much* better than API duplication; indeed, the PR adds `dcx()` to numerous types that didn't have API duplication: `TyCtxt`, `LoweringCtxt`, `ConstCx`, `FnCtxt`, `TypeErrCtxt`, `InferCtxt`, `CrateLoader`, `CheckAttrVisitor`, and `Resolver`. These result in a lot of changes from `foo.tcx.sess.emit_err()` to `foo.dcx().emit_err()`. (You could do this with more types, but it gets into diminishing returns territory for types that don't emit many diagnostics.) After all these changes, some call sites are more verbose, some are less verbose, and many are the same. The total number of lines is reduced, mostly because of the removed API duplication. And consistency is increased, because calls to `emit_err` and friends are always preceded with `.dcx()` or `.dcx`. r? `@compiler-errors`
Relevant PRs: - rust-lang/rust#119601 - rust-lang/rust#119146 - rust-lang/rust#119174 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
DiagCtxt
defines the internal API for creating and emitting diagnostics: methods likestruct_err
,struct_span_warn
,note
,create_fatal
,emit_bug
. There are over 50 methods.Some of these methods are then duplicated across several other types:
Session
,ParseSess
,Parser
,ExtCtxt
, andMirBorrowckCtxt
.Session
duplicates the most, though half the ones it does are unused. Each duplicated method just calls forward to the corresponding method inDiagCtxt
. So this duplication exists to (in the best case) shorten chains likeecx.tcx.sess.parse_sess.dcx.emit_err()
toecx.emit_err()
.This API duplication is ugly and has been bugging me for a while. And it's inconsistent: there's no real logic about which methods are duplicated, and the use of
#[rustc_lint_diagnostic]
and#[track_caller]
attributes vary across the duplicates.This PR removes the duplicated API methods and makes all diagnostic creation and emission go through
DiagCtxt
. It also addsdcx
getter methods to several types to shorten chains. This approach scales much better than API duplication; indeed, the PR addsdcx()
to numerous types that didn't have API duplication:TyCtxt
,LoweringCtxt
,ConstCx
,FnCtxt
,TypeErrCtxt
,InferCtxt
,CrateLoader
,CheckAttrVisitor
, andResolver
. These result in a lot of changes fromfoo.tcx.sess.emit_err()
tofoo.dcx().emit_err()
. (You could do this with more types, but it gets into diminishing returns territory for types that don't emit many diagnostics.)After all these changes, some call sites are more verbose, some are less verbose, and many are the same. The total number of lines is reduced, mostly because of the removed API duplication. And consistency is increased, because calls to
emit_err
and friends are always preceded with.dcx()
or.dcx
.r? @compiler-errors