Skip to content

Commit 4b342f7

Browse files
Only add constraints on test function dependencies
Instead of adding all constraints corresponding to a string function call, we look at which strings may be used in a testing function (such as endsWith, equals, compare, etc...). We only add constraints for these function calls, since the other operations cannot matter for the satisfiability problem.
1 parent 3c61cf2 commit 4b342f7

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/solvers/refinement/string_refinement_util.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <util/graph.h>
1818
#include <util/magic.h>
1919
#include <util/make_unique.h>
20+
#include <unordered_set>
2021
#include "string_refinement_util.h"
2122

2223
bool is_char_type(const typet &type)
@@ -410,9 +411,28 @@ void string_dependenciest::output_dot(std::ostream &stream) const
410411
void string_dependenciest::add_constraints(
411412
string_constraint_generatort &generator)
412413
{
414+
std::unordered_set<nodet, node_hash> test_dependencies;
413415
for(const auto &builtin : builtin_function_nodes)
414416
{
415-
const exprt return_value = builtin.data->add_constraints(generator);
416-
generator.add_lemma(equal_exprt(return_value, builtin.data->return_code));
417+
if(builtin.data->maybe_testing_function())
418+
test_dependencies.insert(nodet(builtin));
419+
}
420+
421+
get_reachable(
422+
test_dependencies,
423+
[&](
424+
const nodet &n,
425+
const std::function<void(const nodet &)> &f) { // NOLINT
426+
for_each_successor(n, f);
427+
});
428+
429+
for(const auto &node : test_dependencies)
430+
{
431+
if(node.kind == node.BUILTIN)
432+
{
433+
const auto &builtin = builtin_function_nodes[node.index];
434+
const exprt return_value = builtin.data->add_constraints(generator);
435+
generator.add_lemma(equal_exprt(return_value, builtin.data->return_code));
436+
}
417437
}
418438
}

0 commit comments

Comments
 (0)