Skip to content

Commit 005fa14

Browse files
committed
Annotate the compiler with information about what it is doing when.
1 parent aa26586 commit 005fa14

File tree

29 files changed

+171
-50
lines changed

29 files changed

+171
-50
lines changed

src/librustc/lint/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
//! for all lint attributes.
2626
use self::TargetLint::*;
2727

28+
use dep_graph::DepNode;
2829
use middle::privacy::AccessLevels;
2930
use middle::ty;
3031
use session::{early_error, Session};
@@ -1071,6 +1072,8 @@ impl LateLintPass for GatherNodeLevels {
10711072
///
10721073
/// Consumes the `lint_store` field of the `Session`.
10731074
pub fn check_crate(tcx: &ty::ctxt, access_levels: &AccessLevels) {
1075+
let _task = tcx.dep_graph.in_task(DepNode::LateLintCheck);
1076+
10741077
let krate = tcx.map.krate();
10751078
let mut cx = LateContext::new(tcx, krate, access_levels);
10761079

src/librustc/middle/check_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// - It's not possible to take the address of a static item with unsafe interior. This is enforced
2525
// by borrowck::gather_loans
2626

27+
use dep_graph::DepNode;
2728
use middle::ty::cast::{CastKind};
2829
use middle::const_eval::{self, ConstEvalErr};
2930
use middle::const_eval::ErrKind::IndexOpFeatureGated;
@@ -842,13 +843,12 @@ fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Exp
842843
}
843844

844845
pub fn check_crate(tcx: &ty::ctxt) {
845-
tcx.map.krate().visit_all_items(&mut CheckCrateVisitor {
846+
tcx.visit_all_items_in_krate(DepNode::CheckConst, &mut CheckCrateVisitor {
846847
tcx: tcx,
847848
mode: Mode::Var,
848849
qualif: ConstQualif::NOT_CONST,
849850
rvalue_borrows: NodeMap()
850851
});
851-
852852
tcx.sess.abort_if_errors();
853853
}
854854

src/librustc/middle/check_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub use self::Constructor::*;
1212
use self::Usefulness::*;
1313
use self::WitnessPreference::*;
1414

15+
use dep_graph::DepNode;
1516
use middle::const_eval::{compare_const_vals, ConstVal};
1617
use middle::const_eval::{eval_const_expr, eval_const_expr_partial};
1718
use middle::const_eval::{const_expr_to_pat, lookup_const_by_id};
@@ -155,7 +156,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MatchCheckCtxt<'a, 'tcx> {
155156
}
156157

157158
pub fn check_crate(tcx: &ty::ctxt) {
158-
tcx.map.krate().visit_all_items(&mut MatchCheckCtxt {
159+
tcx.visit_all_items_in_krate(DepNode::MatchCheck, &mut MatchCheckCtxt {
159160
tcx: tcx,
160161
param_env: tcx.empty_parameter_environment(),
161162
});

src/librustc/middle/check_rvalues.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
// Checks that all rvalues in a crate have statically known size. check_crate
1212
// is the public starting point.
1313

14+
use dep_graph::DepNode;
1415
use middle::expr_use_visitor as euv;
1516
use middle::infer;
1617
use middle::mem_categorization as mc;
1718
use middle::ty::ParameterEnvironment;
1819
use middle::ty;
1920

20-
use syntax::ast;
2121
use rustc_front::hir;
22-
use syntax::codemap::Span;
2322
use rustc_front::intravisit;
23+
use syntax::ast;
24+
use syntax::codemap::Span;
2425

25-
pub fn check_crate(tcx: &ty::ctxt,
26-
krate: &hir::Crate) {
26+
pub fn check_crate(tcx: &ty::ctxt) {
2727
let mut rvcx = RvalueContext { tcx: tcx };
28-
krate.visit_all_items(&mut rvcx);
28+
tcx.visit_all_items_in_krate(DepNode::RvalueCheck, &mut rvcx);
2929
}
3030

3131
struct RvalueContext<'a, 'tcx: 'a> {

src/librustc/middle/dead.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// closely. The idea is that all reachable symbols are live, codes called
1313
// from live codes are live, and everything else is dead.
1414

15+
use dep_graph::DepNode;
1516
use front::map as ast_map;
1617
use rustc_front::hir;
1718
use rustc_front::intravisit::{self, Visitor};
@@ -590,6 +591,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
590591
}
591592

592593
pub fn check_crate(tcx: &ty::ctxt, access_levels: &privacy::AccessLevels) {
594+
let _task = tcx.dep_graph.in_task(DepNode::DeadCheck);
593595
let krate = tcx.map.krate();
594596
let live_symbols = find_live(tcx, access_levels, krate);
595597
let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols };

src/librustc/middle/intrinsicck.rs

Lines changed: 2 additions & 1 deletion
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 dep_graph::DepNode;
1112
use middle::def::DefFn;
1213
use middle::def_id::DefId;
1314
use middle::subst::{Subst, Substs, EnumeratedItems};
@@ -29,7 +30,7 @@ pub fn check_crate(tcx: &ctxt) {
2930
dummy_sized_ty: tcx.types.isize,
3031
dummy_unsized_ty: tcx.mk_slice(tcx.types.isize),
3132
};
32-
tcx.map.krate().visit_all_items(&mut visitor);
33+
tcx.visit_all_items_in_krate(DepNode::IntrinsicCheck, &mut visitor);
3334
}
3435

3536
struct IntrinsicCheckingVisitor<'a, 'tcx: 'a> {

src/librustc/middle/reachable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// makes all other generics or inline functions that it references
1616
// reachable as well.
1717

18+
use dep_graph::DepNode;
1819
use front::map as ast_map;
1920
use middle::def;
2021
use middle::def_id::DefId;
@@ -349,6 +350,7 @@ impl<'a, 'v> Visitor<'v> for CollectPrivateImplItemsVisitor<'a> {
349350
pub fn find_reachable(tcx: &ty::ctxt,
350351
access_levels: &privacy::AccessLevels)
351352
-> NodeSet {
353+
let _task = tcx.dep_graph.in_task(DepNode::Reachability);
352354

353355
let mut reachable_context = ReachableContext::new(tcx);
354356

src/librustc/middle/stability.rs

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

16+
use dep_graph::DepNode;
1617
use session::Session;
1718
use lint;
1819
use middle::cstore::{CrateStore, LOCAL_CRATE};
@@ -328,6 +329,7 @@ impl<'tcx> Index<'tcx> {
328329
/// features used.
329330
pub fn check_unstable_api_usage(tcx: &ty::ctxt)
330331
-> FnvHashMap<InternedString, StabilityLevel> {
332+
let _task = tcx.dep_graph.in_task(DepNode::StabilityCheck);
331333
let ref active_lib_features = tcx.sess.features.borrow().declared_lib_features;
332334

333335
// Put the active features into a map for quick lookup
@@ -341,8 +343,7 @@ pub fn check_unstable_api_usage(tcx: &ty::ctxt)
341343
};
342344
intravisit::walk_crate(&mut checker, tcx.map.krate());
343345

344-
let used_features = checker.used_features;
345-
return used_features;
346+
checker.used_features
346347
}
347348

348349
struct Checker<'a, 'tcx: 'a> {

src/librustc/middle/traits/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ pub use self::FulfillmentErrorCode::*;
1515
pub use self::Vtable::*;
1616
pub use self::ObligationCauseCode::*;
1717

18+
use dep_graph::DepNode;
1819
use middle::def_id::DefId;
1920
use middle::free_region::FreeRegionMap;
2021
use middle::subst;
2122
use middle::ty::{self, HasTypeFlags, Ty};
23+
use middle::ty::fast_reject;
2224
use middle::ty::fold::TypeFoldable;
2325
use middle::infer::{self, fixup_err_to_string, InferCtxt};
2426

@@ -599,6 +601,18 @@ impl<'tcx> FulfillmentError<'tcx> {
599601
}
600602

601603
impl<'tcx> TraitObligation<'tcx> {
604+
/// Creates the dep-node for selecting/evaluating this trait reference.
605+
fn dep_node(&self, tcx: &ty::ctxt<'tcx>) -> DepNode {
606+
let simplified_ty =
607+
fast_reject::simplify_type(tcx,
608+
self.predicate.skip_binder().self_ty(), // (*)
609+
true);
610+
611+
// (*) skip_binder is ok because `simplify_type` doesn't care about regions
612+
613+
DepNode::TraitSelect(self.predicate.def_id(), simplified_ty)
614+
}
615+
602616
fn self_ty(&self) -> ty::Binder<Ty<'tcx>> {
603617
ty::Binder(self.predicate.skip_binder().self_ty())
604618
}

src/librustc/middle/traits/select.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
310310
debug!("select({:?})", obligation);
311311
assert!(!obligation.predicate.has_escaping_regions());
312312

313+
let dep_node = obligation.dep_node(self.tcx());
314+
let _task = self.tcx().dep_graph.in_task(dep_node);
315+
313316
let stack = self.push_stack(TraitObligationStackList::empty(), obligation);
314317
match try!(self.candidate_from_obligation(&stack)) {
315318
None => {
@@ -411,7 +414,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
411414
/// accurate if inference variables are involved.
412415
pub fn evaluate_obligation_conservatively(&mut self,
413416
obligation: &PredicateObligation<'tcx>)
414-
-> bool
417+
-> bool
415418
{
416419
debug!("evaluate_obligation_conservatively({:?})",
417420
obligation);

src/librustc/middle/ty/mod.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use syntax::parse::token::{InternedString, special_idents};
5151

5252
use rustc_front::hir;
5353
use rustc_front::hir::{ItemImpl, ItemTrait};
54+
use rustc_front::intravisit::Visitor;
5455

5556
pub use self::sty::{Binder, DebruijnIndex};
5657
pub use self::sty::{BuiltinBound, BuiltinBounds, ExistentialBounds};
@@ -1946,7 +1947,14 @@ fn lookup_locally_or_in_crate_store<V, F>(descr: &str,
19461947
panic!("No def'n found for {:?} in tcx.{}", def_id, descr);
19471948
}
19481949
let v = load_external();
1949-
map.borrow_mut().insert(def_id, v.clone());
1950+
1951+
// Don't consider this a write from the current task, since we are
1952+
// loading from another crate. (Note that the current task will
1953+
// already have registered a read in the call to `get` above.)
1954+
dep_graph.with_ignore(|| {
1955+
map.borrow_mut().insert(def_id, v.clone());
1956+
});
1957+
19501958
v
19511959
}
19521960

@@ -2458,6 +2466,10 @@ impl<'tcx> ctxt<'tcx> {
24582466
return
24592467
}
24602468

2469+
// The primitive is not local, hence we are reading this out
2470+
// of metadata.
2471+
let _ignore = self.dep_graph.in_ignore();
2472+
24612473
if self.populated_external_primitive_impls.borrow().contains(&primitive_def_id) {
24622474
return
24632475
}
@@ -2480,6 +2492,10 @@ impl<'tcx> ctxt<'tcx> {
24802492
return
24812493
}
24822494

2495+
// The type is not local, hence we are reading this out of
2496+
// metadata and don't need to track edges.
2497+
let _ignore = self.dep_graph.in_ignore();
2498+
24832499
if self.populated_external_types.borrow().contains(&type_id) {
24842500
return
24852501
}
@@ -2505,6 +2521,10 @@ impl<'tcx> ctxt<'tcx> {
25052521
return
25062522
}
25072523

2524+
// The type is not local, hence we are reading this out of
2525+
// metadata and don't need to track edges.
2526+
let _ignore = self.dep_graph.in_ignore();
2527+
25082528
let def = self.lookup_trait_def(trait_id);
25092529
if def.flags.get().intersects(TraitFlags::IMPLS_VALID) {
25102530
return;
@@ -2727,6 +2747,15 @@ impl<'tcx> ctxt<'tcx> {
27272747
pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
27282748
Some(self.tables.borrow().upvar_capture_map.get(&upvar_id).unwrap().clone())
27292749
}
2750+
2751+
2752+
pub fn visit_all_items_in_krate<V,F>(&self,
2753+
dep_node_fn: F,
2754+
visitor: &mut V)
2755+
where F: FnMut(DefId) -> DepNode, V: Visitor<'tcx>
2756+
{
2757+
dep_graph::visit_all_items_in_krate(self, dep_node_fn, visitor);
2758+
}
27302759
}
27312760

27322761
/// The category of explicit self.

src/librustc/session/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ pub struct Options {
125125
pub parse_only: bool,
126126
pub no_trans: bool,
127127
pub treat_err_as_bug: bool,
128+
pub incremental_compilation: bool,
129+
pub dump_dep_graph: bool,
128130
pub no_analysis: bool,
129131
pub debugging_opts: DebuggingOptions,
130132
pub prints: Vec<PrintRequest>,
@@ -234,6 +236,8 @@ pub fn basic_options() -> Options {
234236
parse_only: false,
235237
no_trans: false,
236238
treat_err_as_bug: false,
239+
incremental_compilation: false,
240+
dump_dep_graph: false,
237241
no_analysis: false,
238242
debugging_opts: basic_debugging_options(),
239243
prints: Vec::new(),
@@ -606,6 +610,10 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
606610
"run all passes except translation; no output"),
607611
treat_err_as_bug: bool = (false, parse_bool,
608612
"treat all errors that occur as bugs"),
613+
incr_comp: bool = (false, parse_bool,
614+
"enable incremental compilation (experimental)"),
615+
dump_dep_graph: bool = (false, parse_bool,
616+
"dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv)"),
609617
no_analysis: bool = (false, parse_bool,
610618
"parse and expand the source, but run no analysis"),
611619
extra_plugins: Vec<String> = (Vec::new(), parse_list,
@@ -932,6 +940,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
932940
let parse_only = debugging_opts.parse_only;
933941
let no_trans = debugging_opts.no_trans;
934942
let treat_err_as_bug = debugging_opts.treat_err_as_bug;
943+
let incremental_compilation = debugging_opts.incr_comp;
944+
let dump_dep_graph = debugging_opts.dump_dep_graph;
935945
let no_analysis = debugging_opts.no_analysis;
936946

937947
if debugging_opts.debug_llvm {
@@ -1106,6 +1116,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
11061116
parse_only: parse_only,
11071117
no_trans: no_trans,
11081118
treat_err_as_bug: treat_err_as_bug,
1119+
incremental_compilation: incremental_compilation || dump_dep_graph,
1120+
dump_dep_graph: dump_dep_graph,
11091121
no_analysis: no_analysis,
11101122
debugging_opts: debugging_opts,
11111123
prints: prints,

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub use self::MovedValueUseKind::*;
2020

2121
use self::InteriorKind::*;
2222

23+
use rustc::dep_graph::DepNode;
2324
use rustc::front::map as hir_map;
2425
use rustc::front::map::blocks::FnParts;
2526
use rustc::middle::cfg;
@@ -109,7 +110,7 @@ pub fn check_crate(tcx: &ty::ctxt) {
109110
}
110111
};
111112

112-
tcx.map.krate().visit_all_items(&mut bccx);
113+
tcx.visit_all_items_in_krate(DepNode::BorrowCheck, &mut bccx);
113114

114115
if tcx.sess.borrowck_stats() {
115116
println!("--- borrowck stats ---");

src/librustc_driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
801801

802802
time(time_passes,
803803
"rvalue checking",
804-
|| middle::check_rvalues::check_crate(tcx, krate));
804+
|| middle::check_rvalues::check_crate(tcx));
805805

806806
// Avoid overwhelming user with errors if type checking failed.
807807
// I'm not sure how helpful this is, to be honest, but it avoids

src/librustc_driver/pretty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ impl PpSourceMode {
204204
let annotation = TypedAnnotation {
205205
tcx: tcx,
206206
};
207+
let _ignore = tcx.dep_graph.in_ignore();
207208
f(&annotation,
208209
payload,
209210
&ast_map.forest.krate)

src/librustc_mir/mir_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern crate rustc_front;
2323
use build;
2424
use graphviz;
2525
use transform::*;
26+
use rustc::dep_graph::DepNode;
2627
use rustc::mir::repr::Mir;
2728
use hair::cx::Cx;
2829
use std::fs::File;
@@ -47,7 +48,7 @@ pub fn build_mir_for_crate<'tcx>(tcx: &ty::ctxt<'tcx>) -> MirMap<'tcx> {
4748
tcx: tcx,
4849
map: &mut map,
4950
};
50-
tcx.map.krate().visit_all_items(&mut dump);
51+
tcx.visit_all_items_in_krate(DepNode::MirMapConstruction, &mut dump);
5152
}
5253
map
5354
}

src/librustc_privacy/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::mem::replace;
3535
use rustc_front::hir;
3636
use rustc_front::intravisit::{self, Visitor};
3737

38+
use rustc::dep_graph::DepNode;
3839
use rustc::lint;
3940
use rustc::middle::def;
4041
use rustc::middle::def_id::DefId;
@@ -1674,6 +1675,8 @@ pub fn check_crate(tcx: &ty::ctxt,
16741675
export_map: &def::ExportMap,
16751676
external_exports: ExternalExports)
16761677
-> AccessLevels {
1678+
let _task = tcx.dep_graph.in_task(DepNode::Privacy);
1679+
16771680
let krate = tcx.map.krate();
16781681

16791682
// Sanity check to make sure that all privacy usage and controls are

0 commit comments

Comments
 (0)