Skip to content

Commit b2a57e6

Browse files
committed
Tweak -Zinput-stats and -Zmeta-stats output.
To make it match `-Zmacro-stats`, and work better if you have enabled it for multiple crates. - Print each crate's name. - Print a `===` banner at the start and end for separation.
1 parent 1e7e173 commit b2a57e6

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
370370
let mut lint_buffer = resolver.lint_buffer.steal();
371371

372372
if sess.opts.unstable_opts.input_stats {
373-
input_stats::print_ast_stats(krate);
373+
input_stats::print_ast_stats(tcx, krate);
374374
}
375375

376376
// Needs to go *after* expansion to be able to check the results of macro expansion.

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
794794
// `RUSTFLAGS='-Zmeta-stats' cargo build`). It still doesn't guarantee
795795
// non-interleaving, though.
796796
let mut s = String::new();
797-
_ = writeln!(s, "{prefix} METADATA STATS");
797+
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
798+
_ = writeln!(s, "{prefix} METADATA STATS: {}", tcx.crate_name(LOCAL_CRATE));
798799
_ = writeln!(s, "{prefix} {:<section_w$}{:>size_w$}", "Section", "Size");
799800
_ = writeln!(s, "{prefix} {}", "-".repeat(banner_w));
800801
for (label, size) in stats {
@@ -814,7 +815,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
814815
usize_with_underscores(total_bytes),
815816
perc(zero_bytes)
816817
);
817-
_ = writeln!(s, "{prefix}");
818+
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
818819
eprint!("{s}");
819820
}
820821

compiler/rustc_passes/src/input_stats.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ pub fn print_hir_stats(tcx: TyCtxt<'_>) {
6565
StatCollector { tcx: Some(tcx), nodes: FxHashMap::default(), seen: FxHashSet::default() };
6666
tcx.hir_walk_toplevel_module(&mut collector);
6767
tcx.hir_walk_attributes(&mut collector);
68-
collector.print("HIR STATS", "hir-stats");
68+
collector.print(tcx, "HIR STATS", "hir-stats");
6969
}
7070

71-
pub fn print_ast_stats(krate: &ast::Crate) {
71+
pub fn print_ast_stats(tcx: TyCtxt<'_>, krate: &ast::Crate) {
7272
use rustc_ast::visit::Visitor;
7373

7474
let mut collector =
7575
StatCollector { tcx: None, nodes: FxHashMap::default(), seen: FxHashSet::default() };
7676
collector.visit_crate(krate);
77-
collector.print("POST EXPANSION AST STATS", "ast-stats");
77+
collector.print(tcx, "POST EXPANSION AST STATS", "ast-stats");
7878
}
7979

8080
impl<'k> StatCollector<'k> {
@@ -116,7 +116,7 @@ impl<'k> StatCollector<'k> {
116116
}
117117
}
118118

119-
fn print(&self, title: &str, prefix: &str) {
119+
fn print(&self, tcx: TyCtxt<'_>, title: &str, prefix: &str) {
120120
use std::fmt::Write;
121121

122122
// We will soon sort, so the initial order does not matter.
@@ -142,7 +142,8 @@ impl<'k> StatCollector<'k> {
142142
// `RUSTFLAGS='-Zinput-stats' cargo build`). It still doesn't guarantee
143143
// non-interleaving, though.
144144
let mut s = String::new();
145-
_ = writeln!(s, "{prefix} {title}");
145+
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
146+
_ = writeln!(s, "{prefix} {title}: {}", tcx.crate_name(hir::def_id::LOCAL_CRATE));
146147
_ = writeln!(
147148
s,
148149
"{prefix} {:<name_w$}{:>acc_size_w$}{:>count_w$}{:>item_size_w$}",
@@ -193,7 +194,7 @@ impl<'k> StatCollector<'k> {
193194
"",
194195
usize_with_underscores(total_count),
195196
);
196-
_ = writeln!(s, "{prefix}");
197+
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
197198
eprint!("{s}");
198199
}
199200
}

tests/ui/stats/input-stats.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
ast-stats POST EXPANSION AST STATS
1+
ast-stats ================================================================
2+
ast-stats POST EXPANSION AST STATS: input_stats
23
ast-stats Name Accumulated Size Count Item Size
34
ast-stats ----------------------------------------------------------------
45
ast-stats Item 1_584 (NN.N%) 11 144
@@ -57,8 +58,9 @@ ast-stats - AngleBracketed 40 (NN.N%) 1
5758
ast-stats Crate 40 (NN.N%) 1 40
5859
ast-stats ----------------------------------------------------------------
5960
ast-stats Total 7_416 127
60-
ast-stats
61-
hir-stats HIR STATS
61+
ast-stats ================================================================
62+
hir-stats ================================================================
63+
hir-stats HIR STATS: input_stats
6264
hir-stats Name Accumulated Size Count Item Size
6365
hir-stats ----------------------------------------------------------------
6466
hir-stats PathSegment 1_776 (NN.N%) 37 48
@@ -118,4 +120,4 @@ hir-stats Lifetime 28 (NN.N%) 1 28
118120
hir-stats ForeignItemRef 24 (NN.N%) 1 24
119121
hir-stats ----------------------------------------------------------------
120122
hir-stats Total 8_676 172
121-
hir-stats
123+
hir-stats ================================================================

0 commit comments

Comments
 (0)