-
Notifications
You must be signed in to change notification settings - Fork 267
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] Add loop-contract symbols into symbol table during typecheck #8359
[CONTRACTS] Add loop-contract symbols into symbol table during typecheck #8359
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8359 +/- ##
===========================================
- Coverage 78.28% 78.28% -0.01%
===========================================
Files 1726 1726
Lines 188577 188594 +17
Branches 18443 18230 -213
===========================================
+ Hits 147629 147641 +12
- Misses 40948 40953 +5 ☔ View full report in Codecov by Sentry. |
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.
Approving of the goal, but I think the implementation should look a little different. See detailed comments.
src/util/find_symbols.cpp
Outdated
dest.insert(e.get_identifier()); | ||
return true; | ||
}); | ||
find_symbols_in_expr_and_subs( |
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.
You could substantially reduce the churn by adding a variant of find_symbols_in_expr_and_subs
that either doesn't require the "subs" argument, or uses a default value of {}
. By extension of this I'd argue that you can reduce churn even further by just making find_symbols
have this capability.
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 great. I made the static find_symbols
take the "subs" argument without default value and the public function find_type_and_expr_symbols
take the subs
argument with the default value of {}
.
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.
Hmm, I think if you did it the other way around (make the non-public function use a default value) you could substantially reduce the size of the diff in this PR. Also, I don't think the default value on the (new!) public function adds as much value for any use of that function without the third argument just amounts to using one of the other, pre-existing functions.
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 moved the default value to the static function and it actually reduce the diff of this PR.
The public function with the new subs_to_find
argument is different from other pre-existing functions. It calls the static function find_symbols
with kind symbol_kindt::F_ALL
while others call find_symbols
with different kind arguments.
04d6bbc
to
7dec291
Compare
7dec291
to
32ed640
Compare
I strongly disagree with this PR, and would like to see it reverted. There is a fundamental misunderstanding how bound symbols work. In particular, they should never show up in the symbol table. |
I appreciate this is trying to fix something, but there needs to be an entirely different approach for this fix. |
This PR will add the symbols declared in loop contracts into the symbol table so that we can in the future allow non |
Currently, when type-checking functions with contracts, we only keep function contracts symbols (see https://github.com/diffblue/cbmc/blob/develop/src/linking/remove_internal_symbols.cpp#L69). It was OK as there couldn't be any new symbol declared in loop contracts. However, if we want to support statement expressions or pure functions in loop contracts, we shouldn't remove loop contract symbols during type checking.
This PR will keep symbols in loop contracts---not removing them in
remove_internal_symbols
. In detail, we not only find symbols in sub-expressions (find_symbols
) but also find symbols in given named subs (find_symbols_in_expr_and_subs
) when finding symbols to keep.The test of #8360 covers the change of this PR.