Skip to content

Implement sending commands to solver in incremental SMT2 backend #6357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CORE
test.c
--incremental-smt2-solver z3
Passing problem to incremental SMT2 solving via "z3"
--incremental-smt2-solver "z3 --smt2 -in"
Passing problem to incremental SMT2 solving via "z3 --smt2 -in"
^EXIT=(0|127|134|137)$
^SIGNAL=0$
identifier: main::1::x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

#include "smt2_incremental_decision_procedure.h"

#include <solvers/smt2_incremental/smt_commands.h>
#include <solvers/smt2_incremental/smt_to_smt2_string.h>
#include <util/expr.h>
#include <util/string_utils.h>

smt2_incremental_decision_proceduret::smt2_incremental_decision_proceduret(
std::string solver_command)
: solver_command{std::move(solver_command)}, number_of_solver_calls{0}
std::string _solver_command)
: solver_command{std::move(_solver_command)},
number_of_solver_calls{0},
solver_process{split_string(solver_command, ' ', false, true)}
{
send_to_solver(smt_set_option_commandt{smt_option_produce_modelst{true}});
send_to_solver(smt_set_logic_commandt{
smt_logic_quantifier_free_uninterpreted_functions_bit_vectorst{}});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to send these at solver construction time, or do we want to send/update these per query? I don't have a good answer now, but there was comment on another issue/PR that the logic could vary for different calls/inputs. Also do we want to be able to change these later (and is this allowed/easy to do)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to section 4.1 of the SMTLIB standard version 2.6, the set-logic command can only be issued whilst the solver is in "Start mode" and the only way to return to this mode is to issue the reset command. The actions of the reset command include undefining all functions and assertions we have sent to the solver. Therefore if we were reseting and setting different logics for different rounds of solving, then we would no longer be carrying out incremental solving.

TLDR; We should be sending these commands at construction time.

}

exprt smt2_incremental_decision_proceduret::handle(const exprt &expr)
Expand Down Expand Up @@ -71,3 +79,9 @@ decision_proceduret::resultt smt2_incremental_decision_proceduret::dec_solve()
++number_of_solver_calls;
UNIMPLEMENTED_FEATURE("solving.");
}

void smt2_incremental_decision_proceduret::send_to_solver(
const smt_commandt &command)
{
solver_process.send(smt_to_smt2_string(command) + "\n");
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#define CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT2_INCREMENTAL_DECISION_PROCEDURE_H

#include <solvers/stack_decision_procedure.h>
#include <util/piped_process.h>

class smt_commandt;

class smt2_incremental_decision_proceduret final
: public stack_decision_proceduret
Expand All @@ -32,10 +35,15 @@ class smt2_incremental_decision_proceduret final
protected:
// Implementation of protected decision_proceduret member function.
resultt dec_solve() override;
/// \brief Converts given SMT2 command to SMT2 string and sends it to the
/// solver process.
void send_to_solver(const smt_commandt &command);

/// This is where we store the solver command for reporting the solver used.
std::string solver_command;
size_t number_of_solver_calls;

piped_processt solver_process;
};

#endif // CPROVER_SOLVERS_SMT2_INCREMENTAL_SMT2_INCREMENTAL_DECISION_PROCEDURE_H