Open and answer this issue on GitHub.
blocked, safety · opened 2026-11-22 · updated 2026-11-29 · 1 comment
Records ADR-proof-kani-v1 (Kani checks the prover’s proofs on the emitted Rust, in a mode of its own); the third of its six issues. Needs #2721
In the Kani mode the emitter writes, on each unchanged for loop the prover proved, the invariant the prover used as #[kani::loop_invariant(…)], so Kani checks the induction the prover claims. Loops Kani cannot take a contract on are unwound and reported.
ADR-proof-kani-v1 D2 (invariants on the unchanged for), D4 (the invariant is an obligation, never an assumption), D5 (loops outside Kani’s coverage are unwound and reported). ADR-361 D4, D5, D10 (what a loop’s invariant is). ADR-306 D19 (a dropped check).
bounding_loop_invariant (bounds_walk.nika); the walk’s result per function by bounds_proven (bounds_proven.nika), which takes through_loops, facts and ledgers.for in emit_stmt.nika (the arm writing f"{allowed}for {bound} in "); it does not see the walk’s invariants.tests/compiler/tests/kani_mode_writes_the_loop_invariant.nika, a counted loop over xs.len() with a dropped read; its .stdout is its output, and the lowered loop with the switch is shown by the issue-1 probe run (quoted in the report).0 <= k && (k as usize) <= xs.len()); a fact with no Rust spelling (a ledger fact over a field, ADR-306 D21) drops the whole invariant for that loop and the loop goes to item 3. Test: the same program with a loop over xs.iter() and one with a while over a counter.#[kani::unwind(9)] (the vector bound of the harness plus one); the report line is unwound: f: loop at FILE:LINE: <why>. Test: a loop over a map’s values_mut()..stderr.Done when, with the Kani mode on, cargo kani -Z loop-contracts -Z function-contracts proves every loop of the first issue’s probe program by its invariant (no unwinding), refuses the weakened one of item 4, and reports each unwound loop by item 3’s line; without the switch the lowering is byte-identical (lower-std diff empty, quoted). Item 4’s commit carries Fixes #N. Each surprise is a Found: line in the report, never a new issue number.
bounds_walk.nika or bounds_proven.nika (the record), emit_stmt.nika (the attribute) and their lowered .rs (output). No Rust by hand.--bounds row of the suite the same); the lowering without the switch; the walk’s time without the switch (nothing is recorded then).kani::assume of the invariant (ADR-proof-kani-v1 D4): it would let a wrong prover pass.for into while (option E): Kani takes for contracts since 0.66.Related decision: ADR-342 D6 (owner, 2026-11-29, 56f8c93f). A chain over a sequence (xs.iter().map(f).sum(), io::lines().filter(...)) is lowered as a loop the compiler writes instead of the language below’s adapters. Such a chain then has a for or while in the emitted code that this issue’s invariant can stand on, instead of a loop inside std’s iterator that Kani has to unwind. The first build is #2899 (chains over io::lines()).
Generated by Claude Code