Skip to content

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

Merged
merged 2 commits into from
Aug 6, 2019

Conversation

kroening
Copy link
Member

@kroening kroening commented Aug 4, 2019

This improves type safety. It's the final major interface in the simplifier to use the new API style.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link
Contributor

@allredj allredj left a 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

Copy link
Collaborator

@tautschnig tautschnig left a 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)));
Copy link
Collaborator

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)));
Copy link
Collaborator

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?

Copy link
Member Author

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));
Copy link
Collaborator

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));
Copy link
Collaborator

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.

Copy link
Member Author

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.


// 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));
Copy link
Collaborator

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)

Copy link
Member Author

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));
Copy link
Collaborator

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));
Copy link
Collaborator

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.

@@ -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());
Copy link
Collaborator

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(...

Copy link
Member Author

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);
Copy link
Collaborator

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));
Copy link
Collaborator

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

@tautschnig tautschnig assigned kroening and unassigned tautschnig Aug 5, 2019
@kroening kroening force-pushed the simplify_node_interface branch 2 times, most recently from 5a1c799 to 1107bf1 Compare August 5, 2019 15:33
@kroening
Copy link
Member Author

kroening commented Aug 5, 2019

I'll do a follow-up PR reviewing whether simplify_node is appropriate to use.
This seems to be beyond the interface change in terms of scope.

@kroening kroening force-pushed the simplify_node_interface branch from 1107bf1 to 4b90551 Compare August 5, 2019 16:21
Daniel Kroening added 2 commits August 5, 2019 19:46
This improves type safety.
This is shorter and easier to read.
@kroening kroening force-pushed the simplify_node_interface branch from 4b90551 to 85e8337 Compare August 5, 2019 18:46
@codecov-io
Copy link

Codecov Report

Merging #4982 into develop will decrease coverage by <.01%.
The diff coverage is 90%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
src/util/simplify_expr_class.h 88.88% <ø> (ø) ⬆️
src/util/simplify_expr_if.cpp 35.39% <100%> (-3.77%) ⬇️
src/util/simplify_expr_struct.cpp 85.71% <100%> (-0.16%) ⬇️
src/util/simplify_expr_boolean.cpp 88.73% <100%> (-0.16%) ⬇️
src/util/simplify_expr_int.cpp 80.49% <100%> (ø) ⬆️
src/util/simplify_expr_array.cpp 86.76% <100%> (-0.2%) ⬇️
src/util/simplify_expr_pointer.cpp 79.45% <82.35%> (-0.15%) ⬇️
src/util/simplify_expr.cpp 87.6% <82.35%> (+0.22%) ⬆️
jbmc/src/java_bytecode/java_entry_point.cpp 87.68% <0%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a990c7...85e8337. Read the comment docs.

Copy link
Contributor

@allredj allredj left a 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

@tautschnig tautschnig merged commit 3af0130 into develop Aug 6, 2019
@tautschnig tautschnig deleted the simplify_node_interface branch August 6, 2019 00:03
kroening pushed a commit that referenced this pull request Aug 6, 2019
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)).
kroening pushed a commit that referenced this pull request Aug 6, 2019
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)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants