diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 3e43c8e2c93..f2c9d0b1220 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -32,6 +32,10 @@ pub enum DepNode { // Represents the HIR node with the given node-id Hir(D), + // Represents the metadata for a given HIR node, typically found + // in an extern crate. + MetaData(D), + // Represents different phases in the compiler. CrateReader, CollectLanguageItems, @@ -175,6 +179,7 @@ impl DepNode { TransCrate => Some(TransCrate), TransWriteMetadata => Some(TransWriteMetadata), Hir(ref d) => op(d).map(Hir), + MetaData(ref d) => op(d).map(MetaData), CollectItem(ref d) => op(d).map(CollectItem), CoherenceCheckImpl(ref d) => op(d).map(CoherenceCheckImpl), CoherenceOverlapCheck(ref d) => op(d).map(CoherenceOverlapCheck), diff --git a/src/librustc_metadata/csearch.rs b/src/librustc_metadata/csearch.rs index 8d464099783..ac094676ae8 100644 --- a/src/librustc_metadata/csearch.rs +++ b/src/librustc_metadata/csearch.rs @@ -20,6 +20,7 @@ use middle::lang_items; use rustc::ty::{self, Ty, TyCtxt, VariantKind}; use rustc::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX}; +use rustc::dep_graph::DepNode; use rustc::hir::map as hir_map; use rustc::mir::repr::Mir; use rustc::mir::mir_map::MirMap; @@ -37,19 +38,20 @@ use rustc_back::target::Target; use rustc::hir; impl<'tcx> CrateStore<'tcx> for cstore::CStore { - fn stability(&self, def: DefId) -> Option - { + fn stability(&self, def: DefId) -> Option { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_stability(&cdata, def.index) } - fn deprecation(&self, def: DefId) -> Option - { + fn deprecation(&self, def: DefId) -> Option { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_deprecation(&cdata, def.index) } fn visibility(&self, def: DefId) -> ty::Visibility { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_visibility(&cdata, def.index) } @@ -57,23 +59,26 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind { assert!(!def_id.is_local()); + self.dep_graph.read(DepNode::MetaData(def_id)); let cdata = self.get_crate_data(def_id.krate); decoder::closure_kind(&cdata, def_id.index) } - fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::ClosureTy<'tcx> - { + fn closure_ty(&self, tcx: &TyCtxt<'tcx>, def_id: DefId) -> ty::ClosureTy<'tcx> { assert!(!def_id.is_local()); + self.dep_graph.read(DepNode::MetaData(def_id)); let cdata = self.get_crate_data(def_id.krate); decoder::closure_ty(&cdata, def_id.index, tcx) } fn item_variances(&self, def: DefId) -> ty::ItemVariances { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_item_variances(&cdata, def.index) } fn repr_attrs(&self, def: DefId) -> Vec { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_repr_attrs(&cdata, def.index) } @@ -81,6 +86,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::TypeScheme<'tcx> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_type(&cdata, def.index, tcx) } @@ -88,6 +94,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::GenericPredicates<'tcx> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_predicates(&cdata, def.index, tcx) } @@ -95,41 +102,48 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::GenericPredicates<'tcx> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_super_predicates(&cdata, def.index, tcx) } fn item_attrs(&self, def_id: DefId) -> Vec { + self.dep_graph.read(DepNode::MetaData(def_id)); let cdata = self.get_crate_data(def_id.krate); decoder::get_item_attrs(&cdata, def_id.index) } fn item_symbol(&self, def: DefId) -> String { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_symbol(&cdata, def.index) } fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::TraitDef<'tcx> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_trait_def(&cdata, def.index, tcx) } fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_adt_def(&self.intr, &cdata, def.index, tcx) } fn method_arg_names(&self, did: DefId) -> Vec { + self.dep_graph.read(DepNode::MetaData(did)); let cdata = self.get_crate_data(did.krate); decoder::get_method_arg_names(&cdata, did.index) } fn item_name(&self, def: DefId) -> ast::Name { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_item_name(&self.intr, &cdata, def.index) } @@ -137,6 +151,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec { + self.dep_graph.read(DepNode::MetaData(def_id)); let mut result = vec![]; let cdata = self.get_crate_data(def_id.krate); decoder::each_inherent_implementation_for_type(&cdata, def_id.index, @@ -146,6 +161,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn implementations_of_trait(&self, def_id: DefId) -> Vec { + self.dep_graph.read(DepNode::MetaData(def_id)); let mut result = vec![]; self.iter_crate_data(|_, cdata| { decoder::each_implementation_for_trait(cdata, def_id, &mut |iid| { @@ -158,6 +174,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn provided_trait_methods<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Vec>> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_provided_trait_methods(self.intr.clone(), &cdata, def.index, tcx) } @@ -165,18 +182,21 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn trait_item_def_ids(&self, def: DefId) -> Vec { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_trait_item_def_ids(&cdata, def.index) } fn impl_items(&self, impl_def_id: DefId) -> Vec { + self.dep_graph.read(DepNode::MetaData(impl_def_id)); let cdata = self.get_crate_data(impl_def_id.krate); decoder::get_impl_items(&cdata, impl_def_id.index) } fn impl_polarity(&self, def: DefId) -> Option { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_impl_polarity(&cdata, def.index) } @@ -184,6 +204,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Option> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_impl_trait(&cdata, def.index, tcx) } @@ -191,6 +212,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn custom_coerce_unsized_kind(&self, def: DefId) -> Option { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_custom_coerce_unsized_kind(&cdata, def.index) } @@ -198,17 +220,20 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { // FIXME: killme fn associated_consts<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Vec>> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_associated_consts(self.intr.clone(), &cdata, def.index, tcx) } fn impl_parent(&self, impl_def: DefId) -> Option { + self.dep_graph.read(DepNode::MetaData(impl_def)); let cdata = self.get_crate_data(impl_def.krate); decoder::get_parent_impl(&*cdata, impl_def.index) } fn trait_of_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option { + self.dep_graph.read(DepNode::MetaData(def_id)); let cdata = self.get_crate_data(def_id.krate); decoder::get_trait_of_item(&cdata, def_id.index, tcx) } @@ -216,6 +241,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn impl_or_trait_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Option> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_impl_or_trait_item( self.intr.clone(), @@ -226,34 +252,40 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn is_const_fn(&self, did: DefId) -> bool { + self.dep_graph.read(DepNode::MetaData(did)); let cdata = self.get_crate_data(did.krate); decoder::is_const_fn(&cdata, did.index) } fn is_defaulted_trait(&self, trait_def_id: DefId) -> bool { + self.dep_graph.read(DepNode::MetaData(trait_def_id)); let cdata = self.get_crate_data(trait_def_id.krate); decoder::is_defaulted_trait(&cdata, trait_def_id.index) } fn is_impl(&self, did: DefId) -> bool { + self.dep_graph.read(DepNode::MetaData(did)); let cdata = self.get_crate_data(did.krate); decoder::is_impl(&cdata, did.index) } fn is_default_impl(&self, impl_did: DefId) -> bool { + self.dep_graph.read(DepNode::MetaData(impl_did)); let cdata = self.get_crate_data(impl_did.krate); decoder::is_default_impl(&cdata, impl_did.index) } fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool { + self.dep_graph.read(DepNode::MetaData(did)); let cdata = self.get_crate_data(did.krate); decoder::is_extern_item(&cdata, did.index, tcx) } fn is_static_method(&self, def: DefId) -> bool { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::is_static_method(&cdata, def.index) } @@ -264,6 +296,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { } fn is_typedef(&self, did: DefId) -> bool { + self.dep_graph.read(DepNode::MetaData(did)); let cdata = self.get_crate_data(did.krate); decoder::is_typedef(&cdata, did.index) } @@ -379,40 +412,47 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { /// parent `DefId` as well as some idea of what kind of data the /// `DefId` refers to. fn def_key(&self, def: DefId) -> hir_map::DefKey { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::def_key(&cdata, def.index) } fn relative_def_path(&self, def: DefId) -> hir_map::DefPath { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::def_path(&cdata, def.index) } fn variant_kind(&self, def_id: DefId) -> Option { + self.dep_graph.read(DepNode::MetaData(def_id)); let cdata = self.get_crate_data(def_id.krate); decoder::get_variant_kind(&cdata, def_id.index) } fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option { + self.dep_graph.read(DepNode::MetaData(struct_def_id)); let cdata = self.get_crate_data(struct_def_id.krate); decoder::get_struct_ctor_def_id(&cdata, struct_def_id.index) } fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option { + self.dep_graph.read(DepNode::MetaData(did)); let cdata = self.get_crate_data(did.krate); decoder::get_tuple_struct_definition_if_ctor(&cdata, did.index) } fn struct_field_names(&self, def: DefId) -> Vec { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::get_struct_field_names(&self.intr, &cdata, def.index) } fn item_children(&self, def_id: DefId) -> Vec { + self.dep_graph.read(DepNode::MetaData(def_id)); let mut result = vec![]; let crate_data = self.get_crate_data(def_id.krate); let get_crate_data = |cnum| self.get_crate_data(cnum); @@ -445,17 +485,20 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { fn maybe_get_item_ast<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> FoundAst<'tcx> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::maybe_get_item_ast(&cdata, tcx, def.index) } fn maybe_get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Option> { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::maybe_get_item_mir(&cdata, tcx, def.index) } fn is_item_mir_available(&self, def: DefId) -> bool { + self.dep_graph.read(DepNode::MetaData(def)); let cdata = self.get_crate_data(def.krate); decoder::is_item_mir_available(&cdata, def.index) } diff --git a/src/librustc_metadata/cstore.rs b/src/librustc_metadata/cstore.rs index 940688f5507..d3c4c5b0292 100644 --- a/src/librustc_metadata/cstore.rs +++ b/src/librustc_metadata/cstore.rs @@ -87,7 +87,7 @@ pub struct crate_metadata { } pub struct CStore { - _dep_graph: DepGraph, + pub dep_graph: DepGraph, metas: RefCell>>, /// Map from NodeId's of local extern crate statements to crate numbers extern_mod_crate_map: RefCell>, @@ -103,7 +103,7 @@ impl CStore { pub fn new(dep_graph: &DepGraph, intr: Rc) -> CStore { CStore { - _dep_graph: dep_graph.clone(), + dep_graph: dep_graph.clone(), metas: RefCell::new(FnvHashMap()), extern_mod_crate_map: RefCell::new(FnvHashMap()), used_crate_sources: RefCell::new(Vec::new()),