Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge -Zhir-stats into -Zinput-stats #133023

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
pub mod ast_validation;
mod errors;
pub mod feature_gate;
pub mod node_count;
pub mod show_span;

rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
129 changes: 0 additions & 129 deletions compiler/rustc_ast_passes/src/node_count.rs

This file was deleted.

29 changes: 7 additions & 22 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl<'k> StatCollector<'k> {
});

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

eprintln!("{prefix} {title}");
eprintln!(
Expand Down Expand Up @@ -167,7 +168,13 @@ impl<'k> StatCollector<'k> {
}
}
eprintln!("{prefix} ----------------------------------------------------------------");
eprintln!("{} {:<18}{:>10}", prefix, "Total", to_readable_str(total_size));
eprintln!(
"{} {:<18}{:>10} {:>14}",
prefix,
"Total",
to_readable_str(total_size),
to_readable_str(total_count),
);
eprintln!("{prefix}");
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod entry;
mod errors;
#[cfg(debug_assertions)]
pub mod hir_id_validator;
pub mod hir_stats;
pub mod input_stats;
mod lang_items;
pub mod layout_test;
mod lib_features;
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1805,8 +1805,6 @@ options! {
environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)"),
has_thread_local: Option<bool> = (None, parse_opt_bool, [TRACKED],
"explicitly enable the `cfg(target_thread_local)` directive"),
hir_stats: bool = (false, parse_bool, [UNTRACKED],
"print some statistics about AST and HIR (default: no)"),
human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
"generate human-readable, predictable names for codegen units (default: no)"),
identify_regions: bool = (false, parse_bool, [UNTRACKED],
Expand Down Expand Up @@ -1838,7 +1836,7 @@ options! {
inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
"a default MIR inlining threshold (default: 50)"),
input_stats: bool = (false, parse_bool, [UNTRACKED],
"gather statistics about the input (default: no)"),
"print some statistics about AST and HIR (default: no)"),
instrument_mcount: bool = (false, parse_bool, [TRACKED],
"insert function instrument code for mcount-based tracing (default: no)"),
instrument_xray: Option<InstrumentXRay> = (None, parse_instrument_xray, [TRACKED],
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/stats/hir-stats.rs → tests/ui/stats/input-stats.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ check-pass
//@ compile-flags: -Zhir-stats
//@ only-x86_64
//@ compile-flags: -Zinput-stats
//@ only-64bit
// layout randomization affects the hir stat output
//@ needs-deterministic-layouts

Expand All @@ -11,7 +11,7 @@


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

#![allow(dead_code)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ast-stats-1 - Enum 136 ( 2.0%) 1
ast-stats-1 - Fn 272 ( 4.1%) 2
ast-stats-1 - Use 408 ( 6.1%) 3
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 Total 6_640
ast-stats-1 Total 6_640 116
ast-stats-1
ast-stats-2 POST EXPANSION AST STATS
ast-stats-2 Name Accumulated Size Count Item Size
Expand Down Expand Up @@ -113,7 +113,7 @@ ast-stats-2 - ForeignMod 136 ( 1.9%) 1
ast-stats-2 - Fn 272 ( 3.7%) 2
ast-stats-2 - Use 544 ( 7.5%) 4
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 Total 7_288
ast-stats-2 Total 7_288 127
ast-stats-2
hir-stats HIR STATS
hir-stats Name Accumulated Size Count Item Size
Expand Down Expand Up @@ -174,5 +174,5 @@ hir-stats - Use 352 ( 3.9%) 4
hir-stats Path 1_240 (13.7%) 31 40
hir-stats PathSegment 1_920 (21.3%) 40 48
hir-stats ----------------------------------------------------------------
hir-stats Total 9_024
hir-stats Total 9_024 180
hir-stats
2 changes: 1 addition & 1 deletion triagebot.toml
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ message = "This PR changes a file inside `tests/crashes`. If a crash was fixed,
message = "Changes to the code generated for builtin derived traits."
cc = ["@nnethercote"]

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

Expand Down
Loading