Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
ded56d8
add for loop transformation
thanhnguyen-aws Jun 18, 2025
2f782bf
add support for array, slice and Iter + expected tests
thanhnguyen-aws Jun 18, 2025
d0a902e
add support for Range, StepBy + expected tests
thanhnguyen-aws Jun 18, 2025
32e978c
add support for Vec + expected tests
thanhnguyen-aws Jun 18, 2025
8529488
add expected tests for quantifiers and tuples
thanhnguyen-aws Jun 18, 2025
d028bb0
add support for Zip, Chain, Map + expected tests
thanhnguyen-aws Jun 18, 2025
3fc2abc
add support for Enumerate + expected tests
thanhnguyen-aws Jun 18, 2025
8e69667
edit loop-contract docs
thanhnguyen-aws Jun 18, 2025
746311a
edit doc and some typos
thanhnguyen-aws Jun 19, 2025
475718e
Merge branch 'main' into forloopnew1
Jun 24, 2025
09f5dcc
merge origin
thanhnguyen-aws Jul 1, 2025
ded103c
restore mod.rs after merge
thanhnguyen-aws Jul 1, 2025
418f4f3
Merge branch 'main' into forloopnew1
thanhnguyen-aws Jul 14, 2025
2712069
handling StorageLive/StorageDead for forloop variables
thanhnguyen-aws Jul 17, 2025
da1666d
add expected tests for nested forloop
thanhnguyen-aws Jul 17, 2025
f9a3c2f
fix clippy
thanhnguyen-aws Jul 17, 2025
f8e2232
Merge branch 'main' into forloopnew1
thanhnguyen-aws Jul 18, 2025
8eb51e6
add for-loop rewrite method in loop-contract rfc
thanhnguyen-aws Jul 18, 2025
b4f470d
Merge branch 'forloopnew1' of https://github.com/thanhnguyen-aws/kani…
thanhnguyen-aws Jul 18, 2025
6c3e159
Update docs/src/reference/experimental/loop-contracts.md
thanhnguyen-aws Jul 22, 2025
fa5436e
Merge branch 'main' into forloopnew1
thanhnguyen-aws Jul 22, 2025
ceaed0b
add more docs
thanhnguyen-aws Jul 23, 2025
cbcc7c3
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Jul 25, 2025
8618f55
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Jul 25, 2025
42e6fc6
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Jul 25, 2025
1e4ffdd
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Jul 28, 2025
bb3f439
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Jul 28, 2025
b716b97
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Jul 28, 2025
e67148d
Update docs/src/reference/experimental/loop-contracts.md
thanhnguyen-aws Jul 28, 2025
860430f
Update docs/src/reference/experimental/loop-contracts.md
thanhnguyen-aws Jul 28, 2025
64833dd
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Jul 28, 2025
202880e
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Jul 28, 2025
57950a5
add suuport for Take
thanhnguyen-aws Jul 31, 2025
4fc4402
fix the bug of using reference in for-loop pat
thanhnguyen-aws Jul 31, 2025
6cf3afc
gerge branch 'forloopnew1' of https://github.com/thanhnguyen-aws/kani…
thanhnguyen-aws Jul 31, 2025
8bc3f59
update upstream
thanhnguyen-aws Jul 31, 2025
dfbf9eb
fix import
thanhnguyen-aws Jul 31, 2025
cf41994
change kaniindex to kani_index + kaniiterlen to kani_iter_len
thanhnguyen-aws Aug 1, 2025
9b7f100
change loop-invariant to loop invariant
thanhnguyen-aws Aug 1, 2025
2d71127
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Aug 1, 2025
12b0fda
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Aug 1, 2025
2ec15b4
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Aug 1, 2025
a837f80
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Aug 1, 2025
558460b
change kani_index to kani::index and kani_iter_len to kani::iter_len
thanhnguyen-aws Aug 8, 2025
6926302
unchange loop contracts to loop invariants
thanhnguyen-aws Aug 8, 2025
969b414
add replacer for macro
thanhnguyen-aws Aug 8, 2025
0948b90
Merge remote-tracking branch 'upstream/main' into forloopnew1
thanhnguyen-aws Aug 8, 2025
94736ac
merge while-let loop
thanhnguyen-aws Aug 8, 2025
b28f1d5
fix clippy
thanhnguyen-aws Aug 8, 2025
0d1d2d2
add KaniIntoIter impl for Rev
thanhnguyen-aws Aug 11, 2025
8f7410b
fix variable name & indentation
thanhnguyen-aws Aug 11, 2025
333eeab
Update docs/src/reference/experimental/loop-contracts.md
thanhnguyen-aws Aug 11, 2025
fd2945d
Update docs/src/reference/experimental/loop-contracts.md
thanhnguyen-aws Aug 11, 2025
edf339d
Update docs/src/reference/experimental/loop-contracts.md
thanhnguyen-aws Aug 11, 2025
d1eee1f
Update rfc/src/rfcs/0012-loop-contracts.md
thanhnguyen-aws Aug 11, 2025
da30387
Merge branch 'forloopnew1' of https://github.com/thanhnguyen-aws/kani…
thanhnguyen-aws Aug 11, 2025
a121b1b
add underscores to function name
thanhnguyen-aws Aug 11, 2025
222f89c
fix typo comments
thanhnguyen-aws Aug 11, 2025
149674d
add impl KaniIter for u128 and i128 for Range
thanhnguyen-aws Aug 11, 2025
cff691a
change function name indexing to nth
thanhnguyen-aws Aug 11, 2025
b22d152
edit for-loop docs
thanhnguyen-aws Aug 12, 2025
1299e5a
add Rod Chapman example as fixme expected test
thanhnguyen-aws Aug 12, 2025
259fcf8
Update docs/src/reference/experimental/loop-contracts.md
thanhnguyen-aws Aug 13, 2025
d7b3f0a
Update docs/src/reference/experimental/loop-contracts.md
thanhnguyen-aws Aug 13, 2025
fcb696d
fix typo mistakes in doc
thanhnguyen-aws Aug 13, 2025
7d9257a
Update library/kani_macros/src/sysroot/loop_contracts/mod.rs
thanhnguyen-aws Aug 13, 2025
97aa688
add KaniIter impl for Range of i128 and u128 + remove comments
thanhnguyen-aws Aug 13, 2025
3dd9587
Merge branch 'forloopnew1' of https://github.com/thanhnguyen-aws/kani…
thanhnguyen-aws Aug 13, 2025
f90cb1a
remove comments + fix typos
thanhnguyen-aws Aug 13, 2025
0f9f59d
remove unneccessary mut
thanhnguyen-aws Aug 13, 2025
2edf3c7
fix typo
thanhnguyen-aws Aug 13, 2025
7e03b83
fix indentation
thanhnguyen-aws Aug 13, 2025
b4bffda
fix comments
thanhnguyen-aws Aug 13, 2025
80e8822
change traitbound for KaniRefIter & KaniPtrIter
thanhnguyen-aws Aug 13, 2025
a77f0cd
fix arr_inc test
thanhnguyen-aws Aug 13, 2025
1b613e9
Merge branch 'main' into forloopnew1
thanhnguyen-aws Aug 14, 2025
7a7e158
remove array clone in arr_inc test
thanhnguyen-aws Aug 14, 2025
b2d3758
Merge branch 'forloopnew1' of https://github.com/thanhnguyen-aws/kani…
thanhnguyen-aws Aug 14, 2025
1f99e4c
Update docs/src/reference/experimental/loop-contracts.md
thanhnguyen-aws Aug 14, 2025
67b38c1
fix typo mistakes
thanhnguyen-aws Aug 14, 2025
afc7322
revert loop contract -> loop invariant
thanhnguyen-aws Aug 15, 2025
c4915cc
fix typo
thanhnguyen-aws Aug 15, 2025
10db6f2
Merge branch 'main' into forloopnew1
thanhnguyen-aws Aug 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/reference/experimental/loop-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Kani automatically contracts (instead of unwinds) all loops in the functions tha

Loop contracts comes with the following limitations.

1. `while` loops and `loop` loops are supported. The other kinds of loops are not supported: [`while let` loops](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops), and [`for` loops](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops).
1. `while` loops, `loop` loops are supported. `for` loops are supported for array, slice, Iter, Vec, Range, StepBy, Chain, Zip, Map, and Enumerate. The other kinds of loops are not supported: [`while let` loops](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops).
2. Kani infers *loop modifies* with alias analysis. Loop modifies are those variables we assume to be arbitrary in the inductive hypothesis, and should cover all memory locations that are written to during
the execution of the loops. A proof will fail if the inferred loop modifies misses some targets written in the loops.
We observed this happens when some fields of structs are modified by some other functions called in the loops.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl LoopContractPass {
for stmt in &new_body.blocks()[bb_idx].statements {
if let StatementKind::Assign(place, rvalue) = &stmt.kind {
match rvalue {
Rvalue::Ref(_,_,rplace) | Rvalue::CopyForDeref(rplace) => {
Rvalue::Ref(_,_,rplace) | Rvalue::CopyForDeref(rplace) | Rvalue::Use(Operand::Copy(rplace)) => {
if supported_vars.contains(&rplace.local) {
supported_vars.push(place.local);
} }
Expand Down
15 changes: 15 additions & 0 deletions library/kani/src/iter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This macro generates implementations of the `KaniIntoIter` trait for various common types that are used in `for` loops.
//! We use this trait to overwrite the Rust IntoIter trait to reduce call stacks and avoid complicated loop invariant specifications,
//! while maintaining the semantics of the loop.
use crate::{KaniIntoIter, KaniPtrIter};

impl<T: Copy> KaniIntoIter for Vec<T> {
type Iter = KaniPtrIter<T>;
fn kani_into_iter(self) -> Self::Iter {
let s = self.iter();
KaniPtrIter::new(s.as_slice().as_ptr(), s.len())
}
}
1 change: 1 addition & 0 deletions library/kani/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod bounded_arbitrary;
mod concrete_playback;
pub mod futures;
pub mod invariant;
pub mod iter;
pub mod shadow;
pub mod vec;

Expand Down
Loading
Loading