-
Notifications
You must be signed in to change notification settings - Fork 274
cleanup array theory solver #1145
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
Conversation
kroening
commented
Jul 16, 2017
- Use ranged for
- Use full index_exprt constructors
- Cleaned out unused method prototype
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.
See detailed comments; also I don't see how this PR delivers on "Use full index_exprt constructors" or
"Cleaned out unused method prototype".
src/solvers/flattening/arrays.cpp
Outdated
for(const auto & i2 : i1.second) | ||
std::cout << "Index set (" << i1.first << " = " | ||
<< arrays.find_number(i1.first) << " = " | ||
<< from_expr(ns, "", arrays[arrays.find_number(i1.first)]) | ||
<< "): " | ||
<< from_expr(ns, "", *i2) << '\n'; |
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 no longer compiles, it should be i2
instead of *i2
src/solvers/flattening/arrays.cpp
Outdated
array_equalities.begin(); | ||
it!=array_equalities.end(); | ||
it++) | ||
for(const auto & it : array_equalities) |
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.
Please use a name different from it
as this isn't an iterator anymore (and avoid the space after &
for consistency)
src/solvers/flattening/arrays.cpp
Outdated
it=update_indices.begin(); | ||
it!=update_indices.end(); it++) | ||
update_index_map(*it); | ||
for(const auto & it : update_indices) |
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.
See above (not an iterator, space)
src/solvers/flattening/arrays.cpp
Outdated
it=index_set.begin(); | ||
it!=index_set.end(); | ||
it++) | ||
for(const auto & it : index_set) |
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.
See above (not an iterator, space)
src/solvers/flattening/arrays.cpp
Outdated
it=index_set.begin(); | ||
it!=index_set.end(); | ||
it++) | ||
for(const auto & it : index_set) | ||
{ | ||
index_exprt index_expr1; |
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.
index_exprt index_expr1(array_equality.f1, it);
instead of the multi-step assignment.
src/solvers/flattening/arrays.cpp
Outdated
it=index_set.begin(); | ||
it!=index_set.end(); | ||
it++) | ||
for(const auto & it : index_set) |
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.
See above (not an iterator, space); specifically use other_index
to avoid the useless assignment below.
src/solvers/flattening/arrays.cpp
Outdated
{ | ||
exprt other_index=*it; | ||
exprt other_index=it; |
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.
See above (multiple)
src/solvers/flattening/arrays.cpp
Outdated
it=index_set.begin(); | ||
it!=index_set.end(); | ||
it++) | ||
for(const auto & it : index_set) |
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.
See above
src/solvers/flattening/arrays.cpp
Outdated
{ | ||
index_exprt index_expr1; | ||
index_expr1.type()=ns.follow(expr.type()).subtype(); | ||
index_expr1.array()=expr; | ||
index_expr1.index()=*it; | ||
index_expr1.index()=it; |
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.
See above
src/solvers/flattening/arrays.cpp
Outdated
it=index_set.begin(); | ||
it!=index_set.end(); | ||
it++) | ||
for(const auto & it : index_set) |
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.
See above
78ce76d
to
7f29114
Compare
Many thanks, should now be all done. |
The linter isn't quite happy yet? (Stray whitespace at end of line.) |
src/solvers/flattening/arrays.cpp
Outdated
index_expr.type()=array_type.subtype(); | ||
index_expr.array()=a.op0(); | ||
index_expr.index()=a.op1(); | ||
index_exprt index_expr(a.op0(), a.op1(), array_type.subtype()); |
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.
Nit picking: the third operand is unnecessary. Also: would it be possible to use to_with_expr
above so that the rather anonymous a.op0()
and a.op1()
become more readable?
src/solvers/flattening/arrays.cpp
Outdated
index_expr.type()=array_type.subtype(); | ||
index_expr.array()=a.op0(); | ||
index_expr.index()=a.op1(); | ||
index_exprt index_expr(a.op0(), a.op1(), array_type.subtype()); |
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.
Same nit pick: the third operand...
index_expr1.type()=ns.follow(arrays[i].type()).subtype(); | ||
index_expr1.array()=arrays[i]; | ||
index_expr1.index()=*i1; | ||
const typet &subtype=ns.follow(arrays[i].type()).subtype(); |
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: I believe this is unnecessary.
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.
There is a subtle difference here: the array type is anticipated to be a symbol, and the index_exprt() constructor doesn't consider that case.
I am hoping that the front-end doesn't generate these any more, which should be checked, followed by a clean-out of the ns.follow() expressions.
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.
Wouldn't later bitvector conversion do any such namespace lookups anyway (if needed)? (Anyhow I do agree that the front-end should not even be generating any symbol types for arrays.)
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.
No, the arrays handled by the array theory solver won't get touched by bitvector conversion.
Yes, this code should be obsolete; symbol types are only to be generated for structs (and should eventually get replaced by struct_tag types).
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.
Hmm, wouldn't prop.l_set_to_true(convert(...))
eventually see those equalities?
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, but that will then eventually pass it to the array decision procedure, without rewriting the types.
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.
Sorry, I was on the wrong track, it's completely irrelevant what the later steps do or don't do as picking the subtype()
of a symbol type wouldn't work (which the constructor uses).
For the C front-end, the only place that introduces symbol types is c_typecheck_baset::typecheck_compound_type
.
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 per #1148 this will be cleaned up in one go at a later stage. Removing all further comments about the use of ns.follow
.
src/solvers/flattening/arrays.cpp
Outdated
std::cout << "Index set (" << index_entry.first << " = " | ||
<< arrays.find_number(index_entry.first) << " = " | ||
<< from_expr(ns, "", | ||
arrays[arrays.find_number(index_entry.first)]) |
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 indent here is a bit strange
it=index_set.begin(); | ||
it!=index_set.end(); | ||
it++) | ||
for(auto other_index : index_set) |
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.
for(const auto &other_index : index_set)
(to make sure this does not introduce any copies)
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.
That won't work, as other_index may be changed later on; i.e., the copy is intentional.
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.
My apologies, I should have looked at more context.
index_expr2.index()=*it; | ||
const typet &subtype=ns.follow(expr.type()).subtype(); | ||
index_exprt index_expr1(expr, index, subtype); | ||
index_exprt index_expr2(expr.op0(), index, subtype); | ||
|
||
assert(index_expr1.type()==index_expr2.type()); |
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 note that this assertion is trivially true at present (and had been trivially true before), but wouldn't necessarily be so if the third argument to the constructors were omitted.
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.
Removed the very trivial assertions.
src/solvers/flattening/arrays.cpp
Outdated
@@ -111,21 +111,20 @@ void arrayst::collect_arrays(const exprt &a) | |||
if(a.operands().size()!=3) |
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 check is now unnecessary given the use of to_with_expr
(which does that check).
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.
Indeed, gone
src/solvers/flattening/arrays.cpp
Outdated
index_expr.type()=array_type.subtype(); | ||
index_expr.array()=a.op0(); | ||
index_expr.index()=a.op1(); | ||
index_exprt index_expr(a.op0(), a.op1()); |
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.
Please use update_exprt
(to_update_expr
)
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.
done
@@ -564,17 +524,9 @@ void arrayst::add_array_constraints_with( | |||
|
|||
if(guard_lit!=const_literal(true)) |
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.
Just curious: would it also make sense to special-case guard_lit==const_literal(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.
That case should not exist.
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 that the case?
I'm sorry that I keep suggesting/requesting more changes - this code just appears to have so much room for cleanup... |