mirror of
https://github.com/Z3Prover/z3
synced 2025-08-24 20:16:00 +00:00
remove level of indirection for context and ast_manager in smt_theory (#4253)
* remove level of indirection for context and ast_manager in smt_theory Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * add request by #4252 Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * move to def Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com> * int Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
17b8db95c1
commit
becf423c77
57 changed files with 750 additions and 1257 deletions
|
@ -57,10 +57,10 @@ namespace smt {
|
|||
|
||||
|
||||
template<typename Ext>
|
||||
theory_utvpi<Ext>::theory_utvpi(ast_manager& m):
|
||||
theory(m.mk_family_id("arith")),
|
||||
a(m),
|
||||
m_arith_eq_adapter(*this, m_params, a),
|
||||
theory_utvpi<Ext>::theory_utvpi(context& ctx):
|
||||
theory(ctx, ctx.get_manager().mk_family_id("arith")),
|
||||
a(ctx.get_manager()),
|
||||
m_arith_eq_adapter(*this, a),
|
||||
m_consistent(true),
|
||||
m_izero(null_theory_var),
|
||||
m_rzero(null_theory_var),
|
||||
|
@ -70,7 +70,7 @@ namespace smt {
|
|||
m_lia(false),
|
||||
m_lra(false),
|
||||
m_non_utvpi_exprs(false),
|
||||
m_test(m),
|
||||
m_test(ctx.get_manager()),
|
||||
m_factory(nullptr),
|
||||
m_var_value_table(DEFAULT_HASHTABLE_INITIAL_CAPACITY, var_value_hash(*this), var_value_eq(*this)) {
|
||||
}
|
||||
|
@ -98,16 +98,15 @@ namespace smt {
|
|||
template<typename Ext>
|
||||
theory_var theory_utvpi<Ext>::mk_var(enode* n) {
|
||||
th_var v = theory::mk_var(n);
|
||||
TRACE("utvpi", tout << v << " " << mk_pp(n->get_owner(), get_manager()) << "\n";);
|
||||
TRACE("utvpi", tout << v << " " << mk_pp(n->get_owner(), m) << "\n";);
|
||||
m_graph.init_var(to_var(v));
|
||||
m_graph.init_var(neg(to_var(v)));
|
||||
get_context().attach_th_var(n, this, v);
|
||||
ctx.attach_th_var(n, this, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
template<typename Ext>
|
||||
theory_var theory_utvpi<Ext>::mk_var(expr* n) {
|
||||
context & ctx = get_context();
|
||||
enode* e = nullptr;
|
||||
th_var v = null_theory_var;
|
||||
m_lia |= a.is_int(n);
|
||||
|
@ -154,8 +153,6 @@ namespace smt {
|
|||
rational k(0);
|
||||
th_var s = expand(true, v1, k);
|
||||
th_var t = expand(false, v2, k);
|
||||
context& ctx = get_context();
|
||||
ast_manager& m = get_manager();
|
||||
|
||||
if (s == t) {
|
||||
if (is_eq != k.is_zero()) {
|
||||
|
@ -193,7 +190,7 @@ namespace smt {
|
|||
|
||||
template<typename Ext>
|
||||
void theory_utvpi<Ext>::inc_conflicts() {
|
||||
get_context().push_trail(value_trail<context, bool>(m_consistent));
|
||||
ctx.push_trail(value_trail<context, bool>(m_consistent));
|
||||
m_consistent = false;
|
||||
m_stats.m_num_conflicts++;
|
||||
if (m_params.m_arith_adaptive) {
|
||||
|
@ -206,7 +203,6 @@ namespace smt {
|
|||
void theory_utvpi<Ext>::set_conflict() {
|
||||
inc_conflicts();
|
||||
literal_vector const& lits = m_nc_functor.get_lits();
|
||||
context & ctx = get_context();
|
||||
IF_VERBOSE(20, ctx.display_literals_smt2(verbose_stream() << "conflict:\n", lits));
|
||||
TRACE("utvpi", ctx.display_literals_smt2(tout << "conflict:\n", lits););
|
||||
|
||||
|
@ -216,7 +212,7 @@ namespace smt {
|
|||
}
|
||||
|
||||
vector<parameter> params;
|
||||
if (get_manager().proofs_enabled()) {
|
||||
if (m.proofs_enabled()) {
|
||||
params.push_back(parameter(symbol("farkas")));
|
||||
for (unsigned i = 0; i < m_nc_functor.get_coeffs().size(); ++i) {
|
||||
params.push_back(parameter(rational(m_nc_functor.get_coeffs()[i])));
|
||||
|
@ -238,24 +234,18 @@ namespace smt {
|
|||
return;
|
||||
}
|
||||
std::stringstream msg;
|
||||
msg << "found non utvpi logic expression:\n" << mk_pp(n, get_manager()) << "\n";
|
||||
msg << "found non utvpi logic expression:\n" << mk_pp(n, m) << "\n";
|
||||
TRACE("utvpi", tout << msg.str(););
|
||||
warning_msg("%s", msg.str().c_str());
|
||||
get_context().push_trail(value_trail<context, bool>(m_non_utvpi_exprs));
|
||||
ctx.push_trail(value_trail<context, bool>(m_non_utvpi_exprs));
|
||||
m_non_utvpi_exprs = true;
|
||||
}
|
||||
|
||||
template<typename Ext>
|
||||
void theory_utvpi<Ext>::init(context* ctx) {
|
||||
theory::init(ctx);
|
||||
init_zero();
|
||||
}
|
||||
|
||||
template<typename Ext>
|
||||
void theory_utvpi<Ext>::init_zero() {
|
||||
if (m_izero == null_theory_var) {
|
||||
m_izero = mk_var(get_context().mk_enode(a.mk_numeral(rational(0), true), false, false, true));
|
||||
m_rzero = mk_var(get_context().mk_enode(a.mk_numeral(rational(0), false), false, false, true));
|
||||
m_izero = mk_var(ctx.mk_enode(a.mk_numeral(rational(0), true), false, false, true));
|
||||
m_rzero = mk_var(ctx.mk_enode(a.mk_numeral(rational(0), false), false, false, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,7 +287,6 @@ namespace smt {
|
|||
|
||||
template<typename Ext>
|
||||
void theory_utvpi<Ext>::internalize_eq_eh(app * atom, bool_var v) {
|
||||
context & ctx = get_context();
|
||||
app * lhs = to_app(atom->get_arg(0));
|
||||
app * rhs = to_app(atom->get_arg(1));
|
||||
if (a.is_numeral(rhs)) {
|
||||
|
@ -317,7 +306,6 @@ namespace smt {
|
|||
bool theory_utvpi<Ext>::internalize_atom(app * n, bool) {
|
||||
if (!m_consistent)
|
||||
return false;
|
||||
context & ctx = get_context();
|
||||
if (!a.is_le(n) && !a.is_ge(n) && !a.is_lt(n) && !a.is_gt(n)) {
|
||||
found_non_utvpi_expr(n);
|
||||
return false;
|
||||
|
@ -357,7 +345,7 @@ namespace smt {
|
|||
m_atoms.push_back(atom(bv, pos, neg));
|
||||
|
||||
TRACE("utvpi",
|
||||
tout << mk_pp(n, get_manager()) << "\n";
|
||||
tout << mk_pp(n, m) << "\n";
|
||||
m_graph.display_edge(tout << "pos: ", pos);
|
||||
m_graph.display_edge(tout << "neg: ", neg);
|
||||
);
|
||||
|
@ -369,8 +357,8 @@ namespace smt {
|
|||
bool theory_utvpi<Ext>::internalize_term(app * term) {
|
||||
if (!m_consistent)
|
||||
return false;
|
||||
bool result = !get_context().inconsistent() && null_theory_var != mk_term(term);
|
||||
CTRACE("utvpi", !result, tout << "Did not internalize " << mk_pp(term, get_manager()) << "\n";);
|
||||
bool result = !ctx.inconsistent() && null_theory_var != mk_term(term);
|
||||
CTRACE("utvpi", !result, tout << "Did not internalize " << mk_pp(term, m) << "\n";);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -378,8 +366,8 @@ namespace smt {
|
|||
void theory_utvpi<Ext>::assign_eh(bool_var v, bool is_true) {
|
||||
m_stats.m_num_assertions++;
|
||||
unsigned idx = m_bool_var2atom.find(v);
|
||||
SASSERT(get_context().get_assignment(v) != l_undef);
|
||||
SASSERT((get_context().get_assignment(v) == l_true) == is_true);
|
||||
SASSERT(ctx.get_assignment(v) != l_undef);
|
||||
SASSERT((ctx.get_assignment(v) == l_true) == is_true);
|
||||
m_atoms[idx].assign_eh(is_true);
|
||||
m_asserted_atoms.push_back(idx);
|
||||
}
|
||||
|
@ -471,7 +459,7 @@ namespace smt {
|
|||
m_nc_functor.reset();
|
||||
VERIFY(m_graph.find_shortest_zero_edge_path(v1, v2, UINT_MAX, m_nc_functor));
|
||||
VERIFY(m_graph.find_shortest_zero_edge_path(v2, v1, UINT_MAX, m_nc_functor));
|
||||
IF_VERBOSE(1, verbose_stream() << "parity conflict " << mk_pp(e->get_owner(), get_manager()) << "\n";);
|
||||
IF_VERBOSE(1, verbose_stream() << "parity conflict " << mk_pp(e->get_owner(), m) << "\n";);
|
||||
set_conflict();
|
||||
|
||||
return false;
|
||||
|
@ -510,7 +498,7 @@ namespace smt {
|
|||
|
||||
template<typename Ext>
|
||||
void theory_utvpi<Ext>::propagate() {
|
||||
bool consistent = is_consistent() && !get_context().inconsistent();
|
||||
bool consistent = is_consistent() && !ctx.inconsistent();
|
||||
while (consistent && can_propagate()) {
|
||||
unsigned idx = m_asserted_atoms[m_asserted_qhead];
|
||||
m_asserted_qhead++;
|
||||
|
@ -532,8 +520,7 @@ namespace smt {
|
|||
|
||||
template<typename Ext>
|
||||
theory_var theory_utvpi<Ext>::mk_term(app* n) {
|
||||
TRACE("utvpi", tout << mk_pp(n, get_manager()) << "\n";);
|
||||
context& ctx = get_context();
|
||||
TRACE("utvpi", tout << mk_pp(n, m) << "\n";);
|
||||
|
||||
bool cl = m_test.linearize(n);
|
||||
if (!cl) {
|
||||
|
@ -571,7 +558,6 @@ namespace smt {
|
|||
template<typename Ext>
|
||||
theory_var theory_utvpi<Ext>::mk_num(app* n, rational const& r) {
|
||||
theory_var v = null_theory_var;
|
||||
context& ctx = get_context();
|
||||
if (r.is_zero()) {
|
||||
v = get_zero(n);
|
||||
if (!ctx.e_internalized(n)) {
|
||||
|
@ -602,7 +588,6 @@ namespace smt {
|
|||
|
||||
template<typename Ext>
|
||||
theory_var theory_utvpi<Ext>::expand(bool pos, th_var v, rational & k) {
|
||||
context& ctx = get_context();
|
||||
enode* e = get_enode(v);
|
||||
expr* x, *y;
|
||||
rational r;
|
||||
|
@ -831,7 +816,6 @@ namespace smt {
|
|||
|
||||
template<typename Ext>
|
||||
void theory_utvpi<Ext>::model_validate() {
|
||||
context& ctx = get_context();
|
||||
for (auto const& a : m_atoms) {
|
||||
bool_var b = a.get_bool_var();
|
||||
if (!ctx.is_relevant(b)) {
|
||||
|
@ -853,13 +837,13 @@ namespace smt {
|
|||
CTRACE("utvpi", !ok,
|
||||
tout << "validation failed:\n";
|
||||
tout << "Assignment: " << assign << "\n";
|
||||
tout << mk_pp(e, get_manager()) << "\n";
|
||||
tout << mk_pp(e, m) << "\n";
|
||||
a.display(*this, tout);
|
||||
tout << "\n";
|
||||
display(tout);
|
||||
m_graph.display_agl(tout);
|
||||
);
|
||||
// CTRACE("utvpi", ok, tout << "validation success: " << mk_pp(e, get_manager()) << "\n";);
|
||||
// CTRACE("utvpi", ok, tout << "validation success: " << mk_pp(e, m) << "\n";);
|
||||
SASSERT(ok);
|
||||
}
|
||||
}
|
||||
|
@ -873,10 +857,10 @@ namespace smt {
|
|||
if (a.is_lt(e, e1, e2) || a.is_gt(e, e2, e1)) {
|
||||
return eval_num(e1) < eval_num(e2);
|
||||
}
|
||||
if (get_manager().is_eq(e, e1, e2)) {
|
||||
if (m.is_eq(e, e1, e2)) {
|
||||
return eval_num(e1) == eval_num(e2);
|
||||
}
|
||||
TRACE("utvpi", tout << "expression not handled: " << mk_pp(e, get_manager()) << "\n";);
|
||||
TRACE("utvpi", tout << "expression not handled: " << mk_pp(e, m) << "\n";);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -909,7 +893,7 @@ namespace smt {
|
|||
if (is_uninterp_const(e)) {
|
||||
return mk_value(mk_var(e), a.is_int(e));
|
||||
}
|
||||
TRACE("utvpi", tout << "expression not handled: " << mk_pp(e, get_manager()) << "\n";);
|
||||
TRACE("utvpi", tout << "expression not handled: " << mk_pp(e, m) << "\n";);
|
||||
UNREACHABLE();
|
||||
return rational(0);
|
||||
}
|
||||
|
@ -926,7 +910,7 @@ namespace smt {
|
|||
SASSERT(!is_int || num.is_int());
|
||||
TRACE("utvpi",
|
||||
expr* n = get_enode(v)->get_owner();
|
||||
tout << mk_pp(n, get_manager()) << " |-> (" << val1 << " - " << val2 << ")/2 = " << num << "\n";);
|
||||
tout << mk_pp(n, m) << " |-> (" << val1 << " - " << val2 << ")/2 = " << num << "\n";);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
@ -936,7 +920,7 @@ namespace smt {
|
|||
theory_var v = n->get_th_var(get_id());
|
||||
bool is_int = a.is_int(n->get_owner());
|
||||
rational num = mk_value(v, is_int);
|
||||
TRACE("utvpi", tout << mk_pp(n->get_owner(), get_manager()) << " |-> " << num << "\n";);
|
||||
TRACE("utvpi", tout << mk_pp(n->get_owner(), m) << " |-> " << num << "\n";);
|
||||
return alloc(expr_wrapper_proc, m_factory->mk_num_value(num, is_int));
|
||||
}
|
||||
|
||||
|
@ -980,7 +964,7 @@ namespace smt {
|
|||
|
||||
template<typename Ext>
|
||||
theory* theory_utvpi<Ext>::mk_fresh(context* new_ctx) {
|
||||
return alloc(theory_utvpi<Ext>, new_ctx->get_manager());
|
||||
return alloc(theory_utvpi<Ext>, *new_ctx);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue