3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00

User-functions fix (#5868)

This commit is contained in:
Clemens Eisenhofer 2022-02-26 18:21:01 +01:00 committed by GitHub
parent 689e2d41de
commit 412b05076c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 107 additions and 54 deletions

View file

@ -171,7 +171,7 @@ namespace smt {
dst_ctx.setup_context(dst_ctx.m_fparams.m_auto_config);
dst_ctx.internalize_assertions();
dst_ctx.copy_user_propagator(src_ctx);
dst_ctx.copy_user_propagator(src_ctx, true);
TRACE("smt_context",
src_ctx.display(tout);
@ -193,13 +193,16 @@ namespace smt {
}
}
void context::copy_user_propagator(context& src_ctx) {
void context::copy_user_propagator(context& src_ctx, bool copy_registered) {
if (!src_ctx.m_user_propagator)
return;
ast_translation tr(src_ctx.m, m, false);
auto* p = get_theory(m.mk_family_id("user_propagator"));
m_user_propagator = reinterpret_cast<theory_user_propagator*>(p);
SASSERT(m_user_propagator);
if (!copy_registered) {
return;
}
ast_translation tr(src_ctx.m, m, false);
for (unsigned i = 0; i < src_ctx.m_user_propagator->get_num_vars(); ++i) {
app* e = src_ctx.m_user_propagator->get_expr(i);
m_user_propagator->add_expr(tr(e));
@ -211,7 +214,7 @@ namespace smt {
new_ctx->m_is_auxiliary = true;
new_ctx->set_logic(l == nullptr ? m_setup.get_logic() : *l);
copy_plugins(*this, *new_ctx);
new_ctx->copy_user_propagator(*this);
new_ctx->copy_user_propagator(*this, false);
return new_ctx;
}

View file

@ -1576,7 +1576,7 @@ namespace smt {
void log_stats();
void copy_user_propagator(context& src);
void copy_user_propagator(context& src, bool copy_registered);
public:
context(ast_manager & m, smt_params & fp, params_ref const & p = params_ref());

View file

@ -94,8 +94,14 @@ void theory_user_propagator::register_cb(expr* e) {
}
theory * theory_user_propagator::mk_fresh(context * new_ctx) {
auto* th = alloc(theory_user_propagator, *new_ctx);
void* ctx = m_fresh_eh(m_user_context, new_ctx->get_manager(), th->m_api_context);
auto* th = alloc(theory_user_propagator, *new_ctx);
void* ctx;
try {
ctx = m_fresh_eh(m_user_context, new_ctx->get_manager(), th->m_api_context);
}
catch (...) {
throw default_exception("Exception thrown in \"fresh\"-callback");
}
th->add(ctx, m_push_eh, m_pop_eh, m_fresh_eh);
if ((bool)m_fixed_eh) th->register_fixed(m_fixed_eh);
if ((bool)m_final_eh) th->register_final(m_final_eh);
@ -110,7 +116,12 @@ final_check_status theory_user_propagator::final_check_eh() {
return FC_DONE;
force_push();
unsigned sz = m_prop.size();
m_final_eh(m_user_context, this);
try {
m_final_eh(m_user_context, this);
}
catch (...) {
throw default_exception("Exception thrown in \"final\"-callback");
}
propagate();
bool done = (sz == m_prop.size()) && !ctx.inconsistent();
return done ? FC_DONE : FC_CONTINUE;
@ -125,7 +136,12 @@ void theory_user_propagator::new_fixed_eh(theory_var v, expr* value, unsigned nu
m_fixed.insert(v);
ctx.push_trail(insert_map<uint_set, unsigned>(m_fixed, v));
m_id2justification.setx(v, literal_vector(num_lits, jlits), literal_vector());
m_fixed_eh(m_user_context, this, var2expr(v), value);
try {
m_fixed_eh(m_user_context, this, var2expr(v), value);
}
catch (...) {
throw default_exception("Exception thrown in \"fixed\"-callback");
}
}
void theory_user_propagator::push_scope_eh() {
@ -228,11 +244,17 @@ bool theory_user_propagator::internalize_term(app* term) {
ctx.mk_enode(term, true, false, true);
add_expr(term);
if (!m_created_eh)
throw default_exception("You have to register a created event handler for new terms if you track them");
if (!m_created_eh && (m_fixed_eh || m_eq_eh || m_diseq_eh))
return true;
if (m_created_eh)
try {
m_created_eh(m_user_context, this, term);
}
catch (...) {
throw default_exception("Exception thrown in \"created\"-callback");
}
return true;
}

View file

@ -142,7 +142,7 @@ namespace smt {
void collect_statistics(::statistics & st) const override;
model_value_proc * mk_value(enode * n, model_generator & mg) override { return nullptr; }
void init_model(model_generator & m) override {}
bool include_func_interp(func_decl* f) override { return true; }
bool include_func_interp(func_decl* f) override { return false; }
bool can_propagate() override;
void propagate() override;
void display(std::ostream& out) const override {}