]> git.lizzy.rs Git - rust.git/commitdiff
Merge branch 'hide-trait-map' into rollup
authorAlex Crichton <alex@alexcrichton.com>
Wed, 30 Aug 2017 16:12:53 +0000 (09:12 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 30 Aug 2017 20:17:40 +0000 (13:17 -0700)
src/librustc/dep_graph/dep_node.rs
src/librustc/ich/hcx.rs
src/librustc/ty/context.rs
src/librustc/ty/maps.rs
src/librustc/ty/mod.rs
src/librustc_metadata/encoder.rs
src/librustc_privacy/lib.rs
src/librustc_typeck/check/method/probe.rs
src/librustdoc/visit_ast.rs

index 5114b94571d5a6b4eb5351ce8a0623758baf17e6..ea827fb3139a86a21dede30a567cb030dbd79903 100644 (file)
@@ -62,6 +62,7 @@
 
 use hir::def_id::{CrateNum, DefId};
 use hir::map::DefPathHash;
+use hir::HirId;
 
 use ich::Fingerprint;
 use ty::{TyCtxt, Instance, InstanceDef};
@@ -528,6 +529,8 @@ pub fn to_dep_node(self, tcx: TyCtxt, kind: DepKind) -> DepNode {
     [] ExternCrate(DefId),
     [] LintLevels,
     [] Specializes { impl1: DefId, impl2: DefId },
+    [] InScopeTraits(HirId),
+    [] ModuleExports(HirId),
 );
 
 trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
index 544c824f83ce2f9e4c048da32ac0efce704d6577..9c841022fcb8225df851b314d6473c3f702d393c 100644 (file)
@@ -205,13 +205,15 @@ fn hash_stable<W: StableHasherResult>(&self,
                 // corresponding entry in the `trait_map` we need to hash that.
                 // Make sure we don't ignore too much by checking that there is
                 // no entry in a debug_assert!().
-                debug_assert!(hcx.tcx.trait_map.get(self).is_none());
+                let hir_id = hcx.tcx.hir.node_to_hir_id(*self);
+                debug_assert!(hcx.tcx.in_scope_traits(hir_id).is_none());
             }
             NodeIdHashingMode::HashDefPath => {
                 hcx.tcx.hir.definitions().node_to_hir_id(*self).hash_stable(hcx, hasher);
             }
             NodeIdHashingMode::HashTraitsInScope => {
-                if let Some(traits) = hcx.tcx.trait_map.get(self) {
+                let hir_id = hcx.tcx.hir.node_to_hir_id(*self);
+                if let Some(traits) = hcx.tcx.in_scope_traits(hir_id) {
                     // The ordering of the candidates is not fixed. So we hash
                     // the def-ids and then sort them and hash the collection.
                     let mut candidates: AccumulateVec<[_; 8]> =
index 1255a9c1f1e5c1dfa9835d657791dd846999dffe..14d47d5d195e3f400a53d9b50cee6aa2324a012d 100644 (file)
@@ -14,8 +14,8 @@
 use errors::DiagnosticBuilder;
 use session::Session;
 use middle;
-use hir::{TraitMap};
-use hir::def::{Def, ExportMap};
+use hir::{TraitCandidate, HirId};
+use hir::def::{Def, Export};
 use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
 use hir::map as hir_map;
 use hir::map::DefPathHash;
@@ -817,10 +817,10 @@ pub struct GlobalCtxt<'tcx> {
 
     /// Map indicating what traits are in scope for places where this
     /// is relevant; generated by resolve.
-    pub trait_map: TraitMap,
+    trait_map: FxHashMap<HirId, Rc<Vec<TraitCandidate>>>,
 
     /// Export map produced by name resolution.
-    pub export_map: ExportMap,
+    export_map: FxHashMap<HirId, Rc<Vec<Export>>>,
 
     pub named_region_map: resolve_lifetime::NamedRegionMap,
 
@@ -1075,8 +1075,12 @@ pub fn create_and_enter<F, R>(s: &'tcx Session,
             dep_graph: dep_graph.clone(),
             types: common_types,
             named_region_map,
-            trait_map: resolutions.trait_map,
-            export_map: resolutions.export_map,
+            trait_map: resolutions.trait_map.into_iter().map(|(k, v)| {
+                (hir.node_to_hir_id(k), Rc::new(v))
+            }).collect(),
+            export_map: resolutions.export_map.into_iter().map(|(k, v)| {
+                (hir.node_to_hir_id(k), Rc::new(v))
+            }).collect(),
             hir,
             def_path_hash_to_def_id,
             maps: maps::Maps::new(providers),
@@ -1994,3 +1998,20 @@ fn intern_with<I: Iterator<Item=Self>, F: FnOnce(&[T]) -> R>(iter: I, f: F) -> S
         Ok(f(&iter.collect::<Result<AccumulateVec<[_; 8]>, _>>()?))
     }
 }
+
+fn in_scope_traits<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: HirId)
+    -> Option<Rc<Vec<TraitCandidate>>>
+{
+    tcx.gcx.trait_map.get(&id).cloned()
+}
+
+fn module_exports<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: HirId)
+    -> Option<Rc<Vec<Export>>>
+{
+    tcx.gcx.export_map.get(&id).cloned()
+}
+
+pub fn provide(providers: &mut ty::maps::Providers) {
+    providers.in_scope_traits = in_scope_traits;
+    providers.module_exports = module_exports;
+}
index c7303c749a4af6623b326d28ae0e1124db8466ae..da81bfbb0dc4f21643d0cd99356d1f9270108d73 100644 (file)
@@ -11,8 +11,8 @@
 use dep_graph::{DepConstructor, DepNode, DepNodeIndex};
 use errors::{Diagnostic, DiagnosticBuilder};
 use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
-use hir::def::Def;
-use hir;
+use hir::def::{Def, Export};
+use hir::{self, TraitCandidate, HirId};
 use lint;
 use middle::const_val;
 use middle::cstore::{ExternCrate, LinkagePreference};
@@ -80,6 +80,15 @@ fn default_span(&self, _: TyCtxt) -> Span {
     }
 }
 
