mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
Optimize calls to Z3_eval_smtlib2_string (#6422)
* Allow reseting the stream of smt2::scanner * Put the parser of parse_smt2_commands in the cmd_context * Move parser streams to cmd_context * Move parser fields from cmd_context to api::context * Move forward declarations from cmd_context.h to api_context.h * Change parse_smt2_commands_with_parser to use *& instead of ** * Add tests for Z3_eval_smtlib2_string * Don't reuse the streams in Z3_eval_smtlib2_string * Fix indentation * Add back unnecessary deleted line Co-authored-by: Nuno Lopes <nuno.lopes@tecnico.ulisboa.pt>
This commit is contained in:
parent
a409a4a677
commit
91cdc082c4
8 changed files with 154 additions and 9 deletions
|
@ -149,6 +149,8 @@ namespace api {
|
|||
|
||||
|
||||
context::~context() {
|
||||
if (m_parser)
|
||||
smt2::free_parser(m_parser);
|
||||
m_last_obj = nullptr;
|
||||
flush_objects();
|
||||
for (auto& kv : m_allocated_objects) {
|
||||
|
|
|
@ -50,6 +50,11 @@ namespace realclosure {
|
|||
class manager;
|
||||
};
|
||||
|
||||
namespace smt2 {
|
||||
class parser;
|
||||
void free_parser(parser*);
|
||||
};
|
||||
|
||||
namespace api {
|
||||
|
||||
class seq_expr_solver : public expr_solver {
|
||||
|
@ -233,6 +238,19 @@ namespace api {
|
|||
|
||||
void check_sorts(ast * n);
|
||||
|
||||
|
||||
// ------------------------------------------------
|
||||
//
|
||||
// State reused by calls to Z3_eval_smtlib2_string
|
||||
//
|
||||
// ------------------------------------------------
|
||||
//
|
||||
// The m_parser field is reused by all calls of Z3_eval_smtlib2_string using this context.
|
||||
// It is an optimization to save the cost of recreating these objects on each invocation.
|
||||
//
|
||||
// See https://github.com/Z3Prover/z3/pull/6422 for the motivation
|
||||
smt2::parser* m_parser = nullptr;
|
||||
|
||||
// ------------------------
|
||||
//
|
||||
// Polynomial manager & caches
|
||||
|
|
|
@ -246,7 +246,8 @@ extern "C" {
|
|||
ctx->set_diagnostic_stream(ous);
|
||||
cmd_context::scoped_redirect _redirect(*ctx);
|
||||
try {
|
||||
if (!parse_smt2_commands(*ctx.get(), is)) {
|
||||
// See api::context::m_parser for a motivation about the reuse of the parser
|
||||
if (!parse_smt2_commands_with_parser(mk_c(c)->m_parser, *ctx.get(), is)) {
|
||||
SET_ERROR_CODE(Z3_PARSER_ERROR, ous.str());
|
||||
RETURN_Z3(mk_c(c)->mk_external_string(ous.str()));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue