Skip to content

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

Merged
merged 1 commit into from
Jul 20, 2017
Merged

cleanup array theory solver #1145

merged 1 commit into from
Jul 20, 2017

Conversation

kroening
Copy link
Member

  • Use ranged for
  • Use full index_exprt constructors
  • Cleaned out unused method prototype

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.

See detailed comments; also I don't see how this PR delivers on "Use full index_exprt constructors" or
"Cleaned out unused method prototype".

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';
Copy link
Collaborator

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

array_equalities.begin();
it!=array_equalities.end();
it++)
for(const auto & it : array_equalities)
Copy link
Collaborator

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)

it=update_indices.begin();
it!=update_indices.end(); it++)
update_index_map(*it);
for(const auto & it : update_indices)
Copy link
Collaborator

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)

it=index_set.begin();
it!=index_set.end();
it++)
for(const auto & it : index_set)
Copy link
Collaborator

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)

it=index_set.begin();
it!=index_set.end();
it++)
for(const auto & it : index_set)
{
index_exprt index_expr1;
Copy link
Collaborator

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.

it=index_set.begin();
it!=index_set.end();
it++)
for(const auto & it : index_set)
Copy link
Collaborator

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.

{
exprt other_index=*it;
exprt other_index=it;
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above (multiple)

it=index_set.begin();
it!=index_set.end();
it++)
for(const auto & it : index_set)
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above

{
index_exprt index_expr1;
index_expr1.type()=ns.follow(expr.type()).subtype();
index_expr1.array()=expr;
index_expr1.index()=*it;
index_expr1.index()=it;
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above

it=index_set.begin();
it!=index_set.end();
it++)
for(const auto & it : index_set)
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above

@kroening kroening force-pushed the array_cleanup branch 3 times, most recently from 78ce76d to 7f29114 Compare July 17, 2017 10:26
@kroening
Copy link
Member Author

Many thanks, should now be all done.

@tautschnig
Copy link
Collaborator

Many thanks, should now be all done.

The linter isn't quite happy yet? (Stray whitespace at end of line.)

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());
Copy link
Collaborator

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?

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());
Copy link
Collaborator

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();
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: I believe this is unnecessary.

Copy link
Member Author

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.

Copy link
Collaborator

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.)

Copy link
Member Author

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).

Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

std::cout << "Index set (" << index_entry.first << " = "
<< arrays.find_number(index_entry.first) << " = "
<< from_expr(ns, "",
arrays[arrays.find_number(index_entry.first)])
Copy link
Collaborator

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)
Copy link
Collaborator

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)

Copy link
Member Author

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.

Copy link
Collaborator

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());
Copy link
Collaborator

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.

Copy link
Member Author

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.

@@ -111,21 +111,20 @@ void arrayst::collect_arrays(const exprt &a)
if(a.operands().size()!=3)
Copy link
Collaborator

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).

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, gone

index_expr.type()=array_type.subtype();
index_expr.array()=a.op0();
index_expr.index()=a.op1();
index_exprt index_expr(a.op0(), a.op1());
Copy link
Collaborator

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)

Copy link
Member Author

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))
Copy link
Collaborator

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)?

Copy link
Member Author

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.

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 that the case?

@tautschnig
Copy link
Collaborator

I'm sorry that I keep suggesting/requesting more changes - this code just appears to have so much room for cleanup...

@tautschnig tautschnig merged commit 4577401 into master Jul 20, 2017
@tautschnig tautschnig deleted the array_cleanup branch July 20, 2017 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants