Skip to content

Replace some uses of forall_operands by ranged-for #5790

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 1 commit into from
Dec 1, 2022

Conversation

tautschnig
Copy link
Collaborator

In some (but not all!) cases of forall_operands we do not actually need the
iterator.

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

@tautschnig tautschnig changed the title Replace some uses forall_operands by ranged-for Replace some uses of forall_operands by ranged-for Jan 26, 2021
@codecov
Copy link

codecov bot commented Jan 26, 2021

Codecov Report

Base: 78.38% // Head: 78.34% // Decreases project coverage by -0.03% ⚠️

Coverage data is based on head (e4aaa48) compared to base (794f6f7).
Patch coverage: 69.83% of modified lines in pull request are covered.

❗ Current head e4aaa48 differs from pull request most recent head 7cb1f5b. Consider uploading reports for the commit 7cb1f5b to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5790      +/-   ##
===========================================
- Coverage    78.38%   78.34%   -0.04%     
===========================================
  Files         1647     1645       -2     
  Lines       190343   190355      +12     
===========================================
- Hits        149196   149131      -65     
- Misses       41147    41224      +77     
Impacted Files Coverage Δ
src/analyses/invariant_set.cpp 0.00% <0.00%> (ø)
.../goto-instrument/accelerate/acceleration_utils.cpp 2.23% <0.00%> (ø)
src/goto-programs/goto_convert_side_effect.cpp 94.50% <0.00%> (ø)
src/jsil/parser.y 0.00% <0.00%> (ø)
src/solvers/flattening/boolbv_case.cpp 0.00% <0.00%> (ø)
src/solvers/flattening/boolbv_cond.cpp 0.00% <0.00%> (ø)
...olvers/flattening/boolbv_constraint_select_one.cpp 0.00% <0.00%> (ø)
src/util/simplify_expr_if.cpp 39.15% <0.00%> (ø)
src/goto-programs/interpreter_evaluate.cpp 33.88% <14.81%> (ø)
src/analyses/goto_rw.cpp 66.59% <50.00%> (ø)
... and 139 more

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

forall_operands(it, expr)
if(!is_constant(expr.op0()))
return false;
#if 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions about style but nothing blocking.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -693,9 +693,11 @@ bool custom_bitvector_domaint::has_get_must_or_may(const exprt &src)
if(src.id() == ID_get_must || src.id() == ID_get_may)
return true;

forall_operands(it, src)
if(has_get_must_or_may(*it))
for(const auto &op : src.operands())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this is just std::any(src.operands.begin(), src.operands.end(), has_get_must_or_may)

@@ -132,9 +132,9 @@ procedure_decl: TOK_PROCEDURE proc_ident '(' parameters_opt ')'
{
symbol_exprt proc(to_symbol_expr(parser_stack($2)));
code_typet::parameterst parameters;
forall_operands(it, parser_stack($4))
for(const auto &op : as_const(parser_stack($4)).operands())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deviates from the pattern elsewhere -- why the as_const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because .operands() would trigger a(n unnecessary) write on the underlying irep, temporarly breaking (probably non-existing) sharing.

In some (but not all!) cases of forall_operands we do not actually need the
iterator.
@tautschnig tautschnig merged commit 837cd1b into diffblue:develop Dec 1, 2022
@tautschnig tautschnig deleted the forall-operands branch December 1, 2022 22:51
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.

8 participants