about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <ariel.byd@gmail.com>2017-09-05 15:19:07 +0300
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2017-09-05 15:19:07 +0300
commitd14ed92f6b5aa23fd06f8affe4554f2c370bc79d (patch)
tree76bb30e32ada0184124c1f7a8d699b5612f15a23 /src
parent2f1ef9ef1181298d46e79d5dde6bafeb6483926f (diff)
downloadrust-d14ed92f6b5aa23fd06f8affe4554f2c370bc79d.tar.gz
rust-d14ed92f6b5aa23fd06f8affe4554f2c370bc79d.zip
Avoid hashing when creating a DepNode from a HirId
Instead, combine the already-present DefPathHash with the 32-bit
ItemLocalIndex.

Should fix #44323.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/dep_graph/dep_node.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs
index c438944cf01..57be2eb4c24 100644
--- a/src/librustc/dep_graph/dep_node.rs
+++ b/src/librustc/dep_graph/dep_node.rs
@@ -62,7 +62,7 @@
 
 use hir::def_id::{CrateNum, DefId};
 use hir::map::DefPathHash;
-use hir::HirId;
+use hir::{HirId, ItemLocalId};
 
 use ich::Fingerprint;
 use ty::{TyCtxt, Instance, InstanceDef};
@@ -638,6 +638,25 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefIdList
     }
 }
 
+impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (HirId,) {
+    const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
+
+    // We actually would not need to specialize the implementation of this
+    // method but it's faster to combine the hashes than to instantiate a full
+    // hashing context and stable-hashing state.
+    fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
+        let (HirId {
+            owner,
+            local_id: ItemLocalId(local_id),
+        },) = *self;
+
+        let def_path_hash = tcx.def_path_hash(DefId::local(owner));
+        let local_id = Fingerprint::from_smaller_hash(local_id as u64);
+
+        def_path_hash.0.combine(local_id)
+    }
+}
+
 /// A "work product" corresponds to a `.o` (or other) file that we
 /// save in between runs. These ids do not have a DefId but rather
 /// some independent path or string that persists between runs without