-
Notifications
You must be signed in to change notification settings - Fork 274
Simplify when combining string-refinement result constraints #4957
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
Simplify when combining string-refinement result constraints #4957
Conversation
0976b08
to
40a3138
Compare
40a3138
to
c70f7ef
Compare
Codecov Report
@@ Coverage Diff @@
## develop #4957 +/- ##
===========================================
- Coverage 69.47% 69.44% -0.04%
===========================================
Files 1310 1310
Lines 108763 108747 -16
===========================================
- Hits 75566 75520 -46
- Misses 33197 33227 +30
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: c70f7ef).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/121394358
merge(result2.second, std::move(result1.second)); | ||
simplify(return_code, ns); | ||
|
||
return {return_code, std::move(result2.second)}; |
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.
May I suggest to use return {simplify_expr(return_code, ns), std::move(result2.second)};
at which point the return_code
can be made const exprt
.
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.
👍
merge(result2.second, std::move(result1.second)); | ||
simplify(return_code, ns); |
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.
the change should be documented
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.
Anywhere specific?
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.
in the documentation of combine_results
c70f7ef
to
46cf072
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 46cf072).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/121998505
@@ -78,6 +78,7 @@ add_axioms_for_empty_string(const function_application_exprt &f) | |||
/// \param arg: expression of type string typet | |||
/// \param guard: condition under which `res` should be equal to arg | |||
/// \param array_pool: pool of arrays representing strings | |||
/// \param ns: the namespace |
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.
💡 Maybe it will be good to say that this argument is so that we can simplify some expressions. We could pass a function simplify_expr
as argument instead to make that obvious (just an idea)
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.
Or maybe we could have a class and have some const members (such as a namespacet
)? The architecture of the string solver code makes it really painful to add new capabilities.
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.
We could basically use the string_constraint_generatort
class for that (either pass it as an argument of the function or make the function a member), but we should clean-up the members of the class first: the string_constraintst
field should just be an output of the methods and not a field and I think the messaget
field does not belong there.
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 don't know what exactly the right solution looks like, but I get the impression that making everything free functions has been taken a little too far here. It severely hampers maintainability. The PR we are looking at could have been a one-line change, but instead it's currently +87/-48. We need to make sure we find a good balance between perfectly clean code and maintainability.
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 is the clean-up I suggest #4995, you could then replace the fresh_symbol
, array_pool
, and ns
arguments in these functions by just a string_constraint_generatort object and then further changes like this one could be small.
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'll happily do that. I was tempted to do it originally while doing this, but the changes were just under the acceptable threshold for me.
Is this good to go? |
Not yet, I'll make the required changes now to help clean it up then should be good. |
902389c
to
326d02c
Compare
e1c7a85
to
dad8579
Compare
I've made the changes which results in the original change being one line. Right now the clean-up commits are all in separate blocks of work to make things a little easier to see what's been done, but I'll squash them together before merging. |
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: dad8579).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/123219879
|
||
/// \todo The specification may not be correct for the case where the | ||
/// string is shorter than end. An actual java program should throw an | ||
/// exception in that 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.
💡 this looks outdated compared to the add_axioms_for_substring(const function_application_exprt)
(but not related to this PR)
const function_application_exprt &f, | ||
array_poolt &array_pool); | ||
public: | ||
std::pair<exprt, string_constraintst> add_axioms_for_concat( |
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.
💡 at some point we should remove the add_
from these method names, since it doesn't add them but return them (doesn't need to be in this PR)
auto pair = add_axioms_for_insert( | ||
generator.fresh_symbol, result, input1, input2, args[0], array_pool); | ||
auto pair = generator.add_axioms_for_insert( | ||
result, input1, input2, args[0]); |
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 commit should be squashed in the previous one if it doesn't compile without it
dad8579
to
8868378
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 8868378).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/123237780
Also removed all arguments that can now be accessed directly via their fields.
Due to the improvements in constant prop we increasingly have constraints that are trivially simplified, like: if 5 >= 2 do x else y Also because of the way these conditions are combined - the resulting merged if gets added to all subsequent conditions and values - we end up with expressions like this: if 5 >= 2 then (if 5 >= 2 do x ... else y ...) else (if 5 >= 2 do x ... else y ...) Where the size of the expression increases exponentially to the complexity of the original if statement even if the entire conditional is trivial to prove right/wrong. This could likely be worked out by the SAT solver happily enough but due to the size of the resulting expressions (I've seen ones 1.34 billion nodes deep) it never gets there within a reasonable time-frame.
8868378
to
303ec4d
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 303ec4d).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/125072367
Due to the improvements in constant prop we increasingly have constraints that are trivially simplified, like:
if 5 >= 2 do x else y
Also because of the way these conditions are combined - the resulting merged if gets added to all subsequent conditions and values - we end up with expressions like this:
if 5 >= 2 then (if 5 >= 2 do x ... else y ...) else (if 5 >= 2 do x ... else y ...)
Where the size of the expression increases exponentially to the complexity of the original if statement even if the entire conditional is trivial to prove right/wrong. This could likely be worked out by the SAT solver happily enough but due to the size of the resulting expressions (I've seen ones 1.34 billion nodes deep) it never gets there within a reasonable time-frame.