Skip to content

Commit eb2dd92

Browse files
2 parents c996a66 + b0d8b27 commit eb2dd92

6 files changed

Lines changed: 31 additions & 23 deletions

File tree

src/api/api_solver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,8 @@ extern "C" {
883883
Z3_TRY;
884884
RESET_ERROR_CODE();
885885
init_solver(c, s);
886-
user_propagator::push_eh_t _push = push_eh;
887-
user_propagator::pop_eh_t _pop = pop_eh;
886+
user_propagator::push_eh_t _push = (void(*)(void*,user_propagator::callback*)) push_eh;
887+
user_propagator::pop_eh_t _pop = (void(*)(void*,user_propagator::callback*,unsigned)) pop_eh;
888888
user_propagator::fresh_eh_t _fresh = [=](void * user_ctx, ast_manager& m, user_propagator::context_obj*& _ctx) {
889889
ast_context_params params;
890890
params.set_foreign_manager(&m);

src/api/c++/z3++.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,18 +3964,23 @@ namespace z3 {
39643964
}
39653965
};
39663966

3967-
static void push_eh(void* p) {
3967+
static void push_eh(void* _p, Z3_solver_callback cb) {
3968+
user_propagator_base* p = static_cast<user_propagator_base*>(_p);
3969+
scoped_cb _cb(p, cb);
39683970
static_cast<user_propagator_base*>(p)->push();
39693971
}
39703972

3971-
static void pop_eh(void* p, unsigned num_scopes) {
3972-
static_cast<user_propagator_base*>(p)->pop(num_scopes);
3973+
static void pop_eh(void* _p, Z3_solver_callback cb, unsigned num_scopes) {
3974+
user_propagator_base* p = static_cast<user_propagator_base*>(_p);
3975+
scoped_cb _cb(p, cb);
3976+
static_cast<user_propagator_base*>(_p)->pop(num_scopes);
39733977
}
39743978

3975-
static void* fresh_eh(void* p, Z3_context ctx) {
3979+
static void* fresh_eh(void* _p, Z3_context ctx) {
3980+
user_propagator_base* p = static_cast<user_propagator_base*>(_p);
39763981
context* c = new context(ctx);
3977-
static_cast<user_propagator_base*>(p)->subcontexts.push_back(c);
3978-
return static_cast<user_propagator_base*>(p)->fresh(*c);
3982+
p->subcontexts.push_back(c);
3983+
return p->fresh(*c);
39793984
}
39803985

39813986
static void fixed_eh(void* _p, Z3_solver_callback cb, Z3_ast _var, Z3_ast _value) {

src/api/z3_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,8 @@ Z3_DECLARE_CLOSURE(Z3_error_handler, void, (Z3_context c, Z3_error_code e));
14341434
/**
14351435
\brief callback functions for user propagator.
14361436
*/
1437-
Z3_DECLARE_CLOSURE(Z3_push_eh, void, (void* ctx));
1438-
Z3_DECLARE_CLOSURE(Z3_pop_eh, void, (void* ctx, unsigned num_scopes));
1437+
Z3_DECLARE_CLOSURE(Z3_push_eh, void, (void* ctx, Z3_solver_callback cb));
1438+
Z3_DECLARE_CLOSURE(Z3_pop_eh, void, (void* ctx, Z3_solver_callback cb, unsigned num_scopes));
14391439
Z3_DECLARE_CLOSURE(Z3_fresh_eh, void*, (void* ctx, Z3_context new_context));
14401440
Z3_DECLARE_CLOSURE(Z3_fixed_eh, void, (void* ctx, Z3_solver_callback cb, Z3_ast t, Z3_ast value));
14411441
Z3_DECLARE_CLOSURE(Z3_eq_eh, void, (void* ctx, Z3_solver_callback cb, Z3_ast s, Z3_ast t));

src/sat/smt/user_solver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ namespace user_solver {
8888
void solver::push_core() {
8989
th_euf_solver::push_core();
9090
m_prop_lim.push_back(m_prop.size());
91-
m_push_eh(m_user_context);
91+
m_push_eh(m_user_context, this);
9292
}
9393

9494
void solver::pop_core(unsigned num_scopes) {
9595
th_euf_solver::pop_core(num_scopes);
9696
unsigned old_sz = m_prop_lim.size() - num_scopes;
9797
m_prop.shrink(m_prop_lim[old_sz]);
9898
m_prop_lim.shrink(old_sz);
99-
m_pop_eh(m_user_context, num_scopes);
99+
m_pop_eh(m_user_context, this, num_scopes);
100100
}
101101

102102
void solver::propagate_consequence(prop_info const& prop) {

src/smt/theory_user_propagator.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using namespace smt;
2525
theory_user_propagator::theory_user_propagator(context& ctx):
2626
theory(ctx, ctx.get_manager().mk_family_id(user_propagator::plugin::name())),
2727
m_var2expr(ctx.get_manager()),
28+
m_push_popping(false),
2829
m_to_add(ctx.get_manager())
2930
{}
3031

@@ -38,7 +39,7 @@ void theory_user_propagator::force_push() {
3839
theory::push_scope_eh();
3940
m_prop_lim.push_back(m_prop.size());
4041
m_to_add_lim.push_back(m_to_add.size());
41-
m_push_eh(m_user_context);
42+
m_push_eh(m_user_context, this);
4243
}
4344
}
4445

@@ -122,15 +123,17 @@ final_check_status theory_user_propagator::final_check_eh() {
122123
if (!(bool)m_final_eh)
123124
return FC_DONE;
124125
force_push();
125-
unsigned sz = m_prop.size();
126+
unsigned sz1 = m_prop.size();
127+
unsigned sz2 = m_expr2var.size();
126128
try {
127129
m_final_eh(m_user_context, this);
128130
}
129131
catch (...) {
130132
throw default_exception("Exception thrown in \"final\"-callback");
131133
}
132134
propagate();
133-
bool done = (sz == m_prop.size()) && !ctx.inconsistent();
135+
// check if it became inconsistent or something new was propagated/registered
136+
bool done = !can_propagate() && !ctx.inconsistent();
134137
return done ? FC_DONE : FC_CONTINUE;
135138
}
136139

@@ -169,11 +172,11 @@ void theory_user_propagator::pop_scope_eh(unsigned num_scopes) {
169172
old_sz = m_to_add_lim.size() - num_scopes;
170173
m_to_add.shrink(m_to_add_lim[old_sz]);
171174
m_to_add_lim.shrink(old_sz);
172-
m_pop_eh(m_user_context, num_scopes);
175+
m_pop_eh(m_user_context, this, num_scopes);
173176
}
174177

175178
bool theory_user_propagator::can_propagate() {
176-
return m_qhead < m_prop.size() || !m_to_add.empty();
179+
return m_qhead < m_prop.size() || m_to_add_qhead < m_to_add.size();
177180
}
178181

179182
void theory_user_propagator::propagate_consequence(prop_info const& prop) {

src/tactic/user_propagator_base.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ namespace user_propagator {
1717
virtual ~context_obj() = default;
1818
};
1919

20-
typedef std::function<void(void*, callback*)> final_eh_t;
21-
typedef std::function<void(void*, callback*, expr*, expr*)> fixed_eh_t;
22-
typedef std::function<void(void*, callback*, expr*, expr*)> eq_eh_t;
20+
typedef std::function<void(void*, callback*)> final_eh_t;
21+
typedef std::function<void(void*, callback*, expr*, expr*)> fixed_eh_t;
22+
typedef std::function<void(void*, callback*, expr*, expr*)> eq_eh_t;
2323
typedef std::function<void*(void*, ast_manager&, context_obj*&)> fresh_eh_t;
24-
typedef std::function<void(void*)> push_eh_t;
25-
typedef std::function<void(void*,unsigned)> pop_eh_t;
26-
typedef std::function<void(void*, callback*, expr*)> created_eh_t;
24+
typedef std::function<void(void*, callback*)> push_eh_t;
25+
typedef std::function<void(void*, callback*, unsigned)> pop_eh_t;
26+
typedef std::function<void(void*, callback*, expr*)> created_eh_t;
2727

2828

2929
class plugin : public decl_plugin {

0 commit comments

Comments
 (0)