]> git.lizzy.rs Git - rust.git/commitdiff
Update `visit_item_likes_in_module`
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Fri, 7 Feb 2020 17:25:36 +0000 (18:25 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sat, 14 Mar 2020 21:52:29 +0000 (22:52 +0100)
13 files changed:
src/librustc/dep_graph/dep_node.rs
src/librustc/hir/map/collector.rs
src/librustc/hir/map/definitions.rs
src/librustc/hir/map/mod.rs
src/librustc/hir/mod.rs
src/librustc/ich/hcx.rs
src/librustc/ich/impls_hir.rs
src/librustc/query/mod.rs
src/librustc_hir/hir.rs
src/librustc_hir/stable_hash_impls.rs
src/librustc_incremental/assert_dep_graph.rs
src/librustc_metadata/rmeta/decoder.rs
src/librustc_span/def_id.rs

index 03218920ef1aa293a045a670a53ec349141d9d9f..755bc15ba9380f44ce022f7be5cebfa8787e9031 100644 (file)
@@ -223,8 +223,8 @@ impl DepNode {
             /// Construct a DepNode from the given DepKind and DefPathHash. This
             /// method will assert that the given DepKind actually requires a
             /// single DefId/DefPathHash parameter.
-            pub fn from_def_path_hash(kind: DepKind,
-                                      def_path_hash: DefPathHash)
+            pub fn from_def_path_hash(def_path_hash: DefPathHash,
+                                      kind: DepKind)
                                       -> DepNode {
                 debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
                 DepNode {
@@ -280,7 +280,7 @@ pub fn from_label_string(label: &str,
                 }
 
                 if kind.has_params() {
-                    Ok(def_path_hash.to_dep_node(kind))
+                    Ok(DepNode::from_def_path_hash(def_path_hash, kind))
                 } else {
                     Ok(DepNode::new_no_params(kind))
                 }
@@ -337,12 +337,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-impl DefPathHash {
-    pub fn to_dep_node(self, kind: DepKind) -> DepNode {
-        DepNode::from_def_path_hash(kind, self)
-    }
-}
-
 rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
     // We use this for most things when incr. comp. is turned off.
     [] Null,
index 7e626f79c0c9db75436e1ea45ac2b762f93366c2..231d0ee482196ac11fd3f72b780578d2951a8d08 100644 (file)
@@ -86,7 +86,7 @@ fn alloc_hir_dep_nodes(
 ) -> (DepNodeIndex, DepNodeIndex) {
     let sig = dep_graph
         .input_task(
-            def_path_hash.to_dep_node(DepKind::Hir),
+            DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
             &mut *hcx,
             HirItemLike { item_like: &item_like, hash_bodies: false },
         )
@@ -94,7 +94,7 @@ fn alloc_hir_dep_nodes(
     let (full, hash) = input_dep_node_and_hash(
         dep_graph,
         hcx,
-        def_path_hash.to_dep_node(DepKind::HirBody),
+        DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody),
         HirItemLike { item_like: &item_like, hash_bodies: true },
     );
     hir_body_nodes.push((def_path_hash, hash));
index e1b5ec041db060624fced447af1dd25ef26bdcff..50117f73d48ccce701580e81f206a0ce71f1d9cb 100644 (file)
@@ -6,7 +6,6 @@
 
 use rustc_ast::ast;
 use rustc_ast::node_id::NodeMap;
-use rustc_data_structures::fingerprint::Fingerprint;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::stable_hasher::StableHasher;
 use rustc_hir as hir;
 use rustc_span::symbol::{sym, Symbol};
 use rustc_span::Span;
 
-use std::borrow::Borrow;
 use std::fmt::Write;
 use std::hash::Hash;
 
+pub use rustc_hir::def_id::DefPathHash;
+
 /// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.
 /// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
 /// stores the `DefIndex` of its parent.
@@ -282,28 +282,6 @@ pub enum DefPathData {
     ImplTrait,
 }
 
-#[derive(
-    Copy,
-    Clone,
-    Hash,
-    PartialEq,
-    Eq,
-    PartialOrd,
-    Ord,
-    Debug,
-    RustcEncodable,
-    RustcDecodable,
-    HashStable
-)]
-pub struct DefPathHash(pub Fingerprint);
-
-impl Borrow<Fingerprint> for DefPathHash {
-    #[inline]
-    fn borrow(&self) -> &Fingerprint {
-        &self.0
-    }
-}
-
 impl Definitions {
     pub fn def_path_table(&self) -> &DefPathTable {
         &self.table
index 106475e5e1337b308dec5a7f7e5333e1946934e4..f7990ca01494adec49cb5a5c50d192f67c5ab802 100644 (file)
@@ -562,15 +562,7 @@ pub fn visit_item_likes_in_module<V>(&self, module: DefId, visitor: &mut V)
     where
         V: ItemLikeVisitor<'hir>,
     {
-        let hir_id = self.as_local_hir_id(module).unwrap();
-
-        // Read the module so we'll be re-executed if new items
-        // appear immediately under in the module. If some new item appears
-        // in some nested item in the module, we'll be re-executed due to reads
-        // in the expect_* calls the loops below
-        self.read(hir_id);
-
-        let module = &self.krate.modules[&hir_id];
+        let module = self.tcx.hir_module_items(module);
 
         for id in &module.items {
             visitor.visit_item(self.expect_item(*id));
@@ -639,7 +631,7 @@ pub fn get_parent_node(&self, hir_id: HirId) -> HirId {
         if self.dep_graph.is_fully_enabled() {
             let hir_id_owner = hir_id.owner;
             let def_path_hash = self.definitions.def_path_hash(hir_id_owner);
-            self.dep_graph.read(def_path_hash.to_dep_node(DepKind::HirBody));
+            self.dep_graph.read(DepNode::from_def_path_hash(def_path_hash, DepKind::HirBody));
         }
 
         self.find_entry(hir_id).and_then(|x| x.parent_node()).unwrap_or(hir_id)
index d7999ee5f515d82074d3400c0fdaeccc7eaf7d38..f113efa6300925d052c059141ac90c5ad75b2e4c 100644 (file)
@@ -114,6 +114,12 @@ pub fn provide(providers: &mut Providers<'_>) {
             hir_to_node_id: early.hir_to_node_id,
         })
     };
+    providers.hir_module_items = |tcx, id| {
+        assert_eq!(id.krate, LOCAL_CRATE);
+        let hir = tcx.hir();
+        let module = hir.as_local_hir_id(id).unwrap();
+        &hir.untracked_krate().modules[&module]
+    };
     providers.hir_owner = |tcx, id| {
         assert_eq!(id.krate, LOCAL_CRATE);
         *tcx.hir().map.owner_map.get(&id.index).unwrap()
index 5a49d9a1f1ae1607f456b73c446e6ffa5598b3cb..c15d54745a10523f4730735248c365e2a011ef05 100644 (file)
@@ -7,7 +7,7 @@
 
 use rustc_ast::ast;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
+use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_data_structures::sync::Lrc;
 use rustc_hir as hir;
 use rustc_hir::def_id::{DefId, DefIndex};
@@ -197,19 +197,6 @@ fn get_stable_hashing_context(&self) -> StableHashingContext<'a> {
 
 impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {}
 
-impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::HirId {
-    type KeyType = (DefPathHash, hir::ItemLocalId);
-
-    #[inline]
-    fn to_stable_hash_key(
-        &self,
-        hcx: &StableHashingContext<'a>,
-    ) -> (DefPathHash, hir::ItemLocalId) {
-        let def_path_hash = hcx.local_def_path_hash(self.owner);
-        (def_path_hash, self.local_id)
-    }
-}
-
 impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
     fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) {
         panic!("Node IDs should not appear in incremental state");
index 1015ffdbf2833a916890a7b142771f388d40a425..06bfd782b59ce5b9a5421f3774bf658f9f225ba9 100644 (file)
@@ -6,7 +6,7 @@
 use rustc_attr as attr;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
 use rustc_hir as hir;
-use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
+use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
 use smallvec::SmallVec;
 use std::mem;
 
@@ -114,6 +114,11 @@ fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F) {
 
         self.node_id_hashing_mode = prev_hash_node_ids;
     }
+
+    #[inline]
+    fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash {
+        self.local_def_path_hash(def_index)
+    }
 }
 
 impl<'a> ToStableHashKey<StableHashingContext<'a>> for DefId {
index b843bc17d2c6c52ad34cf5b43b0f057e65d7a326..2a8e34ddc2521b684a3cfe05f4061a1b01b09eb3 100644 (file)
@@ -61,6 +61,10 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
             desc { "index HIR" }
         }
 
+        query hir_module_items(key: DefId) -> &'tcx hir::ModuleItems {
+            eval_always
+        }
+
         query hir_owner(key: DefId) -> &'tcx HirOwner<'tcx> {
             eval_always
         }
index 65bb4b9a6a1f2bcdc08a697acaf1d46b1e23a23d..88cc863933198ed35e3e239b8c58f62719e713b3 100644 (file)
@@ -597,7 +597,7 @@ pub struct WhereEqPredicate<'hir> {
     pub rhs_ty: &'hir Ty<'hir>,
 }
 
-#[derive(RustcEncodable, RustcDecodable, Debug)]
+#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
 pub struct ModuleItems {
     // Use BTreeSets here so items are in the same order as in the
     // list of all items in Crate
index 9756edc3f4dcb03b5c3c3c287966e47b38fde0f8..7ca2bfded3c2d9921956296fb13ec81a39283a02 100644 (file)
@@ -1,10 +1,11 @@
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
+use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
 
 use crate::hir::{
     BodyId, Expr, ImplItem, ImplItemId, Item, ItemId, Mod, TraitItem, TraitItemId, Ty,
     VisibilityKind,
 };
-use crate::hir_id::HirId;
+use crate::hir_id::{HirId, ItemLocalId};
+use rustc_span::def_id::{DefIndex, DefPathHash};
 
 /// Requirements for a `StableHashingContext` to be used in this crate.
 /// This is a hack to allow using the `HashStable_Generic` derive macro
@@ -20,6 +21,35 @@ pub trait HashStableContext:
     fn hash_hir_ty(&mut self, _: &Ty<'_>, hasher: &mut StableHasher);
     fn hash_hir_visibility_kind(&mut self, _: &VisibilityKind<'_>, hasher: &mut StableHasher);
     fn hash_hir_item_like<F: FnOnce(&mut Self)>(&mut self, f: F);
+    fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash;
+}
+
+impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
+    type KeyType = (DefPathHash, ItemLocalId);
+
+    #[inline]
+    fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
+        let def_path_hash = hcx.local_def_path_hash(self.owner);
+        (def_path_hash, self.local_id)
+    }
+}
+
+impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
+    type KeyType = (DefPathHash, ItemLocalId);
+
+    #[inline]
+    fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
+        self.hir_id.to_stable_hash_key(hcx)
+    }
+}
+
+impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
+    type KeyType = (DefPathHash, ItemLocalId);
+
+    #[inline]
+    fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
+        self.hir_id.to_stable_hash_key(hcx)
+    }
 }
 
 impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HirId {
index 5f186f0e1b2bd4ca68488671219e54102c96a1c5..7686a507ff5266f742547e0598a4ed6c15939710 100644 (file)
@@ -120,7 +120,7 @@ fn process_attrs(&mut self, hir_id: hir::HirId, attrs: &[ast::Attribute]) {
             if attr.check_name(sym::rustc_if_this_changed) {
                 let dep_node_interned = self.argument(attr);
                 let dep_node = match dep_node_interned {
-                    None => def_path_hash.to_dep_node(DepKind::Hir),
+                    None => DepNode::from_def_path_hash(def_path_hash, DepKind::Hir),
                     Some(n) => match DepNode::from_label_string(&n.as_str(), def_path_hash) {
                         Ok(n) => n,
                         Err(()) => {
index 1d8eb0cde468af20fb6008e4688ca89a354a1ab8..7126f86c326c614d4575228b34f312aac16e2e90 100644 (file)
@@ -4,7 +4,7 @@
 use crate::rmeta::table::{FixedSizeEncoding, Table};
 use crate::rmeta::*;
 
-use rustc::dep_graph::{self, DepNodeIndex};
+use rustc::dep_graph::{self, DepNode, DepNodeIndex};
 use rustc::hir::exports::Export;
 use rustc::hir::map::definitions::DefPathTable;
 use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
@@ -1607,7 +1607,8 @@ fn get_crate_dep_node_index(&self, tcx: TyCtxt<'tcx>) -> DepNodeIndex {
             // would always write the same value.
 
             let def_path_hash = self.def_path_hash(CRATE_DEF_INDEX);
-            let dep_node = def_path_hash.to_dep_node(dep_graph::DepKind::CrateMetadata);
+            let dep_node =
+                DepNode::from_def_path_hash(def_path_hash, dep_graph::DepKind::CrateMetadata);
 
             dep_node_index = tcx.dep_graph.dep_node_index_of(&dep_node);
             assert!(dep_node_index != DepNodeIndex::INVALID);
index 66cdf46bd4e5febcef386a39b33e75b63562a4d3..a2944782e91d4fbace3414b7e8f5ecf9e4f33ed2 100644 (file)
@@ -1,8 +1,11 @@
 use crate::HashStableContext;
+use rustc_data_structures::fingerprint::Fingerprint;
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_data_structures::AtomicRef;
 use rustc_index::vec::Idx;
+use rustc_macros::HashStable_Generic;
 use rustc_serialize::{Decoder, Encoder};
+use std::borrow::Borrow;
 use std::fmt;
 use std::{u32, u64};
 
@@ -102,6 +105,28 @@ fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
     }
 }
 
+#[derive(
+    Copy,
+    Clone,
+    Hash,
+    PartialEq,
+    Eq,
+    PartialOrd,
+    Ord,
+    Debug,
+    RustcEncodable,
+    RustcDecodable,
+    HashStable_Generic
+)]
+pub struct DefPathHash(pub Fingerprint);
+
+impl Borrow<Fingerprint> for DefPathHash {
+    #[inline]
+    fn borrow(&self) -> &Fingerprint {
+        &self.0
+    }
+}
+
 rustc_index::newtype_index! {
     /// A DefIndex is an index into the hir-map for a crate, identifying a
     /// particular definition. It should really be considered an interned