Skip to content

Commit ef5192d

Browse files
committed
Add sending the SMT solver the object size definitions
The tracking of whether the object size definitions have been sent to the solver or not is currently being stored in a `std::vector<bool>` rather than in `decision_procedure_objectt` because this will use less memory. `std::vector<bool>` will pack the booleans such that they are stored 8 flags per byte - overall memory will be number of objects / 8. Storing them directly in the object map would use number of objects * sizeof(bool).
1 parent 13e601b commit ef5192d

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

src/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,26 @@ static decision_proceduret::resultt lookup_decision_procedure_result(
323323
UNREACHABLE;
324324
}
325325

326+
void smt2_incremental_decision_proceduret::define_object_sizes()
327+
{
328+
object_size_defined.resize(object_map.size());
329+
for(const auto &key_value : object_map)
330+
{
331+
const decision_procedure_objectt &object = key_value.second;
332+
if(object_size_defined[object.unique_id])
333+
continue;
334+
else
335+
object_size_defined[object.unique_id] = true;
336+
define_dependent_functions(object.size);
337+
solver_process->send(object_size_function.make_definition(
338+
object.unique_id, convert_expr_to_smt(object.size)));
339+
}
340+
}
341+
326342
decision_proceduret::resultt smt2_incremental_decision_proceduret::dec_solve()
327343
{
328344
++number_of_solver_calls;
345+
define_object_sizes();
329346
const smt_responset result =
330347
get_response_to_command(*solver_process, smt_check_sat_commandt{});
331348
if(const auto check_sat_response = result.cast<smt_check_sat_responset>())

src/solvers/smt2_incremental/smt2_incremental_decision_procedure.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class smt2_incremental_decision_proceduret final
6161
/// \brief Add objects in \p expr to object_map if needed and convert to smt.
6262
/// \note This function is non-const because it mutates the object_map.
6363
smt_termt convert_expr_to_smt(const exprt &expr);
64+
/// Sends the solver the definitions of the object sizes.
65+
void define_object_sizes();
6466

6567
const namespacet &ns;
6668

@@ -85,6 +87,7 @@ class smt2_incremental_decision_proceduret final
8587
std::unordered_map<exprt, smt_identifier_termt, irep_hash>
8688
expression_identifiers;
8789
smt_object_mapt object_map;
90+
std::vector<bool> object_size_defined;
8891
smt_object_sizet object_size_function;
8992
};
9093

unit/solvers/smt2_incremental/smt2_incremental_decision_procedure.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// Author: Diffblue Ltd.
22

3-
#include <testing-utils/use_catch.h>
3+
#include <util/arith_tools.h>
4+
#include <util/bitvector_types.h>
5+
#include <util/config.h>
6+
#include <util/exception_utils.h>
7+
#include <util/make_unique.h>
8+
#include <util/namespace.h>
9+
#include <util/symbol_table.h>
410

511
#include <solvers/smt2_incremental/smt2_incremental_decision_procedure.h>
612
#include <solvers/smt2_incremental/smt_commands.h>
@@ -10,12 +16,7 @@
1016
#include <solvers/smt2_incremental/smt_sorts.h>
1117
#include <solvers/smt2_incremental/smt_terms.h>
1218
#include <testing-utils/invariant.h>
13-
#include <util/arith_tools.h>
14-
#include <util/bitvector_types.h>
15-
#include <util/exception_utils.h>
16-
#include <util/make_unique.h>
17-
#include <util/namespace.h>
18-
#include <util/symbol_table.h>
19+
#include <testing-utils/use_catch.h>
1920

2021
// Used by catch framework for printing in the case of test failures. This
2122
// means that we get error messages showing the smt formula expressed as SMT2
@@ -104,12 +105,26 @@ struct decision_procedure_test_environmentt final
104105
std::deque<smt_responset> mock_responses;
105106
std::vector<smt_commandt> sent_commands;
106107
null_message_handlert message_handler;
108+
smt_object_sizet object_size_function;
107109
smt2_incremental_decision_proceduret procedure{
108110
ns,
109111
util_make_unique<smt_mock_solver_processt>(
110112
[&](const smt_commandt &smt_command) { this->send(smt_command); },
111113
[&]() { return this->receive_response(); }),
112114
message_handler};
115+
static decision_procedure_test_environmentt make()
116+
{
117+
// These config lines are necessary before construction because pointer
118+
// widths and object bit width encodings depend on the global configuration.
119+
config.ansi_c.mode = configt::ansi_ct::flavourt::GCC;
120+
config.ansi_c.set_arch_spec_i386();
121+
return {};
122+
}
123+
124+
private:
125+
// This is private to ensure the above make() function is used to make
126+
// correctly configured instances.
127+
decision_procedure_test_environmentt() = default;
113128
};
114129

