-
Notifications
You must be signed in to change notification settings - Fork 274
Add support for __CPROVER_DYNAMIC_OBJECT
to incremental SMT decision procedure
#7313
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 __CPROVER_DYNAMIC_OBJECT
to incremental SMT decision procedure
#7313
Conversation
bool dynamic_type = object.type().get_bool(ID_C_dynamic); | ||
const auto symbol = expr_try_dynamic_cast<symbol_exprt>(object); | ||
bool symbol_is_dynamic = | ||
symbol && | ||
has_prefix(id2string(symbol->get_identifier()), SYMEX_DYNAMIC_PREFIX); | ||
return dynamic_type || symbol_is_dynamic; |
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 seems like it is overly inefficient, can't we return on the dynamic_type
immediately and then only progress to the casting and string prefix check if necessary?
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.
Yes, we could. I was thinking about readability rather than optimisation when I wrote this.
🤔 has_prefix
, id2string
and get_identifier
are all header defined functions. An optimising compiler may potentially be able to work out that these functions are all side-effect free and add in the early return...
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've added the suggested optimisation for the moment.
8855491
to
4d64be8
Compare
Codecov ReportBase: 78.28% // Head: 78.30% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## develop #7313 +/- ##
===========================================
+ Coverage 78.28% 78.30% +0.01%
===========================================
Files 1642 1644 +2
Lines 190004 190141 +137
===========================================
+ Hits 148744 148889 +145
+ Misses 41260 41252 -8
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View 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.
Looks good to me (with few minor suggestions)
/// Makes the command to define the resulting \p size of calling the is | ||
/// dynamic object function with \p unique_id. |
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.
⛏️ Change is dynamic object
to is_dynamic_object
as that's the function name
#include <solvers/smt2_incremental/ast/smt_commands.h> | ||
#include <solvers/smt2_incremental/ast/smt_terms.h> | ||
|
||
struct smt_is_dynamic_objectt final |
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.
💡 Documentation inside looks very good, why not dropping a line to document the class itself?
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.
Added.
@@ -159,6 +160,7 @@ class smt2_incremental_decision_proceduret final | |||
/// stateful because it depends on the configuration of the number of object | |||
/// bits and how many bits wide the size type is configured to be. | |||
smt_object_sizet object_size_function; | |||
smt_is_dynamic_objectt is_dynamic_object_function; |
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.
⛏️ Add documentation
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.
Added.
@@ -255,6 +255,7 @@ smt2_incremental_decision_proceduret::smt2_incremental_decision_proceduret( | |||
smt_set_option_commandt{smt_option_produce_modelst{true}}); | |||
solver_process->send(smt_set_logic_commandt{smt_logic_allt{}}); | |||
solver_process->send(object_size_function.declaration); | |||
solver_process->send(is_dynamic_object_function.declaration); |
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.
⛏️ Personal opinion: I know smt_is_dynamic_objectt
is default-constructed, but readability would benefit if we explicitly construct it 5 lines above as in object_map{initial_smt_object_map()}
.
const auto null_object_dynamic_definition = | ||
test.is_dynamic_object_function.make_definition(0, false); |
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.
❓ Where do we handle the null_object_dynamic_definition
case?
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 is currently defaulted to false in the definition of decision_procedure_objectt
. I should set it explicitly in the make_null_object
function.
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.
Done.
@@ -0,0 +1,17 @@ | |||
#include <assert.h> |
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.
⛏️ As we have a test checking that the object is not dynamic, should we avoid the nondeterministic boolean so that one verification leads to FAILURE
and one to SUCCESS
?
Otherwise we never check for SUCCESS
(UNSAT
on the SMT level).
So that the information is available in subsequent conversions.
The resolves a potential issue which clang-tidy warns about.
The SMT function which this commit implements declaration / application / definition will be used in follow up commits in order to convert dynamic_object expressions to smt terms.
In preparation for calling the new function in the conversion of is_dynamic_object expressions to SMT terms.
Because this now covers both the size and the definition of whether the object is dynamic or not.
This is the final step required to complete the implementation of the support for this kind of expression.
4d64be8
to
5b55ebc
Compare
5b55ebc
to
f398ace
Compare
This PR adds support for
__CPROVER_DYNAMIC_OBJECT
to incremental SMT decision procedure. Note that it is currently based on top of #7311 . So the first commit titled "Add unit test of object size tracking" should be reviewed as part of that separate PR, rather than this one.