Skip to content

Commit 8f04d57

Browse files
committed
Auto merge of rust-lang#127754 - Urgau:blake3-hash, r=<try>
[perf] Change stable hasher to Blake3 Based on rust-lang/rustc-stable-hash@main...Urgau:rustc-stable-hash:blake3 cc `@michaelwoerister` r? ghost
2 parents 0da95bd + 38b97bc commit 8f04d57

File tree

7 files changed

+52
-11
lines changed

7 files changed

+52
-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.

src/tools/tidy/src/deps.rs

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const LICENSES: &[&str] = &[
2121
"Apache-2.0",
2222
"Apache-2.0/MIT",
2323
"BSD-2-Clause OR Apache-2.0 OR MIT", // zerocopy
24+
"BSD-2-Clause", // arrayref
25+
"CC0-1.0 OR Apache-2.0 OR Apache-2.0 WITH LLVM-exception", // blake3
26+
"CC0-1.0 OR MIT-0 OR Apache-2.0", // constant_time_eq
2427
"ISC",
2528
"MIT / Apache-2.0",
2629
"MIT OR Apache-2.0 OR LGPL-2.1-or-later", // r-efi, r-efi-alloc
@@ -232,15 +235,18 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
232235
"annotate-snippets",
233236
"anstyle",
234237
"ar_archive_writer",
238+
"arrayref",
235239
"arrayvec",
236240
"autocfg",
237241
"bitflags",
242+
"blake3",
238243
"block-buffer",
239244
"byteorder", // via ruzstd in object in thorin-dwp
240245
"cc",
241246
"cfg-if",
242247
"cfg_aliases",
243248
"compiler_builtins",
249+
"constant_time_eq",
244250
"cpufeatures",
245251
"crc32fast",
246252
"crossbeam-channel",

src/tools/tidy/src/extdeps.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const ALLOWED_SOURCES: &[&str] = &[
99
r#""registry+https://github.com/rust-lang/crates.io-index""#,
1010
// This is `rust_team_data` used by `site` in src/tools/rustc-perf,
1111
r#""git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec""#,
12+
// WIP blake3
13+
r#""git+https://github.com/Urgau/rustc-stable-hash.git?rev=368f4ef#368f4ef468ca97fd4757c896f53349d9fa4def1b""#,
1214
];
1315

1416
/// Checks for external package sources. `root` is the path to the directory that contains the

0 commit comments

Comments
 (0)