Skip to content

Commit dc73791

Browse files
authored
Unrolled build for rust-lang#133023
Rollup merge of rust-lang#133023 - samestep:hir-stats-total-count, r=nnethercote Merge `-Zhir-stats` into `-Zinput-stats` Currently `-Z hir-stats` prints the size and count of various kinds of nodes, and the total size of all the nodes it counted, but not the total count of nodes. So, before this PR: ``` $ git clone https://github.com/BurntSushi/ripgrep $ cd ripgrep $ cargo +nightly rustc -- -Z hir-stats ast-stats-1 PRE EXPANSION AST STATS ast-stats-1 Name Accumulated Size Count Item Size ast-stats-1 ---------------------------------------------------------------- ast-stats-1 ... ast-stats-1 ---------------------------------------------------------------- ast-stats-1 Total 93_576 ast-stats-1 ast-stats-2 POST EXPANSION AST STATS ast-stats-2 Name Accumulated Size Count Item Size ast-stats-2 ---------------------------------------------------------------- ast-stats-2 ... ast-stats-2 ---------------------------------------------------------------- ast-stats-2 Total 2_430_648 ast-stats-2 hir-stats HIR STATS hir-stats Name Accumulated Size Count Item Size hir-stats ---------------------------------------------------------------- hir-stats ... hir-stats ---------------------------------------------------------------- hir-stats Total 3_678_512 hir-stats ``` For consistency, this PR adds a total for the count as well: ``` $ cargo +stage1 rustc -- -Z hir-stats ast-stats-1 PRE EXPANSION AST STATS ast-stats-1 Name Accumulated Size Count Item Size ast-stats-1 ---------------------------------------------------------------- ast-stats-1 ... ast-stats-1 ---------------------------------------------------------------- ast-stats-1 Total 93_576 1_877 ast-stats-1 ast-stats-2 POST EXPANSION AST STATS ast-stats-2 Name Accumulated Size Count Item Size ast-stats-2 ---------------------------------------------------------------- ast-stats-2 ... ast-stats-2 ---------------------------------------------------------------- ast-stats-2 Total 2_430_648 48_625 ast-stats-2 hir-stats HIR STATS hir-stats Name Accumulated Size Count Item Size hir-stats ---------------------------------------------------------------- hir-stats ... hir-stats ---------------------------------------------------------------- hir-stats Total 3_678_512 73_418 hir-stats ``` I wasn't sure if I was supposed to update `tests/ui/stats/hir-stats.stderr` to reflect this. I ran it locally, thinking it would fail, but it didn't: ``` $ ./x test tests/ui/stats ... running 2 tests i. test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 17949 filtered out ``` Also: is there a reason `-Z hir-stats` and `-Z input-stats` both exist? The former seems like it should completely supercede the latter. But strangely, the two give very different numbers for node counts: ``` $ cargo +nightly rustc -- -Z input-stats ... Lines of code: 483 Pre-expansion node count: 2386 Post-expansion node count: 63844 ``` That's a 30% difference in this case. Is it intentional that these numbers are so different? I see comments for both saying that they are merely approximations and should not be expected to be correct: https://github.com/rust-lang/rust/blob/bd0826a4521a845f36cce1b00e1dd2918ba09e90/compiler/rustc_ast_passes/src/node_count.rs#L1 https://github.com/rust-lang/rust/blob/bd0826a4521a845f36cce1b00e1dd2918ba09e90/compiler/rustc_passes/src/hir_stats.rs#L1-L3
2 parents 89b6885 + 090c24f commit dc73791

File tree

10 files changed

+24
-165
lines changed

10 files changed

+24
-165
lines changed

compiler/rustc_ast_passes/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
pub mod ast_validation;
1919
mod errors;
2020
pub mod feature_gate;
21-
pub mod node_count;
2221
pub mod show_span;
2322

2423
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

compiler/rustc_ast_passes/src/node_count.rs

-129
This file was deleted.

compiler/rustc_interface/src/passes.rs

+7-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
55
use std::sync::{Arc, LazyLock};
66
use std::{env, fs, iter};
77

8-
use rustc_ast::{self as ast, visit};
8+
use rustc_ast as ast;
99
use rustc_codegen_ssa::traits::CodegenBackend;
1010
use rustc_data_structures::parallel;
1111
use rustc_data_structures::steal::Steal;
@@ -24,7 +24,7 @@ use rustc_middle::util::Providers;
2424
use rustc_parse::{
2525
new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal, validate_attr,
2626
};
27-
use rustc_passes::{abi_test, hir_stats, layout_test};
27+
use rustc_passes::{abi_test, input_stats, layout_test};
2828
use rustc_resolve::Resolver;
2929
use rustc_session::code_stats::VTableSizeInfo;
3030
use rustc_session::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
@@ -54,28 +54,17 @@ pub(crate) fn parse<'a>(sess: &'a Session) -> Result<ast::Crate> {
5454
})
5555
.map_err(|parse_error| parse_error.emit())?;
5656

57-
if sess.opts.unstable_opts.input_stats {
58-
eprintln!("Lines of code: {}", sess.source_map().count_lines());
59-
eprintln!("Pre-expansion node count: {}", count_nodes(&krate));
60-
}
61-
6257
if let Some(ref s) = sess.opts.unstable_opts.show_span {
6358
rustc_ast_passes::show_span::run(sess.dcx(), s, &krate);
6459
}
6560

66-
if sess.opts.unstable_opts.hir_stats {
67-
hir_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS", "ast-stats-1");
61+
if sess.opts.unstable_opts.input_stats {
62+
input_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS", "ast-stats-1");
6863
}
6964

7065
Ok(krate)
7166
}
7267

73-
fn count_nodes(krate: &ast::Crate) -> usize {
74-
let mut counter = rustc_ast_passes::node_count::NodeCounter::new();
75-
visit::walk_crate(&mut counter, krate);
76-
counter.count
77-
}
78-
7968
fn pre_expansion_lint<'a>(
8069
sess: &Session,
8170
features: &Features,
@@ -290,11 +279,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
290279
let mut lint_buffer = resolver.lint_buffer.steal();
291280

292281
if sess.opts.unstable_opts.input_stats {
293-
eprintln!("Post-expansion node count: {}", count_nodes(krate));
294-
}
295-
296-
if sess.opts.unstable_opts.hir_stats {
297-
hir_stats::print_ast_stats(krate, "POST EXPANSION AST STATS", "ast-stats-2");
282+
input_stats::print_ast_stats(krate, "POST EXPANSION AST STATS", "ast-stats-2");
298283
}
299284

300285
// Needs to go *after* expansion to be able to check the results of macro expansion.
@@ -820,8 +805,8 @@ pub(crate) fn create_global_ctxt<'tcx>(
820805
/// Runs all analyses that we guarantee to run, even if errors were reported in earlier analyses.
821806
/// This function never fails.
822807
fn run_required_analyses(tcx: TyCtxt<'_>) {
823-
if tcx.sess.opts.unstable_opts.hir_stats {
824-
rustc_passes::hir_stats::print_hir_stats(tcx);
808+
if tcx.sess.opts.unstable_opts.input_stats {
809+
rustc_passes::input_stats::print_hir_stats(tcx);
825810
}
826811
#[cfg(debug_assertions)]
827812
rustc_passes::hir_id_validator::check_crate(tcx);

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ fn test_unstable_options_tracking_hash() {
698698
untracked!(dylib_lto, true);
699699
untracked!(emit_stack_sizes, true);
700700
untracked!(future_incompat_test, true);
701-
untracked!(hir_stats, true);
702701
untracked!(identify_regions, true);
703702
untracked!(incremental_info, true);
704703
untracked!(incremental_verify_ich, true);

compiler/rustc_passes/src/hir_stats.rs compiler/rustc_passes/src/input_stats.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl<'k> StatCollector<'k> {
126126
});
127127

128128
let total_size = nodes.iter().map(|(_, node)| node.stats.count * node.stats.size).sum();
129+
let total_count = nodes.iter().map(|(_, node)| node.stats.count).sum();
129130

130131
eprintln!("{prefix} {title}");
131132
eprintln!(
@@ -167,7 +168,13 @@ impl<'k> StatCollector<'k> {
167168
}
168169
}
169170
eprintln!("{prefix} ----------------------------------------------------------------");
170-
eprintln!("{} {:<18}{:>10}", prefix, "Total", to_readable_str(total_size));
171+
eprintln!(
172+
"{} {:<18}{:>10} {:>14}",
173+
prefix,
174+
"Total",
175+
to_readable_str(total_size),
176+
to_readable_str(total_count),
177+
);
171178
eprintln!("{prefix}");
172179
}
173180
}

compiler/rustc_passes/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub mod entry;
2727
mod errors;
2828
#[cfg(debug_assertions)]
2929
pub mod hir_id_validator;
30-
pub mod hir_stats;
30+
pub mod input_stats;
3131
mod lang_items;
3232
pub mod layout_test;
3333
mod lib_features;

compiler/rustc_session/src/options.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1805,8 +1805,6 @@ options! {
18051805
environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)"),
18061806
has_thread_local: Option<bool> = (None, parse_opt_bool, [TRACKED],
18071807
"explicitly enable the `cfg(target_thread_local)` directive"),
1808-
hir_stats: bool = (false, parse_bool, [UNTRACKED],
1809-
"print some statistics about AST and HIR (default: no)"),
18101808
human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
18111809
"generate human-readable, predictable names for codegen units (default: no)"),
18121810
identify_regions: bool = (false, parse_bool, [UNTRACKED],
@@ -1838,7 +1836,7 @@ options! {
18381836
inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
18391837
"a default MIR inlining threshold (default: 50)"),
18401838
input_stats: bool = (false, parse_bool, [UNTRACKED],
1841-
"gather statistics about the input (default: no)"),
1839+
"print some statistics about AST and HIR (default: no)"),
18421840
instrument_mcount: bool = (false, parse_bool, [TRACKED],
18431841
"insert function instrument code for mcount-based tracing (default: no)"),
18441842
instrument_xray: Option<InstrumentXRay> = (None, parse_instrument_xray, [TRACKED],

tests/ui/stats/hir-stats.rs tests/ui/stats/input-stats.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ check-pass
2-
//@ compile-flags: -Zhir-stats
3-
//@ only-x86_64
2+
//@ compile-flags: -Zinput-stats
3+
//@ only-64bit
44
// layout randomization affects the hir stat output
55
//@ needs-deterministic-layouts
66

@@ -11,7 +11,7 @@
1111

1212

1313
// The aim here is to include at least one of every different type of top-level
14-
// AST/HIR node reported by `-Zhir-stats`.
14+
// AST/HIR node reported by `-Zinput-stats`.
1515

1616
#![allow(dead_code)]
1717

tests/ui/stats/hir-stats.stderr tests/ui/stats/input-stats.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ast-stats-1 - Enum 136 ( 2.0%) 1
5353
ast-stats-1 - Fn 272 ( 4.1%) 2
5454
ast-stats-1 - Use 408 ( 6.1%) 3
5555
ast-stats-1 ----------------------------------------------------------------
56-
ast-stats-1 Total 6_640
56+
ast-stats-1 Total 6_640 116
5757
ast-stats-1
5858
ast-stats-2 POST EXPANSION AST STATS
5959
ast-stats-2 Name Accumulated Size Count Item Size
@@ -113,7 +113,7 @@ ast-stats-2 - ForeignMod 136 ( 1.9%) 1
113113
ast-stats-2 - Fn 272 ( 3.7%) 2
114114
ast-stats-2 - Use 544 ( 7.5%) 4
115115
ast-stats-2 ----------------------------------------------------------------
116-
ast-stats-2 Total 7_288
116+
ast-stats-2 Total 7_288 127
117117
ast-stats-2
118118
hir-stats HIR STATS
119119
hir-stats Name Accumulated Size Count Item Size
@@ -174,5 +174,5 @@ hir-stats - Use 352 ( 3.9%) 4
174174
hir-stats Path 1_240 (13.7%) 31 40
175175
hir-stats PathSegment 1_920 (21.3%) 40 48
176176
hir-stats ----------------------------------------------------------------
177-
hir-stats Total 9_024
177+
hir-stats Total 9_024 180
178178
hir-stats

triagebot.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ message = "This PR changes a file inside `tests/crashes`. If a crash was fixed,
901901
message = "Changes to the code generated for builtin derived traits."
902902
cc = ["@nnethercote"]
903903

904-
[mentions."tests/ui/stats/hir-stats.stderr"]
904+
[mentions."tests/ui/stats/input-stats.stderr"]
905905
message = "Changes to the size of AST and/or HIR nodes."
906906
cc = ["@nnethercote"]
907907

0 commit comments

Comments
 (0)