-
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
Streamline rustc_driver_impl
pretty-printing.
#116619
Conversation
This PR is probably best reviewed one commit at a time. Each commit is a self-contained change, but the progress through the commits is not entirely a straight line; I was feeling my way as I went. Some things in earlier commits are undone in later commits (and the log messages indicate some of these). If I did it again from scratch I would end up with slightly fewer commits, but I don't think that's worth the effort. |
☔ The latest upstream changes (presumably #115948) made this pull request unmergeable. Please resolve the merge conflicts. |
c096758
to
d1e3dc6
Compare
I fixed the 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.
r=me after nits or not
- Rename `pprust` as `pprust_ast`, to align with `pprust_hir`. - Rename `PrinterSupport` as `AstPrinterSupport`, to align with `HirPrinterSupport`.
The callback is trivial and no pp support is actually needed. This makes the `HirTree` case more like the `AstTree` case above.
`phase_3_run_analysis_passes` no longer exists, and AFAICT this code has been refactored so much since this comment was written that it no longer has any useful meaning.
It's simpler to distinguish the two AST modes directly in `PpMode`.
First, both `AstPrinterSupport` and `HirPrinterSupport` have a `sess` method. This commit introduces a `Sess` trait and makes the support traits be subtraits of `Sess`, to avoid some duplication. Second, both support traits have a `pp_ann` method that isn't needed if we enable `trait_upcasting`. This commit removes those methods. (Both of these traits will be removed in a subsequent commit, as will the `trait_upcasting` use.)
The handling of the `PpMode` variants is currently spread across three functions: `print_after_parsing`, `print_after_hir_lowering`, and `print_with_analysis`. Each one handles some of the variants. This split is primarily because `print_after_parsing` has slightly different arguments to the other two. This commit changes the structure. It merges the three functions into a single `print` function, and encapsulates the different arguments in a new enum `PrintExtra`. Benefits: - The code is a little shorter. - All the `PpMode` variants are handled in a single `match`, with no need for `unreachable!` arms. - It enables the trait removal in the subsequent commit by reducing the number of `call_with_pp_support_ast` call sites from two to one.
`call_with_pp_support_ast` and `call_with_pp_support_hir` how each have a single call site. This commit inlines and removes them, which also removes the need for all the supporting traits: `Sess`, `AstPrinterSupport`, and `HirPrinterSupport`. The `sess` member is also removed from several structs.
Because they all end up within a `TyCtxt`.
This avoids the need for a bespoke `tcx.analysis()` call.
`NoAnn` and `IdentifiedAnnotation` impl both `pprust_ast::PpAnn` and `pprust_hir::PpAnn`, which is a bit confusing, because the optional `tcx` is only needed for the HIR cases. (Currently the `tcx` is unnecessarily provided in the `expanded` AST cases.) This commit splits each one into `Ast` and `Hir` versions, which makes things clear about where the `tcx` is needed. The commit also renames all the traits so they consistently end with `Ann`.
d1e3dc6
to
2b4c338
Compare
@bors r=compiler-errors |
☀️ Test successful - checks-actions |
Finished benchmarking commit (2763ca5): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. 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: 628.344s -> 627.545s (-0.13%) |
50: Automated pull from upstream `master` r=Dajamante a=github-actions[bot] This PR pulls the following changes from the upstream repository: * rust-lang/rust#116619 * rust-lang/rust#115964 * rust-lang/rust#116391 * rust-lang/rust#116510 * rust-lang/rust#116671 * rust-lang/rust#116669 * rust-lang/rust#116654 * rust-lang/rust#116642 * rust-lang/rust#116625 * rust-lang/rust#116593 * rust-lang/rust#116649 * rust-lang/rust#116600 * rust-lang/rust#116628 Co-authored-by: Nadrieril <[email protected]> Co-authored-by: Scott McMurray <[email protected]> Co-authored-by: bjorn3 <[email protected]> Co-authored-by: Nicholas Nethercote <[email protected]> Co-authored-by: Trevor Gross <[email protected]> Co-authored-by: Georg Semmler <[email protected]> Co-authored-by: Guillaume Gomez <[email protected]> Co-authored-by: Gurinder Singh <[email protected]> Co-authored-by: bors <[email protected]>
This PR simplifies a lot of unnecessary structure in
rustc_driver_impl/src/pretty.rs
. It removes some traits and functions,simplifies some structs, renames some things for increased consistency, and
eliminates some boilerplate code. Overall it cuts more than 150 lines of code.
r? @compiler-errors