diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2021-01-27 14:28:07 +0100 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo.de> | 2021-02-02 17:40:29 +0100 |
| commit | 22d489be76271e36259ab1c7f76dbd88e6fdca2e (patch) | |
| tree | 92663d83350193797f1d201b16416056aea80491 /compiler/rustc_data_structures | |
| parent | a3ed564c130ec3f19e933a9ea31faca5a717ce91 (diff) | |
| download | rust-22d489be76271e36259ab1c7f76dbd88e6fdca2e.tar.gz rust-22d489be76271e36259ab1c7f76dbd88e6fdca2e.zip | |
Let a portion of DefPathHash uniquely identify the DefPath's crate.
This allows to directly map from a DefPathHash to the crate it originates from, without constructing side tables to do that mapping. It also allows to reliably and cheaply check for DefPathHash collisions.
Diffstat (limited to 'compiler/rustc_data_structures')
| -rw-r--r-- | compiler/rustc_data_structures/src/fingerprint.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_data_structures/src/fingerprint.rs b/compiler/rustc_data_structures/src/fingerprint.rs index 08c3419a842..fecc51324cc 100644 --- a/compiler/rustc_data_structures/src/fingerprint.rs +++ b/compiler/rustc_data_structures/src/fingerprint.rs @@ -7,19 +7,30 @@ use std::hash::{Hash, Hasher}; use std::mem::{self, MaybeUninit}; #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Copy)] +#[repr(C)] pub struct Fingerprint(u64, u64); impl Fingerprint { pub const ZERO: Fingerprint = Fingerprint(0, 0); #[inline] + pub fn new(_0: u64, _1: u64) -> Fingerprint { + Fingerprint(_0, _1) + } + + #[inline] pub fn from_smaller_hash(hash: u64) -> Fingerprint { Fingerprint(hash, hash) } #[inline] pub fn to_smaller_hash(&self) -> u64 { - self.0 + // Even though both halves of the fingerprint are expected to be good + // quality hash values, let's still combine the two values because the + // Fingerprints in DefPathHash have the StableCrateId portion which is + // the same for all DefPathHashes from the same crate. Combining the + // two halfs makes sure we get a good quality hash in such cases too. + self.0.wrapping_mul(3).wrapping_add(self.1) } #[inline] @@ -93,7 +104,7 @@ impl FingerprintHasher for crate::unhash::Unhasher { #[inline] fn write_fingerprint(&mut self, fingerprint: &Fingerprint) { // `Unhasher` only wants a single `u64` - self.write_u64(fingerprint.0); + self.write_u64(fingerprint.0.wrapping_add(fingerprint.1)); } } |
