Skip to content

Commit 35b6e2b

Browse files
committed
Instrument a bunch of tasks that employ the HIR map in one way or
another and were not previously instrumented.
1 parent d09fd1a commit 35b6e2b

File tree

17 files changed

+123
-42
lines changed

17 files changed

+123
-42
lines changed

src/librustc/dep_graph/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,21 @@ pub enum DepNode {
4040
Hir(DefId),
4141

4242
// Represents different phases in the compiler.
43+
CrateReader,
44+
CollectLanguageItems,
45+
CheckStaticRecursion,
46+
ResolveLifetimes,
47+
RegionResolveCrate,
48+
CheckLoops,
49+
PluginRegistrar,
50+
StabilityIndex,
4351
CollectItem(DefId),
4452
Coherence,
53+
EffectCheck,
54+
Liveness,
55+
Resolve,
56+
EntryPoint,
57+
CheckEntryFn,
4558
CoherenceCheckImpl(DefId),
4659
CoherenceOverlapCheck(DefId),
4760
CoherenceOverlapCheckSpecial(DefId),

src/librustc/middle/effect.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! `unsafe`.
1313
use self::RootUnsafeContext::*;
1414

15+
use dep_graph::DepNode;
1516
use middle::def::Def;
1617
use middle::ty::{self, Ty};
1718
use middle::ty::MethodCall;
@@ -182,6 +183,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
182183
}
183184

184185
pub fn check_crate(tcx: &ty::ctxt) {
186+
let _task = tcx.dep_graph.in_task(DepNode::EffectCheck);
187+
185188
let mut visitor = EffectCheckVisitor {
186189
tcx: tcx,
187190
unsafe_context: UnsafeContext::new(SafeContext),

src/librustc/middle/entry.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111

12+
use dep_graph::DepNode;
1213
use front::map as ast_map;
1314
use middle::def_id::{CRATE_DEF_INDEX};
1415
use session::{config, Session};
@@ -48,6 +49,8 @@ impl<'a, 'tcx> Visitor<'tcx> for EntryContext<'a, 'tcx> {
4849
}
4950

5051
pub fn find_entry_point(session: &Session, ast_map: &ast_map::Map) {
52+
let _task = ast_map.dep_graph.in_task(DepNode::EntryPoint);
53+
5154
let any_exe = session.crate_types.borrow().iter().any(|ty| {
5255
*ty == config::CrateTypeExecutable
5356
});

src/librustc/middle/lang_items.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
pub use self::LangItem::*;
2323

24+
use dep_graph::DepNode;
2425
use front::map as hir_map;
2526
use session::Session;
2627
use middle::cstore::CrateStore;
@@ -234,6 +235,7 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<InternedString> {
234235
pub fn collect_language_items(session: &Session,
235236
map: &hir_map::Map)
236237
-> LanguageItems {
238+
let _task = map.dep_graph.in_task(DepNode::CollectLanguageItems);
237239
let krate: &hir::Crate = map.krate();
238240
let mut collector = LanguageItemCollector::new(session, map);
239241
collector.collect(krate);

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ use self::LoopKind::*;
109109
use self::LiveNodeKind::*;
110110
use self::VarKind::*;
111111

112+
use dep_graph::DepNode;
112113
use middle::def::*;
113114
use middle::pat_util;
114115
use middle::ty;
@@ -192,6 +193,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for IrMaps<'a, 'tcx> {
192193
}
193194

194195
pub fn check_crate(tcx: &ty::ctxt) {
196+
let _task = tcx.dep_graph.in_task(DepNode::Liveness);
195197
tcx.map.krate().visit_all_items(&mut IrMaps::new(tcx));
196198
tcx.sess.abort_if_errors();
197199
}

src/librustc/middle/region.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//! Most of the documentation on regions can be found in
1717
//! `middle/infer/region_inference/README.md`
1818
19+
use dep_graph::DepNode;
1920
use front::map as ast_map;
2021
use session::Session;
2122
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
@@ -1224,7 +1225,10 @@ impl<'a, 'v> Visitor<'v> for RegionResolutionVisitor<'a> {
12241225
}
12251226
}
12261227

1227-
pub fn resolve_crate(sess: &Session, krate: &hir::Crate) -> RegionMaps {
1228+
pub fn resolve_crate(sess: &Session, map: &ast_map::Map) -> RegionMaps {
1229+
let _task = map.dep_graph.in_task(DepNode::RegionResolveCrate);
1230+
let krate = map.krate();
1231+
12281232
let maps = RegionMaps {
12291233
code_extents: RefCell::new(vec![]),
12301234
code_extent_interner: RefCell::new(FnvHashMap()),

src/librustc/middle/resolve_lifetime.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
pub use self::DefRegion::*;
1919
use self::ScopeChain::*;
2020

21+
use dep_graph::DepNode;
22+
use front::map::Map;
2123
use session::Session;
2224
use middle::def::{Def, DefMap};
2325
use middle::region;
@@ -94,9 +96,11 @@ type Scope<'a> = &'a ScopeChain<'a>;
9496
static ROOT_SCOPE: ScopeChain<'static> = RootScope;
9597

9698
pub fn krate(sess: &Session,
97-
krate: &hir::Crate,
99+
hir_map: &Map,
98100
def_map: &DefMap)
99101
-> Result<NamedRegionMap, usize> {
102+
let _task = hir_map.dep_graph.in_task(DepNode::ResolveLifetimes);
103+
let krate = hir_map.krate();
100104
let mut named_region_map = NodeMap();
101105
try!(sess.track_errors(|| {
102106
krate.visit_all_items(&mut LifetimeContext {

src/librustc/middle/stability.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
pub use self::StabilityLevel::*;
1515

1616
use dep_graph::DepNode;
17+
use front::map as hir_map;
1718
use session::Session;
1819
use lint;
1920
use middle::cstore::{CrateStore, LOCAL_CRATE};
@@ -30,7 +31,7 @@ use syntax::attr::{self, Stability, Deprecation, AttrMetaMethods};
3031
use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap};
3132

3233
use rustc_front::hir;
33-
use rustc_front::hir::{Crate, Item, Generics, StructField, Variant};
34+
use rustc_front::hir::{Item, Generics, StructField, Variant};
3435
use rustc_front::intravisit::{self, Visitor};
3536

3637
use std::mem::replace;
@@ -278,7 +279,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
278279

279280
impl<'tcx> Index<'tcx> {
280281
/// Construct the stability index for a crate being compiled.
281-
pub fn build(&mut self, tcx: &ty::ctxt<'tcx>, krate: &Crate, access_levels: &AccessLevels) {
282+
pub fn build(&mut self, tcx: &ty::ctxt<'tcx>, access_levels: &AccessLevels) {
283+
let _task = tcx.dep_graph.in_task(DepNode::StabilityIndex);
284+
let krate = tcx.map.krate();
282285
let mut annotator = Annotator {
283286
tcx: tcx,
284287
index: self,
@@ -291,7 +294,10 @@ impl<'tcx> Index<'tcx> {
291294
|v| intravisit::walk_crate(v, krate));
292295
}
293296

294-
pub fn new(krate: &Crate) -> Index<'tcx> {
297+
pub fn new(hir_map: &hir_map::Map) -> Index<'tcx> {
298+
let _task = hir_map.dep_graph.in_task(DepNode::StabilityIndex);
299+
let krate = hir_map.krate();
300+
295301
let mut is_staged_api = false;
296302
for attr in &krate.attrs {
297303
if attr.name() == "stable" || attr.name() == "unstable" {

src/librustc_driver/driver.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use rustc::dep_graph::DepGraph;
1112
use rustc::front;
1213
use rustc::front::map as hir_map;
1314
use rustc_mir as mir;
@@ -115,9 +116,11 @@ pub fn compile_input(sess: &Session,
115116
let expanded_crate = assign_node_ids(sess, expanded_crate);
116117
// Lower ast -> hir.
117118
let lcx = LoweringContext::new(sess, Some(&expanded_crate));
119+
let dep_graph = DepGraph::new(sess.opts.build_dep_graph);
118120
let mut hir_forest = time(sess.time_passes(),
119121
"lowering ast -> hir",
120-
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate)));
122+
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate),
123+
dep_graph));
121124

122125
// Discard MTWT tables that aren't required past lowering to HIR.
123126
if !sess.opts.debugging_opts.keep_mtwt_tables &&
@@ -130,17 +133,20 @@ pub fn compile_input(sess: &Session,
130133

131134
write_out_deps(sess, &outputs, &id);
132135

133-
controller_entry_point!(after_write_deps,
134-
sess,
135-
CompileState::state_after_write_deps(input,
136-
sess,
137-
outdir,
138-
&hir_map,
139-
&expanded_crate,
140-
&hir_map.krate(),
141-
&id[..],
142-
&lcx),
143-
Ok(()));
136+
{
137+
let _ignore = hir_map.dep_graph.in_ignore();
138+
controller_entry_point!(after_write_deps,
139+
sess,
140+
CompileState::state_after_write_deps(input,
141+
sess,
142+
outdir,
143+
&hir_map,
144+
&expanded_crate,
145+
&hir_map.krate(),
146+
&id[..],
147+
&lcx),
148+
Ok(()));
149+
}
144150

145151
time(sess.time_passes(), "attribute checking", || {
146152
front::check_attr::check_crate(sess, &expanded_crate);
@@ -166,6 +172,9 @@ pub fn compile_input(sess: &Session,
166172
control.make_glob_map,
167173
|tcx, mir_map, analysis, result| {
168174
{
175+
// Eventually, we will want to track plugins.
176+
let _ignore = tcx.dep_graph.in_ignore();
177+
169178
let state = CompileState::state_after_analysis(input,
170179
&tcx.sess,
171180
outdir,
@@ -735,11 +744,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
735744
}
736745

737746
let time_passes = sess.time_passes();
738-
let krate = hir_map.krate();
739747

740748
time(time_passes,
741749
"external crate/lib resolution",
742-
|| LocalCrateReader::new(sess, cstore, &hir_map).read_crates(krate));
750+
|| LocalCrateReader::new(sess, cstore, &hir_map).read_crates());
743751

744752
let lang_items = try!(time(time_passes, "language item collection", || {
745753
sess.track_errors(|| {
@@ -769,28 +777,30 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
769777
let named_region_map = try!(time(time_passes,
770778
"lifetime resolution",
771779
|| middle::resolve_lifetime::krate(sess,
772-
krate,
780+
&hir_map,
773781
&def_map.borrow())));
774782

775783
time(time_passes,
776784
"looking for entry point",
777785
|| middle::entry::find_entry_point(sess, &hir_map));
778786

779787
sess.plugin_registrar_fn.set(time(time_passes, "looking for plugin registrar", || {
780-
plugin::build::find_plugin_registrar(sess.diagnostic(), krate)
788+
plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
781789
}));
782790

783791
let region_map = time(time_passes,
784792
"region resolution",
785-
|| middle::region::resolve_crate(sess, krate));
793+
|| middle::region::resolve_crate(sess, &hir_map));
786794

787795
time(time_passes,
788796
"loop checking",
789-
|| loops::check_crate(sess, krate));
797+
|| loops::check_crate(sess, &hir_map));
790798

791799
try!(time(time_passes,
792800
"static item recursion checking",
793-
|| static_recursion::check_crate(sess, krate, &def_map.borrow(), &hir_map)));
801+
|| static_recursion::check_crate(sess, &def_map.borrow(), &hir_map)));
802+
803+
let index = stability::Index::new(&hir_map);
794804

795805
ty::ctxt::create_and_enter(sess,
796806
arenas,
@@ -800,7 +810,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
800810
freevars,
801811
region_map,
802812
lang_items,
803-
stability::Index::new(krate),
813+
index,
804814
|tcx| {
805815
// passes are timed inside typeck
806816
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,
818828

819829
// Do not move this check past lint
820830
time(time_passes, "stability index", || {
821-
tcx.stability.borrow_mut().build(tcx, krate, &analysis.access_levels)
831+
tcx.stability.borrow_mut().build(tcx, &analysis.access_levels)
822832
});
823833

824834
time(time_passes,

src/librustc_driver/pretty.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_trans::back::link;
1919

2020
use {driver, abort_on_err};
2121

22+
use rustc::dep_graph::DepGraph;
2223
use rustc::middle::ty;
2324
use rustc::middle::cfg;
2425
use rustc::middle::cfg::graphviz::LabelledCFG;
@@ -183,15 +184,15 @@ impl PpSourceMode {
183184
sess: sess,
184185
ast_map: Some(ast_map.clone()),
185186
};
186-
f(&annotation, payload, &ast_map.forest.krate)
187+
f(&annotation, payload, ast_map.forest.krate())
187188
}
188189

189190
PpmIdentified => {
190191
let annotation = IdentifiedAnnotation {
191192
sess: sess,
192193
ast_map: Some(ast_map.clone()),
193194
};
194-
f(&annotation, payload, &ast_map.forest.krate)
195+
f(&annotation, payload, ast_map.forest.krate())
195196
}
196197
PpmTyped => {
197198
abort_on_err(driver::phase_3_run_analysis_passes(sess,
@@ -207,7 +208,7 @@ impl PpSourceMode {
207208
let _ignore = tcx.dep_graph.in_ignore();
208209
f(&annotation,
209210
payload,
210-
&ast_map.forest.krate)
211+
ast_map.forest.krate())
211212
}), sess)
212213
}
213214
_ => panic!("Should use call_with_pp_support"),
@@ -706,8 +707,10 @@ pub fn pretty_print_input(sess: Session,
706707
let mut hir_forest;
707708
let lcx = LoweringContext::new(&sess, Some(&krate));
708709
let arenas = ty::CtxtArenas::new();
710+
let dep_graph = DepGraph::new(false);
711+
let _ignore = dep_graph.in_ignore();
709712
let ast_map = if compute_ast_map {
710-
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
713+
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
711714
let map = driver::make_map(&sess, &mut hir_forest);
712715
Some(map)
713716
} else {

src/librustc_driver/test.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! # Standalone Tests for the Inference Module
1212
1313
use driver;
14+
use rustc::dep_graph::DepGraph;
1415
use rustc_lint;
1516
use rustc_resolve as resolve;
1617
use rustc_typeck::middle::lang_items;
@@ -118,17 +119,19 @@ fn test_env<F>(source_string: &str,
118119

119120
let krate = driver::assign_node_ids(&sess, krate);
120121
let lcx = LoweringContext::new(&sess, Some(&krate));
121-
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
122+
let dep_graph = DepGraph::new(false);
123+
let _ignore = dep_graph.in_ignore();
124+
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
122125
let arenas = ty::CtxtArenas::new();
123126
let ast_map = driver::make_map(&sess, &mut hir_forest);
124-
let krate = ast_map.krate();
125127

126128
// run just enough stuff to build a tcx:
127129
let lang_items = lang_items::collect_language_items(&sess, &ast_map);
128130
let resolve::CrateMap { def_map, freevars, .. } =
129131
resolve::resolve_crate(&sess, &ast_map, resolve::MakeGlobMap::No);
130-
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map.borrow());
131-
let region_map = region::resolve_crate(&sess, krate);
132+
let named_region_map = resolve_lifetime::krate(&sess, &ast_map, &def_map.borrow());
133+
let region_map = region::resolve_crate(&sess, &ast_map);
134+
let index = stability::Index::new(&ast_map);
132135
ty::ctxt::create_and_enter(&sess,
133136
&arenas,
134137
def_map,
@@ -137,7 +140,7 @@ fn test_env<F>(source_string: &str,
137140
freevars,
138141
region_map,
139142
lang_items,
140-
stability::Index::new(krate),
143+
index,
141144
|tcx| {
142145
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
143146
body(Env { infcx: &infcx });

0 commit comments

Comments
 (0)