115130
void decision_procedure_test_environmentt::send(const smt_commandt &smt_command)
@@ -147,17 +162,16 @@ TEST_CASE(
147162
"smt2_incremental_decision_proceduret commands sent",
148163
"[core][smt2_incremental]")
149164
{
150-
decision_procedure_test_environmentt test{};
165+
auto test = decision_procedure_test_environmentt::make();
151166
SECTION("Construction / solver initialisation.")
152167
{
153-
smt_object_sizet object_size_function;
154168
REQUIRE(
155169
test.sent_commands ==
156170
std::vector<smt_commandt>{
157171
smt_set_option_commandt{smt_option_produce_modelst{true}},
158172
smt_set_logic_commandt{
159173
smt_logic_quantifier_free_uninterpreted_functions_bit_vectorst{}},
160-
object_size_function.declaration});
174+
test.object_size_function.declaration});
161175
test.sent_commands.clear();
162176
SECTION("Set symbol to true.")
163177
{
@@ -296,7 +310,7 @@ TEST_CASE(
296310
"smt2_incremental_decision_proceduret number of solver calls.",
297311
"[core][smt2_incremental]")
298312
{
299-
decision_procedure_test_environmentt test{};
313+
auto test = decision_procedure_test_environmentt::make();
300314
REQUIRE(test.procedure.get_number_of_solver_calls() == 0);
301315
test.mock_responses.push_back(smt_check_sat_responset{smt_unsat_responset{}});
302316
test.procedure();
@@ -311,7 +325,7 @@ TEST_CASE(
311325
"internal decision_proceduret::resultt",
312326
"[core][smt2_incremental]")
313327
{
314-
decision_procedure_test_environmentt test{};
328+
auto test = decision_procedure_test_environmentt::make();
315329
SECTION("sat")
316330
{
317331
test.mock_responses = {smt_check_sat_responset{smt_sat_responset{}}};
@@ -334,7 +348,7 @@ TEST_CASE(
334348
"response.",
335349
"[core][smt2_incremental]")
336350
{
337-
decision_procedure_test_environmentt test{};
351+
auto test = decision_procedure_test_environmentt::make();
338352
SECTION("Expected success response.")
339353
{
340354
test.mock_responses = {smt_success_responset{},
@@ -359,7 +373,7 @@ TEST_CASE(
359373
"check-sat.",
360374
"[core][smt2_incremental]")
361375
{
362-
decision_procedure_test_environmentt test{};
376+
auto test = decision_procedure_test_environmentt::make();
363377
SECTION("get-value response")
364378
{
365379
test.mock_responses = {
@@ -394,7 +408,10 @@ TEST_CASE(
394408
"smt2_incremental_decision_proceduret getting values back from solver.",
395409
"[core][smt2_incremental]")
396410
{
397-
decision_procedure_test_environmentt test{};
411+
auto test = decision_procedure_test_environmentt::make();
412+
const auto null_object_size_definition =
413+
test.object_size_function.make_definition(
414+
0, smt_bit_vector_constant_termt{0, 32});
398415
const symbolt foo = make_test_symbol("foo", signedbv_typet{16});
399416
const smt_identifier_termt foo_term{"foo", smt_bit_vector_sortt{16}};
400417
const exprt expr_42 = from_integer({42}, signedbv_typet{16});
@@ -411,6 +428,7 @@ TEST_CASE(
411428
std::vector<smt_commandt>{
412429
smt_declare_function_commandt{foo_term, {}},
413430
smt_assert_commandt{smt_core_theoryt::equal(foo_term, term_42)},
431+
null_object_size_definition,
414432
smt_check_sat_commandt{}});
415433
SECTION("Get \"foo\" value back")
416434
{

0 commit comments

Comments
 (0)