-
Notifications
You must be signed in to change notification settings - Fork 273
Refactor in value_set #4702
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 value_set #4702
Conversation
@@ -147,8 +146,9 @@ exprt value_set_dereferencet::dereference(const exprt &pointer) | |||
std::cout << '}' << std::endl; | |||
#endif | |||
|
|||
for(const auto &value : retained_values) | |||
values.push_back(build_reference_to(value, compare_against_pointer, ns)); | |||
std::list<valuet> values = |
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.
While you're here: consider not using std::list
, since we don't need any of the properties of a doubly-linked list here
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.
To be clear, you're suggesting using std::forward_list
, right?
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 suggesting std::vector
, as the default sequence container if you don't need particular insertion / deletion / iterator stability properties
src/pointer-analysis/value_set.h
Outdated
void output( | ||
const namespacet &ns, | ||
std::ostream &out) const; | ||
std::ostream &out, | ||
std::string indent = "") 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.
(a) const
(b) take by reference?
@@ -147,8 +146,9 @@ exprt value_set_dereferencet::dereference(const exprt &pointer) | |||
std::cout << '}' << std::endl; | |||
#endif | |||
|
|||
for(const auto &value : retained_values) | |||
values.push_back(build_reference_to(value, compare_against_pointer, ns)); | |||
std::list<valuet> values = |
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.
To be clear, you're suggesting using std::forward_list
, right?
values.push_back(build_reference_to(value, compare_against_pointer, ns)); | ||
std::list<valuet> values = | ||
make_range(retained_values).map([&](const exprt &value){ | ||
return build_reference_to(value, compare_against_pointer, ns);}); |
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.
Is this better than using std::transform
with std::back_inserter(values)
and the same lambda? I guess it lets you make it const
, and it's slightly easier to read.
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 mostly the same thing as std::transform
but I find the range version clearer
const std::vector<exprt> retained_values = | ||
make_range(points_to_set).filter([&](const exprt &value) { | ||
return !should_ignore_value(value, exclude_null_derefs, language_mode); | ||
}); |
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.
Again, could use std::transform
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.
you mean copy_if
I think
dc808d3
to
61bb1dc
Compare
61bb1dc
to
6592983
Compare
@romainbrenguier clang-format and cpp-lint aren't happy. |
e7aca28
to
9293111
Compare
Use #ifdef DEBUG instead of #if 0 so that compilation of the code can be tested on CI, and make the messages more explecit so that their origin can be recovered when seen in the logs.
Allows to customize the indentation of the output, for clearer logging of the value set.
Use #ifdef DEBUG instead of #if 0 so that compilation can be checked on CI; give more information about what we are logging; which also makes it easier to find the origin of the output when seen from logs.
This allows `values` to be const and clarifies that this list is a direct mapping from retained_values.
This makes it clearer that retained_values corresponds to a filtered `points_to_set` and allows retained values to be const.
9293111
to
4f40147
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.
This PR failed Diffblue compatibility checks (cbmc commit: 4f40147).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/113459194
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.
This improves logging of debug information and clarifies the definition of
values
andretained_values