diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-02-07 11:47:35 +0200 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-02-25 17:07:59 +0200 |
| commit | cc8a3a93b70f6805e235199029c3948515f99226 (patch) | |
| tree | d77bf3230bff39264a87c5ac7b8553917a488848 | |
| parent | e96a171453973bad66ed9b5df3a7f6e37d9bce31 (diff) | |
| download | rust-cc8a3a93b70f6805e235199029c3948515f99226.tar.gz rust-cc8a3a93b70f6805e235199029c3948515f99226.zip | |
rustc: consolidate dep-tracked hashmaps in tcx.maps.
29 files changed, 200 insertions, 222 deletions
diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index ae349667f9d..592e4cb9235 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -478,7 +478,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { // method of a private type is used, but the type itself is never // called directly. if let Some(impl_list) = - self.tcx.inherent_impls.borrow().get(&self.tcx.hir.local_def_id(id)) { + self.tcx.maps.inherent_impls.borrow().get(&self.tcx.hir.local_def_id(id)) { for &impl_did in impl_list.iter() { for &item_did in &self.tcx.associated_item_def_ids(impl_did)[..] { if let Some(item_node_id) = self.tcx.hir.as_local_node_id(item_did) { diff --git a/src/librustc/mir/transform.rs b/src/librustc/mir/transform.rs index 652fef76f28..4cbbb67c7e4 100644 --- a/src/librustc/mir/transform.rs +++ b/src/librustc/mir/transform.rs @@ -114,14 +114,14 @@ impl<'tcx, T: MirPass<'tcx>> MirMapPass<'tcx> for T { tcx: TyCtxt<'a, 'tcx, 'tcx>, hooks: &mut [Box<for<'s> MirPassHook<'s>>]) { - let def_ids = tcx.mir_map.borrow().keys(); + let def_ids = tcx.maps.mir.borrow().keys(); for def_id in def_ids { if !def_id.is_local() { continue; } let _task = tcx.dep_graph.in_task(DepNode::Mir(def_id)); - let mir = &mut tcx.mir_map.borrow()[&def_id].borrow_mut(); + let mir = &mut tcx.maps.mir.borrow()[&def_id].borrow_mut(); tcx.dep_graph.write(DepNode::Mir(def_id)); let id = tcx.hir.as_local_node_id(def_id).unwrap(); diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs index 23c28037a3c..e28a8392e58 100644 --- a/src/librustc/traits/fulfill.rs +++ b/src/librustc/traits/fulfill.rs @@ -155,7 +155,7 @@ impl<'a, 'gcx, 'tcx> DeferredObligation<'tcx> { -> Option<Vec<PredicateObligation<'tcx>>> { if let ty::TyAnon(def_id, substs) = self.predicate.skip_binder().self_ty().sty { let ty = if def_id.is_local() { - tcx.item_types.borrow().get(&def_id).cloned() + tcx.maps.types.borrow().get(&def_id).cloned() } else { Some(tcx.item_type(def_id)) }; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index c7e7fac2759..665d60281d1 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -10,7 +10,7 @@ //! type context book-keeping -use dep_graph::{DepGraph, DepTrackingMap}; +use dep_graph::DepGraph; use session::Session; use lint; use middle; @@ -412,44 +412,9 @@ pub struct GlobalCtxt<'tcx> { // borrowck. (They are not used during trans, and hence are not // serialized or needed for cross-crate fns.) free_region_maps: RefCell<NodeMap<FreeRegionMap>>, - // FIXME: jroesch make this a refcell - - pub tables: RefCell<DepTrackingMap<maps::TypeckTables<'tcx>>>, - - /// Maps from a trait item to the trait item "descriptor" - pub associated_items: RefCell<DepTrackingMap<maps::AssociatedItems<'tcx>>>, - - /// Maps from an impl/trait def-id to a list of the def-ids of its items - pub associated_item_def_ids: RefCell<DepTrackingMap<maps::AssociatedItemDefIds<'tcx>>>, - - pub impl_trait_refs: RefCell<DepTrackingMap<maps::ImplTraitRefs<'tcx>>>, - pub trait_defs: RefCell<DepTrackingMap<maps::TraitDefs<'tcx>>>, - pub adt_defs: RefCell<DepTrackingMap<maps::AdtDefs<'tcx>>>, - pub adt_sized_constraint: RefCell<DepTrackingMap<maps::AdtSizedConstraint<'tcx>>>, - - /// Maps from the def-id of an item (trait/struct/enum/fn) to its - /// associated generics and predicates. - pub generics: RefCell<DepTrackingMap<maps::Generics<'tcx>>>, - pub predicates: RefCell<DepTrackingMap<maps::Predicates<'tcx>>>, - - /// Maps from the def-id of a trait to the list of - /// super-predicates. This is a subset of the full list of - /// predicates. We store these in a separate map because we must - /// evaluate them even during type conversion, often before the - /// full predicates are available (note that supertraits have - /// additional acyclicity requirements). - pub super_predicates: RefCell<DepTrackingMap<maps::Predicates<'tcx>>>, pub hir: hir_map::Map<'tcx>, - - /// Maps from the def-id of a function/method or const/static - /// to its MIR. Mutation is done at an item granularity to - /// allow MIR optimization passes to function and still - /// access cross-crate MIR (e.g. inlining or const eval). - /// - /// Note that cross-crate MIR appears to be always borrowed - /// (in the `RefCell` sense) to prevent accidental mutation. - pub mir_map: RefCell<DepTrackingMap<maps::Mir<'tcx>>>, + pub maps: maps::Maps<'tcx>, // Records the free variables refrenced by every closure // expression. Do not track deps for this, just recompute it from @@ -458,9 +423,6 @@ pub struct GlobalCtxt<'tcx> { pub maybe_unused_trait_imports: NodeSet, - // Records the type of every item. - pub item_types: RefCell<DepTrackingMap<maps::Types<'tcx>>>, - // Internal cache for metadata decoding. No need to track deps on this. pub rcache: RefCell<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>, @@ -474,18 +436,9 @@ pub struct GlobalCtxt<'tcx> { pub lang_items: middle::lang_items::LanguageItems, - /// Maps from def-id of a type or region parameter to its - /// (inferred) variance. - pub item_variance_map: RefCell<DepTrackingMap<maps::ItemVariances<'tcx>>>, - /// True if the variance has been computed yet; false otherwise. pub variance_computed: Cell<bool>, - /// Maps a DefId of a type to a list of its inherent impls. - /// Contains implementations of methods that are inherent to a type. - /// Methods in these implementations don't need to be exported. - pub inherent_impls: RefCell<DepTrackingMap<maps::InherentImpls<'tcx>>>, - /// Set of used unsafe nodes (functions or blocks). Unsafe nodes not /// present in this set can be warned about. pub used_unsafe: RefCell<NodeSet>, @@ -495,10 +448,6 @@ pub struct GlobalCtxt<'tcx> { /// about. pub used_mut_nodes: RefCell<NodeSet>, - /// Set of trait imports actually used in the method resolution. - /// This is used for warning unused imports. - pub used_trait_imports: RefCell<DepTrackingMap<maps::UsedTraitImports<'tcx>>>, - /// The set of external nominal types whose implementations have been read. /// This is used for lazy resolution of methods. pub populated_external_types: RefCell<DefIdSet>, @@ -507,10 +456,6 @@ pub struct GlobalCtxt<'tcx> { /// FIXME(arielb1): why is this separate from populated_external_types? pub populated_external_primitive_impls: RefCell<DefIdSet>, - /// Results of evaluating monomorphic constants embedded in - /// other items, such as enum variant explicit discriminants. - pub monomorphic_const_eval: RefCell<DepTrackingMap<maps::MonomorphicConstEval<'tcx>>>, - /// Maps any item's def-id to its stability index. pub stability: RefCell<stability::Index<'tcx>>, @@ -529,23 +474,9 @@ pub struct GlobalCtxt<'tcx> { /// (i.e., no type or lifetime parameters). pub fulfilled_predicates: RefCell<traits::GlobalFulfilledPredicates<'tcx>>, - /// Caches the representation hints for struct definitions. - repr_hint_cache: RefCell<DepTrackingMap<maps::ReprHints<'tcx>>>, - /// Maps Expr NodeId's to `true` iff `&expr` can have 'static lifetime. pub rvalue_promotable_to_static: RefCell<NodeMap<bool>>, - /// Caches CoerceUnsized kinds for impls on custom types. - pub custom_coerce_unsized_kinds: RefCell<DefIdMap<ty::adjustment::CustomCoerceUnsized>>, - - /// Records the type of each closure. The def ID is the ID of the - /// expression defining the closure. - pub closure_tys: RefCell<DepTrackingMap<maps::ClosureTypes<'tcx>>>, - - /// Records the type of each closure. The def ID is the ID of the - /// expression defining the closure. - pub closure_kinds: RefCell<DepTrackingMap<maps::ClosureKinds<'tcx>>>, - /// Maps Fn items to a collection of fragment infos. /// /// The main goal is to identify data (each of which may be moved @@ -754,46 +685,27 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { named_region_map: named_region_map, region_maps: region_maps, free_region_maps: RefCell::new(FxHashMap()), - item_variance_map: RefCell::new(DepTrackingMap::new(dep_graph.clone())), variance_computed: Cell::new(false), sess: s, trait_map: resolutions.trait_map, - tables: RefCell::new(DepTrackingMap::new(dep_graph.clone())), - impl_trait_refs: RefCell::new(DepTrackingMap::new(dep_graph.clone())), - trait_defs: RefCell::new(DepTrackingMap::new(dep_graph.clone())), - adt_defs: RefCell::new(DepTrackingMap::new(dep_graph.clone())), - adt_sized_constraint: RefCell::new(DepTrackingMap::new(dep_graph.clone())), - generics: RefCell::new(DepTrackingMap::new(dep_graph.clone())), - predicates: RefCell::new(DepTrackingMap::new(dep_graph.clone())), - super_predicates: RefCell::new(DepTrackingMap::new(dep_graph.clone())), fulfilled_predicates: RefCell::new(fulfilled_predicates), hir: hir, - mir_map: RefCell::new(DepTrackingMap::new(dep_graph.clone())), + maps: maps::Maps::new(dep_graph), freevars: RefCell::new(resolutions.freevars), maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports, - item_types: RefCell::new(DepTrackingMap::new(dep_graph.clone())), rcache: RefCell::new(FxHashMap()), tc_cache: RefCell::new(FxHashMap()), - associated_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())), - associated_item_def_ids: RefCell::new(DepTrackingMap::new(dep_graph.clone())), normalized_cache: RefCell::new(FxHashMap()), inhabitedness_cache: RefCell::new(FxHashMap()), lang_items: lang_items, - inherent_impls: RefCell::new(DepTrackingMap::new(dep_graph.clone())), used_unsafe: RefCell::new(NodeSet()), used_mut_nodes: RefCell::new(NodeSet()), - used_trait_imports: RefCell::new(DepTrackingMap::new(dep_graph.clone())), populated_external_types: RefCell::new(DefIdSet()), populated_external_primitive_impls: RefCell::new(DefIdSet()), - monomorphic_const_eval: RefCell::new(DepTrackingMap::new(dep_graph.clone())), stability: RefCell::new(stability), selection_cache: traits::SelectionCache::new(), evaluation_cache: traits::EvaluationCache::new(), - repr_hint_cache: RefCell::new(DepTrackingMap::new(dep_graph.clone())), rvalue_promotable_to_static: RefCell::new(NodeMap()), - custom_coerce_unsized_kinds: RefCell::new(DefIdMap()), - closure_tys: RefCell::new(DepTrackingMap::new(dep_graph.clone())), - closure_kinds: RefCell::new(DepTrackingMap::new(dep_graph.clone())), fragment_infos: RefCell::new(DefIdMap()), crate_name: Symbol::intern(crate_name), data_layout: data_layout, @@ -1541,7 +1453,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Obtain the representation annotation for a struct definition. pub fn lookup_repr_hints(self, did: DefId) -> Rc<Vec<attr::ReprAttr>> { - self.repr_hint_cache.memoize(did, || { + self.maps.repr_hints.memoize(did, || { Rc::new(self.get_attrs(did).iter().flat_map(|meta| { attr::find_repr_attrs(self.sess.diagnostic(), meta).into_iter() }).collect()) diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index f45f00b4dec..c31895b3e9d 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -201,7 +201,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } else { // for local crates, check whether type info is // available; typeck might not have completed yet - self.impl_trait_refs.borrow().contains_key(&impl_def_id) + self.maps.impl_trait_refs.borrow().contains_key(&impl_def_id) }; if !use_types { diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index cedb0307495..3e37bd50f94 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -8,10 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use dep_graph::{DepNode, DepTrackingMapConfig}; +use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig}; use hir::def_id::DefId; use middle::const_val::ConstVal; -use mir; use ty::{self, Ty}; use util::nodemap::DefIdSet; @@ -20,36 +19,101 @@ use std::marker::PhantomData; use std::rc::Rc; use syntax::attr; -macro_rules! dep_map_ty { - ($ty_name:ident : $node_name:ident ($key:ty) -> $value:ty) => { - pub struct $ty_name<'tcx> { +macro_rules! define_maps { + ($($(#[$attr:meta])* pub $field:ident: $node_name:ident($key:ty) -> $value:ty),*) => { + pub struct Maps<'tcx> { + $($(#[$attr])* pub $field: RefCell<DepTrackingMap<$field<'tcx>>>),* + } + + impl<'tcx> Maps<'tcx> { + pub fn new(dep_graph: DepGraph) -> Self { + Maps { + $($field: RefCell::new(DepTrackingMap::new(dep_graph.clone()))),* + } + } + } + + $(#[allow(bad_style)] + pub struct $field<'tcx> { data: PhantomData<&'tcx ()> } - impl<'tcx> DepTrackingMapConfig for $ty_name<'tcx> { + impl<'tcx> DepTrackingMapConfig for $field<'tcx> { type Key = $key; type Value = $value; fn to_dep_node(key: &$key) -> DepNode<DefId> { DepNode::$node_name(*key) } - } + })* } } -dep_map_ty! { AssociatedItems: AssociatedItems(DefId) -> ty::AssociatedItem } -dep_map_ty! { Types: ItemSignature(DefId) -> Ty<'tcx> } -dep_map_ty! { Generics: ItemSignature(DefId) -> &'tcx ty::Generics } -dep_map_ty! { Predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> } -dep_map_ty! { SuperPredicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> } -dep_map_ty! { AssociatedItemDefIds: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>> } -dep_map_ty! { ImplTraitRefs: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>> } -dep_map_ty! { TraitDefs: ItemSignature(DefId) -> &'tcx ty::TraitDef } -dep_map_ty! { AdtDefs: ItemSignature(DefId) -> &'tcx ty::AdtDef } -dep_map_ty! { AdtSizedConstraint: SizedConstraint(DefId) -> Ty<'tcx> } -dep_map_ty! { ItemVariances: ItemSignature(DefId) -> Rc<Vec<ty::Variance>> } -dep_map_ty! { InherentImpls: InherentImpls(DefId) -> Vec<DefId> } -dep_map_ty! { ReprHints: ReprHints(DefId) -> Rc<Vec<attr::ReprAttr>> } -dep_map_ty! { Mir: Mir(DefId) -> &'tcx RefCell<mir::Mir<'tcx>> } -dep_map_ty! { ClosureKinds: ItemSignature(DefId) -> ty::ClosureKind } -dep_map_ty! { ClosureTypes: ItemSignature(DefId) -> ty::ClosureTy<'tcx> } -dep_map_ty! { TypeckTables: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx> } -dep_map_ty! { UsedTraitImports: UsedTraitImports(DefId) -> DefIdSet } -dep_map_ty! { MonomorphicConstEval: MonomorphicConstEval(DefId) -> Result<ConstVal, ()> } +define_maps! { + /// Maps from a trait item to the trait item "descriptor" + pub associated_items: AssociatedItems(DefId) -> ty::AssociatedItem, + + /// Records the type of every item. + pub types: ItemSignature(DefId) -> Ty<'tcx>, + + /// Maps from the def-id of an item (trait/struct/enum/fn) to its + /// associated generics and predicates. + pub generics: ItemSignature(DefId) -> &'tcx ty::Generics, + pub predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>, + + /// Maps from the def-id of a trait to the list of + /// super-predicates. This is a subset of the full list of + /// predicates. We store these in a separate map because we must + /// evaluate them even during type conversion, often before the + /// full predicates are available (note that supertraits have + /// additional acyclicity requirements). + pub super_predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx>, + + /// Maps from an impl/trait def-id to a list of the def-ids of its items + pub associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>, + + pub impl_trait_refs: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>>, + pub trait_defs: ItemSignature(DefId) -> &'tcx ty::TraitDef, + pub adt_defs: ItemSignature(DefId) -> &'tcx ty::AdtDef, + pub adt_sized_constraint: SizedConstraint(DefId) -> Ty<'tcx>, + + /// Maps from def-id of a type or region parameter to its + /// (inferred) variance. + pub variances: ItemSignature(DefId) -> Rc<Vec<ty::Variance>>, + + /// Maps a DefId of a type to a list of its inherent impls. + /// Contains implementations of methods that are inherent to a type. + /// Methods in these implementations don't need to be exported. + pub inherent_impls: InherentImpls(DefId) -> Vec<DefId>, + + /// Caches the representation hints for struct definitions. + pub repr_hints: ReprHints(DefId) -> Rc<Vec<attr::ReprAttr>>, + + /// Maps from the def-id of a function/method or const/static + /// to its MIR. Mutation is done at an item granularity to + /// allow MIR optimization passes to function and still + /// access cross-crate MIR (e.g. inlining or const eval). + /// + /// Note that cross-crate MIR appears to be always borrowed + /// (in the `RefCell` sense) to prevent accidental mutation. + pub mir: Mir(DefId) -> &'tcx RefCell<::mir::Mir<'tcx>>, + + /// Records the type of each closure. The def ID is the ID of the + /// expression defining the closure. + pub closure_kinds: ItemSignature(DefId) -> ty::ClosureKind, + + /// Records the type of each closure. The def ID is the ID of the + /// expression defining the closure. + pub closure_types: ItemSignature(DefId) -> ty::ClosureTy<'tcx>, + + /// Caches CoerceUnsized kinds for impls on custom types. + pub custom_coerce_unsized_kinds: ItemSignature(DefId) + -> ty::adjustment::CustomCoerceUnsized, + + pub typeck_tables: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>, + + /// Set of trait imports actually used in the method resolution. + /// This is used for warning unused imports. + pub used_trait_imports: UsedTraitImports(DefId) -> DefIdSet, + + /// Results of evaluating monomorphic constants embedded in + /// other items, such as enum variant explicit discriminants. + pub monomorphic_const_eval: MonomorphicConstEval(DefId) -> Result<ConstVal, ()> +} diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index be4ec881482..7e0a35916d0 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1592,7 +1592,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { self.variants.iter().map(move |v| { let mut discr = prev_discr.map_or(initial, |d| d.wrap_incr()); if let VariantDiscr::Explicit(expr_did) = v.discr { - match tcx.monomorphic_const_eval.borrow()[&expr_did] { + match tcx.maps.monomorphic_const_eval.borrow()[&expr_did] { Ok(ConstVal::Integral(v)) => { discr = v; } @@ -1646,7 +1646,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { stack: &mut Vec<DefId>) -> Ty<'tcx> { - if let Some(ty) = tcx.adt_sized_constraint.borrow().get(&self.did) { + if let Some(ty) = tcx.maps.adt_sized_constraint.borrow().get(&self.did) { return ty; } @@ -1660,7 +1660,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { // // Consider the type as Sized in the meanwhile to avoid // further errors. - tcx.adt_sized_constraint.borrow_mut().insert(self.did, tcx.types.err); + tcx.maps.adt_sized_constraint.borrow_mut().insert(self.did, tcx.types.err); return tcx.types.err; } @@ -1684,7 +1684,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { _ => tcx.intern_tup(&tys[..], false) }; - let old = tcx.adt_sized_constraint.borrow().get(&self.did).cloned(); + let old = tcx.maps.adt_sized_constraint.borrow().get(&self.did).cloned(); match old { Some(old_ty) => { debug!("calculate_sized_constraint: {:?} recurred", self); @@ -1693,7 +1693,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { } None => { debug!("calculate_sized_constraint: {:?} => {:?}", self, ty); - tcx.adt_sized_constraint.borrow_mut().insert(self.did, ty); + tcx.maps.adt_sized_constraint.borrow_mut().insert(self.did, ty); ty } } @@ -1969,7 +1969,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn item_tables(self, def_id: DefId) -> &'gcx TypeckTables<'gcx> { - self.tables.memoize(def_id, || { + self.maps.typeck_tables.memoize(def_id, || { if def_id.is_local() { // Closures' tables come from their outermost function, // as they are part of the same "inference environment". @@ -1983,7 +1983,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // Cross-crate side-tables only exist alongside serialized HIR. self.sess.cstore.maybe_get_item_body(self.global_tcx(), def_id).map(|_| { - self.tables.borrow()[&def_id] + self.maps.typeck_tables.borrow()[&def_id] }).unwrap_or_else(|| { bug!("tcx.item_tables({:?}): missing from metadata", def_id) }) @@ -2095,7 +2095,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn custom_coerce_unsized_kind(self, did: DefId) -> adjustment::CustomCoerceUnsized { - self.custom_coerce_unsized_kinds.memoize(did, || { + self.maps.custom_coerce_unsized_kinds.memoize(did, || { let (kind, src) = if did.krate != LOCAL_CRATE { (self.sess.cstore.custom_coerce_unsized_kind(did), "external") } else { @@ -2114,7 +2114,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn associated_item(self, def_id: DefId) -> AssociatedItem { - self.associated_items.memoize(def_id, || { + self.maps.associated_items.memoize(def_id, || { if !def_id.is_local() { return self.sess.cstore.associated_item(def_id) .expect("missing AssociatedItem in metadata"); @@ -2141,7 +2141,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.associated_item_from_impl_item_ref(parent_def_id, impl_trait_ref.is_some(), impl_item_ref); - self.associated_items.borrow_mut().insert(assoc_item.def_id, assoc_item); + self.maps.associated_items.borrow_mut() + .insert(assoc_item.def_id, assoc_item); } } @@ -2149,7 +2150,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { for trait_item_ref in trait_item_refs { let assoc_item = self.associated_item_from_trait_item_ref(parent_def_id, trait_item_ref); - self.associated_items.borrow_mut().insert(assoc_item.def_id, assoc_item); + self.maps.associated_items.borrow_mut() + .insert(assoc_item.def_id, assoc_item); } } @@ -2160,7 +2162,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // memoize wants us to return something, so return // the one we generated for this def-id - *self.associated_items.borrow().get(&def_id).unwrap() + *self.maps.associated_items.borrow().get(&def_id).unwrap() }) } @@ -2218,7 +2220,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn associated_item_def_ids(self, def_id: DefId) -> Rc<Vec<DefId>> { - self.associated_item_def_ids.memoize(def_id, || { + self.maps.associated_item_def_ids.memoize(def_id, || { if !def_id.is_local() { return Rc::new(self.sess.cstore.associated_item_def_ids(def_id)); } @@ -2255,7 +2257,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// an inherent impl. pub fn impl_trait_ref(self, id: DefId) -> Option<TraitRef<'gcx>> { lookup_locally_or_in_crate_store( - "impl_trait_refs", id, &self.impl_trait_refs, + "impl_trait_refs", id, &self.maps.impl_trait_refs, || self.sess.cstore.impl_trait_ref(self.global_tcx(), id)) } @@ -2336,14 +2338,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // the type cache. Returns the type parameters and type. pub fn item_type(self, did: DefId) -> Ty<'gcx> { lookup_locally_or_in_crate_store( - "item_types", did, &self.item_types, + "item_types", did, &self.maps.types, || self.sess.cstore.item_type(self.global_tcx(), did)) } /// Given the did of a trait, returns its canonical trait ref. pub fn lookup_trait_def(self, did: DefId) -> &'gcx TraitDef { lookup_locally_or_in_crate_store( - "trait_defs", did, &self.trait_defs, + "trait_defs", did, &self.maps.trait_defs, || self.alloc_trait_def(self.sess.cstore.trait_def(self.global_tcx(), did)) ) } @@ -2351,34 +2353,34 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Given the did of an ADT, return a reference to its definition. pub fn lookup_adt_def(self, did: DefId) -> &'gcx AdtDef { lookup_locally_or_in_crate_store( - "adt_defs", did, &self.adt_defs, + "adt_defs", did, &self.maps.adt_defs, || self.sess.cstore.adt_def(self.global_tcx(), did)) } /// Given the did of an item, returns its generics. pub fn item_generics(self, did: DefId) -> &'gcx Generics { lookup_locally_or_in_crate_store( - "generics", did, &self.generics, + "generics", did, &self.maps.generics, || self.alloc_generics(self.sess.cstore.item_generics(did))) } /// Given the did of an item, returns its full set of predicates. pub fn item_predicates(self, did: DefId) -> GenericPredicates<'gcx> { lookup_locally_or_in_crate_store( - "predicates", did, &self.predicates, + "predicates", did, &self.maps.predicates, || self.sess.cstore.item_predicates(self.global_tcx(), did)) } /// Given the did of a trait, returns its superpredicates. pub fn item_super_predicates(self, did: DefId) -> GenericPredicates<'gcx> { lookup_locally_or_in_crate_store( - "super_predicates", did, &self.super_predicates, + "super_predicates", did, &self.maps.super_predicates, || self.sess.cstore.item_super_predicates(self.global_tcx(), did)) } /// Given the did of an item, returns its MIR, borrowed immutably. pub fn item_mir(self, did: DefId) -> Ref<'gcx, Mir<'gcx>> { - lookup_locally_or_in_crate_store("mir_map", did, &self.mir_map, || { + lookup_locally_or_in_crate_store("mir_map", did, &self.maps.mir, || { let mir = self.sess.cstore.get_item_mir(self.global_tcx(), did); let mir = self.alloc_mir(mir); @@ -2450,7 +2452,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn item_variances(self, item_id: DefId) -> Rc<Vec<ty::Variance>> { lookup_locally_or_in_crate_store( - "item_variance_map", item_id, &self.item_variance_map, + "item_variance_map", item_id, &self.maps.variances, || Rc::new(self.sess.cstore.item_variances(item_id))) } @@ -2488,7 +2490,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let inherent_impls = self.sess.cstore.inherent_implementations_for_type(type_id); - self.inherent_impls.borrow_mut().insert(type_id, inherent_impls); + self.maps.inherent_impls.borrow_mut().insert(type_id, inherent_impls); self.populated_external_types.borrow_mut().insert(type_id); } @@ -2529,12 +2531,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // If this is a local def-id, it should be inserted into the // tables by typeck; else, it will be retreived from // the external crate metadata. - if let Some(&kind) = self.closure_kinds.borrow().get(&def_id) { + if let Some(&kind) = self.maps.closure_kinds.borrow().get(&def_id) { return kind; } let kind = self.sess.cstore.closure_kind(def_id); - self.closure_kinds.borrow_mut().insert(def_id, kind); + self.maps.closure_kinds.borrow_mut().insert(def_id, kind); kind } @@ -2546,12 +2548,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // If this is a local def-id, it should be inserted into the // tables by typeck; else, it will be retreived from // the external crate metadata. - if let Some(ty) = self.closure_tys.borrow().get(&def_id) { + if let Some(ty) = self.maps.closure_types.borrow().get(&def_id) { return ty.subst(self, substs.substs); } let ty = self.sess.cstore.closure_ty(self.global_tcx(), def_id); - self.closure_tys.borrow_mut().insert(def_id, ty.clone()); + self.maps.closure_types.borrow_mut().insert(def_id, ty.clone()); ty.subst(self, substs.substs) } @@ -2572,7 +2574,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } }); } - match self.associated_items.borrow().get(&def_id).cloned() { + match self.maps.associated_items.borrow().get(&def_id).cloned() { Some(trait_item) => { match trait_item.container { TraitContainer(_) => None, @@ -2590,7 +2592,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { if def_id.krate != LOCAL_CRATE { return self.sess.cstore.trait_of_item(def_id); } - match self.associated_items.borrow().get(&def_id) { + match self.maps.associated_items.borrow().get(&def_id) { Some(associated_item) => { match associated_item.container { TraitContainer(def_id) => Some(def_id), diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 2a5cd7b37ca..fa53760eca4 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -770,7 +770,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> { TyAdt(def, substs) => { ty::tls::with(|tcx| { if def.did.is_local() && - !tcx.item_types.borrow().contains_key(&def.did) { + !tcx.maps.types.borrow().contains_key(&def.did) { write!(f, "{}<..>", tcx.item_path_str(def.did)) } else { parameterized(f, substs, def.did, &[]) diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index af4f63a0561..13ece31f4ce 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -58,7 +58,7 @@ fn lookup_variant_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return variant.node.disr_expr.map(|e| { let def_id = tcx.hir.body_owner_def_id(e); (&tcx.hir.body(e).value, - tcx.tables.borrow().get(&def_id).cloned()) + tcx.maps.typeck_tables.borrow().get(&def_id).cloned()) }); } } @@ -89,7 +89,7 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node: hir::ImplItemKind::Const(ref ty, body), .. })) => { Some((&tcx.hir.body(body).value, - tcx.tables.borrow().get(&def_id).cloned(), + tcx.maps.typeck_tables.borrow().get(&def_id).cloned(), tcx.ast_ty_to_prim_ty(ty))) } Some(hir_map::NodeTraitItem(ti)) => match ti.node { @@ -102,7 +102,7 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let trait_id = tcx.hir.local_def_id(trait_id); let default_value = default.map(|body| { (&tcx.hir.body(body).value, - tcx.tables.borrow().get(&def_id).cloned(), + tcx.maps.typeck_tables.borrow().get(&def_id).cloned(), tcx.ast_ty_to_prim_ty(ty)) }); resolve_trait_associated_const(tcx, def_id, default_value, trait_id, substs) @@ -156,7 +156,7 @@ fn lookup_const_fn_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) FnLikeNode::from_node(tcx.hir.get(node_id)).and_then(|fn_like| { if fn_like.constness() == hir::Constness::Const { Some((tcx.hir.body(fn_like.body()), - tcx.tables.borrow().get(&def_id).cloned())) + tcx.maps.typeck_tables.borrow().get(&def_id).cloned())) } else { None } @@ -231,7 +231,7 @@ impl<'a, 'tcx> ConstContext<'a, 'tcx> { let def_id = tcx.hir.body_owner_def_id(body); ConstContext { tcx: tcx, - tables: tcx.tables.borrow().get(&def_id).cloned(), + tables: tcx.maps.typeck_tables.borrow().get(&def_id).cloned(), fn_args: None } } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 21fe13997b7..429e4ffef0c 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -996,11 +996,13 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, } else { match ppm { PpmMir => { - write_mir_pretty(tcx, tcx.mir_map.borrow().keys().into_iter(), &mut out) + write_mir_pretty(tcx, + tcx.maps.mir.borrow().keys().into_iter(), + &mut out) } PpmMirCFG => { write_mir_graphviz(tcx, - tcx.mir_map.borrow().keys().into_iter(), + tcx.maps.mir.borrow().keys().into_iter(), &mut out) } _ => unreachable!(), diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index 0c86eb42e7a..5fcefe0d539 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -29,7 +29,7 @@ pub enum MethodLateContext { pub fn method_context(cx: &LateContext, id: ast::NodeId, span: Span) -> MethodLateContext { let def_id = cx.tcx.hir.local_def_id(id); - match cx.tcx.associated_items.borrow().get(&def_id) { + match cx.tcx.maps.associated_items.borrow().get(&def_id) { None => span_bug!(span, "missing method descriptor?!"), Some(item) => { match item.container { diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 88b06e29e10..aa18fbe2ba8 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -527,7 +527,7 @@ impl<'a, 'tcx> CrateMetadata { if let ty::VariantDiscr::Explicit(def_id) = data.discr { let result = data.evaluated_discr.map_or(Err(()), Ok); - tcx.monomorphic_const_eval.borrow_mut().insert(def_id, result); + tcx.maps.monomorphic_const_eval.borrow_mut().insert(def_id, result); } (ty::VariantDef { @@ -584,7 +584,7 @@ impl<'a, 'tcx> CrateMetadata { let adt = tcx.alloc_adt_def(did, kind, variants, repr); if let Some(ctor_index) = ctor_index { // Make adt definition available through constructor id as well. - tcx.adt_defs.borrow_mut().insert(self.local_def_id(ctor_index), adt); + tcx.maps.adt_defs.borrow_mut().insert(self.local_def_id(ctor_index), adt); } adt @@ -789,7 +789,7 @@ impl<'a, 'tcx> CrateMetadata { let ast = ast.decode(self); let tables = ast.tables.decode((self, tcx)); - tcx.tables.borrow_mut().insert(def_id, tcx.alloc_tables(tables)); + tcx.maps.typeck_tables.borrow_mut().insert(def_id, tcx.alloc_tables(tables)); let body = ast.body.decode((self, tcx)); tcx.hir.intern_inlined_body(def_id, body) diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 725d54c227a..e6110172fc4 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -264,7 +264,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { discr: variant.discr, evaluated_discr: match variant.discr { ty::VariantDiscr::Explicit(def_id) => { - tcx.monomorphic_const_eval.borrow()[&def_id].clone().ok() + tcx.maps.monomorphic_const_eval.borrow()[&def_id].clone().ok() } ty::VariantDiscr::Relative(_) => None }, @@ -604,12 +604,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } fn encode_mir(&mut self, def_id: DefId) -> Option<Lazy<mir::Mir<'tcx>>> { - self.tcx.mir_map.borrow().get(&def_id).map(|mir| self.lazy(&*mir.borrow())) + self.tcx.maps.mir.borrow().get(&def_id).map(|mir| self.lazy(&*mir.borrow())) } // Encodes the inherent implementations of a structure, enumeration, or trait. fn encode_inherent_implementations(&mut self, def_id: DefId) -> LazySeq<DefIndex> { - match self.tcx.inherent_impls.borrow().get(&def_id) { + match self.tcx.maps.inherent_impls.borrow().get(&def_id) { None => LazySeq::empty(), Some(implementations) => { self.lazy_seq(implementations.iter().map(|&def_id| { @@ -711,7 +711,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let data = ImplData { polarity: polarity, parent_impl: parent, - coerce_unsized_kind: tcx.custom_coerce_unsized_kinds + coerce_unsized_kind: tcx.maps.custom_coerce_unsized_kinds .borrow() .get(&def_id) .cloned(), @@ -1096,7 +1096,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let data = ClosureData { kind: tcx.closure_kind(def_id), - ty: self.lazy(&tcx.closure_tys.borrow()[&def_id]), + ty: self.lazy(&tcx.maps.closure_types.borrow()[&def_id]), }; Entry { diff --git a/src/librustc_mir/mir_map.rs b/src/librustc_mir/mir_map.rs index b7f90682c7c..913b0d5fb8a 100644 --- a/src/librustc_mir/mir_map.rs +++ b/src/librustc_mir/mir_map.rs @@ -139,7 +139,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> { let mir = tcx.alloc_mir(mir); let def_id = tcx.hir.local_def_id(src.item_id()); - tcx.mir_map.borrow_mut().insert(def_id, mir); + tcx.maps.mir.borrow_mut().insert(def_id, mir); }); let body = self.tcx.hir.body(body_id); diff --git a/src/librustc_passes/mir_stats.rs b/src/librustc_passes/mir_stats.rs index 33b7089c382..ad20c535dec 100644 --- a/src/librustc_passes/mir_stats.rs +++ b/src/librustc_passes/mir_stats.rs @@ -44,7 +44,7 @@ pub fn print_mir_stats<'tcx, 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, title: &str) { // For debugging instrumentation like this, we don't need to worry // about maintaining the dep graph. let _ignore = tcx.dep_graph.in_ignore(); - let mir_map = tcx.mir_map.borrow(); + let mir_map = tcx.maps.mir.borrow(); for def_id in mir_map.keys() { let mir = mir_map.get(&def_id).unwrap(); collector.visit_mir(&mir.borrow()); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 6667a3199a8..3c275e0996d 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -112,7 +112,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { where F: FnOnce(&mut DumpVisitor<'l, 'tcx, 'll, D>) { let item_def_id = self.tcx.hir.local_def_id(item_id); - match self.tcx.tables.borrow().get(&item_def_id) { + match self.tcx.maps.typeck_tables.borrow().get(&item_def_id) { Some(tables) => { let old_tables = self.save_ctxt.tables; self.save_ctxt.tables = tables; diff --git a/src/librustc_trans/disr.rs b/src/librustc_trans/disr.rs index 00c0e0d5415..a940faac838 100644 --- a/src/librustc_trans/disr.rs +++ b/src/librustc_trans/disr.rs @@ -28,7 +28,7 @@ impl Disr { explicit_index -= distance; } ty::VariantDiscr::Explicit(expr_did) => { - match tcx.monomorphic_const_eval.borrow()[&expr_did] { + match tcx.maps.monomorphic_const_eval.borrow()[&expr_did] { Ok(ConstVal::Integral(v)) => { explicit_value = Disr::from(v); break; diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index cd7474cf50b..11ad47eef71 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1209,7 +1209,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { ast_ty.span); let predicates = bounds.predicates(tcx, ty); let predicates = tcx.lift_to_global(&predicates).unwrap(); - tcx.predicates.borrow_mut().insert(def_id, ty::GenericPredicates { + tcx.maps.predicates.borrow_mut().insert(def_id, ty::GenericPredicates { parent: None, predicates: predicates }); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index fd29ff0be43..468a38cd2ba 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -483,7 +483,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { // metadata if necessary. self.tcx.populate_inherent_implementations_for_type_if_necessary(def_id); - if let Some(impl_infos) = self.tcx.inherent_impls.borrow().get(&def_id) { + if let Some(impl_infos) = self.tcx.maps.inherent_impls.borrow().get(&def_id) { for &impl_def_id in impl_infos.iter() { self.assemble_inherent_impl_probe(impl_def_id); } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index a25e5f3f283..b3a4b83b683 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -56,12 +56,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { wbcx.visit_lints(); let tables = self.tcx.alloc_tables(wbcx.tables); - self.tcx.tables.borrow_mut().insert(item_def_id, tables); + self.tcx.maps.typeck_tables.borrow_mut().insert(item_def_id, tables); let used_trait_imports = mem::replace(&mut *self.used_trait_imports.borrow_mut(), DefIdSet()); debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports); - self.tcx.used_trait_imports.borrow_mut().insert(item_def_id, used_trait_imports); + self.tcx.maps.used_trait_imports.borrow_mut().insert(item_def_id, used_trait_imports); } } @@ -290,12 +290,12 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { for (&id, closure_ty) in self.fcx.tables.borrow().closure_tys.iter() { let closure_ty = self.resolve(closure_ty, ResolvingClosure(id)); let def_id = self.tcx().hir.local_def_id(id); - self.tcx().closure_tys.borrow_mut().insert(def_id, closure_ty); + self.tcx().maps.closure_types.borrow_mut().insert(def_id, closure_ty); } for (&id, &closure_kind) in self.fcx.tables.borrow().closure_kinds.iter() { let def_id = self.tcx().hir.local_def_id(id); - self.tcx().closure_kinds.borrow_mut().insert(def_id, closure_kind); + self.tcx().maps.closure_kinds.borrow_mut().insert(def_id, closure_kind); } } @@ -361,7 +361,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { } }); - gcx.item_types.borrow_mut().insert(def_id, outside_ty); + gcx.maps.types.borrow_mut().insert(def_id, outside_ty); } } diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 6dff6d57e4f..0f992f75fce 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -70,7 +70,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { let item_def_id = tcx.hir.local_def_id(item_id); // this will have been written by the main typeck pass - if let Some(imports) = tcx.used_trait_imports.borrow().get(&item_def_id) { + if let Some(imports) = tcx.maps.used_trait_imports.borrow().get(&item_def_id) { debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports); used_trait_imports.extend(imports); } else { diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 96875fce468..e15386b87ad 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -341,7 +341,7 @@ fn visit_implementation_of_coerce_unsized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, infcx.resolve_regions_and_report_errors(&free_regions, impl_node_id); if let Some(kind) = kind { - tcx.custom_coerce_unsized_kinds.borrow_mut().insert(impl_did, kind); + tcx.maps.custom_coerce_unsized_kinds.borrow_mut().insert(impl_did, kind); } }); } diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index b6a863fd2ed..1301f33d30b 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -39,7 +39,7 @@ mod unsafety; struct CoherenceCollect<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, - inherent_impls: RefMut<'a, DepTrackingMap<maps::InherentImpls<'tcx>>>, + inherent_impls: RefMut<'a, DepTrackingMap<maps::inherent_impls<'tcx>>>, } impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CoherenceCollect<'a, 'tcx> { @@ -58,7 +58,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CoherenceCollect<'a, 'tcx> { impl<'a, 'tcx> CoherenceCollect<'a, 'tcx> { fn check(tcx: TyCtxt<'a, 'tcx, 'tcx>) { - let inherent_impls = tcx.inherent_impls.borrow_mut(); + let inherent_impls = tcx.maps.inherent_impls.borrow_mut(); let mut this = &mut CoherenceCollect { tcx, inherent_impls }; // Check implementations and traits. This populates the tables diff --git a/src/librustc_typeck/coherence/overlap.rs b/src/librustc_typeck/coherence/overlap.rs index 56c17dc2f6e..45493d40eb8 100644 --- a/src/librustc_typeck/coherence/overlap.rs +++ b/src/librustc_typeck/coherence/overlap.rs @@ -79,7 +79,7 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> { fn check_for_overlapping_inherent_impls(&self, ty_def_id: DefId) { let _task = self.tcx.dep_graph.in_task(DepNode::CoherenceOverlapInherentCheck(ty_def_id)); - let inherent_impls = self.tcx.inherent_impls.borrow(); + let inherent_impls = self.tcx.maps.inherent_impls.borrow(); let impls = match inherent_impls.get(&ty_def_id) { Some(impls) => impls, None => return, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 3f3fc40320e..3851cd2bb44 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -606,8 +606,8 @@ fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, { generics_of_def_id(ccx, ty_f.did); let tt = ccx.icx(ty_f.did).to_ty(&field.ty); - ccx.tcx.item_types.borrow_mut().insert(ty_f.did, tt); - ccx.tcx.predicates.borrow_mut().insert(ty_f.did, ty::GenericPredicates { + ccx.tcx.maps.types.borrow_mut().insert(ty_f.did, tt); + ccx.tcx.maps.predicates.borrow_mut().insert(ty_f.did, ty::GenericPredicates { parent: Some(ccx.tcx.hir.get_parent_did(field.id)), predicates: vec![] }); @@ -619,7 +619,7 @@ fn convert_method(ccx: &CrateCtxt, id: ast::NodeId, sig: &hir::MethodSig) { let fty = AstConv::ty_of_fn(&ccx.icx(def_id), sig.unsafety, sig.abi, &sig.decl); let substs = mk_item_substs(ccx, def_id); let fty = ccx.tcx.mk_fn_def(def_id, substs, fty); - ccx.tcx.item_types.borrow_mut().insert(def_id, fty); + ccx.tcx.maps.types.borrow_mut().insert(def_id, fty); ty_generic_predicates(ccx, def_id, &sig.generics); } @@ -634,8 +634,8 @@ fn convert_associated_const<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, predicates: vec![] }; let def_id = ccx.tcx.hir.local_def_id(id); - ccx.tcx.predicates.borrow_mut().insert(def_id, predicates); - ccx.tcx.item_types.borrow_mut().insert(def_id, ty); + ccx.tcx.maps.predicates.borrow_mut().insert(def_id, predicates); + ccx.tcx.maps.types.borrow_mut().insert(def_id, ty); } fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, @@ -648,10 +648,10 @@ fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, predicates: vec![] }; let def_id = ccx.tcx.hir.local_def_id(id); - ccx.tcx.predicates.borrow_mut().insert(def_id, predicates); + ccx.tcx.maps.predicates.borrow_mut().insert(def_id, predicates); if let Some(ty) = ty { - ccx.tcx.item_types.borrow_mut().insert(def_id, ty); + ccx.tcx.maps.types.borrow_mut().insert(def_id, ty); } } @@ -725,8 +725,8 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { tcx.record_trait_has_default_impl(trait_ref.def_id); - tcx.impl_trait_refs.borrow_mut().insert(ccx.tcx.hir.local_def_id(it.id), - Some(trait_ref)); + tcx.maps.impl_trait_refs.borrow_mut().insert(ccx.tcx.hir.local_def_id(it.id), + Some(trait_ref)); } hir::ItemImpl(.., ref opt_trait_ref, _, _) => { generics_of_def_id(ccx, def_id); @@ -735,7 +735,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) { let trait_ref = opt_trait_ref.as_ref().map(|ast_trait_ref| { AstConv::instantiate_mono_trait_ref(&icx, ast_trait_ref, selfty) }); - tcx.impl_trait_refs.borrow_mut().insert(def_id, trait_ref); + tcx.maps.impl_trait_refs.borrow_mut().insert(def_id, trait_ref); predicates_of_item(ccx, it); }, @@ -864,8 +864,8 @@ fn convert_variant_ctor<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, })) } }; - tcx.item_types.borrow_mut().insert(def_id, ctor_ty); - tcx.predicates.borrow_mut().insert(def_id, ty::GenericPredicates { + tcx.maps.types.borrow_mut().insert(def_id, ctor_ty); + tcx.maps.predicates.borrow_mut().insert(def_id, ty::GenericPredicates { parent: Some(ccx.tcx.hir.get_parent_did(ctor_id)), predicates: vec![] }); @@ -888,7 +888,7 @@ fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, let result = evaluate_disr_expr(ccx, repr_type, e); let expr_did = tcx.hir.local_def_id(e.node_id); - tcx.monomorphic_const_eval.borrow_mut() + tcx.maps.monomorphic_const_eval.borrow_mut() .insert(expr_did, result.map(ConstVal::Integral)); result.ok() @@ -966,10 +966,10 @@ fn convert_struct_def<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, ReprOptions::new(&ccx.tcx, did)); if let Some(ctor_id) = ctor_id { // Make adt definition available through constructor id as well. - ccx.tcx.adt_defs.borrow_mut().insert(ctor_id, adt); + ccx.tcx.maps.adt_defs.borrow_mut().insert(ctor_id, adt); } - ccx.tcx.adt_defs.borrow_mut().insert(did, adt); + ccx.tcx.maps.adt_defs.borrow_mut().insert(did, adt); adt } @@ -983,7 +983,7 @@ fn convert_union_def<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, ty::VariantDiscr::Relative(0), def)]; let adt = ccx.tcx.alloc_adt_def(did, AdtKind::Union, variants, ReprOptions::new(&ccx.tcx, did)); - ccx.tcx.adt_defs.borrow_mut().insert(did, adt); + ccx.tcx.maps.adt_defs.borrow_mut().insert(did, adt); adt } @@ -1061,7 +1061,7 @@ fn convert_enum_def<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, let did = tcx.hir.local_def_id(it.id); let adt = tcx.alloc_adt_def(did, AdtKind::Enum, variants, ReprOptions::new(&ccx.tcx, did)); - tcx.adt_defs.borrow_mut().insert(did, adt); + tcx.maps.adt_defs.borrow_mut().insert(did, adt); adt } @@ -1091,7 +1091,7 @@ fn ensure_super_predicates_step(ccx: &CrateCtxt, return Vec::new(); }; - let superpredicates = tcx.super_predicates.borrow().get(&trait_def_id).cloned(); + let superpredicates = tcx.maps.super_predicates.borrow().get(&trait_def_id).cloned(); let superpredicates = superpredicates.unwrap_or_else(|| { let item = match ccx.tcx.hir.get(trait_node_id) { hir_map::NodeItem(item) => item, @@ -1130,7 +1130,7 @@ fn ensure_super_predicates_step(ccx: &CrateCtxt, tcx.hir.local_def_id(item.id), superpredicates); - tcx.super_predicates.borrow_mut().insert(trait_def_id, superpredicates.clone()); + tcx.maps.super_predicates.borrow_mut().insert(trait_def_id, superpredicates.clone()); superpredicates }); @@ -1150,7 +1150,7 @@ fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &hir::Item) -> &'t let tcx = ccx.tcx; let def_id = tcx.hir.local_def_id(it.id); - tcx.trait_defs.memoize(def_id, || { + tcx.maps.trait_defs.memoize(def_id, || { let unsafety = match it.node { hir::ItemTrait(unsafety, ..) => unsafety, _ => span_bug!(it.span, "trait_def_of_item invoked on non-trait"), @@ -1182,7 +1182,7 @@ fn generics_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } else { return tcx.item_generics(def_id); }; - tcx.generics.memoize(def_id, || { + tcx.maps.generics.memoize(def_id, || { use rustc::hir::map::*; use rustc::hir::*; @@ -1380,7 +1380,7 @@ fn type_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } else { return ccx.tcx.item_type(def_id); }; - ccx.tcx.item_types.memoize(def_id, || { + ccx.tcx.maps.types.memoize(def_id, || { use rustc::hir::map::*; use rustc::hir::*; @@ -1718,7 +1718,7 @@ fn ty_generic_predicates(ccx: &CrateCtxt, def_id: DefId, ast_generics: &hir::Gen &mut ctp::parameters_for_impl(self_ty, trait_ref)); } - tcx.predicates.borrow_mut().insert(def_id, ty::GenericPredicates { + tcx.maps.predicates.borrow_mut().insert(def_id, ty::GenericPredicates { parent: generics.parent, predicates: predicates }); diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index b22db940798..3d2b746b855 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -13,12 +13,10 @@ //! The second pass over the AST determines the set of constraints. //! We walk the set of items and, for each member, generate new constraints. -use dep_graph::DepTrackingMapConfig; use hir::def_id::DefId; use middle::resolve_lifetime as rl; use rustc::ty::subst::Substs; use rustc::ty::{self, Ty, TyCtxt}; -use rustc::ty::maps::ItemVariances; use rustc::hir::map as hir_map; use syntax::ast; use rustc::hir; @@ -28,6 +26,8 @@ use super::terms::*; use super::terms::VarianceTerm::*; use super::xform::*; +use dep_graph::DepNode::ItemSignature as VarianceDepNode; + pub struct ConstraintContext<'a, 'tcx: 'a> { pub terms_cx: TermsContext<'a, 'tcx>, @@ -65,8 +65,7 @@ pub fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>) }; // See README.md for a discussion on dep-graph management. - tcx.visit_all_item_likes_in_krate(|def_id| ItemVariances::to_dep_node(&def_id), - &mut constraint_cx); + tcx.visit_all_item_likes_in_krate(VarianceDepNode, &mut constraint_cx); constraint_cx } @@ -291,7 +290,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { // This edge is actually implied by the call to // `lookup_trait_def`, but I'm trying to be future-proof. See // README.md for a discussion on dep-graph management. - self.tcx().dep_graph.read(ItemVariances::to_dep_node(&trait_ref.def_id)); + self.tcx().dep_graph.read(VarianceDepNode(trait_ref.def_id)); self.add_constraints_from_substs(generics, trait_ref.def_id, @@ -350,7 +349,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { // This edge is actually implied by the call to // `lookup_trait_def`, but I'm trying to be future-proof. See // README.md for a discussion on dep-graph management. - self.tcx().dep_graph.read(ItemVariances::to_dep_node(&def.did)); + self.tcx().dep_graph.read(VarianceDepNode(def.did)); self.add_constraints_from_substs(generics, def.did, @@ -367,7 +366,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { // This edge is actually implied by the call to // `lookup_trait_def`, but I'm trying to be future-proof. See // README.md for a discussion on dep-graph management. - self.tcx().dep_graph.read(ItemVariances::to_dep_node(&trait_ref.def_id)); + self.tcx().dep_graph.read(VarianceDepNode(trait_ref.def_id)); self.add_constraints_from_substs(generics, trait_ref.def_id, diff --git a/src/librustc_typeck/variance/solve.rs b/src/librustc_typeck/variance/solve.rs index 3ccec97d606..6628c7c521f 100644 --- a/src/librustc_typeck/variance/solve.rs +++ b/src/librustc_typeck/variance/solve.rs @@ -137,7 +137,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { item_variances); } - tcx.item_variance_map + tcx.maps.variances .borrow_mut() .insert(item_def_id, Rc::new(item_variances)); } diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index 253d7a25b63..36352f50e44 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -20,9 +20,7 @@ // a variable. use arena::TypedArena; -use dep_graph::DepTrackingMapConfig; use rustc::ty::{self, TyCtxt}; -use rustc::ty::maps::ItemVariances; use std::fmt; use std::rc::Rc; use syntax::ast; @@ -34,6 +32,8 @@ use self::VarianceTerm::*; pub type VarianceTermPtr<'a> = &'a VarianceTerm<'a>; +use dep_graph::DepNode::ItemSignature as VarianceDepNode; + #[derive(Copy, Clone, Debug)] pub struct InferredIndex(pub usize); @@ -109,7 +109,7 @@ pub fn determine_parameters_to_be_inferred<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx> }; // See README.md for a discussion on dep-graph management. - tcx.visit_all_item_likes_in_krate(|def_id| ItemVariances::to_dep_node(&def_id), &mut terms_cx); + tcx.visit_all_item_likes_in_krate(|def_id| VarianceDepNode(def_id), &mut terms_cx); terms_cx } @@ -178,8 +178,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { // parameters". if self.num_inferred() == inferreds_on_entry { let item_def_id = self.tcx.hir.local_def_id(item_id); - self.tcx - .item_variance_map + self.tcx.maps.variances .borrow_mut() .insert(item_def_id, self.empty_variances.clone()); } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 93854193762..02d934783d4 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -238,7 +238,7 @@ pub fn build_impls(cx: &DocContext, did: DefId) -> Vec<clean::Item> { tcx.populate_inherent_implementations_for_type_if_necessary(did); let mut impls = Vec::new(); - if let Some(i) = tcx.inherent_impls.borrow().get(&did) { + if let Some(i) = tcx.maps.inherent_impls.borrow().get(&did) { for &did in i.iter() { build_impl(cx, did, &mut impls); } |
