Skip to content

Commit

Permalink
SMT2: simplify interface
Browse files Browse the repository at this point in the history
This relieves the user of the dec_solve(assumption) interface from the need
to obtain a handle for the assumption.

The typing of the assumptions member is strengthened; instead of maintaining
the invariant that the expression stored is a literal_exprt, the vector now
stores literals directly.
  • Loading branch information
kroening committed Dec 19, 2023
1 parent 3a1272a commit 09718c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void smt2_convt::write_footer()
{
out << "(check-sat-assuming (";
for(const auto &assumption : assumptions)
convert_literal(to_literal_expr(assumption).get_literal());
convert_literal(assumption);

Check warning on line 217 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L217

Added line #L217 was not covered by tests
out << "))\n";
}
else
Expand All @@ -227,7 +227,7 @@ void smt2_convt::write_footer()
for(const auto &assumption : assumptions)
{
out << "(assert ";
convert_literal(to_literal_expr(assumption).get_literal());
convert_literal(assumption);

Check warning on line 230 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L230

Added line #L230 was not covered by tests
out << ")"
<< "\n";
}
Expand Down Expand Up @@ -323,7 +323,7 @@ decision_proceduret::resultt smt2_convt::dec_solve(const exprt &assumption)
write_footer();
else
{
assumptions.push_back(literal_exprt(convert(assumption)));
assumptions.push_back(convert(assumption));

Check warning on line 326 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L326

Added line #L326 was not covered by tests
write_footer();
assumptions.pop_back();
}
Expand Down Expand Up @@ -987,7 +987,9 @@ void smt2_convt::push(const std::vector<exprt> &_assumptions)
{
INVARIANT(assumptions.empty(), "nested contexts are not supported");

assumptions = _assumptions;
assumptions.reserve(_assumptions.size());
for(auto &assumption : _assumptions)
assumptions.push_back(convert(assumption));

Check warning on line 992 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L990-L992

Added lines #L990 - L992 were not covered by tests
}

void smt2_convt::pop()
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/smt2/smt2_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class smt2_convt : public stack_decision_proceduret
unordered_map<irep_idt, std::function<void(const exprt &)>, irep_id_hash>;
converterst converters;

std::vector<exprt> assumptions;
std::vector<literalt> assumptions;
boolbv_widtht boolbv_width;

std::size_t number_of_solver_calls = 0;
Expand Down
14 changes: 13 additions & 1 deletion src/solvers/smt2/smt2_dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Author: Daniel Kroening, [email protected]
#include <util/run.h>
#include <util/tempfile.h>

#include <solvers/prop/literal_expr.h>

#include "smt2irep.h"

std::string smt2_dect::decision_procedure_text() const
Expand Down Expand Up @@ -44,10 +46,20 @@ decision_proceduret::resultt smt2_dect::dec_solve(const exprt &assumption)
const auto write_problem_to_file = [&](std::ofstream problem_out) {
cached_output << stringstream.str();
stringstream.str(std::string{});
write_footer();

if(assumption.is_nil())
write_footer();
else
{
assumptions.push_back(convert(assumption));
write_footer();
assumptions.pop_back();

Check warning on line 56 in src/solvers/smt2/smt2_dec.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_dec.cpp#L54-L56

Added lines #L54 - L56 were not covered by tests
}

problem_out << cached_output.str() << stringstream.str();
stringstream.str(std::string{});
};

write_problem_to_file(std::ofstream(
temp_file_problem(), std::ios_base::out | std::ios_base::trunc));

Expand Down

0 comments on commit 09718c3

Please sign in to comment.