Skip to content

Commit ede2fa1

Browse files
Clear string_dependencies in calls to dec_solve
If the content is kept between calls to dec_solve, some nodes can be duplicated in the graph, which leads to more constraints added and decreased performance.
1 parent d483c81 commit ede2fa1

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/solvers/refinement/string_refinement.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -648,20 +648,24 @@ decision_proceduret::resultt string_refinementt::dec_solve()
648648
output_equations(debug(), equations, ns);
649649
#endif
650650

651+
// The object `dependencies` is also used by get, so we have to use it as a
652+
// class member but we make sure it is cleared at each `dec_solve` call.
653+
dependencies.clear();
651654
debug() << "dec_solve: compute dependency graph and remove function "
652655
<< "applications captured by the dependencies:" << eom;
653-
const auto new_equation_end = std::remove_if(
654-
equations.begin(), equations.end(), [&](const equal_exprt &eq) { // NOLINT
655-
return add_node(dependencies, eq, generator.array_pool);
656-
});
657-
equations.erase(new_equation_end, equations.end());
656+
std::vector<exprt> local_equations;
657+
for(const equal_exprt &eq : equations)
658+
{
659+
if(!add_node(dependencies, eq, generator.array_pool))
660+
local_equations.push_back(eq);
661+
}
658662

659663
#ifdef DEBUG
660664
dependencies.output_dot(debug());
661665
#endif
662666

663667
debug() << "dec_solve: add constraints" << eom;
664-
dependencies.add_constraints(generator);
668+
dependencies.add_constraints(generator);
665669

666670
#ifdef DEBUG
667671
output_equations(debug(), equations, ns);
@@ -676,7 +680,7 @@ decision_proceduret::resultt string_refinementt::dec_solve()
676680
}
677681
#endif
678682

679-
for(const auto &eq : equations)
683+
for(const auto &eq : local_equations)
680684
{
681685
#ifdef DEBUG
682686
debug() << "dec_solve: set_to " << format(eq) << eom;

src/solvers/refinement/string_refinement_util.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ void string_dependenciest::add_dependency(
259259
});
260260
}
261261

262+
void string_dependenciest::clear()
263+
{
264+
builtin_function_nodes.clear();
265+
string_nodes.clear();
266+
node_index_pool.clear();
267+
clean_cache();
268+
}
269+
262270
static void add_dependency_to_string_subexprs(
263271
string_dependenciest &dependencies,
264272
const function_application_exprt &fun_app,

src/solvers/refinement/string_refinement_util.h

+3
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ class string_dependenciest
254254
/// only add constraints on the length.
255255
void add_constraints(string_constraint_generatort &generatort);
256256

257+
/// Clear the content of the dependency graph
258+
void clear();
259+
257260
private:
258261
/// Set of nodes representing builtin_functions
259262
std::vector<builtin_function_nodet> builtin_function_nodes;

0 commit comments

Comments
 (0)