Skip to content

Commit 4d5d529

Browse files
committed
Avoid assuming that converted arrays have bit vector indices
This means that there will be fewer changes required if we ever change the encoding of arrays such that they do not have a bit vector sorted index. It also means that there is no need to add an invariant for this previously implicitly assumed property.
1 parent 010090b commit 4d5d529

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "smt2_incremental_decision_procedure.h"
44

5+
#include <util/arith_tools.h>
56
#include <util/expr.h>
67
#include <util/namespace.h>
78
#include <util/nodiscard.h>
@@ -78,23 +79,21 @@ static std::vector<exprt> gather_dependent_expressions(const exprt &expr)
7879
void smt2_incremental_decision_proceduret::define_array_function(
7980
const array_exprt &array)
8081
{
81-
const auto array_sort =
82-
convert_type_to_smt_sort(array.type()).cast<smt_array_sortt>();
82+
const smt_sortt array_sort = convert_type_to_smt_sort(array.type());
8383
INVARIANT(
84-
array_sort,
84+
array_sort.cast<smt_array_sortt>(),
8585
"Converting array typed expression to SMT should result in a term of array "
8686
"sort.");
8787
const smt_identifier_termt array_identifier = smt_identifier_termt{
88-
"array_" + std::to_string(array_sequence()), *array_sort};
88+
"array_" + std::to_string(array_sequence()), array_sort};
8989
solver_process->send(smt_declare_function_commandt{array_identifier, {}});
9090
const std::vector<exprt> &elements = array.operands();
91-
const std::size_t index_width =
92-
array_sort->index_sort().cast<smt_bit_vector_sortt>()->bit_width();
91+
const typet &index_type = array.type().index_type();
9392
for(std::size_t i = 0; i < elements.size(); ++i)
9493
{
94+
const smt_termt index = convert_expr_to_smt(from_integer(i, index_type));
9595
const smt_assert_commandt element_definition{smt_core_theoryt::equal(
96-
smt_array_theoryt::select(
97-
array_identifier, smt_bit_vector_constant_termt{i, index_width}),
96+
smt_array_theoryt::select(array_identifier, index),
9897
convert_expr_to_smt(elements.at(i)))};
9998
solver_process->send(element_definition);
10099
}

0 commit comments

Comments
 (0)