Skip to content

Refactoring of symex_assign_symbol #4642

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 13 commits into from
May 13, 2019

Conversation

romainbrenguier
Copy link
Contributor

Having to debug some changes related to symex_assign I found it difficult to understand what variable represents what in the execution of symex_assign_symbol because of several functions which have parameters that are also output. This pull request is an attempt to get rid of these.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • 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).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

tmp,
source,
symex_targett::assignment_typet::PHI);

expr = set_indices<L2>(std::move(ssa_l1), ns).get();
// TODO: are we setting l2 indices of something that is already l2?
expr = set_indices<L2>(std::move(ssa_l2), ns).get();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you try adding an assertion that this effectively returns ssa_l2 - I agree that this seems unnecessary, but maybe we're missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've now added an invariant before the call to check that ssa_l2 was correctly renamed.

@@ -452,8 +452,7 @@ bool goto_symex_statet::l2_thread_read_encoding(
source,
symex_targett::assignment_typet::PHI);

// TODO: are we setting l2 indices of something that is already l2?
expr = set_indices<L2>(std::move(ssa_l2), ns).get();
expr = std::move(ssa_l2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

See my earlier comment: did you add an assertion to confirm this is doing what you expected across our regression tests?

The name better reflects what the variable represent and using move is
clearer than swap.
guarded_rhs is only used to define l2_rhs, we make this explicit in the code.
This makes it a bit clearer what the shift_indexed_access_to_lhs
function produced.
It also avoids errors where the argument as a specific type but the
identifier is overwritten, for instance:
```
symbol_exprt s1 = ...;
shift_indexed_access_to_lhs(state, s1, lhs, ns, true);
assert(s1 == ID_symbol); // may fail though s1 has type symbol_exprt
```
This avoids having an input that is also an output and makes what is
modified by the call clearer.
The argument was copied before the call anyway.
This avoids having parameters that are also output value, which is not
clear from the calling site, and could cause some type mistakes when the
exprt parameters is from a subtype of exprt.
This simplifies the call to this function and is clearer about the
semantical relation between the lhs and rhs arguments.
This makes the relation between lhs and rhs clearer.
This avoids having an input that is also an output and clarifies how lhs
is changed.
In practice there was an implicit stack of record events backup through
the recursive calls, this makes the stack explicit.
The argument of add_to_lhs are const anyway.
It is not modified after assignment.
This avoids having an input that is also an output and make the calls to
get_original_name clearer.
ssa_l2 is already an L2 expression, its indices doesn't need to be reset.
We just check that the renaming was correct instead.
@romainbrenguier romainbrenguier force-pushed the refactor/symex_assign branch from bf73aa7 to fdc03e0 Compare May 13, 2019 07:19
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: fdc03e0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/111540186

@romainbrenguier
Copy link
Contributor Author

@tautschnig I've added the check you suggested and everything works fine

@tautschnig tautschnig merged commit f6c4867 into diffblue:develop May 13, 2019
@romainbrenguier romainbrenguier deleted the refactor/symex_assign branch May 13, 2019 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants