Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for loop-contract historic values #3951

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

thanhnguyen-aws
Copy link
Contributor

Add support for old and prev to refers to historic values in loop contracts where

  • old(expr) refers to the value of the expr before the loop.
  • prev(expr) refers to the value of the expr at the previous iteration.

Resolves #3697

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

@thanhnguyen-aws thanhnguyen-aws requested a review from a team as a code owner March 20, 2025 00:18
@github-actions github-actions bot added the Z-BenchCI Tag a PR to run benchmark CI label Mar 20, 2025
@thanhnguyen-aws thanhnguyen-aws changed the title Add support for loop old and prev Add support for loop-contract historic values Mar 20, 2025
@tautschnig
Copy link
Member

Looks like you want to run kani-fmt.sh to address the test failure.

var_name
}

fn should_replace(&self, expr_path: &syn::ExprPath) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some comments to explain when should_replace return true?

}
}

fn transform_function_calls(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add more comments to the newly added functions?

@remi-delmas-3000
Copy link
Contributor

remi-delmas-3000 commented Mar 21, 2025

Could we use on_entry(...) instead of old(...) ? The doc itself says "old(...) denotes the value on loop entry".

Some documentation describing the transformation at a high level would help the review.

Comment on lines +1 to +4
Check 10: loop_with_old.loop_invariant_base.1
- Status: SUCCESS
- Description: "Check invariant before entry for loop loop_with_old.0"
- Location: src/loop_with_old.rs:16:5 in function loop_with_old
Copy link
Contributor

Choose a reason for hiding this comment

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

You should remove details that will be brittle between runs (like the check number, or the .1). We also don't typically include location. You should have backslashes between the lines to enforce that the lines are consecutive--with this writing, something like this would pass:

loop_with_old.loop_invariant_base.1
	 - Status: FAILURE

random_other_check
     - Status: SUCCESS

Without the backslashes, it'll just check for each line in isolation, so there's nothing tying the success to the particular property we care about.

I'd recommend looking at other expected files for examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-BenchCI Tag a PR to run benchmark CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

loop_old in loop contracts
5 participants