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

Add -Z hir-stats for collecting statistics on HIR and AST #37583

Merged
merged 1 commit into from
Nov 6, 2016
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
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"the directory the MIR is dumped into"),
perf_stats: bool = (false, parse_bool, [UNTRACKED],
"print some performance-related statistics"),
hir_stats: bool = (false, parse_bool, [UNTRACKED],
"print some statistics about AST and HIR"),
}

pub fn default_lib_output() -> CrateType {
Expand Down
34 changes: 34 additions & 0 deletions src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ pub fn duration_to_secs_str(dur: Duration) -> String {
format!("{:.3}", secs)
}

pub fn to_readable_str(mut val: usize) -> String {
let mut groups = vec![];
loop {
let group = val % 1000;

val /= 1000;

if val == 0 {
groups.push(format!("{}", group));
break
} else {
groups.push(format!("{:03}", group));
}
}

groups.reverse();

groups.join("_")
}

pub fn record_time<T, F>(accu: &Cell<Duration>, f: F) -> T where
F: FnOnce() -> T,
{
Expand Down Expand Up @@ -264,3 +284,17 @@ pub fn path2cstr(p: &Path) -> CString {
pub fn path2cstr(p: &Path) -> CString {
CString::new(p.to_str().unwrap()).unwrap()
}


#[test]
fn test_to_readable_str() {
assert_eq!("0", to_readable_str(0));
assert_eq!("1", to_readable_str(1));
assert_eq!("99", to_readable_str(99));
assert_eq!("999", to_readable_str(999));
assert_eq!("1_000", to_readable_str(1_000));
assert_eq!("1_001", to_readable_str(1_001));
assert_eq!("999_999", to_readable_str(999_999));
assert_eq!("1_000_000", to_readable_str(1_000_000));
assert_eq!("1_234_567", to_readable_str(1_234_567));
}
19 changes: 17 additions & 2 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ use rustc_typeck as typeck;
use rustc_privacy;
use rustc_plugin::registry::Registry;
use rustc_plugin as plugin;
use rustc_passes::{ast_validation, no_asm, loops, consts, rvalues, static_recursion};
use rustc_passes::{ast_validation, no_asm, loops, consts, rvalues,
static_recursion, hir_stats};
use rustc_const_eval::check_match;
use super::Compilation;

Expand Down Expand Up @@ -513,6 +514,10 @@ pub fn phase_1_parse_input<'a>(sess: &'a Session, input: &Input) -> PResult<'a,
syntax::show_span::run(sess.diagnostic(), s, &krate);
}

if sess.opts.debugging_opts.hir_stats {
hir_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS");
}

Ok(krate)
}

Expand Down Expand Up @@ -718,6 +723,10 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
println!("Post-expansion node count: {}", count_nodes(&krate));
}

if sess.opts.debugging_opts.hir_stats {
hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS");
}

if sess.opts.debugging_opts.ast_json {
println!("{}", json::as_json(&krate));
}
Expand Down Expand Up @@ -758,7 +767,13 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,

// Lower ast -> hir.
let hir_forest = time(sess.time_passes(), "lowering ast -> hir", || {
hir_map::Forest::new(lower_crate(sess, &krate, &mut resolver), &sess.dep_graph)
let hir_crate = lower_crate(sess, &krate, &mut resolver);

if sess.opts.debugging_opts.hir_stats {
hir_stats::print_hir_stats(&hir_crate);
}

hir_map::Forest::new(hir_crate, &sess.dep_graph)
});

// Discard hygiene data, which isn't required past lowering to HIR.
Expand Down
Loading