add a MetaData node and trigger reads from it

Conflicts:
	src/librustc_metadata/csearch.rs
This commit is contained in:
Niko Matsakis 2016-04-22 15:47:14 -04:00
parent 7734308f89
commit 5bcdf4c192
3 changed files with 56 additions and 8 deletions

View File

@ -32,6 +32,10 @@ pub enum DepNode<D: Clone + Debug> {
// 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<D: Clone + Debug> DepNode<D> {
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),

View File

@ -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<attr::Stability>
{
fn stability(&self, def: DefId) -> Option<attr::Stability> {
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<attr::Deprecation>
{
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> {
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<attr::ReprAttr> {
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<ast::Attribute>
{
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<String>
{
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<DefId>
{
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<DefId>
{
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<Rc<ty::Method<'tcx>>>
{
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<ty::ImplOrTraitItemId>
{
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<ty::ImplOrTraitItemId>
{
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<hir::ImplPolarity>
{
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<ty::TraitRef<'tcx>>
{
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<ty::adjustment::CustomCoerceUnsized>
{
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<Rc<ty::AssociatedConst<'tcx>>> {
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<DefId> {
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<DefId>
{
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<ty::ImplOrTraitItem<'tcx>>
{
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<VariantKind> {
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<DefId>
{
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<DefId>
{
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<ast::Name>
{
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<ChildItem>
{
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<Mir<'tcx>> {
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)
}

View File

@ -87,7 +87,7 @@ pub struct crate_metadata {
}
pub struct CStore {
_dep_graph: DepGraph,
pub dep_graph: DepGraph,
metas: RefCell<FnvHashMap<ast::CrateNum, Rc<crate_metadata>>>,
/// Map from NodeId's of local extern crate statements to crate numbers
extern_mod_crate_map: RefCell<NodeMap<ast::CrateNum>>,
@ -103,7 +103,7 @@ impl CStore {
pub fn new(dep_graph: &DepGraph,
intr: Rc<IdentInterner>) -> 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()),