Instrument a bunch of tasks that employ the HIR map in one way or

another and were not previously instrumented.
This commit is contained in:
Niko Matsakis 2016-01-29 15:04:07 -05:00
parent d09fd1a529
commit 35b6e2b0bb
17 changed files with 123 additions and 42 deletions

View File

@ -40,8 +40,21 @@ pub enum DepNode {
Hir(DefId),
// Represents different phases in the compiler.
CrateReader,
CollectLanguageItems,
CheckStaticRecursion,
ResolveLifetimes,
RegionResolveCrate,
CheckLoops,
PluginRegistrar,
StabilityIndex,
CollectItem(DefId),
Coherence,
EffectCheck,
Liveness,
Resolve,
EntryPoint,
CheckEntryFn,
CoherenceCheckImpl(DefId),
CoherenceOverlapCheck(DefId),
CoherenceOverlapCheckSpecial(DefId),

View File

@ -12,6 +12,7 @@
//! `unsafe`.
use self::RootUnsafeContext::*;
use dep_graph::DepNode;
use middle::def::Def;
use middle::ty::{self, Ty};
use middle::ty::MethodCall;
@ -182,6 +183,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
}
pub fn check_crate(tcx: &ty::ctxt) {
let _task = tcx.dep_graph.in_task(DepNode::EffectCheck);
let mut visitor = EffectCheckVisitor {
tcx: tcx,
unsafe_context: UnsafeContext::new(SafeContext),

View File

@ -9,6 +9,7 @@
// except according to those terms.
use dep_graph::DepNode;
use front::map as ast_map;
use middle::def_id::{CRATE_DEF_INDEX};
use session::{config, Session};
@ -48,6 +49,8 @@ impl<'a, 'tcx> Visitor<'tcx> for EntryContext<'a, 'tcx> {
}
pub fn find_entry_point(session: &Session, ast_map: &ast_map::Map) {
let _task = ast_map.dep_graph.in_task(DepNode::EntryPoint);
let any_exe = session.crate_types.borrow().iter().any(|ty| {
*ty == config::CrateTypeExecutable
});

View File

@ -21,6 +21,7 @@
pub use self::LangItem::*;
use dep_graph::DepNode;
use front::map as hir_map;
use session::Session;
use middle::cstore::CrateStore;
@ -234,6 +235,7 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<InternedString> {
pub fn collect_language_items(session: &Session,
map: &hir_map::Map)
-> LanguageItems {
let _task = map.dep_graph.in_task(DepNode::CollectLanguageItems);
let krate: &hir::Crate = map.krate();
let mut collector = LanguageItemCollector::new(session, map);
collector.collect(krate);

View File

@ -109,6 +109,7 @@ use self::LoopKind::*;
use self::LiveNodeKind::*;
use self::VarKind::*;
use dep_graph::DepNode;
use middle::def::*;
use middle::pat_util;
use middle::ty;
@ -192,6 +193,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IrMaps<'a, 'tcx> {
}
pub fn check_crate(tcx: &ty::ctxt) {
let _task = tcx.dep_graph.in_task(DepNode::Liveness);
tcx.map.krate().visit_all_items(&mut IrMaps::new(tcx));
tcx.sess.abort_if_errors();
}

View File

@ -16,6 +16,7 @@
//! Most of the documentation on regions can be found in
//! `middle/infer/region_inference/README.md`
use dep_graph::DepNode;
use front::map as ast_map;
use session::Session;
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
@ -1224,7 +1225,10 @@ impl<'a, 'v> Visitor<'v> for RegionResolutionVisitor<'a> {
}
}
pub fn resolve_crate(sess: &Session, krate: &hir::Crate) -> RegionMaps {
pub fn resolve_crate(sess: &Session, map: &ast_map::Map) -> RegionMaps {
let _task = map.dep_graph.in_task(DepNode::RegionResolveCrate);
let krate = map.krate();
let maps = RegionMaps {
code_extents: RefCell::new(vec![]),
code_extent_interner: RefCell::new(FnvHashMap()),

View File

@ -18,6 +18,8 @@
pub use self::DefRegion::*;
use self::ScopeChain::*;
use dep_graph::DepNode;
use front::map::Map;
use session::Session;
use middle::def::{Def, DefMap};
use middle::region;
@ -94,9 +96,11 @@ type Scope<'a> = &'a ScopeChain<'a>;
static ROOT_SCOPE: ScopeChain<'static> = RootScope;
pub fn krate(sess: &Session,
krate: &hir::Crate,
hir_map: &Map,
def_map: &DefMap)
-> Result<NamedRegionMap, usize> {
let _task = hir_map.dep_graph.in_task(DepNode::ResolveLifetimes);
let krate = hir_map.krate();
let mut named_region_map = NodeMap();
try!(sess.track_errors(|| {
krate.visit_all_items(&mut LifetimeContext {

View File

@ -14,6 +14,7 @@
pub use self::StabilityLevel::*;
use dep_graph::DepNode;
use front::map as hir_map;
use session::Session;
use lint;
use middle::cstore::{CrateStore, LOCAL_CRATE};
@ -30,7 +31,7 @@ use syntax::attr::{self, Stability, Deprecation, AttrMetaMethods};
use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap};
use rustc_front::hir;
use rustc_front::hir::{Crate, Item, Generics, StructField, Variant};
use rustc_front::hir::{Item, Generics, StructField, Variant};
use rustc_front::intravisit::{self, Visitor};
use std::mem::replace;
@ -278,7 +279,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
impl<'tcx> Index<'tcx> {
/// Construct the stability index for a crate being compiled.
pub fn build(&mut self, tcx: &ty::ctxt<'tcx>, krate: &Crate, access_levels: &AccessLevels) {
pub fn build(&mut self, tcx: &ty::ctxt<'tcx>, access_levels: &AccessLevels) {
let _task = tcx.dep_graph.in_task(DepNode::StabilityIndex);
let krate = tcx.map.krate();
let mut annotator = Annotator {
tcx: tcx,
index: self,
@ -291,7 +294,10 @@ impl<'tcx> Index<'tcx> {
|v| intravisit::walk_crate(v, krate));
}
pub fn new(krate: &Crate) -> Index<'tcx> {
pub fn new(hir_map: &hir_map::Map) -> Index<'tcx> {
let _task = hir_map.dep_graph.in_task(DepNode::StabilityIndex);
let krate = hir_map.krate();
let mut is_staged_api = false;
for attr in &krate.attrs {
if attr.name() == "stable" || attr.name() == "unstable" {

View File

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::dep_graph::DepGraph;
use rustc::front;
use rustc::front::map as hir_map;
use rustc_mir as mir;
@ -115,9 +116,11 @@ pub fn compile_input(sess: &Session,
let expanded_crate = assign_node_ids(sess, expanded_crate);
// Lower ast -> hir.
let lcx = LoweringContext::new(sess, Some(&expanded_crate));
let dep_graph = DepGraph::new(sess.opts.build_dep_graph);
let mut hir_forest = time(sess.time_passes(),
"lowering ast -> hir",
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate)));
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate),
dep_graph));
// Discard MTWT tables that aren't required past lowering to HIR.
if !sess.opts.debugging_opts.keep_mtwt_tables &&
@ -130,17 +133,20 @@ pub fn compile_input(sess: &Session,
write_out_deps(sess, &outputs, &id);
controller_entry_point!(after_write_deps,
sess,
CompileState::state_after_write_deps(input,
sess,
outdir,
&hir_map,
&expanded_crate,
&hir_map.krate(),
&id[..],
&lcx),
Ok(()));
{
let _ignore = hir_map.dep_graph.in_ignore();
controller_entry_point!(after_write_deps,
sess,
CompileState::state_after_write_deps(input,
sess,
outdir,
&hir_map,
&expanded_crate,
&hir_map.krate(),
&id[..],
&lcx),
Ok(()));
}
time(sess.time_passes(), "attribute checking", || {
front::check_attr::check_crate(sess, &expanded_crate);
@ -166,6 +172,9 @@ pub fn compile_input(sess: &Session,
control.make_glob_map,
|tcx, mir_map, analysis, result| {
{
// Eventually, we will want to track plugins.
let _ignore = tcx.dep_graph.in_ignore();
let state = CompileState::state_after_analysis(input,
&tcx.sess,
outdir,
@ -735,11 +744,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
}
let time_passes = sess.time_passes();
let krate = hir_map.krate();
time(time_passes,
"external crate/lib resolution",
|| LocalCrateReader::new(sess, cstore, &hir_map).read_crates(krate));
|| LocalCrateReader::new(sess, cstore, &hir_map).read_crates());
let lang_items = try!(time(time_passes, "language item collection", || {
sess.track_errors(|| {
@ -769,7 +777,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
let named_region_map = try!(time(time_passes,
"lifetime resolution",
|| middle::resolve_lifetime::krate(sess,
krate,
&hir_map,
&def_map.borrow())));
time(time_passes,
@ -777,20 +785,22 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
|| middle::entry::find_entry_point(sess, &hir_map));
sess.plugin_registrar_fn.set(time(time_passes, "looking for plugin registrar", || {
plugin::build::find_plugin_registrar(sess.diagnostic(), krate)
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
}));
let region_map = time(time_passes,
"region resolution",
|| middle::region::resolve_crate(sess, krate));
|| middle::region::resolve_crate(sess, &hir_map));
time(time_passes,
"loop checking",
|| loops::check_crate(sess, krate));
|| loops::check_crate(sess, &hir_map));
try!(time(time_passes,
"static item recursion checking",
|| static_recursion::check_crate(sess, krate, &def_map.borrow(), &hir_map)));
|| static_recursion::check_crate(sess, &def_map.borrow(), &hir_map)));
let index = stability::Index::new(&hir_map);
ty::ctxt::create_and_enter(sess,
arenas,
@ -800,7 +810,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
freevars,
region_map,
lang_items,
stability::Index::new(krate),
index,
|tcx| {
// passes are timed inside typeck
try_with_f!(typeck::check_crate(tcx, trait_map), (tcx, None, analysis));
@ -818,7 +828,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
// Do not move this check past lint
time(time_passes, "stability index", || {
tcx.stability.borrow_mut().build(tcx, krate, &analysis.access_levels)
tcx.stability.borrow_mut().build(tcx, &analysis.access_levels)
});
time(time_passes,

View File

@ -19,6 +19,7 @@ use rustc_trans::back::link;
use {driver, abort_on_err};
use rustc::dep_graph::DepGraph;
use rustc::middle::ty;
use rustc::middle::cfg;
use rustc::middle::cfg::graphviz::LabelledCFG;
@ -183,7 +184,7 @@ impl PpSourceMode {
sess: sess,
ast_map: Some(ast_map.clone()),
};
f(&annotation, payload, &ast_map.forest.krate)
f(&annotation, payload, ast_map.forest.krate())
}
PpmIdentified => {
@ -191,7 +192,7 @@ impl PpSourceMode {
sess: sess,
ast_map: Some(ast_map.clone()),
};
f(&annotation, payload, &ast_map.forest.krate)
f(&annotation, payload, ast_map.forest.krate())
}
PpmTyped => {
abort_on_err(driver::phase_3_run_analysis_passes(sess,
@ -207,7 +208,7 @@ impl PpSourceMode {
let _ignore = tcx.dep_graph.in_ignore();
f(&annotation,
payload,
&ast_map.forest.krate)
ast_map.forest.krate())
}), sess)
}
_ => panic!("Should use call_with_pp_support"),
@ -706,8 +707,10 @@ pub fn pretty_print_input(sess: Session,
let mut hir_forest;
let lcx = LoweringContext::new(&sess, Some(&krate));
let arenas = ty::CtxtArenas::new();
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let ast_map = if compute_ast_map {
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
let map = driver::make_map(&sess, &mut hir_forest);
Some(map)
} else {

View File

@ -11,6 +11,7 @@
//! # Standalone Tests for the Inference Module
use driver;
use rustc::dep_graph::DepGraph;
use rustc_lint;
use rustc_resolve as resolve;
use rustc_typeck::middle::lang_items;
@ -118,17 +119,19 @@ fn test_env<F>(source_string: &str,
let krate = driver::assign_node_ids(&sess, krate);
let lcx = LoweringContext::new(&sess, Some(&krate));
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
let arenas = ty::CtxtArenas::new();
let ast_map = driver::make_map(&sess, &mut hir_forest);
let krate = ast_map.krate();
// run just enough stuff to build a tcx:
let lang_items = lang_items::collect_language_items(&sess, &ast_map);
let resolve::CrateMap { def_map, freevars, .. } =
resolve::resolve_crate(&sess, &ast_map, resolve::MakeGlobMap::No);
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map.borrow());
let region_map = region::resolve_crate(&sess, krate);
let named_region_map = resolve_lifetime::krate(&sess, &ast_map, &def_map.borrow());
let region_map = region::resolve_crate(&sess, &ast_map);
let index = stability::Index::new(&ast_map);
ty::ctxt::create_and_enter(&sess,
&arenas,
def_map,
@ -137,7 +140,7 @@ fn test_env<F>(source_string: &str,
freevars,
region_map,
lang_items,
stability::Index::new(krate),
index,
|tcx| {
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
body(Env { infcx: &infcx });

View File

@ -18,6 +18,7 @@ use decoder;
use loader::{self, CratePaths};
use rustc::back::svh::Svh;
use rustc::dep_graph::DepNode;
use rustc::session::{config, Session};
use rustc::session::search_paths::PathKind;
use rustc::middle::cstore::{CrateStore, validate_crate_name};
@ -723,7 +724,10 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
// Traverses an AST, reading all the information about use'd crates and
// extern libraries necessary for later resolving, typechecking, linking,
// etc.
pub fn read_crates(&mut self, krate: &hir::Crate) {
pub fn read_crates(&mut self) {
let _task = self.ast_map.dep_graph.in_task(DepNode::CrateReader);
let krate = self.ast_map.krate();
self.process_crate(krate);
krate.visit_all_items(self);
self.creader.inject_allocator_crate();

View File

@ -11,9 +11,11 @@ use self::Context::*;
use rustc::session::Session;
use syntax::codemap::Span;
use rustc::dep_graph::DepNode;
use rustc::front::map::Map;
use rustc_front::intravisit::{self, Visitor};
use rustc_front::hir;
use syntax::codemap::Span;
#[derive(Clone, Copy, PartialEq)]
enum Context {
@ -26,7 +28,9 @@ struct CheckLoopVisitor<'a> {
cx: Context
}
pub fn check_crate(sess: &Session, krate: &hir::Crate) {
pub fn check_crate(sess: &Session, map: &Map) {
let _task = map.dep_graph.in_task(DepNode::CheckLoops);
let krate = map.krate();
krate.visit_all_items(&mut CheckLoopVisitor { sess: sess, cx: Normal });
}

View File

@ -11,6 +11,7 @@
// This compiler pass detects constants that refer to themselves
// recursively.
use rustc::dep_graph::DepNode;
use rustc::front::map as ast_map;
use rustc::session::{Session, CompileResult};
use rustc::middle::def::{Def, DefMap};
@ -90,9 +91,11 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
}
pub fn check_crate<'ast>(sess: &Session,
krate: &'ast hir::Crate,
def_map: &DefMap,
ast_map: &ast_map::Map<'ast>) -> CompileResult {
ast_map: &ast_map::Map<'ast>)
-> CompileResult {
let _task = ast_map.dep_graph.in_task(DepNode::CheckStaticRecursion);
let mut visitor = CheckCrateVisitor {
sess: sess,
def_map: def_map,
@ -100,7 +103,7 @@ pub fn check_crate<'ast>(sess: &Session,
discriminant_map: RefCell::new(NodeMap()),
};
sess.track_errors(|| {
krate.visit_all_items(&mut visitor);
ast_map.krate().visit_all_items(&mut visitor);
})
}

View File

@ -14,6 +14,8 @@ use syntax::ast;
use syntax::attr;
use syntax::codemap::Span;
use syntax::errors;
use rustc::dep_graph::DepNode;
use rustc::front::map::Map;
use rustc_front::intravisit::Visitor;
use rustc_front::hir;
@ -34,8 +36,11 @@ impl<'v> Visitor<'v> for RegistrarFinder {
/// Find the function marked with `#[plugin_registrar]`, if any.
pub fn find_plugin_registrar(diagnostic: &errors::Handler,
krate: &hir::Crate)
hir_map: &Map)
-> Option<ast::NodeId> {
let _task = hir_map.dep_graph.in_task(DepNode::PluginRegistrar);
let krate = hir_map.krate();
let mut finder = RegistrarFinder { registrars: Vec::new() };
krate.visit_all_items(&mut finder);

View File

@ -47,6 +47,7 @@ use self::BareIdentifierPatternResolution::*;
use self::ParentLink::*;
use self::FallbackChecks::*;
use rustc::dep_graph::DepNode;
use rustc::front::map as hir_map;
use rustc::session::Session;
use rustc::lint;
@ -3596,6 +3597,15 @@ pub fn resolve_crate<'a, 'tcx>(session: &'a Session,
ast_map: &'a hir_map::Map<'tcx>,
make_glob_map: MakeGlobMap)
-> CrateMap {
// Currently, we ignore the name resolution data structures for
// the purposes of dependency tracking. Instead we will run name
// resolution and include its output in the hash of each item,
// much like we do for macro expansion. In other words, the hash
// reflects not just its contents but the results of name
// resolution on those contents. Hopefully we'll push this back at
// some point.
let _task = ast_map.dep_graph.in_task(DepNode::Resolve);
let krate = ast_map.krate();
let arenas = Resolver::arenas();
let mut resolver = create_resolver(session, ast_map, krate, make_glob_map, &arenas, None);

View File

@ -100,6 +100,7 @@ pub use rustc::middle;
pub use rustc::session;
pub use rustc::util;
use dep_graph::DepNode;
use front::map as hir_map;
use middle::def::Def;
use middle::infer::{self, TypeOrigin};
@ -312,6 +313,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
fn check_for_entry_fn(ccx: &CrateCtxt) {
let tcx = ccx.tcx;
let _task = tcx.dep_graph.in_task(DepNode::CheckEntryFn);
match *tcx.sess.entry_fn.borrow() {
Some((id, sp)) => match tcx.sess.entry_type.get() {
Some(config::EntryMain) => check_main_fn_ty(ccx, id, sp),