]> git.lizzy.rs Git - rust.git/commitdiff
rustc: introduce a query system for type information in ty::maps.
authorEduard Burtescu <edy.burt@gmail.com>
Wed, 28 Sep 2016 23:30:53 +0000 (02:30 +0300)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Sat, 25 Feb 2017 15:07:59 +0000 (17:07 +0200)
27 files changed:
src/librustc/hir/lowering.rs
src/librustc/middle/cstore.rs
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/stability.rs
src/librustc/session/mod.rs
src/librustc/traits/fulfill.rs
src/librustc/ty/context.rs
src/librustc/ty/item_path.rs
src/librustc/ty/maps.rs
src/librustc/ty/mod.rs
src/librustc/util/ppaux.rs
src/librustc_const_eval/eval.rs
src/librustc_driver/driver.rs
src/librustc_driver/test.rs
src/librustc_lint/bad_style.rs
src/librustc_metadata/cstore.rs
src/librustc_metadata/cstore_impl.rs
src/librustc_metadata/decoder.rs
src/librustc_metadata/encoder.rs
src/librustc_metadata/lib.rs
src/librustc_resolve/build_reduced_graph.rs
src/librustc_typeck/check/upvar.rs
src/librustc_typeck/check/writeback.rs
src/librustc_typeck/coherence/builtin.rs
src/librustc_typeck/coherence/mod.rs
src/librustc_typeck/collect.rs
src/librustdoc/visit_lib.rs

index 82e644d710dc2c54d61e33bbf881ca522dab583c..bfcaf1e00f06eca5d4428137b6fac46eacc522dd 100644 (file)
@@ -525,7 +525,7 @@ fn lower_qpath(&mut self,
                         return n;
                     }
                     assert!(!def_id.is_local());
-                    let n = self.sess.cstore.item_generics(def_id).regions.len();
+                    let n = self.sess.cstore.item_generics_cloned(def_id).regions.len();
                     self.type_def_lifetime_params.insert(def_id, n);
                     n
                 });
index 671da0d11972b6338f07323ab7534c9c4c10ccf4..cb5ced57bd8b915e83f98d70055e3f555511f0d6 100644 (file)
 use hir::map::definitions::{Definitions, DefKey, DisambiguatedDefPathData};
 use hir::svh::Svh;
 use middle::lang_items;
-use ty::{self, Ty, TyCtxt};
-use mir::Mir;
+use ty::{self, TyCtxt};
 use session::Session;
 use session::search_paths::PathKind;
 use util::nodemap::{NodeSet, DefIdMap};
 
+use std::any::Any;
 use std::collections::BTreeMap;
 use std::path::PathBuf;
 use std::rc::Rc;
@@ -163,28 +163,18 @@ pub struct ExternCrate {
 
 /// A store of Rust crates, through with their metadata
 /// can be accessed.
-pub trait CrateStore<'tcx> {
+pub trait CrateStore {
+    fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>;
+
     // item info
     fn describe_def(&self, def: DefId) -> Option<Def>;
     fn def_span(&self, sess: &Session, def: DefId) -> Span;
     fn stability(&self, def: DefId) -> Option<attr::Stability>;
     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
     fn visibility(&self, def: DefId) -> ty::Visibility;
-    fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind;
-    fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
-                      -> ty::ClosureTy<'tcx>;
-    fn item_variances(&self, def: DefId) -> Vec<ty::Variance>;
-    fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                     -> Ty<'tcx>;
     fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>;
-    fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                           -> ty::GenericPredicates<'tcx>;
-    fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                                 -> ty::GenericPredicates<'tcx>;
-    fn item_generics(&self, def: DefId) -> ty::Generics;
+    fn item_generics_cloned(&self, def: DefId) -> ty::Generics;
     fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
-    fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef;
-    fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> &'tcx ty::AdtDef;
     fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name>;
     fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
 
@@ -192,17 +182,12 @@ fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
     fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>;
 
     // impl info
-    fn associated_item_def_ids(&self, def_id: DefId) -> Vec<DefId>;
-    fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                          -> Option<ty::TraitRef<'tcx>>;
     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity;
-    fn custom_coerce_unsized_kind(&self, def: DefId)
-                                  -> Option<ty::adjustment::CustomCoerceUnsized>;
     fn impl_parent(&self, impl_def_id: DefId) -> Option<DefId>;
 
     // trait/impl-item info
     fn trait_of_item(&self, def_id: DefId) -> Option<DefId>;
-    fn associated_item(&self, def: DefId) -> Option<ty::AssociatedItem>;
+    fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem;
 
     // flags
     fn is_const_fn(&self, did: DefId) -> bool;
@@ -252,12 +237,11 @@ fn retrace_path(&self,
     fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro;
 
     // misc. metadata
-    fn maybe_get_item_body<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                               -> Option<&'tcx hir::Body>;
+    fn maybe_get_item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
+                                     -> Option<&'tcx hir::Body>;
     fn item_body_nested_bodies(&self, def: DefId) -> BTreeMap<hir::BodyId, hir::Body>;
     fn const_is_rvalue_promotable_to_static(&self, def: DefId) -> bool;
 
-    fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Mir<'tcx>;
     fn is_item_mir_available(&self, def: DefId) -> bool;
 
     // This is basically a 1-based range of ints, which is a little
@@ -272,10 +256,10 @@ fn maybe_get_item_body<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
     fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>;
     fn used_crate_source(&self, cnum: CrateNum) -> CrateSource;
     fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
-    fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                           reexports: &def::ExportMap,
-                           link_meta: &LinkMeta,
-                           reachable: &NodeSet) -> Vec<u8>;
+    fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                                 reexports: &def::ExportMap,
+                                 link_meta: &LinkMeta,
+                                 reachable: &NodeSet) -> Vec<u8>;
     fn metadata_encoding_version(&self) -> &[u8];
 }
 
@@ -309,33 +293,23 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
 /// A dummy crate store that does not support any non-local crates,
 /// for test purposes.
 pub struct DummyCrateStore;
+
 #[allow(unused_variables)]
-impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
+impl CrateStore for DummyCrateStore {
+    fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>
+        { bug!("crate_data_as_rc_any") }
     // item info
     fn describe_def(&self, def: DefId) -> Option<Def> { bug!("describe_def") }
     fn def_span(&self, sess: &Session, def: DefId) -> Span { bug!("def_span") }
     fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }
     fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
-    fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind { bug!("closure_kind") }
-    fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
-                      -> ty::ClosureTy<'tcx>  { bug!("closure_ty") }
-    fn item_variances(&self, def: DefId) -> Vec<ty::Variance> { bug!("item_variances") }
-    fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                     -> Ty<'tcx> { bug!("item_type") }
     fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
         bug!("visible_parent_map")
     }
-    fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                           -> ty::GenericPredicates<'tcx> { bug!("item_predicates") }
-    fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                                 -> ty::GenericPredicates<'tcx> { bug!("item_super_predicates") }
-    fn item_generics(&self, def: DefId) -> ty::Generics { bug!("item_generics") }
+    fn item_generics_cloned(&self, def: DefId) -> ty::Generics
+        { bug!("item_generics_cloned") }
     fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute> { bug!("item_attrs") }
-    fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef
-        { bug!("trait_def") }
-    fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> &'tcx ty::AdtDef
-        { bug!("adt_def") }
     fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name> { bug!("fn_arg_names") }
     fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId> { vec![] }
 
@@ -343,19 +317,13 @@ fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId> { vec![
     fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId> { vec![] }
 
     // impl info
-    fn associated_item_def_ids(&self, def_id: DefId) -> Vec<DefId>
-        { bug!("associated_items") }
-    fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                          -> Option<ty::TraitRef<'tcx>> { bug!("impl_trait_ref") }
     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity { bug!("impl_polarity") }
-    fn custom_coerce_unsized_kind(&self, def: DefId)
-                                  -> Option<ty::adjustment::CustomCoerceUnsized>
-        { bug!("custom_coerce_unsized_kind") }
     fn impl_parent(&self, def: DefId) -> Option<DefId> { bug!("impl_parent") }
 
     // trait/impl-item info
     fn trait_of_item(&self, def_id: DefId) -> Option<DefId> { bug!("trait_of_item") }
-    fn associated_item(&self, def: DefId) -> Option<ty::AssociatedItem> { bug!("associated_item") }
+    fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem
+        { bug!("associated_item_cloned") }
 
     // flags
     fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
@@ -418,8 +386,8 @@ fn item_children(&self, did: DefId) -> Vec<def::Export> { bug!("item_children")
     fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") }
 
     // misc. metadata
-    fn maybe_get_item_body<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                               -> Option<&'tcx hir::Body> {
+    fn maybe_get_item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
+                                     -> Option<&'tcx hir::Body> {
         bug!("maybe_get_item_body")
     }
     fn item_body_nested_bodies(&self, def: DefId) -> BTreeMap<hir::BodyId, hir::Body> {
@@ -429,8 +397,6 @@ fn const_is_rvalue_promotable_to_static(&self, def: DefId) -> bool {
         bug!("const_is_rvalue_promotable_to_static")
     }
 
-    fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                        -> Mir<'tcx> { bug!("get_item_mir") }
     fn is_item_mir_available(&self, def: DefId) -> bool {
         bug!("is_item_mir_available")
     }
@@ -448,7 +414,7 @@ fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>
         { vec![] }
     fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") }
     fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
-    fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
+    fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
                            reexports: &def::ExportMap,
                            link_meta: &LinkMeta,
                            reachable: &NodeSet) -> Vec<u8> { vec![] }
index 95cbd738651d5031be2dd33c6366f94b8d6cd1d1..37749816eb153c725300a0eddba7f66cdc21b917 100644 (file)
@@ -995,7 +995,7 @@ fn visit_segment_parameters(&mut self,
             } else {
                 let cstore = &self.sess.cstore;
                 self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
-                    cstore.item_generics(def_id).types.into_iter().map(|def| {
+                    cstore.item_generics_cloned(def_id).types.into_iter().map(|def| {
                         def.object_lifetime_default
                     }).collect()
                 })
index 487e13b47fec2755effb15a351d6cd056cd592ad..baa22d706143519e6b20605b77d4bfebe2f399a7 100644 (file)
@@ -433,23 +433,27 @@ struct Checker<'a, 'tcx: 'a> {
 
 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
     // (See issue #38412)
-    fn skip_stability_check_due_to_privacy(self, def_id: DefId) -> bool {
-        let visibility = {
-            // Check if `def_id` is a trait method.
-            match self.sess.cstore.associated_item(def_id) {
-                Some(ty::AssociatedItem { container: ty::TraitContainer(trait_def_id), .. }) => {
-                    // Trait methods do not declare visibility (even
-                    // for visibility info in cstore). Use containing
-                    // trait instead, so methods of pub traits are
-                    // themselves considered pub.
-                    self.sess.cstore.visibility(trait_def_id)
-                }
-                _ => {
-                    // Otherwise, cstore info works directly.
-                    self.sess.cstore.visibility(def_id)
+    fn skip_stability_check_due_to_privacy(self, mut def_id: DefId) -> bool {
+        // Check if `def_id` is a trait method.
+        match self.sess.cstore.describe_def(def_id) {
+            Some(Def::Method(_)) |
+            Some(Def::AssociatedTy(_)) |
+            Some(Def::AssociatedConst(_)) => {
+                match self.associated_item(def_id).container {
+                    ty::TraitContainer(trait_def_id) => {
+                        // Trait methods do not declare visibility (even
+                        // for visibility info in cstore). Use containing
+                        // trait instead, so methods of pub traits are
+                        // themselves considered pub.
+                        def_id = trait_def_id;
+                    }
+                    _ => {}
                 }
             }
-        };
+            _ => {}
+        }
+
+        let visibility = self.sess.cstore.visibility(def_id);
 
         match visibility {
             // must check stability for pub items.
index 68edcc60779a10d86be6cc85e8ebdc9428e3453b..3ba82f34c3266a804fece8554e94707fb562c796 100644 (file)
@@ -64,7 +64,7 @@ pub struct Session {
     pub target: config::Config,
     pub host: Target,
     pub opts: config::Options,
-    pub cstore: Rc<for<'a> CrateStore<'a>>,
+    pub cstore: Rc<CrateStore>,
     pub parse_sess: ParseSess,
     // For a library crate, this is always none
     pub entry_fn: RefCell<Option<(NodeId, Span)>>,
@@ -510,7 +510,7 @@ pub fn build_session(sopts: config::Options,
                      dep_graph: &DepGraph,
                      local_crate_source_file: Option<PathBuf>,
                      registry: errors::registry::Registry,
-                     cstore: Rc<for<'a> CrateStore<'a>>)
+                     cstore: Rc<CrateStore>)
                      -> Session {
     build_session_with_codemap(sopts,
                                dep_graph,
@@ -525,7 +525,7 @@ pub fn build_session_with_codemap(sopts: config::Options,
                                   dep_graph: &DepGraph,
                                   local_crate_source_file: Option<PathBuf>,
                                   registry: errors::registry::Registry,
-                                  cstore: Rc<for<'a> CrateStore<'a>>,
+                                  cstore: Rc<CrateStore>,
                                   codemap: Rc<codemap::CodeMap>,
                                   emitter_dest: Option<Box<Write + Send>>)
                                   -> Session {
@@ -575,7 +575,7 @@ pub fn build_session_(sopts: config::Options,
                       local_crate_source_file: Option<PathBuf>,
                       span_diagnostic: errors::Handler,
                       codemap: Rc<codemap::CodeMap>,
-                      cstore: Rc<for<'a> CrateStore<'a>>)
+                      cstore: Rc<CrateStore>)
                       -> Session {
     let host = match Target::search(config::host_triple()) {
         Ok(t) => t,
index e28a8392e58d7da6e2ae1e838a9fbbeb0e1be6f2..c31ab2372b69ce420964601e2361ff199fc97f0e 100644 (file)
@@ -155,7 +155,7 @@ pub fn try_select(&self, tcx: TyCtxt<'a, 'gcx, '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.maps.types.borrow().get(&def_id).cloned()
+                tcx.maps.ty.borrow().get(&def_id).cloned()
             } else {
                 Some(tcx.item_type(def_id))
             };
index 665d60281d1a9b54ada85e163b056894860506bd..62aa6522a7bdcf1bb74775c2f6eebe14dc6121d4 100644 (file)
@@ -44,6 +44,7 @@
 use rustc_data_structures::accumulate_vec::AccumulateVec;
 
 use arena::{TypedArena, DroplessArena};
+use rustc_data_structures::indexed_vec::IndexVec;
 use std::borrow::Borrow;
 use std::cell::{Cell, RefCell};
 use std::hash::{Hash, Hasher};
@@ -220,7 +221,7 @@ pub struct TypeckTables<'tcx> {
     /// Records the type of each closure.
     pub closure_tys: NodeMap<ty::ClosureTy<'tcx>>,
 
-    /// Records the type of each closure.
+    /// Records the kind of each closure.
     pub closure_kinds: NodeMap<ty::ClosureKind>,
 
     /// For each fn, records the "liberated" types of its arguments
@@ -389,6 +390,8 @@ pub struct GlobalCtxt<'tcx> {
     global_arenas: &'tcx GlobalArenas<'tcx>,
     global_interners: CtxtInterners<'tcx>,
 
+    pub sess: &'tcx Session,
+
     pub specializes_cache: RefCell<traits::SpecializesCache>,
 
     pub dep_graph: DepGraph,
@@ -396,8 +399,6 @@ pub struct GlobalCtxt<'tcx> {
     /// Common types, pre-interned for your convenience.
     pub types: CommonTypes<'tcx>,
 
-    pub sess: &'tcx Session,
-
     /// Map indicating what traits are in scope for places where this
     /// is relevant; generated by resolve.
     pub trait_map: TraitMap,
@@ -659,6 +660,8 @@ fn is_global(self) -> bool {
     /// value (types, substs, etc.) can only be used while `ty::tls` has a valid
     /// reference to the context, to allow formatting values that need it.
     pub fn create_and_enter<F, R>(s: &'tcx Session,
+                                  local_providers: ty::maps::Providers<'tcx>,
+                                  extern_providers: ty::maps::Providers<'tcx>,
                                   arenas: &'tcx GlobalArenas<'tcx>,
                                   arena: &'tcx DroplessArena,
                                   resolutions: ty::Resolutions,
@@ -676,7 +679,11 @@ pub fn create_and_enter<F, R>(s: &'tcx Session,
         let common_types = CommonTypes::new(&interners);
         let dep_graph = hir.dep_graph.clone();
         let fulfilled_predicates = traits::GlobalFulfilledPredicates::new(dep_graph.clone());
+        let max_cnum = s.cstore.crates().iter().map(|c| c.as_usize()).max().unwrap_or(0);
+        let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
+        providers[LOCAL_CRATE] = local_providers;
         tls::enter_global(GlobalCtxt {
+            sess: s,
             specializes_cache: RefCell::new(traits::SpecializesCache::new()),
             global_arenas: arenas,
             global_interners: interners,
@@ -686,11 +693,10 @@ pub fn create_and_enter<F, R>(s: &'tcx Session,
             region_maps: region_maps,
             free_region_maps: RefCell::new(FxHashMap()),
             variance_computed: Cell::new(false),
-            sess: s,
             trait_map: resolutions.trait_map,
             fulfilled_predicates: RefCell::new(fulfilled_predicates),
             hir: hir,
-            maps: maps::Maps::new(dep_graph),
+            maps: maps::Maps::new(dep_graph, providers),
             freevars: RefCell::new(resolutions.freevars),
             maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports,
             rcache: RefCell::new(FxHashMap()),
index c31895b3e9df793e39a3162cef883084189929a5..7bf1ba155b53511964c7e95edfc2e755e190a1e3 100644 (file)
@@ -201,7 +201,7 @@ fn push_impl_path<T>(self,
         } else {
             // for local crates, check whether type info is
             // available; typeck might not have completed yet
-            self.maps.impl_trait_refs.borrow().contains_key(&impl_def_id)
+            self.maps.impl_trait_ref.borrow().contains_key(&impl_def_id)
         };
 
         if !use_types {
index 3e37bd50f942c8932e0dceea92fa5e29d90e2f5d..4a91cdd24fcaa99b237aef8715f446797b4af082 100644 (file)
 // except according to those terms.
 
 use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
-use hir::def_id::DefId;
+use hir::def_id::{CrateNum, DefId};
 use middle::const_val::ConstVal;
-use ty::{self, Ty};
+use mir;
+use ty::{self, Ty, TyCtxt};
+use util::common::MemoizationMap;
 use util::nodemap::DefIdSet;
 
+use rustc_data_structures::indexed_vec::IndexVec;
 use std::cell::RefCell;
-use std::marker::PhantomData;
 use std::rc::Rc;
 use syntax::attr;
 
+trait Key {
+    fn map_crate(&self) -> CrateNum;
+}
+
+impl Key for DefId {
+    fn map_crate(&self) -> CrateNum {
+        self.krate
+    }
+}
+
 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>>>),*
+    (<$tcx:tt>
+     $($(#[$attr:meta])*
+       pub $name:ident: $node:ident($K:ty) -> $V:ty),*) => {
+        pub struct Maps<$tcx> {
+            providers: IndexVec<CrateNum, Providers<$tcx>>,
+            $($(#[$attr])* pub $name: RefCell<DepTrackingMap<queries::$name<$tcx>>>),*
         }
 
-        impl<'tcx> Maps<'tcx> {
-            pub fn new(dep_graph: DepGraph) -> Self {
+        impl<$tcx> Maps<$tcx> {
+            pub fn new(dep_graph: DepGraph,
+                       providers: IndexVec<CrateNum, Providers<$tcx>>)
+                       -> Self {
                 Maps {
-                    $($field: RefCell::new(DepTrackingMap::new(dep_graph.clone()))),*
+                    providers,
+                    $($name: RefCell::new(DepTrackingMap::new(dep_graph.clone()))),*
                 }
             }
         }
 
-        $(#[allow(bad_style)]
-        pub struct $field<'tcx> {
-            data: PhantomData<&'tcx ()>
+        pub mod queries {
+            use std::marker::PhantomData;
+
+            $(#[allow(bad_style)]
+            pub struct $name<$tcx> {
+                data: PhantomData<&$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) }
+        $(impl<$tcx> DepTrackingMapConfig for queries::$name<$tcx> {
+            type Key = $K;
+            type Value = $V;
+            fn to_dep_node(key: &$K) -> DepNode<DefId> { DepNode::$node(*key) }
         })*
+
+        pub struct Providers<$tcx> {
+            $(pub $name: for<'a> fn(TyCtxt<'a, $tcx, $tcx>, $K) -> $V),*
+        }
+
+        impl<$tcx> Copy for Providers<$tcx> {}
+        impl<$tcx> Clone for Providers<$tcx> {
+            fn clone(&self) -> Self { *self }
+        }
+
+        impl<$tcx> Default for Providers<$tcx> {
+            fn default() -> Self {
+                $(fn $name<'a, $tcx>(_: TyCtxt<'a, $tcx, $tcx>, key: $K) -> $V {
+                    bug!("tcx.maps.{}({:?}) unsupported by its crate",
+                         stringify!($name), key);
+                })*
+                Providers { $($name),* }
+            }
+        }
+
+        impl<$tcx> Maps<$tcx> {
+            $($(#[$attr])*
+              pub fn $name<'a, 'lcx>(&self, tcx: TyCtxt<'a, $tcx, 'lcx>, key: $K) -> $V {
+                self.$name.memoize(key, || {
+                    (self.providers[key.map_crate()].$name)(tcx.global_tcx(), key)
+                })
+            })*
+        }
     }
 }
 
-define_maps! {
-    /// Maps from a trait item to the trait item "descriptor"
-    pub associated_items: AssociatedItems(DefId) -> ty::AssociatedItem,
-
+// Each of these maps also corresponds to a method on a
+// `Provider` trait for requesting a value of that type,
+// and a method on `Maps` itself for doing that in a
+// a way that memoizes and does dep-graph tracking,
+// wrapping around the actual chain of providers that
+// the driver creates (using several `rustc_*` crates).
+define_maps! { <'tcx>
     /// Records the type of every item.
-    pub types: ItemSignature(DefId) -> Ty<'tcx>,
+    pub ty: ItemSignature(DefId) -> Ty<'tcx>,
 
     /// Maps from the def-id of an item (trait/struct/enum/fn) to its
     /// associated generics and predicates.
@@ -66,18 +119,22 @@ fn to_dep_node(key: &$key) -> DepNode<DefId> { DepNode::$node_name(*key) }
     /// 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 trait_def: ItemSignature(DefId) -> &'tcx ty::TraitDef,
+    pub adt_def: 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 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>>,
+
+    /// Maps from a trait item to the trait item "descriptor"
+    pub associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
+
+    pub impl_trait_ref: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>>,
+
     /// 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.
@@ -93,18 +150,18 @@ fn to_dep_node(key: &$key) -> DepNode<DefId> { DepNode::$node_name(*key) }
     ///
     /// 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>>,
+    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,
+    pub closure_kind: 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>,
+    pub closure_type: ItemSignature(DefId) -> ty::ClosureTy<'tcx>,
 
     /// Caches CoerceUnsized kinds for impls on custom types.
-    pub custom_coerce_unsized_kinds: ItemSignature(DefId)
+    pub custom_coerce_unsized_kind: ItemSignature(DefId)
         -> ty::adjustment::CustomCoerceUnsized,
 
     pub typeck_tables: TypeckTables(DefId) -> &'tcx ty::TypeckTables<'tcx>,
index 7e0a35916d0bcf23e57ae3d806133d482a22139c..dd3ed2d9c2cd8811409f18169d1bc76b2dfb08d1 100644 (file)
@@ -1908,28 +1908,6 @@ pub fn from_mutbl(m: hir::Mutability) -> Self {
     }
 }
 
-/// Helper for looking things up in the various maps that are populated during
-/// typeck::collect (e.g., `tcx.associated_items`, `tcx.types`, etc).  All of
-/// these share the pattern that if the id is local, it should have been loaded
-/// into the map by the `typeck::collect` phase.  If the def-id is external,
-/// then we have to go consult the crate loading code (and cache the result for
-/// the future).
-fn lookup_locally_or_in_crate_store<M, F>(descr: &str,
-                                          def_id: DefId,
-                                          map: &M,
-                                          load_external: F)
-                                          -> M::Value where
-    M: MemoizationMap<Key=DefId>,
-    F: FnOnce() -> M::Value,
-{
-    map.memoize(def_id, || {
-        if def_id.is_local() {
-            bug!("No def'n found for {:?} in tcx.{}", def_id, descr);
-        }
-        load_external()
-    })
-}
-
 impl BorrowKind {
     pub fn from_mutbl(m: hir::Mutability) -> BorrowKind {
         match m {
@@ -2095,31 +2073,15 @@ pub fn trait_relevant_for_never(self, did: DefId) -> bool {
     }
 
     pub fn custom_coerce_unsized_kind(self, did: DefId) -> adjustment::CustomCoerceUnsized {
-        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 {
-                (None, "local")
-            };
-
-            match kind {
-                Some(kind) => kind,
-                None => {
-                    bug!("custom_coerce_unsized_kind: \
-                          {} impl `{}` is missing its kind",
-                          src, self.item_path_str(did));
-                }
-            }
-        })
+        self.maps.custom_coerce_unsized_kind(self, did)
     }
 
     pub fn associated_item(self, def_id: DefId) -> AssociatedItem {
-        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");
-            }
+        if !def_id.is_local() {
+            return self.maps.associated_item(self, def_id);
+        }
 
+        self.maps.associated_item.memoize(def_id, || {
             // When the user asks for a given associated item, we
             // always go ahead and convert all the associated items in
             // the container. Note that we are also careful only to
@@ -2141,7 +2103,7 @@ pub fn associated_item(self, def_id: DefId) -> AssociatedItem {
                             self.associated_item_from_impl_item_ref(parent_def_id,
                                                                     impl_trait_ref.is_some(),
                                                                     impl_item_ref);
-                        self.maps.associated_items.borrow_mut()
+                        self.maps.associated_item.borrow_mut()
                             .insert(assoc_item.def_id, assoc_item);
                     }
                 }
@@ -2150,7 +2112,7 @@ pub fn associated_item(self, def_id: DefId) -> AssociatedItem {
                     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.maps.associated_items.borrow_mut()
+                        self.maps.associated_item.borrow_mut()
                             .insert(assoc_item.def_id, assoc_item);
                     }
                 }
@@ -2162,7 +2124,7 @@ pub fn associated_item(self, def_id: DefId) -> AssociatedItem {
 
             // memoize wants us to return something, so return
             // the one we generated for this def-id
-            *self.maps.associated_items.borrow().get(&def_id).unwrap()
+            *self.maps.associated_item.borrow().get(&def_id).unwrap()
         })
     }
 
@@ -2220,11 +2182,11 @@ fn associated_item_from_impl_item_ref(self,
     }
 
     pub fn associated_item_def_ids(self, def_id: DefId) -> Rc<Vec<DefId>> {
-        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));
-            }
+        if !def_id.is_local() {
+            return self.maps.associated_item_def_ids(self, def_id);
+        }
 
+        self.maps.associated_item_def_ids.memoize(def_id, || {
             let id = self.hir.as_local_node_id(def_id).unwrap();
             let item = self.hir.expect_item(id);
             let vec: Vec<_> = match item.node {
@@ -2256,9 +2218,7 @@ pub fn associated_items(self, def_id: DefId)
     /// Returns the trait-ref corresponding to a given impl, or None if it is
     /// 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.maps.impl_trait_refs,
-            || self.sess.cstore.impl_trait_ref(self.global_tcx(), id))
+        self.maps.impl_trait_ref(self, id)
     }
 
     // Returns `ty::VariantDef` if `def` refers to a struct,
@@ -2337,58 +2297,37 @@ pub fn item_name(self, id: DefId) -> ast::Name {
     // If the given item is in an external crate, looks up its type and adds it to
     // 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.maps.types,
-            || self.sess.cstore.item_type(self.global_tcx(), did))
+        self.maps.ty(self, 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.maps.trait_defs,
-            || self.alloc_trait_def(self.sess.cstore.trait_def(self.global_tcx(), did))
-        )
+        self.maps.trait_def(self, did)
     }
 
     /// 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.maps.adt_defs,
-            || self.sess.cstore.adt_def(self.global_tcx(), did))
+        self.maps.adt_def(self, 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.maps.generics,
-            || self.alloc_generics(self.sess.cstore.item_generics(did)))
+        self.maps.generics(self, 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.maps.predicates,
-            || self.sess.cstore.item_predicates(self.global_tcx(), did))
+        self.maps.predicates(self, 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.maps.super_predicates,
-            || self.sess.cstore.item_super_predicates(self.global_tcx(), did))
+        self.maps.super_predicates(self, 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.maps.mir, || {
-            let mir = self.sess.cstore.get_item_mir(self.global_tcx(), did);
-            let mir = self.alloc_mir(mir);
-
-            // Perma-borrow MIR from extern crates to prevent mutation.
-            mem::forget(mir.borrow());
-
-            mir
-        }).borrow()
+        self.maps.mir(self, did).borrow()
     }
 
     /// If `type_needs_drop` returns true, then `ty` is definitely
@@ -2451,9 +2390,7 @@ pub fn lookup_simd(self, did: DefId) -> bool {
     }
 
     pub fn item_variances(self, item_id: DefId) -> Rc<Vec<ty::Variance>> {
-        lookup_locally_or_in_crate_store(
-            "item_variance_map", item_id, &self.maps.variances,
-            || Rc::new(self.sess.cstore.item_variances(item_id)))
+        self.maps.variances(self, item_id)
     }
 
     pub fn trait_has_default_impl(self, trait_def_id: DefId) -> bool {
@@ -2528,16 +2465,7 @@ pub fn populate_implementations_for_trait_if_necessary(self, trait_id: DefId) {
     }
 
     pub fn closure_kind(self, def_id: DefId) -> ty::ClosureKind {
-        // 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.maps.closure_kinds.borrow().get(&def_id) {
-            return kind;
-        }
-
-        let kind = self.sess.cstore.closure_kind(def_id);
-        self.maps.closure_kinds.borrow_mut().insert(def_id, kind);
-        kind
+        self.maps.closure_kind(self, def_id)
     }
 
     pub fn closure_type(self,
@@ -2545,16 +2473,11 @@ pub fn closure_type(self,
                         substs: ClosureSubsts<'tcx>)
                         -> ty::ClosureTy<'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.maps.closure_types.borrow().get(&def_id) {
+        if let Some(ty) = self.maps.closure_type.borrow().get(&def_id) {
             return ty.subst(self, substs.substs);
         }
 
-        let ty = self.sess.cstore.closure_ty(self.global_tcx(), def_id);
-        self.maps.closure_types.borrow_mut().insert(def_id, ty.clone());
-        ty.subst(self, substs.substs)
+        self.maps.closure_type(self, def_id).subst(self, substs.substs)
     }
 
     /// Given the def_id of an impl, return the def_id of the trait it implements.
@@ -2566,15 +2489,17 @@ pub fn trait_id_of_impl(self, def_id: DefId) -> Option<DefId> {
     /// If the given def ID describes a method belonging to an impl, return the
     /// ID of the impl that the method belongs to. Otherwise, return `None`.
     pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
-        if def_id.krate != LOCAL_CRATE {
-            return self.sess.cstore.associated_item(def_id).and_then(|item| {
-                match item.container {
-                    TraitContainer(_) => None,
-                    ImplContainer(def_id) => Some(def_id),
-                }
-            });
-        }
-        match self.maps.associated_items.borrow().get(&def_id).cloned() {
+        let item = if def_id.krate != LOCAL_CRATE {
+            if let Some(Def::Method(_)) = self.sess.cstore.describe_def(def_id) {
+                Some(self.associated_item(def_id))
+            } else {
+                None
+            }
+        } else {
+            self.maps.associated_item.borrow().get(&def_id).cloned()
+        };
+
+        match item {
             Some(trait_item) => {
                 match trait_item.container {
                     TraitContainer(_) => None,
@@ -2592,7 +2517,7 @@ pub fn trait_of_item(self, def_id: DefId) -> Option<DefId> {
         if def_id.krate != LOCAL_CRATE {
             return self.sess.cstore.trait_of_item(def_id);
         }
-        match self.maps.associated_items.borrow().get(&def_id) {
+        match self.maps.associated_item.borrow().get(&def_id) {
             Some(associated_item) => {
                 match associated_item.container {
                     TraitContainer(def_id) => Some(def_id),
index fa53760eca4666dd2ffe0b4e1f557b98f7a798f8..3981c8a7c4f527260fdb3822a598e17f7e94f301 100644 (file)
@@ -770,7 +770,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
             TyAdt(def, substs) => {
                 ty::tls::with(|tcx| {
                     if def.did.is_local() &&
-                          !tcx.maps.types.borrow().contains_key(&def.did) {
+                          !tcx.maps.ty.borrow().contains_key(&def.did) {
                         write!(f, "{}<..>", tcx.item_path_str(def.did))
                     } else {
                         parameterized(f, substs, def.did, &[])
index 13ece31f4ce13eb4a52938855dbf5cb1aa46cc73..967705c7481611e2c25eb9d208fe440a20cf8258 100644 (file)
@@ -123,7 +123,7 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     } else {
         let expr_tables_ty = tcx.sess.cstore.maybe_get_item_body(tcx, def_id).map(|body| {
             (&body.value, Some(tcx.item_tables(def_id)),
-             Some(tcx.sess.cstore.item_type(tcx, def_id)))
+             Some(tcx.item_type(def_id)))
         });
         match tcx.sess.cstore.describe_def(def_id) {
             Some(Def::AssociatedConst(_)) => {
index de789d5686fcfb81024bb8ebf8e66bfd4f66686d..6dbdf55f1ca377fd6cf2f5197bd9e5a823d79d61 100644 (file)
@@ -28,7 +28,7 @@
 use rustc_incremental::ich::Fingerprint;
 use rustc_resolve::{MakeGlobMap, Resolver};
 use rustc_metadata::creader::CrateLoader;
-use rustc_metadata::cstore::CStore;
+use rustc_metadata::cstore::{self, CStore};
 use rustc_trans::back::{link, write};
 use rustc_trans as trans;
 use rustc_typeck as typeck;
@@ -872,7 +872,14 @@ macro_rules! try_with_f {
 
     let index = stability::Index::new(&hir_map);
 
+    let local_providers = ty::maps::Providers::default();
+    let mut extern_providers = ty::maps::Providers::default();
+
+    cstore::provide(&mut extern_providers);
+
     TyCtxt::create_and_enter(sess,
+                             local_providers,
+                             extern_providers,
                              arenas,
                              arena,
                              resolutions,
index 5481de1811d78b91b411b6b470b288bec54dc154..2aa1b9981b3cd0923f49c7118667eb749b0241d9 100644 (file)
@@ -139,6 +139,8 @@ fn test_env<F>(source_string: &str,
     let region_map = region::resolve_crate(&sess, &hir_map);
     let index = stability::Index::new(&hir_map);
     TyCtxt::create_and_enter(&sess,
+                             ty::maps::Providers::default(),
+                             ty::maps::Providers::default(),
                              &arenas,
                              &arena,
                              resolutions,
index 5fcefe0d53997250b01c637c40ce4d8063fcd9ea..353b86820c405e3811d9f438cc5a55cd797fdeea 100644 (file)
@@ -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.maps.associated_items.borrow().get(&def_id) {
+    match cx.tcx.maps.associated_item.borrow().get(&def_id) {
         None => span_bug!(span, "missing method descriptor?!"),
         Some(item) => {
             match item.container {
index 4709ca6101c7908f11e8ce5ef7e9cd5a96d090ec..bb30245df5f56315a1069c07c9da2d607626795c 100644 (file)
@@ -35,6 +35,8 @@
 pub use rustc::middle::cstore::NativeLibraryKind::*;
 pub use rustc::middle::cstore::{CrateSource, LinkMeta, LibSource};
 
+pub use cstore_impl::provide;
+
 // A map from external crate numbers (as decoded from some crate file) to
 // local crate numbers (as generated during this session). Each external
 // crate may refer to types in other external crates, and each has their
index bd184c5c5e69f98bae4965a087d07ca81f9eebeb..770591bc17ad7e90e1d9554ce0b5b219e18fbcd4 100644 (file)
 use locator;
 use schema;
 
+use rustc::dep_graph::DepTrackingMapConfig;
 use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind, ExternCrate};
 use rustc::middle::cstore::{NativeLibrary, LinkMeta, LinkagePreference, LoadedMacro};
 use rustc::hir::def::{self, Def};
 use rustc::middle::lang_items;
 use rustc::session::Session;
-use rustc::ty::{self, Ty, TyCtxt};
+use rustc::ty::{self, TyCtxt};
+use rustc::ty::maps::Providers;
 use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
 
 use rustc::dep_graph::DepNode;
 use rustc::hir::map::{DefKey, DefPath, DisambiguatedDefPathData};
-use rustc::mir::Mir;
 use rustc::util::nodemap::{NodeSet, DefIdMap};
 use rustc_back::PanicStrategy;
 
+use std::any::Any;
+use std::mem;
+use std::rc::Rc;
+
 use syntax::ast;
 use syntax::attr;
 use syntax::parse::filemap_to_tts;
 
 use std::collections::BTreeMap;
 
-impl<'tcx> CrateStore<'tcx> for cstore::CStore {
+macro_rules! provide {
+    (<$lt:tt> $tcx:ident, $def_id:ident, $cdata:ident $($name:ident => $compute:block)*) => {
+        pub fn provide<$lt>(providers: &mut Providers<$lt>) {
+            $(fn $name<'a, $lt:$lt>($tcx: TyCtxt<'a, $lt, $lt>, $def_id: DefId)
+                                    -> <ty::maps::queries::$name<$lt> as
+                                        DepTrackingMapConfig>::Value {
+                assert!(!$def_id.is_local());
+
+                $tcx.dep_graph.read(DepNode::MetaData($def_id));
+
+                let $cdata = $tcx.sess.cstore.crate_data_as_rc_any($def_id.krate);
+                let $cdata = $cdata.downcast_ref::<cstore::CrateMetadata>()
+                    .expect("CrateStore crated ata is not a CrateMetadata");
+                $compute
+            })*
+
+            *providers = Providers {
+                $($name,)*
+                ..*providers
+            };
+        }
+    }
+}
+
+provide! { <'tcx> tcx, def_id, cdata
+    ty => { cdata.get_type(def_id.index, tcx) }
+    generics => { tcx.alloc_generics(cdata.get_generics(def_id.index)) }
+    predicates => { cdata.get_predicates(def_id.index, tcx) }
+    super_predicates => { cdata.get_super_predicates(def_id.index, tcx) }
+    trait_def => {
+        tcx.alloc_trait_def(cdata.get_trait_def(def_id.index, tcx))
+    }
+    adt_def => { cdata.get_adt_def(def_id.index, tcx) }
+    variances => { Rc::new(cdata.get_item_variances(def_id.index)) }
+    associated_item_def_ids => {
+        let mut result = vec![];
+        cdata.each_child_of_item(def_id.index, |child| result.push(child.def.def_id()));
+        Rc::new(result)
+    }
+    associated_item => { cdata.get_associated_item(def_id.index) }
+    impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
+    custom_coerce_unsized_kind => {
+        cdata.get_custom_coerce_unsized_kind(def_id.index).unwrap_or_else(|| {
+            bug!("custom_coerce_unsized_kind: `{:?}` is missing its kind", def_id);
+        })
+    }
+    mir => {
+        let mir = cdata.maybe_get_item_mir(tcx, def_id.index).unwrap_or_else(|| {
+            bug!("get_item_mir: missing MIR for `{:?}`", def_id)
+        });
+
+        let mir = tcx.alloc_mir(mir);
+
+        // Perma-borrow MIR from extern crates to prevent mutation.
+        mem::forget(mir.borrow());
+
+        mir
+    }
+    closure_kind => { cdata.closure_kind(def_id.index) }
+    closure_type => { cdata.closure_ty(def_id.index, tcx) }
+}
+
+impl CrateStore for cstore::CStore {
+    fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any> {
+        self.get_crate_data(krate)
+    }
+
     fn describe_def(&self, def: DefId) -> Option<Def> {
         self.dep_graph.read(DepNode::MetaData(def));
         self.get_crate_data(def.krate).get_def(def.index)
@@ -64,46 +135,7 @@ fn visibility(&self, def: DefId) -> ty::Visibility {
         self.get_crate_data(def.krate).get_visibility(def.index)
     }
 
-    fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind
-    {
-        assert!(!def_id.is_local());
-        self.dep_graph.read(DepNode::MetaData(def_id));
-        self.get_crate_data(def_id.krate).closure_kind(def_id.index)
-    }
-
-    fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::ClosureTy<'tcx> {
-        assert!(!def_id.is_local());
-        self.dep_graph.read(DepNode::MetaData(def_id));
-        self.get_crate_data(def_id.krate).closure_ty(def_id.index, tcx)
-    }
-
-    fn item_variances(&self, def: DefId) -> Vec<ty::Variance> {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).get_item_variances(def.index)
-    }
-
-    fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                     -> Ty<'tcx>
-    {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).get_type(def.index, tcx)
-    }
-
-    fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                           -> ty::GenericPredicates<'tcx>
-    {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).get_predicates(def.index, tcx)
-    }
-
-    fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                                 -> ty::GenericPredicates<'tcx>
-    {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).get_super_predicates(def.index, tcx)
-    }
-
-    fn item_generics(&self, def: DefId) -> ty::Generics {
+    fn item_generics_cloned(&self, def: DefId) -> ty::Generics {
         self.dep_graph.read(DepNode::MetaData(def));
         self.get_crate_data(def.krate).get_generics(def.index)
     }
@@ -114,18 +146,6 @@ fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>
         self.get_crate_data(def_id.krate).get_item_attrs(def_id.index)
     }
 
-    fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> ty::TraitDef
-    {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).get_trait_def(def.index, tcx)
-    }
-
-    fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> &'tcx ty::AdtDef
-    {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).get_adt_def(def.index, tcx)
-    }
-
     fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name>
     {
         // FIXME(#38501) We've skipped a `read` on the `HirBody` of
@@ -154,34 +174,12 @@ fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>
         result
     }
 
-    fn associated_item_def_ids(&self, def_id: DefId) -> Vec<DefId> {
-        self.dep_graph.read(DepNode::MetaData(def_id));
-        let mut result = vec![];
-        self.get_crate_data(def_id.krate)
-            .each_child_of_item(def_id.index, |child| result.push(child.def.def_id()));
-        result
-    }
-
     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity
     {
         self.dep_graph.read(DepNode::MetaData(def));
         self.get_crate_data(def.krate).get_impl_polarity(def.index)
     }
 
-    fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-                          -> Option<ty::TraitRef<'tcx>>
-    {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).get_impl_trait(def.index, tcx)
-    }
-
-    fn custom_coerce_unsized_kind(&self, def: DefId)
-                                  -> Option<ty::adjustment::CustomCoerceUnsized>
-    {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).get_custom_coerce_unsized_kind(def.index)
-    }
-
     fn impl_parent(&self, impl_def: DefId) -> Option<DefId> {
         self.dep_graph.read(DepNode::MetaData(impl_def));
         self.get_crate_data(impl_def.krate).get_parent_impl(impl_def.index)
@@ -192,7 +190,7 @@ fn trait_of_item(&self, def_id: DefId) -> Option<DefId> {
         self.get_crate_data(def_id.krate).get_trait_of_item(def_id.index)
     }
 
-    fn associated_item(&self, def: DefId) -> Option<ty::AssociatedItem>
+    fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem
     {
         self.dep_graph.read(DepNode::MetaData(def));
         self.get_crate_data(def.krate).get_associated_item(def.index)
@@ -425,10 +423,10 @@ fn load_macro(&self, id: DefId, sess: &Session) -> LoadedMacro {
         })
     }
 
-    fn maybe_get_item_body<'a>(&'tcx self,
-                               tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                               def_id: DefId)
-                               -> Option<&'tcx hir::Body>
+    fn maybe_get_item_body<'a, 'tcx>(&self,
+                                     tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                                     def_id: DefId)
+                                     -> Option<&'tcx hir::Body>
     {
         if let Some(cached) = tcx.hir.get_inlined_body(def_id) {
             return Some(cached);
@@ -450,13 +448,6 @@ fn const_is_rvalue_promotable_to_static(&self, def: DefId) -> bool {
         self.get_crate_data(def.krate).const_is_rvalue_promotable_to_static(def.index)
     }
 
-    fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Mir<'tcx> {
-        self.dep_graph.read(DepNode::MetaData(def));
-        self.get_crate_data(def.krate).maybe_get_item_mir(tcx, def.index).unwrap_or_else(|| {
-            bug!("get_item_mir: missing MIR for {}", tcx.item_path_str(def))
-        })
-    }
-
     fn is_item_mir_available(&self, def: DefId) -> bool {
         self.dep_graph.read(DepNode::MetaData(def));
         self.get_crate_data(def.krate).is_item_mir_available(def.index)
@@ -504,10 +495,10 @@ fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>
         self.do_extern_mod_stmt_cnum(emod_id)
     }
 
-    fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                           reexports: &def::ExportMap,
-                           link_meta: &LinkMeta,
-                           reachable: &NodeSet) -> Vec<u8>
+    fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                                 reexports: &def::ExportMap,
+                                 link_meta: &LinkMeta,
+                                 reachable: &NodeSet) -> Vec<u8>
     {
         encoder::encode_metadata(tcx, self, reexports, link_meta, reachable)
     }
index aa18fbe2ba8cdaaee35962dec7f7b89e5eb5cf66..3f8873ddc27427d14858adff1b1efcc3a6fb61a1 100644 (file)
@@ -584,7 +584,7 @@ pub fn get_adt_def(&self,
         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.maps.adt_defs.borrow_mut().insert(self.local_def_id(ctor_index), adt);
+            tcx.maps.adt_def.borrow_mut().insert(self.local_def_id(ctor_index), adt);
         }
 
         adt
@@ -822,54 +822,35 @@ pub fn maybe_get_item_mir(&self,
         }
     }
 
-    pub fn get_associated_item(&self, id: DefIndex) -> Option<ty::AssociatedItem> {
+    pub fn get_associated_item(&self, id: DefIndex) -> ty::AssociatedItem {
         let item = self.entry(id);
-        let parent_and_name = || {
-            let def_key = self.def_key(id);
-            (self.local_def_id(def_key.parent.unwrap()),
-             def_key.disambiguated_data.data.get_opt_name().unwrap())
-        };
+        let def_key = self.def_key(id);
+        let parent = self.local_def_id(def_key.parent.unwrap());
+        let name = def_key.disambiguated_data.data.get_opt_name().unwrap();
 
-        Some(match item.kind {
+        let (kind, container, has_self) = match item.kind {
             EntryKind::AssociatedConst(container) => {
-                let (parent, name) = parent_and_name();
-                ty::AssociatedItem {
-                    name: name,
-                    kind: ty::AssociatedKind::Const,
-                    vis: item.visibility.decode(self),
-                    defaultness: container.defaultness(),
-                    def_id: self.local_def_id(id),
-                    container: container.with_def_id(parent),
-                    method_has_self_argument: false
-                }
+                (ty::AssociatedKind::Const, container, false)
             }
             EntryKind::Method(data) => {
-                let (parent, name) = parent_and_name();
                 let data = data.decode(self);
-                ty::AssociatedItem {
-                    name: name,
-                    kind: ty::AssociatedKind::Method,
-                    vis: item.visibility.decode(self),
-                    defaultness: data.container.defaultness(),
-                    def_id: self.local_def_id(id),
-                    container: data.container.with_def_id(parent),
-                    method_has_self_argument: data.has_self
-                }
+                (ty::AssociatedKind::Method, data.container, data.has_self)
             }
             EntryKind::AssociatedType(container) => {
-                let (parent, name) = parent_and_name();
-                ty::AssociatedItem {
-                    name: name,
-                    kind: ty::AssociatedKind::Type,
-                    vis: item.visibility.decode(self),
-                    defaultness: container.defaultness(),
-                    def_id: self.local_def_id(id),
-                    container: container.with_def_id(parent),
-                    method_has_self_argument: false
-                }
+                (ty::AssociatedKind::Type, container, false)
             }
-            _ => return None,
-        })
+            _ => bug!()
+        };
+
+        ty::AssociatedItem {
+            name: name,
+            kind: kind,
+            vis: item.visibility.decode(self),
+            defaultness: container.defaultness(),
+            def_id: self.local_def_id(id),
+            container: container.with_def_id(parent),
+            method_has_self_argument: has_self
+        }
     }
 
     pub fn get_item_variances(&self, id: DefIndex) -> Vec<ty::Variance> {
index e6110172fc41fe28ab6fd050cf363543ce13806f..e101dc8cb5892314df5f9564a41e7df82e9b24cf 100644 (file)
@@ -711,7 +711,7 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
                 let data = ImplData {
                     polarity: polarity,
                     parent_impl: parent,
-                    coerce_unsized_kind: tcx.maps.custom_coerce_unsized_kinds
+                    coerce_unsized_kind: tcx.maps.custom_coerce_unsized_kind
                         .borrow()
                         .get(&def_id)
                         .cloned(),
@@ -1096,7 +1096,7 @@ fn encode_info_for_closure(&mut self, def_id: DefId) -> Entry<'tcx> {
 
         let data = ClosureData {
             kind: tcx.closure_kind(def_id),
-            ty: self.lazy(&tcx.maps.closure_types.borrow()[&def_id]),
+            ty: self.lazy(&tcx.maps.closure_type.borrow()[&def_id]),
         };
 
         Entry {
index 2fbdb8c0de676dec7f7921e3037e9c6410811c0f..0ce886ce9e9dfc92a8ad9c35a4a5c76b22478eb3 100644 (file)
@@ -20,6 +20,7 @@
 #![feature(box_patterns)]
 #![feature(conservative_impl_trait)]
 #![feature(core_intrinsics)]
+#![cfg_attr(stage0, feature(field_init_shorthand))]
 #![feature(i128_type)]
 #![feature(proc_macro_internals)]
 #![feature(quote)]
index ec02e9235beaf93b2b26fc14b3de68a0d316bc84..89cff39c59e31317f3af47fe0fa81921c7962925 100644 (file)
@@ -462,8 +462,8 @@ fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'a>, chi
                     self.define(module, ident, ns, (child.def, ty::Visibility::Public,
                                                     DUMMY_SP, Mark::root()));
 
-                    let has_self = self.session.cstore.associated_item(child.def.def_id())
-                                       .map_or(false, |item| item.method_has_self_argument);
+                    let has_self = self.session.cstore.associated_item_cloned(child.def.def_id())
+                                       .method_has_self_argument;
                     self.trait_item_map.insert((def_id, child.name, ns), (child.def, has_self));
                 }
                 module.populated.set(true);
index c2f64b1bd7906187da4c2ae583e3afaafe4ce074..7b14684267173e6fc2492bf662aee95a5cfc6227 100644 (file)
@@ -208,9 +208,9 @@ fn analyze_closure(&mut self,
 
         // If we are also inferred the closure kind here, update the
         // main table and process any deferred resolutions.
-        let closure_def_id = self.fcx.tcx.hir.local_def_id(id);
         if let Some(&kind) = self.temp_closure_kinds.get(&id) {
             self.fcx.tables.borrow_mut().closure_kinds.insert(id, kind);
+            let closure_def_id = self.fcx.tcx.hir.local_def_id(id);
             debug!("closure_kind({:?}) = {:?}", closure_def_id, kind);
 
             let mut deferred_call_resolutions =
index b3a4b83b6832c0e8dfb597c64bfadce8191dfdf9..650f32eb6b216f3fa69b3bda8032eee9ceeb9b1e 100644 (file)
@@ -290,12 +290,12 @@ fn visit_closures(&self) {
         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().maps.closure_types.borrow_mut().insert(def_id, closure_ty);
+            self.tcx().maps.closure_type.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().maps.closure_kinds.borrow_mut().insert(def_id, closure_kind);
+            self.tcx().maps.closure_kind.borrow_mut().insert(def_id, closure_kind);
         }
     }
 
@@ -361,7 +361,7 @@ fn visit_anon_types(&self) {
                 }
             });
 
-            gcx.maps.types.borrow_mut().insert(def_id, outside_ty);
+            gcx.maps.ty.borrow_mut().insert(def_id, outside_ty);
         }
     }
 
index e15386b87ad97ef3e589858c0d919c24daa1096b..bfe8abb201caea401f9618d7280071cfcde8e083 100644 (file)
@@ -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.maps.custom_coerce_unsized_kinds.borrow_mut().insert(impl_did, kind);
+            tcx.maps.custom_coerce_unsized_kind.borrow_mut().insert(impl_did, kind);
         }
     });
 }
index 1301f33d30b0819b21dbfbd93a99986f94b497e6..4aa0650e57f717aa28ca66a360d048c1e6dd3d88 100644 (file)
@@ -39,7 +39,7 @@
 
 struct CoherenceCollect<'a, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
-    inherent_impls: RefMut<'a, DepTrackingMap<maps::inherent_impls<'tcx>>>,
+    inherent_impls: RefMut<'a, DepTrackingMap<maps::queries::inherent_impls<'tcx>>>,
 }
 
 impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CoherenceCollect<'a, 'tcx> {
index 3851cd2bb442ad4bc1f0bcce9337409f8b373e43..90d12b26c6a62861a7a177ac1eb34669edcb81c5 100644 (file)
@@ -606,7 +606,7 @@ 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.maps.types.borrow_mut().insert(ty_f.did, tt);
+    ccx.tcx.maps.ty.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.maps.types.borrow_mut().insert(def_id, fty);
+    ccx.tcx.maps.ty.borrow_mut().insert(def_id, fty);
 
     ty_generic_predicates(ccx, def_id, &sig.generics);
 }
@@ -635,7 +635,7 @@ fn convert_associated_const<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
     };
     let def_id = ccx.tcx.hir.local_def_id(id);
     ccx.tcx.maps.predicates.borrow_mut().insert(def_id, predicates);
-    ccx.tcx.maps.types.borrow_mut().insert(def_id, ty);
+    ccx.tcx.maps.ty.borrow_mut().insert(def_id, ty);
 }
 
 fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
@@ -651,7 +651,7 @@ fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
     ccx.tcx.maps.predicates.borrow_mut().insert(def_id, predicates);
 
     if let Some(ty) = ty {
-        ccx.tcx.maps.types.borrow_mut().insert(def_id, ty);
+        ccx.tcx.maps.ty.borrow_mut().insert(def_id, ty);
     }
 }
 
@@ -725,7 +725,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
 
             tcx.record_trait_has_default_impl(trait_ref.def_id);
 
-            tcx.maps.impl_trait_refs.borrow_mut().insert(ccx.tcx.hir.local_def_id(it.id),
+            tcx.maps.impl_trait_ref.borrow_mut().insert(ccx.tcx.hir.local_def_id(it.id),
                                                          Some(trait_ref));
         }
         hir::ItemImpl(.., ref opt_trait_ref, _, _) => {
@@ -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.maps.impl_trait_refs.borrow_mut().insert(def_id, trait_ref);
+            tcx.maps.impl_trait_ref.borrow_mut().insert(def_id, trait_ref);
 
             predicates_of_item(ccx, it);
         },
@@ -864,7 +864,7 @@ fn convert_variant_ctor<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
             }))
         }
     };
-    tcx.maps.types.borrow_mut().insert(def_id, ctor_ty);
+    tcx.maps.ty.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![]
@@ -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.maps.adt_defs.borrow_mut().insert(ctor_id, adt);
+        ccx.tcx.maps.adt_def.borrow_mut().insert(ctor_id, adt);
     }
 
-    ccx.tcx.maps.adt_defs.borrow_mut().insert(did, adt);
+    ccx.tcx.maps.adt_def.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.maps.adt_defs.borrow_mut().insert(did, adt);
+    ccx.tcx.maps.adt_def.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.maps.adt_defs.borrow_mut().insert(did, adt);
+    tcx.maps.adt_def.borrow_mut().insert(did, adt);
     adt
 }
 
@@ -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.maps.trait_defs.memoize(def_id, || {
+    tcx.maps.trait_def.memoize(def_id, || {
         let unsafety = match it.node {
             hir::ItemTrait(unsafety, ..) => unsafety,
             _ => span_bug!(it.span, "trait_def_of_item invoked on non-trait"),
@@ -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.maps.types.memoize(def_id, || {
+    ccx.tcx.maps.ty.memoize(def_id, || {
         use rustc::hir::map::*;
         use rustc::hir::*;
 
@@ -1389,7 +1389,7 @@ fn type_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
 
         let icx = ccx.icx(def_id);
 
-        let ty = match ccx.tcx.hir.get(node_id) {
+        match ccx.tcx.hir.get(node_id) {
             NodeItem(item) => {
                 match item.node {
                     ItemStatic(ref t, ..) | ItemConst(ref t, _) |
@@ -1455,9 +1455,7 @@ fn type_of_def_id<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
             x => {
                 bug!("unexpected sort of node in type_of_def_id(): {:?}", x);
             }
-        };
-
-        ty
+        }
     })
 }
 
index cee292f99153e4fc318463094d1633f8ac8e6074..852c98eb2fd52fcfb37e4cab0131f3aa415b6338 100644 (file)
@@ -24,7 +24,7 @@
 /// specific rustdoc annotations into account (i.e. `doc(hidden)`)
 pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b> {
     cx: &'a ::core::DocContext<'b, 'tcx>,
-    cstore: &'a CrateStore<'tcx>,
+    cstore: &'a CrateStore,
     // Accessibility levels for reachable nodes
     access_levels: RefMut<'a, AccessLevels<DefId>>,
     // Previous accessibility level, None means unreachable