Skip to content

Cleaning dependencies of the string solver #549

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

Conversation

romainbrenguier
Copy link
Contributor

src/util is a more appropriate place for the string_exprt class, so it was moved there.

We changed the constructor with one type argument to be similar to
other exprt constructors.
This constructor was used to generate a struct with
fresh symbols but this is no longer the case, so we use a function
fresh string instead.

Dependencies in the solver that were not needed have been removed.

For some functions this requires us to now pass the string type as
argument, so the appropriate changes have been made.

@tautschnig
Copy link
Collaborator

The linter warnings appear to be genuine, would you mind addressing them?


// Internal type used for string refinement
class refined_string_typet: public struct_typet
{
public:
explicit refined_string_typet(typet char_type);
explicit refined_string_typet(typet index_type, typet char_type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's safe to get rid of "explicit" now that this constructor takes 2 arguments.

{ }
mode(ID_unknown)
{
next_symbol_id=1;
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 entirely sure, but I think this would actually reset the counter. Place the initialisation with the declaration.

exprt constr2=character_equals_ignore_case(
s1[qvar], s2[qvar], char_a, char_A, char_Z);
string_constraintt a2(qvar, s1.length(), eq, constr2);
axioms.push_back(a2);

symbol_exprt witness=fresh_exist_index("witness_unequal_ignore_case");
exprt zero=from_integer(0, get_index_type());
// TODO: we should have to give the type of witness
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you mind elaborating a bit more to enable others to pick up this TODO? Specifically, I don't know who "we" refers to, and what type that would be - it seems it's using index_type - is that not correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry this shouldn't be there, the call the index_type has been added but the TODO wasn't removed

return string_exprt(length, content, type);
}


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: one blank line will do

@@ -705,14 +707,14 @@ exprt string_refinementt::sum_over_map(
switch(second)
{
case -1:
if(sum==from_integer(0, generator.get_index_type()))
if(sum==nil_exprt())
Copy link
Collaborator

Choose a reason for hiding this comment

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

You might want to use if(sum.is_nil())

exprt index_const=from_integer(constants, generator.get_index_type());
return plus_exprt(sum, index_const);
exprt index_const=from_integer(constants, index_type);
if(sum!=nil_exprt())
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could use if(sum.is_not_nil())

@romainbrenguier
Copy link
Contributor Author

@tautschnig yes, sorry for these, this is now done

@tautschnig
Copy link
Collaborator

Thanks a lot for the immediate cleanup - please see my comments for a few more changes to consider.

@@ -229,8 +256,9 @@ string_exprt string_constraint_generatort::find_or_add_string_of_symbol(
const symbol_exprt &sym)
{
irep_idt id=sym.get_identifier();
auto entry=symbol_to_string.insert(
std::make_pair(id, string_exprt(get_char_type())));
refined_string_typet ref_type=to_refined_string_type(sym.type());
Copy link
Member

Choose a reason for hiding this comment

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

const &

@@ -403,15 +430,16 @@ string_exprt string_constraint_generatort::add_axioms_for_copy(
const function_application_exprt &f)
{
string_exprt s1=add_axioms_for_string_expr(args(f, 1)[0]);
string_exprt res(get_char_type());
refined_string_typet ref_type=to_refined_string_type(s1.type());
Copy link
Member

Choose a reason for hiding this comment

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

const & (and all other instances like this)

@@ -655,7 +638,8 @@ exprt string_constraint_generatort::add_axioms_for_char_at(
const function_application_exprt &f)
{
string_exprt str=add_axioms_for_string_expr(args(f, 2)[0]);
symbol_exprt char_sym=string_exprt::fresh_symbol("char", get_char_type());
refined_string_typet ref_type=to_refined_string_type(str.type());
Copy link
Member

Choose a reason for hiding this comment

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

const &

// Generate a new symbol of the given type with a prefix
static symbol_exprt fresh_symbol(
const irep_idt &prefix, const typet &type=bool_typet());
string_exprt(exprt _length, exprt _content, typet type): string_exprt(type)
Copy link
Member

Choose a reason for hiding this comment

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

const & (twice, and use copy_to_operands)

@@ -705,14 +707,14 @@ exprt string_refinementt::sum_over_map(
switch(second)
{
case -1:
if(sum==from_integer(0, generator.get_index_type()))
if(sum==nil_exprt())
Copy link
Member

Choose a reason for hiding this comment

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

.is_nil() (several instances)

@romainbrenguier
Copy link
Contributor Author

@tautschnig @peterschrammel thanks for the comment, I've now done the corresponding corrections

@romainbrenguier romainbrenguier force-pushed the string-refinement-dependencies branch from 0174939 to 6096c5f Compare February 15, 2017 16:05
@romainbrenguier romainbrenguier force-pushed the string-refinement-dependencies branch from 6096c5f to 0628812 Compare February 16, 2017 12:43
exprt s0,
exprt s1) :
string_exprt s0,
string_exprt s1) :
Copy link
Member

Choose a reason for hiding this comment

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

no space before :

@@ -73,9 +57,14 @@ class string_constraint_generatort
return index_exprt(witness.at(c), univ_val);
}

symbol_exprt fresh_exist_index(const irep_idt &prefix);
symbol_exprt fresh_univ_index(const irep_idt &prefix);
static unsigned next_symbol_id=1;
Copy link
Member

Choose a reason for hiding this comment

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

The initialisation should be in the cpp file.

static irep_idt extract_java_string(const symbol_exprt &s);

static unsigned next_symbol_id;

friend inline string_exprt &to_string_expr(exprt &expr);
};


Copy link
Member

Choose a reason for hiding this comment

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

remove one blank line

@romainbrenguier romainbrenguier force-pushed the string-refinement-dependencies branch from 4aefd87 to a04f840 Compare February 18, 2017 13:18
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.

I would suggest to move the initialisation as indicated in the comment - otherwise this looks ok to me.

@@ -17,42 +17,48 @@ Author: Romain Brenguier, [email protected]
#include <util/pointer_predicates.h>
#include <util/ssa_expr.h>

unsigned string_constraint_generatort::next_symbol_id=1;

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 initialization not done right in the class declaration? I'd rather drop this one instead of the in-class one as you've done in one of your commits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I don't have a preference, but Peter suggested that the initialisation should be in the cpp file.

Copy link
Member

Choose a reason for hiding this comment

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

You can't initialise a non-const static member in the class definition.


// Internal type used for string refinement
class refined_string_typet: public struct_typet
{
public:
explicit refined_string_typet(typet char_type);
refined_string_typet(typet index_type, typet char_type);
Copy link
Member

Choose a reason for hiding this comment

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

const & (twice)


string_not_contains_constraintt(
exprt univ_lower_bound,
exprt univ_bound_sup,
exprt premise,
exprt exists_bound_inf,
exprt exists_bound_sup,
exprt s0,
exprt s1) :
string_exprt s0,
Copy link
Member

Choose a reason for hiding this comment

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

const & (twice)

@@ -22,11 +22,11 @@ Constructor: refined_string_typet::refined_string_typet

\*******************************************************************/

refined_string_typet::refined_string_typet(typet char_type)
refined_string_typet::refined_string_typet(typet index_type, typet char_type)
Copy link
Member

Choose a reason for hiding this comment

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

const & (twice)

boolean_symbols.push_back(b);
return b;
}


Copy link
Member

Choose a reason for hiding this comment

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

remove one blank line

@tautschnig
Copy link
Collaborator

@peterschrammel It seems all concerns have been addressed. I note that the linter is failing with an internal error rather than reporting any problems in the source files...

@forejtv
Copy link
Contributor

forejtv commented Feb 21, 2017

@romainbrenguier can you please rebase, to have a fixed linter output?

@romainbrenguier romainbrenguier force-pushed the string-refinement-dependencies branch from d9b5714 to c29eed4 Compare February 21, 2017 18:03
@romainbrenguier
Copy link
Contributor Author

@forejtv done


static symbol_exprt fresh_symbol(
const irep_idt &prefix, const typet &type=bool_typet());
symbol_exprt fresh_exist_index(const irep_idt &prefix, typet type);
Copy link
Member

Choose a reason for hiding this comment

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

const typet &type (several occurrences)

@romainbrenguier romainbrenguier force-pushed the string-refinement-dependencies branch from f971285 to 0ad726d Compare February 22, 2017 10:06
@romainbrenguier
Copy link
Contributor Author

@peterschrammel it's now done, should I squash the commits?

@peterschrammel
Copy link
Member

Yes, the cleanup commits should be squashed

`src/util` is a more appropriate place for the `string_exprt` class

We changed the constructor with one type argument to be similar to
other `exprt` constructors.
This constructor was used to generate a struct with
fresh symbols but this is no longer the case, so we use a function
fresh string instead.

Dependencies in the solver that were not needed have been removed.

For some functions this requieres us to now pass the string type as
argument.
@romainbrenguier romainbrenguier force-pushed the string-refinement-dependencies branch from 0ad726d to 3cb7bca Compare February 22, 2017 14:37
@romainbrenguier
Copy link
Contributor Author

@peterschrammel commits have been squashed: 3cb7bca

Copy link
Member

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

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

@kroening, this looks ready to go

@kroening kroening merged commit 37163d8 into diffblue:master Mar 1, 2017
NathanJPhillips pushed a commit to NathanJPhillips/cbmc that referenced this pull request Aug 22, 2018
…ween_DO_and_EVSes

SEC-633: Bugfix: added alias-computation between a DO and EVSes in the domain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants