-
Notifications
You must be signed in to change notification settings - Fork 274
simplifier: new interface for simplify_node #4982
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
Conversation
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: a2f0a3b).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/121877686
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.
Touching old code highlights a lot of room for improvement - can we get this done?
simplify_node(tmp); | ||
return std::move(tmp); | ||
return changed(simplify_node( | ||
or_exprt(simplify_node(boolean_negate(cond)), truevalue))); |
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 agreed in another PR, calling simplify_node
on the result of boolean_negate
is unnecessary. Unrelated to this PR, but should be fixed now that we're looking at this code. Applies here and below.
exprt new_value(with.new_value()); | ||
auto tmp = expr; | ||
tmp.set_offset(std::move(new_offset)); | ||
tmp.set_offset(simplify_node(std::move(new_offset))); |
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.
simplify_node
takes a const exprt &
as argument, the std::move
doesn't seem to be useful?
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.
fixed
exprt new_value(with.new_value()); | ||
auto tmp = expr; | ||
tmp.set_offset(std::move(new_offset)); | ||
tmp.set_offset(simplify_node(std::move(new_offset))); | ||
tmp.set_value(std::move(new_value)); |
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 code could really do with some cleanup: 1) I'd move the definitions (new_offset
, new_value
) closer to their use; 2) creating an explicit copy in new_value
just so that we can std::move
it seems to have little value.
auto new_expr = expr; | ||
new_expr.op() = std::move(inequality); | ||
new_expr.op() = simplify_node(std::move(inequality)); |
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.
See below: std::move
doesn't seem to be very useful here.
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.
Fixed -- the method now takes an exprt
as argument.
src/util/simplify_expr.cpp
Outdated
|
||
// index_offset may need a typecast | ||
if(offset.type() != index.type()) | ||
{ | ||
typecast_exprt tmp(index_offset, offset.type()); | ||
simplify_node(tmp); | ||
index_offset.swap(tmp); | ||
index_offset = simplify_node(std::move(tmp)); |
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 above: std::move
seems useless (and tmp
could be inlined, the name doesn't add clarity)
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
simplify_node(new_expr); | ||
|
||
return new_expr; | ||
return changed(simplify_node(new_expr)); |
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.
Is there anything to simplify here? AFAIK we don't usually run simplify_node
on the result of from_integer
.
simplify_node(new_expr); | ||
|
||
return new_expr; | ||
return changed(simplify_node(new_expr)); |
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 above: nothing to simplify.
src/util/simplify_expr_pointer.cpp
Outdated
@@ -524,7 +509,7 @@ simplify_exprt::simplify_inequality_pointer_object(const exprt &expr) | |||
{ | |||
new_inequality_ops.push_back(typecast_exprt::conditional_cast( | |||
op, new_inequality_ops.front().type())); | |||
simplify_node(new_inequality_ops.back()); | |||
new_inequality_ops.back() = simplify_node(new_inequality_ops.back()); |
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.
new_inequality_ops.push_back(simplify_node(typecast_exprt::conditional_cast(...
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
@@ -738,7 +723,7 @@ simplify_exprt::simplify_object_size(const unary_exprt &expr) | |||
if(size.type() != expr_type) | |||
{ | |||
size = typecast_exprt(size, expr_type); | |||
simplify_node(size); | |||
size = simplify_node(size); |
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.
simplify_typecast
?
simplify_node(def); | ||
|
||
return std::move(def); | ||
return changed(simplify_node(def)); |
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.
good_pointer_def
is far from trivial - I believe this requires simplify_rec
5a1c799
to
1107bf1
Compare
I'll do a follow-up PR reviewing whether |
1107bf1
to
4b90551
Compare
This improves type safety.
This is shorter and easier to read.
4b90551
to
85e8337
Compare
Codecov Report
@@ Coverage Diff @@
## develop #4982 +/- ##
===========================================
- Coverage 69.24% 69.24% -0.01%
===========================================
Files 1309 1309
Lines 108478 108463 -15
===========================================
- Hits 75119 75107 -12
+ Misses 33359 33356 -3
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: 85e8337).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/122011510
This is follow-up on a discussion in #4982. boolean_negate performs some, but not all, of the simplifications done by simplify_not. This PR avoids this redundancy by calling simplfify_not(not_exprt(x)) instead of simplify_node(boolean_negate(x)).
This is follow-up on a discussion in #4982. boolean_negate performs some, but not all, of the simplifications done by simplify_not. This PR avoids this redundancy by calling simplify_not(not_exprt(x)) instead of simplify_node(boolean_negate(x)).
This improves type safety. It's the final major interface in the simplifier to use the new API style.