Skip to content

Commit 71d746a

Browse files
committed
Make the order of SMT commands for sub-expressions deterministic
This makes the behaviour of the conversion predictable. This has the advantage of being easier to unit test and reducing the possiblity of hard to re-produce bugs.
1 parent 7a0da55 commit 71d746a

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@
1818

1919
/// \brief Find all sub expressions of the given \p expr which need to be
2020
/// expressed as separate smt commands.
21+
/// \return A collection of sub expressions, which need to be expressed as
22+
/// separate smt commands. This collection is in traversal order. It will
23+
/// include duplicate subexpressions, which need to be removed by the caller
24+
/// in order to avoid duplicate definitions.
2125
/// \note This pass over \p expr is tightly coupled to the implementation of
2226
/// `convert_expr_to_smt`. This is because any sub expressions which
2327
/// `convert_expr_to_smt` translates into function applications, must also be
2428
/// returned by this`gather_dependent_expressions` function.
25-
static std::unordered_set<exprt, irep_hash>
26-
gather_dependent_expressions(const exprt &expr)
29+
static std::vector<exprt> gather_dependent_expressions(const exprt &expr)
2730
{
28-
std::unordered_set<exprt, irep_hash> dependent_expressions;
31+
std::vector<exprt> dependent_expressions;
2932
expr.visit_pre([&](const exprt &expr_node) {
3033
if(can_cast_expr<symbol_exprt>(expr_node))
3134
{
32-
dependent_expressions.insert(expr_node);
35+
dependent_expressions.push_back(expr_node);
3336
}
3437
});
3538
return dependent_expressions;

unit/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,23 @@ TEST_CASE(
143143
REQUIRE(
144144
sent_commands ==
145145
std::vector<smt_commandt>{
146-
smt_declare_function_commandt{nondet_int_b_term, {}},
147146
smt_declare_function_commandt{nondet_int_a_term, {}},
148-
smt_define_function_commandt{
149-
"third_comparison",
150-
{},
151-
smt_core_theoryt::equal(nondet_int_a_term, nondet_int_b_term)},
152147
smt_define_function_commandt{
153148
"forty_two", {}, smt_bit_vector_constant_termt{42, 16}},
149+
smt_define_function_commandt{
150+
"first_comparison",
151+
{},
152+
smt_core_theoryt::equal(nondet_int_a_term, forty_two_term)},
153+
smt_declare_function_commandt{nondet_int_b_term, {}},
154154
smt_define_function_commandt{
155155
"second_comparison",
156156
{},
157157
smt_core_theoryt::make_not(
158158
smt_core_theoryt::equal(nondet_int_b_term, forty_two_term))},
159159
smt_define_function_commandt{
160-
"first_comparison",
160+
"third_comparison",
161161
{},
162-
smt_core_theoryt::equal(nondet_int_a_term, forty_two_term)},
162+
smt_core_theoryt::equal(nondet_int_a_term, nondet_int_b_term)},
163163
smt_define_function_commandt{
164164
"comparison_conjunction",
165165
{},

0 commit comments

Comments
 (0)