Rollup merge of #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:bd0826a452/compiler/rustc_ast_passes/src/node_count.rs (L1)
bd0826a452/compiler/rustc_passes/src/hir_stats.rs (L1-L3)
This commit is contained in:
commit
f25fee3349
10 changed files with 24 additions and 165 deletions
|
@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::sync::{Arc, LazyLock};
|
||||
use std::{env, fs, iter};
|
||||
|
||||
use rustc_ast::{self as ast, visit};
|
||||
use rustc_ast as ast;
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_data_structures::parallel;
|
||||
use rustc_data_structures::steal::Steal;
|
||||
|
@ -24,7 +24,7 @@ use rustc_middle::util::Providers;
|
|||
use rustc_parse::{
|
||||
new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal, validate_attr,
|
||||
};
|
||||
use rustc_passes::{abi_test, hir_stats, layout_test};
|
||||
use rustc_passes::{abi_test, input_stats, layout_test};
|
||||
use rustc_resolve::Resolver;
|
||||
use rustc_session::code_stats::VTableSizeInfo;
|
||||
use rustc_session::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
|
||||
|
@ -54,28 +54,17 @@ pub(crate) fn parse<'a>(sess: &'a Session) -> Result<ast::Crate> {
|
|||
})
|
||||
.map_err(|parse_error| parse_error.emit())?;
|
||||
|
||||
if sess.opts.unstable_opts.input_stats {
|
||||
eprintln!("Lines of code: {}", sess.source_map().count_lines());
|
||||
eprintln!("Pre-expansion node count: {}", count_nodes(&krate));
|
||||
}
|
||||
|
||||
if let Some(ref s) = sess.opts.unstable_opts.show_span {
|
||||
rustc_ast_passes::show_span::run(sess.dcx(), s, &krate);
|
||||
}
|
||||
|
||||
if sess.opts.unstable_opts.hir_stats {
|
||||
hir_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS", "ast-stats-1");
|
||||
if sess.opts.unstable_opts.input_stats {
|
||||
input_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS", "ast-stats-1");
|
||||
}
|
||||
|
||||
Ok(krate)
|
||||
}
|
||||
|
||||
fn count_nodes(krate: &ast::Crate) -> usize {
|
||||
let mut counter = rustc_ast_passes::node_count::NodeCounter::new();
|
||||
visit::walk_crate(&mut counter, krate);
|
||||
counter.count
|
||||
}
|
||||
|
||||
fn pre_expansion_lint<'a>(
|
||||
sess: &Session,
|
||||
features: &Features,
|
||||
|
@ -290,11 +279,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
|
|||
let mut lint_buffer = resolver.lint_buffer.steal();
|
||||
|
||||
if sess.opts.unstable_opts.input_stats {
|
||||
eprintln!("Post-expansion node count: {}", count_nodes(krate));
|
||||
}
|
||||
|
||||
if sess.opts.unstable_opts.hir_stats {
|
||||
hir_stats::print_ast_stats(krate, "POST EXPANSION AST STATS", "ast-stats-2");
|
||||
input_stats::print_ast_stats(krate, "POST EXPANSION AST STATS", "ast-stats-2");
|
||||
}
|
||||
|
||||
// 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>(
|
|||
/// Runs all analyses that we guarantee to run, even if errors were reported in earlier analyses.
|
||||
/// This function never fails.
|
||||
fn run_required_analyses(tcx: TyCtxt<'_>) {
|
||||
if tcx.sess.opts.unstable_opts.hir_stats {
|
||||
rustc_passes::hir_stats::print_hir_stats(tcx);
|
||||
if tcx.sess.opts.unstable_opts.input_stats {
|
||||
rustc_passes::input_stats::print_hir_stats(tcx);
|
||||
}
|
||||
#[cfg(debug_assertions)]
|
||||
rustc_passes::hir_id_validator::check_crate(tcx);
|
||||
|
|
|
@ -698,7 +698,6 @@ fn test_unstable_options_tracking_hash() {
|
|||
untracked!(dylib_lto, true);
|
||||
untracked!(emit_stack_sizes, true);
|
||||
untracked!(future_incompat_test, true);
|
||||
untracked!(hir_stats, true);
|
||||
untracked!(identify_regions, true);
|
||||
untracked!(incremental_info, true);
|
||||
untracked!(incremental_verify_ich, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue