1
Fork 0

Merge print_* functions.

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.
This commit is contained in:
Nicholas Nethercote 2023-10-11 08:49:24 +11:00
parent e3d8bbbfe2
commit 7d145a0fde
2 changed files with 55 additions and 73 deletions

View file

@ -396,7 +396,7 @@ fn run_compiler(
if ppm.needs_ast_map() {
queries.global_ctxt()?.enter(|tcx| {
tcx.ensure().early_lint_checks(());
pretty::print_after_hir_lowering(tcx, *ppm);
pretty::print(sess, *ppm, pretty::PrintExtra::NeedsAstMap { tcx });
Ok(())
})?;
@ -405,7 +405,7 @@ fn run_compiler(
queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
} else {
let krate = queries.parse()?.steal();
pretty::print_after_parsing(sess, &krate, *ppm);
pretty::print(sess, *ppm, pretty::PrintExtra::AfterParsing { krate });
}
trace!("finished pretty-printing");
return early_exit();