Skip to content

Commit 86b37e8

Browse files
authored
Autoharness: use SHA-1 to produce codegen unit file names (#4370)
File names previously had the full Rust access path encoded in the name. This may exceed (OS-specific) file name length limits. SHA-1 hash the (mangled) access path for constant-width file names instead (while maintaining low probability of collision). Resolves: #4367 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent bfb22f1 commit 86b37e8

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

Cargo.lock

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ version = "2.9.4"
175175
source = "registry+https://github.com/rust-lang/crates.io-index"
176176
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
177177

178+
[[package]]
179+
name = "block-buffer"
180+
version = "0.10.4"
181+
source = "registry+https://github.com/rust-lang/crates.io-index"
182+
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
183+
dependencies = [
184+
"generic-array",
185+
]
186+
178187
[[package]]
179188
name = "brownstone"
180189
version = "3.0.0"
@@ -435,6 +444,12 @@ dependencies = [
435444
"windows-sys 0.61.0",
436445
]
437446

447+
[[package]]
448+
name = "const-oid"
449+
version = "0.9.6"
450+
source = "registry+https://github.com/rust-lang/crates.io-index"
451+
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
452+
438453
[[package]]
439454
name = "convert_case"
440455
version = "0.6.0"
@@ -466,6 +481,15 @@ dependencies = [
466481
"tracing",
467482
]
468483

484+
[[package]]
485+
name = "cpufeatures"
486+
version = "0.2.17"
487+
source = "registry+https://github.com/rust-lang/crates.io-index"
488+
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
489+
dependencies = [
490+
"libc",
491+
]
492+
469493
[[package]]
470494
name = "crossbeam-deque"
471495
version = "0.8.6"
@@ -514,6 +538,16 @@ dependencies = [
514538
"winapi",
515539
]
516540

541+
[[package]]
542+
name = "crypto-common"
543+
version = "0.1.6"
544+
source = "registry+https://github.com/rust-lang/crates.io-index"
545+
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
546+
dependencies = [
547+
"generic-array",
548+
"typenum",
549+
]
550+
517551
[[package]]
518552
name = "csv"
519553
version = "1.3.1"
@@ -608,6 +642,17 @@ version = "0.4.0"
608642
source = "registry+https://github.com/rust-lang/crates.io-index"
609643
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
610644

645+
[[package]]
646+
name = "digest"
647+
version = "0.10.7"
648+
source = "registry+https://github.com/rust-lang/crates.io-index"
649+
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
650+
dependencies = [
651+
"block-buffer",
652+
"const-oid",
653+
"crypto-common",
654+
]
655+
611656
[[package]]
612657
name = "displaydoc"
613658
version = "0.2.5"
@@ -747,6 +792,16 @@ dependencies = [
747792
"percent-encoding",
748793
]
749794

795+
[[package]]
796+
name = "generic-array"
797+
version = "0.14.7"
798+
source = "registry+https://github.com/rust-lang/crates.io-index"
799+
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
800+
dependencies = [
801+
"typenum",
802+
"version_check",
803+
]
804+
750805
[[package]]
751806
name = "getopts"
752807
version = "0.2.24"
@@ -1107,6 +1162,7 @@ dependencies = [
11071162
"regex",
11081163
"serde",
11091164
"serde_json",
1165+
"sha1-checked",
11101166
"strum",
11111167
"strum_macros",
11121168
"syn",
@@ -1927,6 +1983,27 @@ dependencies = [
19271983
"unsafe-libyaml",
19281984
]
19291985

1986+
[[package]]
1987+
name = "sha1"
1988+
version = "0.10.6"
1989+
source = "registry+https://github.com/rust-lang/crates.io-index"
1990+
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
1991+
dependencies = [
1992+
"cfg-if",
1993+
"cpufeatures",
1994+
"digest",
1995+
]
1996+
1997+
[[package]]
1998+
name = "sha1-checked"
1999+
version = "0.10.0"
2000+
source = "registry+https://github.com/rust-lang/crates.io-index"
2001+
checksum = "89f599ac0c323ebb1c6082821a54962b839832b03984598375bff3975b804423"
2002+
dependencies = [
2003+
"digest",
2004+
"sha1",
2005+
]
2006+
19302007
[[package]]
19312008
name = "sharded-slab"
19322009
version = "0.1.7"
@@ -2369,6 +2446,12 @@ version = "1.0.3"
23692446
source = "registry+https://github.com/rust-lang/crates.io-index"
23702447
checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c"
23712448

2449+
[[package]]
2450+
name = "typenum"
2451+
version = "1.18.0"
2452+
source = "registry+https://github.com/rust-lang/crates.io-index"
2453+
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
2454+
23722455
[[package]]
23732456
name = "unicode-ident"
23742457
version = "1.0.19"

kani-compiler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ quote = "1.0.36"
2020
regex = "1.11.1"
2121
serde = { version = "1", optional = true }
2222
serde_json = "1"
23+
sha1-checked = "0.10.0"
2324
strum = "0.27.1"
2425
strum_macros = "0.27.1"
2526
syn = { version = "2.0.72", features = ["parsing", "extra-traits"] }

kani-compiler/src/kani_middle/metadata.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use rustc_middle::ty::TyCtxt;
1414
use rustc_public::mir::mono::Instance;
1515
use rustc_public::{CrateDef, CrateItems, DefId};
1616

17+
use sha1_checked::Sha1;
18+
1719
/// Create the harness metadata for a proof harness for a given function.
1820
pub fn gen_proof_metadata(tcx: TyCtxt, instance: Instance, base_name: &Path) -> HarnessMetadata {
1921
let def = instance.def;
@@ -122,8 +124,13 @@ pub fn gen_automatic_proof_metadata(
122124

123125
// Leave the concrete playback instrumentation for now, but this feature does not actually support concrete playback.
124126
let loc = SourceLocation::new(fn_to_verify.body().unwrap().span);
125-
let file_stem =
126-
format!("{}_{mangled_name}_autoharness", base_name.file_stem().unwrap().to_str().unwrap());
127+
let sha1_result = Sha1::try_digest(mangled_name);
128+
assert!(!sha1_result.has_collision());
129+
let file_stem = format!(
130+
"{}_{:x}_autoharness",
131+
base_name.file_stem().unwrap().to_str().unwrap(),
132+
sha1_result.hash()
133+
);
127134
let model_file = base_name.with_file_name(file_stem).with_extension(ArtifactType::SymTabGoto);
128135

129136
let kani_attributes = KaniAttributes::for_instance(tcx, *fn_to_verify);

0 commit comments

Comments
 (0)