Add -Zinput-stats

Emits loc, and node count - before and after expansion.

E.g.,

```
rustc: x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore
Lines of code:             32060
Pre-expansion node count:  120205
Post-expansion node count: 482749
```
This commit is contained in:
Nick Cameron 2015-11-11 18:26:14 +13:00
parent f1f5c04c07
commit f7dc917ba4
5 changed files with 218 additions and 26 deletions

View file

@ -52,6 +52,8 @@ use syntax::feature_gate::UnstableFeatures;
use syntax::fold::Folder;
use syntax::parse;
use syntax::parse::token;
use syntax::util::node_count::NodeCounter;
use syntax::visit;
use syntax;
pub fn compile_input(sess: Session,
@ -398,6 +400,11 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
println!("{}", json::as_json(&krate));
}
if sess.opts.debugging_opts.input_stats {
println!("Lines of code: {}", sess.codemap().count_lines());
println!("Pre-expansion node count: {}", count_nodes(&krate));
}
if let Some(ref s) = sess.opts.show_span {
syntax::show_span::run(sess.diagnostic(), s, &krate);
}
@ -405,6 +412,12 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
krate
}
fn count_nodes(krate: &ast::Crate) -> usize {
let mut counter = NodeCounter::new();
visit::walk_crate(&mut counter, krate);
counter.count
}
// For continuing compilation after a parsed crate has been
// modified
@ -606,6 +619,10 @@ pub fn phase_2_configure_and_expand(sess: &Session,
sess.abort_if_errors();
});
if sess.opts.debugging_opts.input_stats {
println!("Post-expansion node count: {}", count_nodes(&krate));
}
Some(krate)
}