Skip to content

Commit 1049c0b

Browse files
author
Carolyn Zech
committed
improvement: just check for DefId
1 parent 0d1660a commit 1049c0b

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

kani-compiler/src/kani_middle/transform/automatic.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -264,37 +264,21 @@ impl AutomaticArbitraryPass {
264264
/// Transform the dummy body of an automatic_harness Kani intrinsic to be a proof harness for a given function.
265265
#[derive(Debug)]
266266
pub struct AutomaticHarnessPass {
267-
/// The FnDef of KaniModel::Any
268267
kani_any: FnDef,
269268
init_contracts_hook: Instance,
270-
/// All of the automatic harness Instances that we generated in the CodegenUnits constructor
271-
automatic_harnesses: Vec<Instance>,
269+
kani_autoharness_intrinsic: FnDef,
272270
}
273271

274272
impl AutomaticHarnessPass {
275-
// FIXME: this is a bit clunky.
276-
// Historically, in codegen_crate, we reset the BodyTransformation cache on a per-unit basis,
277-
// so the BodyTransformation constructor only accepts a CodegenUnit and thus this constructor can only accept a unit.
278-
// Later, we changed codegen to reset the cache on a per-harness basis (for uninitialized memory instrumentation).
279-
// So BodyTransformation should really be changed to reflect that, so that this constructor can just save the one automatic harness it should transform
280-
// and not all of the possibilities.
281-
pub fn new(unit: &CodegenUnit, query_db: &QueryDb) -> Self {
273+
pub fn new(query_db: &QueryDb) -> Self {
282274
let kani_fns = query_db.kani_functions();
283-
let harness_intrinsic = *kani_fns.get(&KaniIntrinsic::AutomaticHarness.into()).unwrap();
275+
let kani_autoharness_intrinsic =
276+
*kani_fns.get(&KaniIntrinsic::AutomaticHarness.into()).unwrap();
284277
let kani_any = *kani_fns.get(&KaniModel::Any.into()).unwrap();
285278
let init_contracts_hook = *kani_fns.get(&KaniHook::InitContracts.into()).unwrap();
286279
let init_contracts_hook =
287280
Instance::resolve(init_contracts_hook, &GenericArgs(vec![])).unwrap();
288-
let automatic_harnesses = unit
289-
.harnesses
290-
.iter()
291-
.cloned()
292-
.filter(|harness| {
293-
let (def, _) = harness.ty().kind().fn_def().unwrap();
294-
def == harness_intrinsic
295-
})
296-
.collect::<Vec<_>>();
297-
Self { kani_any, init_contracts_hook, automatic_harnesses }
281+
Self { kani_any, init_contracts_hook, kani_autoharness_intrinsic }
298282
}
299283
}
300284

@@ -316,7 +300,7 @@ impl TransformPass for AutomaticHarnessPass {
316300
fn transform(&mut self, tcx: TyCtxt, body: Body, instance: Instance) -> (bool, Body) {
317301
debug!(function=?instance.name(), "AutomaticHarnessPass::transform");
318302

319-
if !self.automatic_harnesses.contains(&instance) {
303+
if instance.def.def_id() != self.kani_autoharness_intrinsic.def_id() {
320304
return (false, body);
321305
}
322306

kani-compiler/src/kani_middle/transform/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl BodyTransformation {
7575
let safety_check_type = CheckType::new_safety_check_assert_assume(queries);
7676
let unsupported_check_type = CheckType::new_unsupported_check_assert_assume_false(queries);
7777
// This has to come first, since creating harnesses affects later stubbing and contract passes.
78-
transformer.add_pass(queries, AutomaticHarnessPass::new(unit, queries));
78+
transformer.add_pass(queries, AutomaticHarnessPass::new(queries));
7979
transformer.add_pass(queries, AutomaticArbitraryPass::new(unit, queries));
8080
transformer.add_pass(queries, FnStubPass::new(&unit.stubs));
8181
transformer.add_pass(queries, ExternFnStubPass::new(&unit.stubs));

0 commit comments

Comments
 (0)