Skip to content

Commit 56eeec9

Browse files
committed
Change stable hasher to Blake3
1 parent 0da95bd commit 56eeec9

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

Cargo.lock

+29-2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ dependencies = [
243243
"object 0.32.2",
244244
]
245245

246+
[[package]]
247+
name = "arrayref"
248+
version = "0.3.7"
249+
source = "registry+https://github.com/rust-lang/crates.io-index"
250+
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
251+
246252
[[package]]
247253
name = "arrayvec"
248254
version = "0.7.4"
@@ -362,6 +368,19 @@ version = "2.5.0"
362368
source = "registry+https://github.com/rust-lang/crates.io-index"
363369
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
364370

371+
[[package]]
372+
name = "blake3"
373+
version = "1.5.3"
374+
source = "registry+https://github.com/rust-lang/crates.io-index"
375+
checksum = "e9ec96fe9a81b5e365f9db71fe00edc4fe4ca2cc7dcb7861f0603012a7caa210"
376+
dependencies = [
377+
"arrayref",
378+
"arrayvec",
379+
"cc",
380+
"cfg-if",
381+
"constant_time_eq",
382+
]
383+
365384
[[package]]
366385
name = "block-buffer"
367386
version = "0.10.4"
@@ -848,6 +867,12 @@ dependencies = [
848867
"windows-sys 0.52.0",
849868
]
850869

870+
[[package]]
871+
name = "constant_time_eq"
872+
version = "0.3.0"
873+
source = "registry+https://github.com/rust-lang/crates.io-index"
874+
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
875+
851876
[[package]]
852877
name = "core"
853878
version = "0.0.0"
@@ -3518,8 +3543,10 @@ checksum = "5be1bdc7edf596692617627bbfeaba522131b18e06ca4df2b6b689e3c5d5ce84"
35183543
[[package]]
35193544
name = "rustc-stable-hash"
35203545
version = "0.1.0"
3521-
source = "registry+https://github.com/rust-lang/crates.io-index"
3522-
checksum = "e5c9f15eec8235d7cb775ee6f81891db79b98fd54ba1ad8fae565b88ef1ae4e2"
3546+
source = "git+https://github.com/Urgau/rustc-stable-hash.git?rev=368f4ef#368f4ef468ca97fd4757c896f53349d9fa4def1b"
3547+
dependencies = [
3548+
"blake3",
3549+
]
35233550

35243551
[[package]]
35253552
name = "rustc-std-workspace-alloc"

compiler/rustc_data_structures/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobserver_crate = { version = "0.1.28", package = "jobserver" }
1515
measureme = "11"
1616
rustc-hash = "1.1.0"
1717
rustc-rayon = { version = "0.5.0", optional = true }
18-
rustc-stable-hash = { version = "0.1.0", features = ["nightly"] }
18+
rustc-stable-hash = { git = "https://github.com/Urgau/rustc-stable-hash.git", rev = "368f4ef", features = ["nightly", "blake3"] }
1919
rustc_arena = { path = "../rustc_arena" }
2020
rustc_graphviz = { path = "../rustc_graphviz" }
2121
rustc_index = { path = "../rustc_index", package = "rustc_index" }

compiler/rustc_data_structures/src/fingerprint.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,12 @@ impl FromStableHash for Fingerprint {
158158
type Hash = StableHasherHash;
159159

160160
#[inline]
161-
fn from(StableHasherHash([_0, _1]): Self::Hash) -> Self {
162-
Fingerprint(_0, _1)
161+
fn from(hash: Self::Hash) -> Self {
162+
let bytes = hash.as_bytes();
163+
Fingerprint(
164+
u64::from_ne_bytes(bytes[0..8].try_into().unwrap()),
165+
u64::from_ne_bytes(bytes[8..16].try_into().unwrap()),
166+
)
163167
}
164168
}
165169

compiler/rustc_data_structures/src/hashes.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ impl FromStableHash for Hash64 {
6060
type Hash = StableHasherHash;
6161

6262
#[inline]
63-
fn from(StableHasherHash([_0, __1]): Self::Hash) -> Self {
64-
Self { inner: _0 }
63+
fn from(hash: Self::Hash) -> Self {
64+
let bytes = hash.as_bytes();
65+
Self { inner: u64::from_ne_bytes(bytes[0..8].try_into().unwrap()) }
6566
}
6667
}
6768

@@ -127,8 +128,9 @@ impl FromStableHash for Hash128 {
127128
type Hash = StableHasherHash;
128129

129130
#[inline]
130-
fn from(StableHasherHash([_0, _1]): Self::Hash) -> Self {
131-
Self { inner: u128::from(_0) | (u128::from(_1) << 64) }
131+
fn from(hash: Self::Hash) -> Self {
132+
let bytes = hash.as_bytes();
133+
Self { inner: u128::from_ne_bytes(bytes[0..16].try_into().unwrap()) }
132134
}
133135
}
134136

compiler/rustc_data_structures/src/stable_hasher.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ mod tests;
1111

1212
pub use crate::hashes::{Hash128, Hash64};
1313

14+
pub use rustc_stable_hash::hashers::Blake3Hash as StableHasherHash;
15+
pub use rustc_stable_hash::hashers::StableBlake3Hasher as StableHasher;
1416
pub use rustc_stable_hash::FromStableHash;
15-
pub use rustc_stable_hash::SipHasher128Hash as StableHasherHash;
16-
pub use rustc_stable_hash::StableSipHasher128 as StableHasher;
1717

1818
/// Something that implements `HashStable<CTX>` can be hashed in a way that is
1919
/// stable across multiple compilation sessions.

0 commit comments

Comments
 (0)