Skip to content

Commit 9464a6f

Browse files
committed
update to allow blake3 per rustc MCP resolution
1 parent 078372d commit 9464a6f

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

Cargo.lock

+26
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ dependencies = [
237237
"object 0.35.0",
238238
]
239239

240+
[[package]]
241+
name = "arrayref"
242+
version = "0.3.7"
243+
source = "registry+https://github.com/rust-lang/crates.io-index"
244+
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
245+
240246
[[package]]
241247
name = "arrayvec"
242248
version = "0.7.4"
@@ -356,6 +362,19 @@ version = "2.5.0"
356362
source = "registry+https://github.com/rust-lang/crates.io-index"
357363
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
358364

365+
[[package]]
366+
name = "blake3"
367+
version = "1.5.2"
368+
source = "registry+https://github.com/rust-lang/crates.io-index"
369+
checksum = "3d08263faac5cde2a4d52b513dadb80846023aade56fcd8fc99ba73ba8050e92"
370+
dependencies = [
371+
"arrayref",
372+
"arrayvec",
373+
"cc",
374+
"cfg-if",
375+
"constant_time_eq",
376+
]
377+
359378
[[package]]
360379
name = "block-buffer"
361380
version = "0.10.4"
@@ -842,6 +861,12 @@ dependencies = [
842861
"windows-sys 0.52.0",
843862
]
844863

864+
[[package]]
865+
name = "constant_time_eq"
866+
version = "0.3.0"
867+
source = "registry+https://github.com/rust-lang/crates.io-index"
868+
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
869+
845870
[[package]]
846871
name = "core"
847872
version = "0.0.0"
@@ -4754,6 +4779,7 @@ dependencies = [
47544779
name = "rustc_span"
47554780
version = "0.0.0"
47564781
dependencies = [
4782+
"blake3",
47574783
"derivative",
47584784
"indexmap",
47594785
"itoa",

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
636636
rustc_span::SourceFileHashAlgorithm::Md5 => llvm::ChecksumKind::MD5,
637637
rustc_span::SourceFileHashAlgorithm::Sha1 => llvm::ChecksumKind::SHA1,
638638
rustc_span::SourceFileHashAlgorithm::Sha256 => llvm::ChecksumKind::SHA256,
639+
rustc_span::SourceFileHashAlgorithm::Blake3 => llvm::ChecksumKind::None,
639640
};
640641
let hash_value = hex_encode(source_file.src_hash.hash_bytes());
641642

compiler/rustc_span/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
blake3 = "1.5.2"
89
derivative = "2.2.0"
910
indexmap = { version = "2.0.0" }
1011
itoa = "1.0"

compiler/rustc_span/src/lib.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -1458,13 +1458,14 @@ pub enum SourceFileHashAlgorithm {
14581458
Md5,
14591459
Sha1,
14601460
Sha256,
1461+
Blake3,
14611462
}
14621463

14631464
impl SourceFileHashAlgorithm {
14641465
pub fn supported_in_cargo(&self) -> bool {
14651466
match self {
14661467
Self::Md5 | Self::Sha1 => false,
1467-
Self::Sha256 => true,
1468+
Self::Sha256 | Self::Blake3 => true,
14681469
}
14691470
}
14701471
}
@@ -1475,6 +1476,7 @@ impl Display for SourceFileHashAlgorithm {
14751476
Self::Md5 => "md5",
14761477
Self::Sha1 => "sha1",
14771478
Self::Sha256 => "sha256",
1479+
Self::Blake3 => "blake3",
14781480
})
14791481
}
14801482
}
@@ -1487,6 +1489,7 @@ impl FromStr for SourceFileHashAlgorithm {
14871489
"md5" => Ok(SourceFileHashAlgorithm::Md5),
14881490
"sha1" => Ok(SourceFileHashAlgorithm::Sha1),
14891491
"sha256" => Ok(SourceFileHashAlgorithm::Sha256),
1492+
"blake3" => Ok(SourceFileHashAlgorithm::Blake3),
14901493
_ => Err(()),
14911494
}
14921495
}
@@ -1526,6 +1529,7 @@ impl SourceFileHash {
15261529
SourceFileHashAlgorithm::Sha256 => {
15271530
value.copy_from_slice(&Sha256::digest(data));
15281531
}
1532+
SourceFileHashAlgorithm::Blake3 => value.copy_from_slice(blake3::hash(data).as_bytes()),
15291533
};
15301534
hash
15311535
}
@@ -1534,11 +1538,9 @@ impl SourceFileHash {
15341538
let mut hash = SourceFileHash { kind, value: Default::default() };
15351539
let len = hash.hash_len();
15361540
let value = &mut hash.value[..len];
1537-
// Buffer size is the same as default for std::io::BufReader.
1538-
// This was completely arbitrary and can probably be improved upon.
1539-
//
1540-
// Mostly I just don't want to read the entire file into memory at once if it's massive.
1541-
let mut buf = vec![0; 8 * 1024];
1541+
// Buffer size is the recommended amount to fully leverage SIMD instructions on AVX-512 as per
1542+
// blake3 documentation.
1543+
let mut buf = vec![0; 16 * 1024];
15421544

15431545
fn digest<T>(
15441546
mut hasher: T,
@@ -1596,6 +1598,18 @@ impl SourceFileHash {
15961598
value,
15971599
)?;
15981600
}
1601+
SourceFileHashAlgorithm::Blake3 => {
1602+
digest(
1603+
blake3::Hasher::new(),
1604+
|h, b| {
1605+
h.update(b);
1606+
},
1607+
|h, out| out.copy_from_slice(h.finalize().as_bytes()),
1608+
src,
1609+
&mut buf,
1610+
value,
1611+
)?;
1612+
}
15991613
}
16001614
Ok(hash)
16011615
}
@@ -1615,7 +1629,7 @@ impl SourceFileHash {
16151629
match self.kind {
16161630
SourceFileHashAlgorithm::Md5 => 16,
16171631
SourceFileHashAlgorithm::Sha1 => 20,
1618-
SourceFileHashAlgorithm::Sha256 => 32,
1632+
SourceFileHashAlgorithm::Sha256 | SourceFileHashAlgorithm::Blake3 => 32,
16191633
}
16201634
}
16211635
}

0 commit comments

Comments
 (0)