-
Notifications
You must be signed in to change notification settings - Fork 274
CONTRACTS: Error-out on unknown functions (replace/enforce). #6733
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
CONTRACTS: Error-out on unknown functions (replace/enforce). #6733
Conversation
84feaf2
to
73fc478
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6733 +/- ##
========================================
Coverage 76.86% 76.86%
========================================
Files 1589 1589
Lines 183813 183809 -4
========================================
+ Hits 141289 141293 +4
+ Misses 42524 42516 -8
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.
LGTM; couple of minor comments below
@@ -0,0 +1,5 @@ | |||
|
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.
[minor] empty line
@@ -0,0 +1,12 @@ | |||
CORE |
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.
[minor] just to reduce code duplication, we can place this .desc
file in enforce-unknown-function
as well.
Concretely, we could:
- rename
enforce-unknown-function
->function-contracts-unknown-function
- rename
function-contracts-unknown-function/test.desc
->test_enforce.desc
- move this
test.desc
->function-contracts-unknown-function/test_replace.desc
--enforce-contract goo | ||
^Invariant check failed$ | ||
^Condition: Precondition$ | ||
^Reason: all_functions_found\(to_enforce\)$ |
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.
Should we also test for the message from PRECONDITION_WITH_DIAGNOSTICS
?
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.
Now throwing an exception instead of using a precondition. The guidelines for error handling are: handle incorrect user input gracefully, throwing informative exceptions from util/exception_utils.h
, use INVARIANT and PRECONDITION for internal checks that shall never fail.
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.
Sounds good
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.
Just minor comments on top of @SaswatPadhi suggestions.
@@ -1150,8 +1150,18 @@ void goto_instrument_parse_optionst::instrument_goto_program() | |||
// first replacement then enforcement. We rely on contract replacement | |||
// and inlining of sub-function calls to properly annotate all | |||
// assignments. | |||
contracts.replace_calls(to_replace); | |||
contracts.enforce_contracts(to_enforce); | |||
if(contracts.replace_calls(to_replace)) |
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.
Do we need to keep these if statements here or just modify replace_calls
and enforce
methods to throw 0
whenever the precondition fail? Is there any case where we actually return false from these methods and use these if statement here? In any case, we could move them.
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.
Since we are now throwing exceptions for incorrect user input I changed the signatures to return void
, and got rid of these checks.
2372e1e
to
d411e97
Compare
We dropped the pattern of returning boolean error flags and accumulating errors in `replace_calls` and `enforce_contracts`. We are now checking that all functions exist upfront and throwing exceptions from `util/exception_utils.h` as soon as the first unknown function is found. Subsequent checks of the same conditions are now INVARIANTS.
d411e97
to
e6402ec
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.
LGTM! Thanks, Remi!
goto-instrument now errors out when attempting to enforce or replace the contract of an unknown function.
replace_calls
andenforce_contracts
are now checking that functions exist upfront and are failing fast by throwing exceptions fromutil/exception_utils.h
, and are now returning void instead of a boolean error flag.