Skip to content

Commit ce89f61

Browse files
authored
Autoharness: Don't panic on _ argument and add _autoharness suffix to GOTO files (#3942)
Turns out that if an argument is just `_`, it doesn't have `var_debug_info` in StableMIR. So this PR changes autoharness behavior to provide `_` for the argument name when `var_debug_info` is None (instead of panicking). I don't currently know of any other cases where there wouldn't be `var_debug_info`, but we should pay extra attention to the cases where autoharness reports `_` as an argument name and update this logic if need be. I also added an `_autoharness` suffix to the generated GOTO files so that it's easier to tell which files are from autoharness and which aren't. 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 30aa50e commit ce89f61

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

kani-compiler/src/kani_middle/codegen_units.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,14 @@ fn automatic_harness_partition(
425425
if !implements_arbitrary {
426426
// Find the name of the argument by referencing var_debug_info.
427427
// Note that enumerate() starts at 0, while StableMIR argument_index starts at 1, hence the idx+1.
428-
let arg_debug_info = body
428+
let arg_name = body
429429
.var_debug_info
430430
.iter()
431431
.find(|var| {
432432
var.argument_index.is_some_and(|arg_idx| idx + 1 == usize::from(arg_idx))
433433
})
434-
.expect("Arguments should have corresponding var debug info");
435-
problematic_args.push(arg_debug_info.name.to_string())
434+
.map_or("_".to_string(), |debug_info| debug_info.name.to_string());
435+
problematic_args.push(arg_name)
436436
}
437437
}
438438
if !problematic_args.is_empty() {

kani-compiler/src/kani_middle/metadata.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ pub fn gen_automatic_proof_metadata(
101101

102102
// Leave the concrete playback instrumentation for now, but this feature does not actually support concrete playback.
103103
let loc = SourceLocation::new(fn_to_verify.body().unwrap().span);
104-
let file_stem = format!("{}_{mangled_name}", base_name.file_stem().unwrap().to_str().unwrap());
104+
let file_stem =
105+
format!("{}_{mangled_name}_autoharness", base_name.file_stem().unwrap().to_str().unwrap());
105106
let model_file = base_name.with_file_name(file_stem).with_extension(ArtifactType::SymTabGoto);
106107

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

tests/script-based-pre/cargo_autoharness_filter/filter.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ If you believe that the provided reason is incorrect and Kani should have genera
147147
|----------------------------------------+------------------------------------------------------|
148148
| no_harness::unsupported_mut_pointer | Missing Arbitrary implementation for argument(s): _y |
149149
|----------------------------------------+------------------------------------------------------|
150+
| no_harness::unsupported_no_arg_name | Missing Arbitrary implementation for argument(s): _ |
151+
|----------------------------------------+------------------------------------------------------|
150152
| no_harness::unsupported_ref | Missing Arbitrary implementation for argument(s): _y |
151153
|----------------------------------------+------------------------------------------------------|
152154
| no_harness::unsupported_slice | Missing Arbitrary implementation for argument(s): _y |

tests/script-based-pre/cargo_autoharness_filter/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,7 @@ mod no_harness {
207207
) -> DoesntImplementArbitrary {
208208
x
209209
}
210+
// Test that we correctly render the name of the argument "_" in the table of skipped functions
211+
// (this argument will have no var_debug_info from StableMIR, unlike arguments with names)
212+
fn unsupported_no_arg_name(_: &()) {}
210213
}

0 commit comments

Comments
 (0)