-
Notifications
You must be signed in to change notification settings - Fork 274
CONTRACTS: store contracts in dedicated symbols #6799
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: store contracts in dedicated symbols #6799
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #6799 +/- ##
===========================================
- Coverage 77.83% 77.83% -0.01%
===========================================
Files 1568 1569 +1
Lines 180365 180634 +269
===========================================
+ Hits 140382 140589 +207
- Misses 39983 40045 +62
Continue to review full report at Codecov.
|
9646592
to
f90e01b
Compare
f90e01b
to
cb1a58c
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.
It would be nice to make the contract completely self-contained by introducing fresh/prefixed names for the parameters, rewriting the contract clauses with the fresh names, and removing the body if any.
src/ansi-c/c_typecheck_base.cpp
Outdated
for(const auto ¶meter : code_type.parameters()) | ||
{ | ||
const irep_idt &identifier = parameter.get_identifier(); | ||
|
||
symbol_tablet::symbolst::const_iterator p_s_it = | ||
symbol_table.symbols.find(identifier); | ||
if(p_s_it != symbol_table.symbols.end()) | ||
symbol_table.erase(p_s_it); |
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.
Here I would rather replace the contract parameters with fresh symbols (maybe just by prefixing the function parameters with a contract::
prefix, and also rewrite the contract clauses with these new parameters using a replacet
.
Later we would be able to generate a body for the contract without symbol clashes between function and contract symbols and make the contract fully self-contained.
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 believe we could still choose to create those fresh symbols if and when needed: all the required information still is in the contract symbol.
} | ||
|
||
const auto &type = to_code_with_contract_type(contract_sym->type); | ||
if(type != function_symbol.type) |
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.
How can this equality work if the function symbol had its contract clauses removed but the contract symbol still has them ?
Would the check still work if in addition we removed the function body from the contract and renamed contract parameters ?
Maybe we could just check that the number of arguments and their types are equal.
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.
This perhaps warrants an extra comment: the comparison works, because all the extra information is stored in comment-elements of the ireps: both the parameter identifiers as well as all the contract clauses have ID_C_...
keys in the irept
. Therefore, equality (but not full equality!) works out. While the body isn't there as indicated in the earlier comment, it wouldn't affect this comparison either way for it's just a comparison of the types, not the symbols' values.
8d40abb
to
8753639
Compare
8753639
to
39690e1
Compare
39690e1
to
1d0340c
Compare
1d0340c
to
adbef76
Compare
c2f8b7b
to
a3f9db2
Compare
@kroening @remi-delmas-3000 I have put the additional changes to make use of |
a3f9db2
to
5914a14
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 @tautschnig!
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 overall; couple of minor comments below.
@chris-ryder, @kroening, @martin-cs, and/or @peterschrammel, could we get one more review on this PR? It's missing code owner approval. |
d235c00
to
2a9d14c
Compare
Contracts can now be placed on declarations or definitions, and result in a fresh symbol being generated. That new symbol has its name prefixed with "contracts::" to place them in a pseudo-namespace, and has "is_property" set (which was an otherwise unused symbolt flag). Co-authored-by: Remi Delmas <[email protected]>
All that was used was its source location, which we can obtain in a different way.
This makes sure contracts are self-contained in that any parameter names that may have only existed in the scope of a function declaration are now bound variables.
2a9d14c
to
d3ed223
Compare
Contract symbols (diffblue#6799) have the same base name as the function symbol they are derived from. This causes both the function and its contract to be found when doing a lookup by base name, when resolving entry points for instance. We now filter out symbols that have the `is_property` set when resolving entry points and interrupt handlers in a goto model.
Contracts can now be placed on declarations or definitions, and result
in a fresh symbol being generated. That new symbol has its name prefixed
with "contracts::" to place them in a pseudo-namespace, and has
"is_property" set (which was an otherwise unused symbolt flag).
Co-authored-by: Remi Delmas [email protected]