about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2023-04-15 13:53:50 -0400
committerBen Kimock <kimockb@gmail.com>2023-04-16 20:05:02 -0400
commit84facac97a3a13a1ea29b227d55513b58ffe7692 (patch)
tree326f52214aeaf6caee30721d55f294099662efdd /compiler
parentfd57c6b407d5f038060d7b94ce9af22ea4b0dcf0 (diff)
downloadrust-84facac97a3a13a1ea29b227d55513b58ffe7692.tar.gz
rust-84facac97a3a13a1ea29b227d55513b58ffe7692.zip
Remove some unnecessary hash truncations
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_data_structures/src/svh.rs34
-rw-r--r--compiler/rustc_middle/src/hir/map/mod.rs2
-rw-r--r--compiler/rustc_query_system/src/ich/impls_syntax.rs2
-rw-r--r--compiler/rustc_span/src/lib.rs4
4 files changed, 9 insertions, 33 deletions
diff --git a/compiler/rustc_data_structures/src/svh.rs b/compiler/rustc_data_structures/src/svh.rs
index 61654b9e8f5..b955df94f16 100644
--- a/compiler/rustc_data_structures/src/svh.rs
+++ b/compiler/rustc_data_structures/src/svh.rs
@@ -5,40 +5,30 @@
 //! mismatches where we have two versions of the same crate that were
 //! compiled from distinct sources.
 
-use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
+use crate::fingerprint::Fingerprint;
 use std::fmt;
-use std::hash::{Hash, Hasher};
 
 use crate::stable_hasher;
 
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
+#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, Hash)]
 pub struct Svh {
-    hash: u64,
+    hash: Fingerprint,
 }
 
 impl Svh {
     /// Creates a new `Svh` given the hash. If you actually want to
     /// compute the SVH from some HIR, you want the `calculate_svh`
     /// function found in `rustc_incremental`.
-    pub fn new(hash: u64) -> Svh {
+    pub fn new(hash: Fingerprint) -> Svh {
         Svh { hash }
     }
 
     pub fn as_u64(&self) -> u64 {
-        self.hash
+        self.hash.to_smaller_hash()
     }
 
     pub fn to_string(&self) -> String {
-        format!("{:016x}", self.hash)
-    }
-}
-
-impl Hash for Svh {
-    fn hash<H>(&self, state: &mut H)
-    where
-        H: Hasher,
-    {
-        self.hash.to_le().hash(state);
+        format!("{:016x}", self.hash.to_smaller_hash())
     }
 }
 
@@ -48,18 +38,6 @@ impl fmt::Display for Svh {
     }
 }
 
-impl<S: Encoder> Encodable<S> for Svh {
-    fn encode(&self, s: &mut S) {
-        s.emit_u64(self.as_u64().to_le());
-    }
-}
-
-impl<D: Decoder> Decodable<D> for Svh {
-    fn decode(d: &mut D) -> Svh {
-        Svh::new(u64::from_le(d.read_u64()))
-    }
-}
-
 impl<T> stable_hasher::HashStable<T> for Svh {
     #[inline]
     fn hash_stable(&self, ctx: &mut T, hasher: &mut stable_hasher::StableHasher) {
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs
index e551c76f8db..64aff27744f 100644
--- a/compiler/rustc_middle/src/hir/map/mod.rs
+++ b/compiler/rustc_middle/src/hir/map/mod.rs
@@ -1199,7 +1199,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
         stable_hasher.finish()
     });
 
-    Svh::new(crate_hash.to_smaller_hash())
+    Svh::new(crate_hash)
 }
 
 fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs
index 0bc811eb044..8865ecf3e05 100644
--- a/compiler/rustc_query_system/src/ich/impls_syntax.rs
+++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs
@@ -75,7 +75,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
             ref normalized_pos,
         } = *self;
 
-        (name_hash as u64).hash_stable(hcx, hasher);
+        name_hash.hash_stable(hcx, hasher);
 
         src_hash.hash_stable(hcx, hasher);
 
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index aa8859ed1a3..16583582933 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -2159,9 +2159,7 @@ where
         };
 
         Hash::hash(&TAG_VALID_SPAN, hasher);
-        // We truncate the stable ID hash and line and column numbers. The chances
-        // of causing a collision this way should be minimal.
-        Hash::hash(&(file.name_hash as u64), hasher);
+        Hash::hash(&file.name_hash, hasher);
 
         // Hash both the length and the end location (line/column) of a span. If we
         // hash only the length, for example, then two otherwise equal spans with