Skip to content

Commit 6f5329c

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 d3dd34a + 29b5718 commit 6f5329c

File tree

8 files changed

+81
-12
lines changed

8 files changed

+81
-12
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

+11-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,17 @@ 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: &[u8; 32] = hash.as_bytes();
163+
164+
let p0 = u64::from_le_bytes(bytes[0..8].try_into().unwrap());
165+
let p1 = u64::from_le_bytes(bytes[8..16].try_into().unwrap());
166+
let p2 = u64::from_le_bytes(bytes[16..24].try_into().unwrap());
167+
let p3 = u64::from_le_bytes(bytes[24..32].try_into().unwrap());
168+
169+
// See https://stackoverflow.com/a/27952689 on why this function is
170+
// implemented this way.
171+
Fingerprint(p0.wrapping_mul(3).wrapping_add(p1), p2.wrapping_mul(3).wrapping_add(p3))
163172
}
164173
}
165174

compiler/rustc_data_structures/src/hashes.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,21 @@ 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+
66+
let p0 = u64::from_le_bytes(bytes[0..8].try_into().unwrap());
67+
let p1 = u64::from_le_bytes(bytes[8..16].try_into().unwrap());
68+
let p2 = u64::from_le_bytes(bytes[16..24].try_into().unwrap());
69+
let p3 = u64::from_le_bytes(bytes[24..32].try_into().unwrap());
70+
71+
// See https://stackoverflow.com/a/27952689 on why this function is
72+
// implemented this way.
73+
let m0 = p0.wrapping_mul(3).wrapping_add(p1);
74+
let m1 = p2.wrapping_mul(3).wrapping_add(p3);
75+
let h = m0.wrapping_mul(3).wrapping_add(m1);
76+
77+
Self { inner: h }
6578
}
6679
}
6780

@@ -127,8 +140,20 @@ impl FromStableHash for Hash128 {
127140
type Hash = StableHasherHash;
128141

129142
#[inline]
130-
fn from(StableHasherHash([_0, _1]): Self::Hash) -> Self {
131-
Self { inner: u128::from(_0) | (u128::from(_1) << 64) }
143+
fn from(hash: Self::Hash) -> Self {
144+
let bytes = hash.as_bytes();
145+
146+
let p0 = u64::from_le_bytes(bytes[0..8].try_into().unwrap());
147+
let p1 = u64::from_le_bytes(bytes[8..16].try_into().unwrap());
148+
let p2 = u64::from_le_bytes(bytes[16..24].try_into().unwrap());
149+
let p3 = u64::from_le_bytes(bytes[24..32].try_into().unwrap());
150+
151+
// See https://stackoverflow.com/a/27952689 on why this function is
152+
// implemented this way.
153+
let upper = p0.wrapping_mul(3).wrapping_add(p1);
154+
let lower = p2.wrapping_mul(3).wrapping_add(p3);
155+
156+
Self { inner: u128::from(lower) | (u128::from(upper) << 64) }
132157
}
133158
}
134159

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/opt-dist/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
155155
.artifact_dir(Utf8PathBuf::from("/tmp/tmp-multistage/opt-artifacts"))
156156
.build_dir(checkout_dir.join("obj"))
157157
.shared_llvm(true)
158-
.use_bolt(true)
158+
.use_bolt(false)
159159
.skipped_tests(vec![
160160
// Fails because of linker errors, as of June 2023.
161161
"tests/ui/process/nofile-limit.rs".to_string(),

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)