+impl Key for HirId {
+    fn map_crate(&self) -> CrateNum {
+        LOCAL_CRATE
+    }
+    fn default_span(&self, _tcx: TyCtxt) -> Span {
+        DUMMY_SP
+    }
+}
+
 impl Key for DefId {
     fn map_crate(&self) -> CrateNum {
         self.krate
@@ -546,6 +555,18 @@ fn describe(_tcx: TyCtxt, _: (DefId, DefId)) -> String {
     }
 }
 
+impl<'tcx> QueryDescription for queries::in_scope_traits<'tcx> {
+    fn describe(_tcx: TyCtxt, _: HirId) -> String {
+        format!("fetching the traits in scope at a particular ast node")
+    }
+}
+
+impl<'tcx> QueryDescription for queries::module_exports<'tcx> {
+    fn describe(_tcx: TyCtxt, _: HirId) -> String {
+        format!("fetching the exported items for a module")
+    }
+}
+
 // If enabled, send a message to the profile-queries thread
 macro_rules! profq_msg {
     ($tcx:expr, $msg:expr) => {
@@ -1116,6 +1137,8 @@ fn default() -> Self {
     [] lint_levels: lint_levels(CrateNum) -> Rc<lint::LintLevelMap>,
 
     [] specializes: specializes_node((DefId, DefId)) -> bool,
+    [] in_scope_traits: InScopeTraits(HirId) -> Option<Rc<Vec<TraitCandidate>>>,
+    [] module_exports: ModuleExports(HirId) -> Option<Rc<Vec<Export>>>,
 }
 
 fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
index 8cabb88ee988d531f28517dca3e3e877d611b64c..ca735599a0da64c4f8641723541540772994a3b3 100644 (file)
@@ -2517,6 +2517,7 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
 
 pub fn provide(providers: &mut ty::maps::Providers) {
     util::provide(providers);
+    context::provide(providers);
     *providers = ty::maps::Providers {
         associated_item,
         associated_item_def_ids,
index be3ac51ccb3bfcdb473b2cc637a613a20c12558e..62aa86995d0aff6d43e422426acdfc0b6f74bc05 100644 (file)
@@ -548,12 +548,13 @@ fn encode_info_for_mod(&mut self,
                                                                  &hir::Visibility)>)
                            -> Entry<'tcx> {
         let tcx = self.tcx;
+        let hir_id = tcx.hir.node_to_hir_id(id);
         let def_id = tcx.hir.local_def_id(id);
         debug!("IsolatedEncoder::encode_info_for_mod({:?})", def_id);
 
         let data = ModData {
-            reexports: match tcx.export_map.get(&id) {
-                Some(exports) if *vis == hir::Public => {
+            reexports: match tcx.module_exports(hir_id) {
+                Some(ref exports) if *vis == hir::Public => {
                     self.lazy_seq_from_slice(exports.as_slice())
                 }
                 _ => LazySeq::empty(),
index e34b0927f67a9010f4e070065924ff4fbc6d6cee..8dc078984193b7008f7f582e272cdec5c65103c4 100644 (file)
@@ -325,8 +325,9 @@ fn visit_mod(&mut self, m: &'tcx hir::Mod, _sp: Span, id: ast::NodeId) {
         // This code is here instead of in visit_item so that the
         // crate module gets processed as well.
         if self.prev_level.is_some() {
-            if let Some(exports) = self.tcx.export_map.get(&id) {
-                for export in exports {
+            let hir_id = self.tcx.hir.node_to_hir_id(id);
+            if let Some(exports) = self.tcx.module_exports(hir_id) {
+                for export in exports.iter() {
                     if let Some(node_id) = self.tcx.hir.as_local_node_id(export.def.def_id()) {
                         self.update(node_id, Some(AccessLevel::Exported));
                     }
index 228b6c88f24db77cbca22040d670d251369c8ce5..ba74c902f55e0fa403f167759c816f61ed6ab860 100644 (file)
@@ -639,10 +639,14 @@ fn elaborate_bounds<F>(&mut self, bounds: &[ty::PolyTraitRef<'tcx>], mut mk_cand
     fn assemble_extension_candidates_for_traits_in_scope(&mut self,
                                                          expr_id: ast::NodeId)
                                                          -> Result<(), MethodError<'tcx>> {
+        if expr_id == ast::DUMMY_NODE_ID {
+            return Ok(())
+        }
         let mut duplicates = FxHashSet();
-        let opt_applicable_traits = self.tcx.trait_map.get(&expr_id);
+        let expr_hir_id = self.tcx.hir.node_to_hir_id(expr_id);
+        let opt_applicable_traits = self.tcx.in_scope_traits(expr_hir_id);
         if let Some(applicable_traits) = opt_applicable_traits {
-            for trait_candidate in applicable_traits {
+            for trait_candidate in applicable_traits.iter() {
                 let trait_did = trait_candidate.def_id;
                 if duplicates.insert(trait_did) {
                     let import_id = trait_candidate.import_id;
index e3426fba1bca18426e8aa8fd1e9bbb34216bedee..1f33cd7765164460d5e53692db597bb27e61d7e3 100644 (file)
@@ -199,8 +199,9 @@ pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec<ast::Attribu
             self.visit_item(item, None, &mut om);
         }
         self.inside_public_path = orig_inside_public_path;
-        if let Some(exports) = self.cx.tcx.export_map.get(&id) {
-            for export in exports {
+        let hir_id = self.cx.tcx.hir.node_to_hir_id(id);
+        if let Some(exports) = self.cx.tcx.module_exports(hir_id) {
+            for export in exports.iter() {
                 if let Def::Macro(def_id, ..) = export.def {
                     if def_id.krate == LOCAL_CRATE || self.reexported_macros.contains(&def_id) {
                         continue // These are `krate.exported_macros`, handled in `self.visit()`.