-
Notifications
You must be signed in to change notification settings - Fork 277
goto instrumentation for decreases clauses on loops #6197
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
Conversation
1422b22
to
a0ba201
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6197 +/- ##
===========================================
+ Coverage 67.40% 74.91% +7.50%
===========================================
Files 1157 1456 +299
Lines 95236 161233 +65997
===========================================
+ Hits 64197 120792 +56595
- Misses 31039 40441 +9402
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial comments below, and could you please:
- fix the formatting issues? (see the build failures for details)
- change the message
Compare the old and new variant values
toCheck that loop variant monotonically decreases
?
6aa3322
to
002c618
Compare
57a9915
to
0a227fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good apart from the things flagged.
// Generate: an assignment to store the loop variant before the loop entry | ||
code_assignt old_variant_assignment{old_variant_symbol, variant}; | ||
old_variant_assignment.add_source_location() = loop_head->source_location; | ||
converter.goto_convert(old_variant_assignment, havoc_code, mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tautschnig is this use of goto_convert
fitting with how and when / where it is supposed to be used?
9c7f67b
to
28aff8e
Compare
c86f3f4
to
17e3e0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of minor comments, but otherwise LGTM! Thanks for all the work!
008519a
to
99540f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for tackling all comments!
loop_head->source_location; | ||
converter.goto_convert(monotonic_decreasing_assertion, havoc_code, mode); | ||
havoc_code.instructions.back().source_location.set_comment( | ||
"Check monotonicity of decreases clause"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"monotonicity" is perhaps not the right word. It might not be an intuitive description for a broader audience, and being pedantic, you need strict monotonicity to get termination.
How about "ranking function decreases"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "ranking function" might also sound unfamiliar, plus we haven't used ranking function elsewhere (the annotation just reads __CPROVER_decreases
).
How about simply, "Check decreases clause on loop iteration"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for both of your suggestions. I will change the comment to "Check decreases clause on loop iteration"
.
What should happen when there are multiple |
Yes, this is a good point. Currently we don't allow multiple invariant and decreases annotations, but my proposal was also to treat multiple decreases clause annotations as tuples that would be compared lexicographically. |
99540f5
to
00608b6
Compare
This pull request contains the full-fledged implementation of one-dimensional loop variants (also known as ranking functions). A loop variant is an integer expression (i) that is bounded below and (ii) strictly decreases after each iteration of a loop. We use loop variants to prove termination of loops.
A loop variant in C is converted to the following statements in the GOTO language: