Skip to content

Fix incorrect kani::index example in loop-contracts documentation#4539

Open
tautschnig wants to merge 1 commit intomodel-checking:mainfrom
tautschnig:loop-contracts-example
Open

Fix incorrect kani::index example in loop-contracts documentation#4539
tautschnig wants to merge 1 commit intomodel-checking:mainfrom
tautschnig:loop-contracts-example

Conversation

@tautschnig
Copy link
Member

The existing example intended to demonstrate how kani::index works with loop invariants, but had a mismatch between the invariant and the loop body:

  • The loop invariant used sum <= (kani::index as u32 * 20) suggesting that array element values (each ≤ 20) were being summed
  • However, the loop body was adding i (the index) instead of *j (the array element value)
  • The use of enumerate() was also unnecessary for the example's purpose

Co-authored-by: Alex Bagnall

Resolves #4534

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

The existing example intended to demonstrate how `kani::index` works
with loop invariants, but had a mismatch between the invariant and the
loop body:
- The loop invariant used `sum <= (kani::index as u32 * 20)` suggesting
  that array element values (each ≤ 20) were being summed
- However, the loop body was adding `i` (the index) instead of `*j` (the
  array element value)
- The use of `enumerate()` was also unnecessary for the example's
  purpose

Co-authored-by: Alex Bagnall

Resolves: model-checking#4534
Copilot AI review requested due to automatic review settings February 11, 2026 13:33
@tautschnig tautschnig requested a review from a team as a code owner February 11, 2026 13:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Kani book’s loop-contracts documentation to fix the kani::index example so the loop body matches the stated invariant (summing array elements bounded by 20).

Changes:

  • Replace the enumerate() loop that incorrectly summed indices with a simpler loop that sums array values.
  • Remove unnecessary iterator plumbing to better focus the example on kani::index and the invariant.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kani::index example in docs

1 participant