-
Notifications
You must be signed in to change notification settings - Fork 274
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
Refactor in symex #3371
Conversation
8c2c3a1
to
908d29b
Compare
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.
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.
src/goto-symex/goto_symex.h
Outdated
@@ -140,6 +130,33 @@ class goto_symext | |||
bool should_pause_symex; | |||
|
|||
protected: | |||
|
|||
struct infot { |
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.
I'm not sure infot
/info
is a great name, I'd have chosen configurationt
/configuration
.
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.
One problem: easily confused with the global config
. How about symex_config
?
src/goto-symex/goto_symex.h
Outdated
void symex_transition( | ||
goto_symext::statet &, | ||
goto_programt::const_targett to, | ||
bool is_backwards_goto); |
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.
Why move them into the global namespace?
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.
The name and type of this function make it hard enough to collide with something else.
src/goto-symex/goto_symex.h
Outdated
@@ -463,6 +460,10 @@ class goto_symext | |||
} | |||
}; | |||
|
|||
nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count); |
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.
Why is this an improvement?
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.
Better static
?
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.
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.
src/cbmc/symex_bmc.cpp
Outdated
@@ -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( |
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.
should_stop_unwind
?
src/goto-symex/goto_symex.cpp
Outdated
simplify(expr, ns); | ||
} | ||
|
||
nondet_symbol_exprt goto_symext::build_symex_nondet(typet &type) | ||
nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count) |
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.
static
? (This and all other functions demoted from class membership)
src/goto-symex/goto_symex.h
Outdated
@@ -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, |
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.
Style: IIRC *
attached to the var name
src/goto-symex/goto_symex.h
Outdated
@@ -140,6 +130,33 @@ class goto_symext | |||
bool should_pause_symex; | |||
|
|||
protected: | |||
|
|||
struct infot { |
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.
One problem: easily confused with the global config
. How about symex_config
?
src/goto-symex/goto_symex.h
Outdated
@@ -463,6 +460,10 @@ class goto_symext | |||
} | |||
}; | |||
|
|||
nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count); |
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.
Better static
?
src/goto-symex/symex_goto.cpp
Outdated
@@ -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()) |
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.
? Unintentional behaviour change? This now happens for new == false, state == false
, whereas before it only happened for new == false, state != false
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.
oh yes it should be new_guard.is_false && !state.guard.is_false
908d29b
to
93fa742
Compare
If you have utility functions that are only intended for use within |
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
}
}; |
also if there are groups of state that are often altered together, that suggests grouping them in a private inner class |
93fa742
to
003f41d
Compare
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. |
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. |
src/goto-symex/goto_symex.h
Outdated
unsigned unwind); | ||
|
||
void parameter_assignments( | ||
const irep_idt function_identifier, | ||
irep_idt function_identifier, |
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.
Shouldn't this instead become a const reference (so add the reference, and don't remove the const).
src/goto-symex/goto_symex.h
Outdated
const goto_functionst::goto_functiont &, | ||
statet &, | ||
const exprt::operandst &arguments); | ||
|
||
void locality( | ||
const irep_idt function_identifier, | ||
irep_idt function_identifier, |
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, 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); |
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 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); |
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.
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? |
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.
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; | ||
|
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.
Ok, but this doesn't quite fit what the title of the PR says?!
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.
Why not? It doesn't introduce any functional change.
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.
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.
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.
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); |
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.
I don't think this change works in here, given the comments that have been removed from the PR.
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.
yes thanks, it wasn't caught while rebasing.
003f41d
to
6165270
Compare
This is prohibited.
Reduce the number of negations
Was not helping making the code clearer
More clearly describe what the return value represents.
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.
1a67555
to
1f9aa83
Compare
@tautschnig I think I addressed all your comments |
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: 1f9aa83).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/91632972
This introduce no functional changes, but should make the code a bit clearer