Skip to content

Commit 821161a

Browse files
committed
Switch StableHasher from SipHash to HighwayHash
This changes the hash in the legacy symbol mangling format - if this is undesired, we could use SipHash just for symbol mangling.
1 parent 60158f4 commit 821161a

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,12 @@ version = "0.4.2"
15781578
source = "registry+https://github.com/rust-lang/crates.io-index"
15791579
checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
15801580

1581+
[[package]]
1582+
name = "highway"
1583+
version = "0.6.3"
1584+
source = "registry+https://github.com/rust-lang/crates.io-index"
1585+
checksum = "66920f2e905206a4aca271ae71f1638f10854e3739f162fc465fb8aecce44446"
1586+
15811587
[[package]]
15821588
name = "home"
15831589
version = "0.5.3"
@@ -3845,6 +3851,7 @@ dependencies = [
38453851
"cfg-if 0.1.10",
38463852
"crossbeam-utils 0.7.2",
38473853
"ena",
3854+
"highway",
38483855
"indexmap",
38493856
"jobserver",
38503857
"libc",

compiler/rustc_data_structures/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ measureme = "9.1.0"
2929
libc = "0.2"
3030
stacker = "0.1.12"
3131
tempfile = "3.0.5"
32+
highway = "0.6.3"
3233

3334
[dependencies.parking_lot]
3435
version = "0.11"

compiler/rustc_data_structures/src/stable_hasher.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::sip128::SipHasher128;
1+
use highway::{HighwayHash, HighwayHasher, Key};
22
use rustc_index::bit_set;
33
use rustc_index::vec;
44
use smallvec::SmallVec;
@@ -16,7 +16,7 @@ mod tests;
1616
/// hashing and the architecture dependent `isize` and `usize` types are
1717
/// extended to 64 bits if needed.
1818
pub struct StableHasher {
19-
state: SipHasher128,
19+
state: HighwayHasher,
2020
}
2121

2222
impl ::std::fmt::Debug for StableHasher {
@@ -32,7 +32,7 @@ pub trait StableHasherResult: Sized {
3232
impl StableHasher {
3333
#[inline]
3434
pub fn new() -> Self {
35-
StableHasher { state: SipHasher128::new_with_keys(0, 0) }
35+
StableHasher { state: HighwayHasher::new(Key([0, 0, 0, 0])) }
3636
}
3737

3838
#[inline]
@@ -50,14 +50,15 @@ impl StableHasherResult for u128 {
5050

5151
impl StableHasherResult for u64 {
5252
fn finish(hasher: StableHasher) -> Self {
53-
hasher.finalize().0
53+
hasher.state.finalize64()
5454
}
5555
}
5656

5757
impl StableHasher {
5858
#[inline]
5959
pub fn finalize(self) -> (u64, u64) {
60-
self.state.finish128()
60+
let [first, second] = self.state.finalize128();
61+
(first, second)
6162
}
6263
}
6364

@@ -68,7 +69,7 @@ impl Hasher for StableHasher {
6869

6970
#[inline]
7071
fn write(&mut self, bytes: &[u8]) {
71-
self.state.write(bytes);
72+
self.state.append(bytes);
7273
}
7374

7475
#[inline]

src/tools/tidy/src/deps.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
105105
"gsgdt",
106106
"hashbrown",
107107
"hermit-abi",
108+
"highway",
108109
"humantime",
109110
"indexmap",
110111
"instant",

0 commit comments

Comments
 (0)