Skip to content

Commit d1a4169

Browse files
authored
Merge pull request #2542 from tautschnig/vs-string-refinement
String refinement: remove unused parameters
2 parents c749b8f + 18faa5a commit d1a4169

6 files changed

+22
-51
lines changed

src/solvers/refinement/string_builtin_function.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class string_insertion_builtin_functiont : public string_builtin_functiont
195195
exprt length_constraint() const override
196196
{
197197
if(args.size() == 1)
198-
return length_constraint_for_insert(result, input1, input2, args[0]);
198+
return length_constraint_for_insert(result, input1, input2);
199199
if(args.size() == 3)
200200
UNIMPLEMENTED;
201201
UNREACHABLE;

src/solvers/refinement/string_constraint_generator.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ class string_constraint_generatort final
365365
const exprt &radix,
366366
const unsigned long radix_ul);
367367
void add_axioms_for_correct_number_format(
368-
const exprt &input_int,
369368
const array_string_exprt &str,
370369
const exprt &radix_as_char,
371370
const unsigned long radix_ul,
@@ -457,7 +456,6 @@ exprt length_constraint_for_concat_substr(
457456
exprt length_constraint_for_insert(
458457
const array_string_exprt &res,
459458
const array_string_exprt &s1,
460-
const array_string_exprt &s2,
461-
const exprt &offset);
459+
const array_string_exprt &s2);
462460

463461
#endif

src/solvers/refinement/string_constraint_generator_insert.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ exprt string_constraint_generatort::add_axioms_for_insert(
4141
maximum(from_integer(0, index_type), minimum(s1.length(), offset));
4242

4343
// Axiom 1.
44-
lemmas.push_back(length_constraint_for_insert(res, s1, s2, offset));
44+
lemmas.push_back(length_constraint_for_insert(res, s1, s2));
4545

4646
// Axiom 2.
4747
constraints.push_back([&] { // NOLINT
@@ -69,13 +69,12 @@ exprt string_constraint_generatort::add_axioms_for_insert(
6969
return from_integer(0, get_return_code_type());
7070
}
7171

72-
/// Add axioms ensuring the length of `res` corresponds that of `s1` where we
73-
/// inserted `s2` at position `offset`.
72+
/// Add axioms ensuring the length of `res` corresponds to that of `s1` where we
73+
/// inserted `s2`.
7474
exprt length_constraint_for_insert(
7575
const array_string_exprt &res,
7676
const array_string_exprt &s1,
77-
const array_string_exprt &s2,
78-
const exprt &offset)
77+
const array_string_exprt &s2)
7978
{
8079
return equal_exprt(res.length(), plus_exprt(s1.length(), s2.length()));
8180
}

src/solvers/refinement/string_constraint_generator_valueof.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ exprt string_constraint_generatort::add_axioms_from_int_with_radix(
169169
const bool strict_formatting=true;
170170

171171
add_axioms_for_correct_number_format(
172-
input_int, res, radix_as_char, radix_ul, max_size, strict_formatting);
172+
res, radix_as_char, radix_ul, max_size, strict_formatting);
173173

174174
add_axioms_for_characters_in_integer_string(
175175
input_int,
@@ -306,7 +306,6 @@ exprt string_constraint_generatort::add_axioms_from_char(
306306

307307
/// Add axioms making the return value true if the given string is a correct
308308
/// number in the given radix
309-
/// \param input_int: the number being represented as a string
310309
/// \param str: string expression
311310
/// \param radix_as_char: the radix as an expression of the same type as the
312311
/// characters in str
@@ -316,7 +315,6 @@ exprt string_constraint_generatort::add_axioms_from_char(
316315
/// \param strict_formatting: if true, don't allow a leading plus, redundant
317316
/// zeros or upper case letters
318317
void string_constraint_generatort::add_axioms_for_correct_number_format(
319-
const exprt &input_int,
320318
const array_string_exprt &str,
321319
const exprt &radix_as_char,
322320
const unsigned long radix_ul,
@@ -515,7 +513,6 @@ exprt string_constraint_generatort::add_axioms_for_parse_int(
515513
/// \note the only thing stopping us from taking longer strings with many
516514
/// leading zeros is the axioms for correct number format
517515
add_axioms_for_correct_number_format(
518-
input_int,
519516
str,
520517
radix_as_char,
521518
radix_ul,

src/solvers/refinement/string_refinement.cpp

+15-37
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static bool is_valid_string_constraint(
3737

3838
static optionalt<exprt> find_counter_example(
3939
const namespacet &ns,
40-
ui_message_handlert::uit ui,
4140
const exprt &axiom,
4241
const symbol_exprt &var);
4342

@@ -63,9 +62,7 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
6362
const std::function<exprt(const exprt &)> &get,
6463
messaget::mstreamt &stream,
6564
const namespacet &ns,
66-
std::size_t max_string_length,
6765
bool use_counter_example,
68-
ui_message_handlert::uit ui,
6966
const union_find_replacet &symbol_resolve);
7067

7168
static void initial_index_set(
@@ -119,7 +116,6 @@ static std::vector<exprt> instantiate(
119116
static optionalt<exprt> get_array(
120117
const std::function<exprt(const exprt &)> &super_get,
121118
const namespacet &ns,
122-
const std::size_t max_string_length,
123119
messaget::mstreamt &stream,
124120
const array_string_exprt &arr);
125121

@@ -171,7 +167,6 @@ string_refinementt::string_refinementt(const infot &info, bool)
171167
: supert(info),
172168
config_(info),
173169
loop_bound_(info.refinement_bound),
174-
max_string_length(info.max_string_length),
175170
generator(*info.ns)
176171
{
177172
}
@@ -232,7 +227,6 @@ static void display_index_set(
232227
/// for details)
233228
static std::vector<exprt> generate_instantiations(
234229
messaget::mstreamt &stream,
235-
const namespacet &ns,
236230
const string_constraint_generatort &generator,
237231
const index_set_pairt &index_set,
238232
const string_axiomst &axioms)
@@ -532,16 +526,17 @@ union_find_replacet string_identifiers_resolution_from_equations(
532526
return result;
533527
}
534528

529+
#ifdef DEBUG
535530
/// Output a vector of equations to the given stream, used for debugging.
536-
void output_equations(
531+
static void output_equations(
537532
std::ostream &output,
538-
const std::vector<equal_exprt> &equations,
539-
const namespacet &ns)
533+
const std::vector<equal_exprt> &equations)
540534
{
541535
for(std::size_t i = 0; i < equations.size(); ++i)
542536
output << " [" << i << "] " << format(equations[i].lhs())
543537
<< " == " << format(equations[i].rhs()) << std::endl;
544538
}
539+
#endif
545540

546541
/// Main decision procedure of the solver. Looks for a valuation of variables
547542
/// compatible with the constraints that have been given to `set_to` so far.
@@ -611,7 +606,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
611606
{
612607
#ifdef DEBUG
613608
debug() << "dec_solve: Initial set of equations" << eom;
614-
output_equations(debug(), equations, ns);
609+
output_equations(debug(), equations);
615610
#endif
616611

617612
debug() << "dec_solve: Build symbol solver from equations" << eom;
@@ -650,7 +645,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
650645
make_char_array_pointer_associations(generator, equations);
651646

652647
#ifdef DEBUG
653-
output_equations(debug(), equations, ns);
648+
output_equations(debug(), equations);
654649
#endif
655650

656651
debug() << "dec_solve: compute dependency graph and remove function "
@@ -671,7 +666,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
671666
dependencies.add_constraints(generator);
672667

673668
#ifdef DEBUG
674-
output_equations(debug(), equations, ns);
669+
output_equations(debug(), equations);
675670
#endif
676671

677672
#ifdef DEBUG
@@ -744,9 +739,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
744739
get,
745740
debug(),
746741
ns,
747-
max_string_length,
748742
config_.use_counter_example,
749-
supert::config_.ui,
750743
symbol_resolve);
751744
if(satisfied)
752745
{
@@ -767,7 +760,6 @@ decision_proceduret::resultt string_refinementt::dec_solve()
767760
for(const auto &instance :
768761
generate_instantiations(
769762
debug(),
770-
ns,
771763
generator,
772764
index_sets,
773765
axioms))
@@ -788,9 +780,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
788780
get,
789781
debug(),
790782
ns,
791-
max_string_length,
792783
config_.use_counter_example,
793-
supert::config_.ui,
794784
symbol_resolve);
795785
if(satisfied)
796786
{
@@ -830,7 +820,6 @@ decision_proceduret::resultt string_refinementt::dec_solve()
830820
for(const auto &instance :
831821
generate_instantiations(
832822
debug(),
833-
ns,
834823
generator,
835824
index_sets,
836825
axioms))
@@ -899,14 +888,12 @@ void string_refinementt::add_lemma(
899888
/// \param super_get: function returning the valuation of an expression
900889
/// in a model
901890
/// \param ns: namespace
902-
/// \param max_string_length: maximum length of strings to analyze
903891
/// \param stream: output stream for warning messages
904892
/// \param arr: expression of type array representing a string
905893
/// \return an optional array expression or array_of_exprt
906894
static optionalt<exprt> get_array(
907895
const std::function<exprt(const exprt &)> &super_get,
908896
const namespacet &ns,
909-
const std::size_t max_string_length,
910897
messaget::mstreamt &stream,
911898
const array_string_exprt &arr)
912899
{
@@ -975,14 +962,12 @@ static std::string string_of_array(const array_exprt &arr)
975962
/// `super_get` and concretize unknown characters.
976963
/// \param super_get: give a valuation to variables
977964
/// \param ns: namespace
978-
/// \param max_string_length: limit up to which we concretize strings
979965
/// \param stream: output stream
980966
/// \param arr: array expression
981967
/// \return expression corresponding to `arr` in the model
982968
static exprt get_char_array_and_concretize(
983969
const std::function<exprt(const exprt &)> &super_get,
984970
const namespacet &ns,
985-
const std::size_t max_string_length,
986971
messaget::mstreamt &stream,
987972
const array_string_exprt &arr)
988973
{
@@ -991,7 +976,7 @@ static exprt get_char_array_and_concretize(
991976
stream << "- " << format(arr) << ":\n";
992977
stream << indent << indent << "- type: " << format(arr.type()) << eom;
993978
const auto arr_model_opt =
994-
get_array(super_get, ns, max_string_length, stream, arr);
979+
get_array(super_get, ns, stream, arr);
995980
if(arr_model_opt)
996981
{
997982
stream << indent << indent << "- char_array: " << format(*arr_model_opt)
@@ -1003,7 +988,7 @@ static exprt get_char_array_and_concretize(
1003988
<< eom;
1004989
if(
1005990
const auto concretized_array = get_array(
1006-
super_get, ns, max_string_length, stream, to_array_string_expr(simple)))
991+
super_get, ns, stream, to_array_string_expr(simple)))
1007992
{
1008993
stream << indent << indent
1009994
<< "- concretized_char_array: " << format(*concretized_array)
@@ -1032,7 +1017,6 @@ void debug_model(
10321017
const string_constraint_generatort &generator,
10331018
messaget::mstreamt &stream,
10341019
const namespacet &ns,
1035-
const std::size_t max_string_length,
10361020
const std::function<exprt(const exprt &)> &super_get,
10371021
const std::vector<symbol_exprt> &boolean_symbols,
10381022
const std::vector<symbol_exprt> &index_symbols)
@@ -1044,7 +1028,7 @@ void debug_model(
10441028
{
10451029
const auto arr = pointer_array.second;
10461030
const exprt model = get_char_array_and_concretize(
1047-
super_get, ns, max_string_length, stream, arr);
1031+
super_get, ns, stream, arr);
10481032

10491033
stream << "- " << format(arr) << ":\n"
10501034
<< indent << "- pointer: " << format(pointer_array.first) << "\n"
@@ -1243,7 +1227,6 @@ static exprt negation_of_not_contains_constraint(
12431227
template <typename T>
12441228
static void debug_check_axioms_step(
12451229
messaget::mstreamt &stream,
1246-
const namespacet &ns,
12471230
const T &axiom,
12481231
const T &axiom_in_model,
12491232
const exprt &negaxiom,
@@ -1269,9 +1252,7 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
12691252
const std::function<exprt(const exprt &)> &get,
12701253
messaget::mstreamt &stream,
12711254
const namespacet &ns,
1272-
std::size_t max_string_length,
12731255
bool use_counter_example,
1274-
ui_message_handlert::uit ui,
12751256
const union_find_replacet &symbol_resolve)
12761257
{
12771258
const auto eom=messaget::eom;
@@ -1297,7 +1278,6 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
12971278
generator,
12981279
stream,
12991280
ns,
1300-
max_string_length,
13011281
get,
13021282
generator.get_boolean_symbols(),
13031283
generator.get_index_symbols());
@@ -1324,11 +1304,11 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
13241304
const exprt with_concretized_arrays =
13251305
substitute_array_access(negaxiom, gen_symbol, true);
13261306
debug_check_axioms_step(
1327-
stream, ns, axiom, axiom_in_model, negaxiom, with_concretized_arrays);
1307+
stream, axiom, axiom_in_model, negaxiom, with_concretized_arrays);
13281308

13291309
if(
13301310
const auto &witness =
1331-
find_counter_example(ns, ui, with_concretized_arrays, axiom.univ_var))
1311+
find_counter_example(ns, with_concretized_arrays, axiom.univ_var))
13321312
{
13331313
stream << indent2 << "- violated_for: " << format(axiom.univ_var) << "="
13341314
<< format(*witness) << eom;
@@ -1354,11 +1334,11 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
13541334

13551335
stream << indent << i << ".\n";
13561336
debug_check_axioms_step(
1357-
stream, ns, nc_axiom, nc_axiom, negated_axiom, negated_axiom);
1337+
stream, nc_axiom, nc_axiom, negated_axiom, negated_axiom);
13581338

13591339
if(
13601340
const auto witness =
1361-
find_counter_example(ns, ui, negated_axiom, univ_var))
1341+
find_counter_example(ns, negated_axiom, univ_var))
13621342
{
13631343
stream << indent2 << "- violated_for: " << univ_var.get_identifier()
13641344
<< "=" << format(*witness) << eom;
@@ -2051,7 +2031,7 @@ exprt string_refinementt::get(const exprt &expr) const
20512031

20522032
if(
20532033
const auto arr_model_opt =
2054-
get_array(super_get, ns, max_string_length, debug(), arr))
2034+
get_array(super_get, ns, debug(), arr))
20552035
return *arr_model_opt;
20562036

20572037
if(generator.get_created_strings().count(arr))
@@ -2073,14 +2053,12 @@ exprt string_refinementt::get(const exprt &expr) const
20732053
/// is SAT, then true is returned and the given evaluation of `var` is stored
20742054
/// in `witness`. If UNSAT, then what witness is is undefined.
20752055
/// \param ns: namespace
2076-
/// \param ui: message handler
20772056
/// \param [in] axiom: the axiom to be checked
20782057
/// \param [in] var: the variable whose evaluation will be stored in witness
20792058
/// \return: the witness of the satisfying assignment if one
20802059
/// exists. If UNSAT, then behaviour is undefined.
20812060
static optionalt<exprt> find_counter_example(
20822061
const namespacet &ns,
2083-
const ui_message_handlert::uit ui,
20842062
const exprt &axiom,
20852063
const symbol_exprt &var)
20862064
{

src/solvers/refinement/string_refinement.h

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class string_refinementt final: public bv_refinementt
6767

6868
const configt config_;
6969
std::size_t loop_bound_;
70-
std::size_t max_string_length;
7170
string_constraint_generatort generator;
7271

7372
// Simple constraints that have been given to the solver

0 commit comments

Comments
 (0)