Skip to content

Refactor in symex #3371

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 17 commits into from
Nov 16, 2018

Conversation

romainbrenguier
Copy link
Contributor

This introduce no functional changes, but should make the code a bit clearer

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

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.

Overall I'd largely agree with the changes. But then it's a lesson as to why PRs with 24 commits are not a good idea: a few commits require further debate or changes, and thus the overall PR is now stalled. Also there are some commits that make changes that crucially depend on changes in the very same PR, and thus those commits ought to be squashed as they could not possibly be independently reverted.

@@ -140,6 +130,33 @@ class goto_symext
bool should_pause_symex;

protected:

struct infot {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure infot/info is a great name, I'd have chosen configurationt/configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

One problem: easily confused with the global config. How about symex_config?

void symex_transition(
goto_symext::statet &,
goto_programt::const_targett to,
bool is_backwards_goto);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why move them into the global namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name and type of this function make it hard enough to collide with something else.

@@ -463,6 +460,10 @@ class goto_symext
}
};

nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this an improvement?

Copy link
Contributor

Choose a reason for hiding this comment

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

Better static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an improvement because the type makes it clear what is the data used and modified by this function, while before it could have effect on any of the class members.
I'm not sure it can be static because it's used in several cpp files.

@@ -105,7 +105,7 @@ void symex_bmct::merge_goto(
symex_coverage.covered(prev_pc, state.source.pc);
}

bool symex_bmct::get_unwind(
bool symex_bmct::stop_unwind(
Copy link
Contributor

Choose a reason for hiding this comment

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

should_stop_unwind?

simplify(expr, ns);
}

nondet_symbol_exprt goto_symext::build_symex_nondet(typet &type)
nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count)
Copy link
Contributor

Choose a reason for hiding this comment

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

static? (This and all other functions demoted from class membership)

@@ -115,7 +93,7 @@ class goto_symext
virtual void resume_symex_from_saved_state(
const get_goto_functiont &get_goto_function,
const statet &saved_state,
symex_target_equationt *const saved_equation,
symex_target_equationt * saved_equation,
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: IIRC * attached to the var name

@@ -140,6 +130,33 @@ class goto_symext
bool should_pause_symex;

protected:

struct infot {
Copy link
Contributor

Choose a reason for hiding this comment

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

One problem: easily confused with the global config. How about symex_config?

@@ -463,6 +460,10 @@ class goto_symext
}
};

nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count);
Copy link
Contributor

Choose a reason for hiding this comment

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

Better static?

@@ -32,12 +32,10 @@ void goto_symext::symex_goto(statet &state)
state.rename(new_guard, ns);
do_simplify(new_guard);

if(new_guard.is_false() ||
state.guard.is_false())
if(new_guard.is_false())
Copy link
Contributor

Choose a reason for hiding this comment

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

? Unintentional behaviour change? This now happens for new == false, state == false, whereas before it only happened for new == false, state != false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yes it should be new_guard.is_false && !state.guard.is_false

@smowton
Copy link
Contributor

smowton commented Nov 13, 2018

If you have utility functions that are only intended for use within goto_symext, but where you don't want to give them this because you want to bound their side-effects, how about making them private static functions?

@smowton
Copy link
Contributor

smowton commented Nov 13, 2018

For example,

class example {

  int will_be_changed, wont_be_changed;
  static void bounded_effects(int &can_alter) { can_alter++; }

public:

  void public_interface() {
    bounded_effects(will_be_changed);
    // We're sure wont_be_changed is unaffected
  }

};

@smowton
Copy link
Contributor

smowton commented Nov 13, 2018

also if there are groups of state that are often altered together, that suggests grouping them in a private inner class

@romainbrenguier
Copy link
Contributor Author

@tautschnig

Overall I'd largely agree with the changes. But then it's a lesson as to why PRs with 24 commits are not a good idea: a few commits require further debate or changes, and thus the overall PR is now stalled. Also there are some commits that make changes that crucially depend on changes in the very same PR, and thus those commits ought to be squashed as they could not possibly be independently reverted.

I've split the PR, and only keep the commits that should be straightforward here. I will make follow up PRs for the ones that may generate discussions.

@romainbrenguier
Copy link
Contributor Author

@smowton

If you have utility functions that are only intended for use within goto_symext, but where you don't want to give them this because you want to bound their side-effects, how about making them private static functions?

That's a relatively good solution, but I think it's not perfect. A private static function could access private static fields. If we want to prevent the function to be used outside of the module, it should be only declared in the goto_symex.cpp file. At the same time there is nothing really wrong with using these functions outside the module, we just want to avoid making it public to lighten the public interface.

unsigned unwind);

void parameter_assignments(
const irep_idt function_identifier,
irep_idt function_identifier,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this instead become a const reference (so add the reference, and don't remove the const).

const goto_functionst::goto_functiont &,
statet &,
const exprt::operandst &arguments);

void locality(
const irep_idt function_identifier,
irep_idt function_identifier,
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, make a const reference.

const get_goto_functiont &get_goto_function,
const irep_idt &function_identifier,
goto_programt::const_targett first,
goto_programt::const_targett limit);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be squash with the preceding commit.

@@ -171,8 +171,6 @@ class goto_symext
const bool allow_pointer_unsoundness;

public:
// these bypass the target maps
virtual void symex_step_goto(statet &, bool taken);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe the commit message could be made to include the names of functions being removed? These have likely been used elsewhere (Satabs comes to mind), and if we ever want to resurrect them, the git history is vital.

@@ -82,10 +82,8 @@ void goto_symext::symex_goto(statet &state)
frame.loop_iterations[goto_programt::loop_id(*state.source.pc)].count;
unwind++;

// continue unwinding?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would recommend squashing with the prior commit. Simple test: would reverting either of these commits in isolation be meaningful? I don't think so.

void offset_sum(
exprt &dest,
const exprt &offset) const;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, but this doesn't quite fit what the title of the PR says?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not? It doesn't introduce any functional change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the PR title says "symex" and I find this change without much of a comment then I have to call it out as a reviewer: based on the information provided in the title, I must assume that it was accidentally included.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right I see, sorry, I will be more careful next time

exprt nondet = build_symex_nondet(object_type);
code_assignt assignment(value_symbol.symbol_expr(), nondet);
const exprt nondet = build_symex_nondet(object_type, nondet_count);
const code_assignt assignment(value_symbol.symbol_expr(), nondet);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this change works in here, given the comments that have been removed from the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes thanks, it wasn't caught while rebasing.

This is clearer for expressing that the method override that of the base
class.
This also make comments about overloading unecessary
Makes it clearer that the methods override that of the base class.
@romainbrenguier romainbrenguier force-pushed the refactor/symex-part1 branch 2 times, most recently from 1a67555 to 1f9aa83 Compare November 16, 2018 07:56
@romainbrenguier
Copy link
Contributor Author

@tautschnig I think I addressed all your comments

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: 1f9aa83).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/91632972

@romainbrenguier romainbrenguier merged commit 10edd29 into diffblue:develop Nov 16, 2018
@romainbrenguier romainbrenguier deleted the refactor/symex-part1 branch November 16, 2018 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants