Skip to content

Commit

Permalink
Rollup merge of rust-lang#118341 - Mark-Simulacrum:shrink-thir-print,…
Browse files Browse the repository at this point in the history
… r=compiler-errors

Simplify indenting in THIR printing

This cuts >100kb from a local librustc_driver.so build, and seems just obviously simpler.
  • Loading branch information
GuillaumeGomez committed Nov 27, 2023
2 parents e1c8ada + 8375fe4 commit 83df769
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions compiler/rustc_mir_build/src/thir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const INDENT: &str = " ";

macro_rules! print_indented {
($writer:ident, $s:expr, $indent_lvl:expr) => {
let indent = (0..$indent_lvl).map(|_| INDENT).collect::<Vec<_>>().concat();
writeln!($writer, "{}{}", indent, $s).expect("unable to write to ThirPrinter");
$writer.indent($indent_lvl);
writeln!($writer, "{}", $s).expect("unable to write to ThirPrinter");
};
}

Expand All @@ -48,6 +48,12 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
Self { thir, fmt: String::new() }
}

fn indent(&mut self, level: usize) {
for _ in 0..level {
self.fmt.push_str(INDENT);
}
}

fn print(&mut self) {
print_indented!(self, "params: [", 0);
for param in self.thir.params.iter() {
Expand Down

0 comments on commit 83df769

Please sign in to comment.