3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-27 16:38:45 +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:
Nikolaj Bjorner 2020-05-08 16:46:03 -07:00 committed by GitHub
parent 17b8db95c1
commit becf423c77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
57 changed files with 750 additions and 1257 deletions

View file

@ -433,17 +433,17 @@ namespace smt {
// ------------------------
// theory_pb
theory_pb::theory_pb(ast_manager& m, theory_pb_params& p):
theory(m.mk_family_id("pb")),
m_params(p),
pb(m),
theory_pb::theory_pb(context& ctx):
theory(ctx, ctx.get_manager().mk_family_id("pb")),
m_params(ctx.get_fparams()),
pb(ctx.get_manager()),
m_restart_lim(3),
m_restart_inc(0),
m_antecedent_exprs(m),
m_cardinality_exprs(m)
m_antecedent_exprs(ctx.get_manager()),
m_cardinality_exprs(ctx.get_manager())
{
m_learn_complements = p.m_pb_learn_complements;
m_conflict_frequency = p.m_pb_conflict_frequency;
m_learn_complements = ctx.get_fparams().m_pb_learn_complements;
m_conflict_frequency = ctx.get_fparams().m_pb_conflict_frequency;
}
theory_pb::~theory_pb() {
@ -451,12 +451,10 @@ namespace smt {
}
theory * theory_pb::mk_fresh(context * new_ctx) {
return alloc(theory_pb, new_ctx->get_manager(), new_ctx->get_fparams());
return alloc(theory_pb, *new_ctx);
}
bool theory_pb::internalize_atom(app * atom, bool gate_ctx) {
context& ctx = get_context();
ast_manager& m = get_manager();
if (ctx.b_internalized(atom)) {
return true;
@ -593,8 +591,6 @@ namespace smt {
}
literal theory_pb::compile_arg(expr* arg) {
context& ctx = get_context();
ast_manager& m = get_manager();
bool_var bv;
bool has_bv = false;
@ -784,7 +780,6 @@ namespace smt {
}
bool theory_pb::internalize_card(app * atom, bool gate_ctx) {
context& ctx = get_context();
if (ctx.b_internalized(atom)) {
return true;
}
@ -841,7 +836,6 @@ namespace smt {
// \brief define cardinality constraint as conjunction.
//
void theory_pb::card2conjunction(card const& c) {
context& ctx = get_context();
literal lit = c.lit();
literal_vector& lits = get_literals();
for (unsigned i = 0; i < c.size(); ++i) {
@ -856,7 +850,6 @@ namespace smt {
}
void theory_pb::card2disjunction(card const& c) {
context& ctx = get_context();
literal lit = c.lit();
literal_vector& lits = get_literals();
for (unsigned i = 0; i < c.size(); ++i) {
@ -902,7 +895,6 @@ namespace smt {
}
std::ostream& theory_pb::display(std::ostream& out, card const& c, bool values) const {
context& ctx = get_context();
out << c.lit();
if (c.lit() != null_literal) {
if (values) {
@ -936,7 +928,6 @@ namespace smt {
void theory_pb::add_clause(card& c, literal_vector const& lits) {
m_stats.m_num_conflicts++;
context& ctx = get_context();
justification* js = nullptr;
c.inc_propagations(*this);
if (!resolve_conflict(c, lits)) {
@ -949,7 +940,6 @@ namespace smt {
}
void theory_pb::add_assign(card& c, literal l) {
context& ctx = get_context();
if (ctx.get_assignment(l) == l_true) {
return;
}
@ -1001,7 +991,6 @@ namespace smt {
void theory_pb::assign_eh(bool_var v, bool is_true) {
ptr_vector<ineq>* ineqs = nullptr;
context& ctx = get_context();
literal nlit(v, is_true);
init_watch(v);
TRACE("pb", tout << "assign: " << ~nlit << "\n";);
@ -1057,7 +1046,6 @@ namespace smt {
}
literal_vector& theory_pb::get_all_literals(ineq& c, bool negate) {
context& ctx = get_context();
literal_vector& lits = get_literals();
for (unsigned i = 0; i < c.size(); ++i) {
literal l = c.lit(i);
@ -1078,7 +1066,6 @@ namespace smt {
literal_vector& theory_pb::get_helpful_literals(ineq& c, bool negate) {
scoped_mpz sum(m_mpz_mgr);
mpz const& k = c.mpz_k();
context& ctx = get_context();
literal_vector& lits = get_literals();
for (unsigned i = 0; sum < k && i < c.size(); ++i) {
literal l = c.lit(i);
@ -1093,7 +1080,6 @@ namespace smt {
}
literal_vector& theory_pb::get_unhelpful_literals(ineq& c, bool negate) {
context& ctx = get_context();
literal_vector& lits = get_literals();
for (unsigned i = 0; i < c.size(); ++i) {
literal l = c.lit(i);
@ -1121,7 +1107,6 @@ namespace smt {
and/or relatively few compared to number of argumets.
*/
void theory_pb::assign_ineq(ineq& c, bool is_true) {
context& ctx = get_context();
ctx.push_trail(value_trail<context, scoped_mpz>(c.m_max_sum));
ctx.push_trail(value_trail<context, scoped_mpz>(c.m_min_sum));
ctx.push_trail(value_trail<context, unsigned>(c.m_nfixed));
@ -1192,7 +1177,6 @@ namespace smt {
*/
bool theory_pb::assign_watch_ge(bool_var v, bool is_true, ineq_watch& watch, unsigned watch_index) {
bool removed = false;
context& ctx = get_context();
ineq& c = *watch[watch_index];
unsigned w = c.find_lit(v, 0, c.watch_size());
SASSERT(ctx.get_assignment(c.lit()) == l_true);
@ -1326,7 +1310,7 @@ namespace smt {
// for testing
literal theory_pb::assert_ge(context& ctx, unsigned k, unsigned n, literal const* xs) {
theory_pb_params p;
theory_pb th(ctx.get_manager(), p);
theory_pb th(ctx);
psort_expr ps(ctx, th);
psort_nw<psort_expr> sort(ps);
return sort.ge(false, k, n, xs);
@ -1342,7 +1326,6 @@ namespace smt {
bool theory_pb::gc() {
context& ctx = get_context();
unsigned z = 0, nz = 0;
m_occs.reset();
@ -1469,7 +1452,6 @@ namespace smt {
void theory_pb::init_watch_literal(ineq& c) {
context& ctx = get_context();
scoped_mpz max_k(m_mpz_mgr);
c.m_watch_sum.reset();
c.m_watch_sz = 0;
@ -1512,7 +1494,6 @@ namespace smt {
void theory_pb::add_assign(ineq& c, literal_vector const& lits, literal l) {
inc_propagations(c);
m_stats.m_num_propagations++;
context& ctx = get_context();
TRACE("pb", tout << "#prop:" << c.m_num_propagations << " - " << lits;
tout << " => " << l << "\n";
display(tout, c, true););
@ -1528,7 +1509,6 @@ namespace smt {
void theory_pb::add_clause(ineq& c, literal_vector const& lits) {
inc_propagations(c);
m_stats.m_num_conflicts++;
context& ctx = get_context();
TRACE("pb", tout << "#prop:" << c.m_num_propagations << " - " << lits << "\n";
display(tout, c, true););
justification* js = nullptr;
@ -1557,7 +1537,6 @@ namespace smt {
}
void theory_pb::process_antecedent(literal l, int offset) {
context& ctx = get_context();
SASSERT(ctx.get_assignment(l) == l_false);
bool_var v = l.var();
unsigned lvl = ctx.get_assign_level(v);
@ -1570,7 +1549,6 @@ namespace smt {
}
void theory_pb::process_card(card& c, int offset) {
context& ctx = get_context();
SASSERT(c.k() <= c.size());
SASSERT(ctx.get_assignment(c.lit()) == l_true);
for (unsigned i = c.k(); i < c.size(); ++i) {
@ -1586,7 +1564,6 @@ namespace smt {
bool theory_pb::validate_lemma() {
int value = -m_bound;
context& ctx = get_context();
normalize_active_coeffs();
for (unsigned i = 0; i < m_active_vars.size(); ++i) {
bool_var v = m_active_vars[i];
@ -1610,7 +1587,6 @@ namespace smt {
static bool validating = true; // false;
if (validating) return true;
validating = true;
ast_manager& m = get_manager();
smt_params fp;
kernel k(m, fp);
expr_ref notB(m.mk_not(B), m);
@ -1628,7 +1604,6 @@ namespace smt {
}
app_ref theory_pb::justification2expr(b_justification& js, literal conseq) {
ast_manager& m = get_manager();
app_ref result(m.mk_true(), m);
expr_ref_vector args(m);
vector<rational> coeffs;
@ -1692,7 +1667,6 @@ namespace smt {
Note that an asserting literal should be false with respect to the resolvent inequality.
*/
literal theory_pb::get_asserting_literal(literal p) {
context& ctx = get_context();
unsigned lvl = 0;
TRACE("pb", tout << p << " " << ctx.get_assignment(p) << "\n";);
@ -1831,8 +1805,6 @@ namespace smt {
TRACE("pb", display(tout, c, true); );
bool_var v;
context& ctx = get_context();
ast_manager& m = get_manager();
m_conflict_lvl = 0;
for (literal lit : confl) {
SASSERT(ctx.get_assignment(lit) == l_false);
@ -2044,14 +2016,14 @@ namespace smt {
}
bool theory_pb::is_proof_justification(justification const& j) const {
return typeid(smt::justification_proof_wrapper) == typeid(j) || get_manager().proofs_enabled();
return typeid(smt::justification_proof_wrapper) == typeid(j) || m.proofs_enabled();
}
justification* theory_pb::justify(literal l1, literal l2) {
literal lits[2] = { l1, l2 };
justification* js = nullptr;
if (proofs_enabled()) {
js = get_context().mk_justification(theory_axiom_justification(get_id(), get_context().get_region(), 2, lits));
js = ctx.mk_justification(theory_axiom_justification(get_id(), ctx.get_region(), 2, lits));
}
return js;
}
@ -2059,7 +2031,7 @@ namespace smt {
justification* theory_pb::justify(literal_vector const& lits) {
justification* js = nullptr;
if (proofs_enabled()) {
js = get_context().mk_justification(theory_axiom_justification(get_id(), get_context().get_region(), lits.size(), lits.c_ptr()));
js = ctx.mk_justification(theory_axiom_justification(get_id(), ctx.get_region(), lits.size(), lits.c_ptr()));
}
return js;
}
@ -2082,11 +2054,11 @@ namespace smt {
void theory_pb::validate_assign(ineq const& c, literal_vector const& lits, literal l) const {
uint_set nlits;
for (literal lit : lits) {
SASSERT(get_context().get_assignment(lit) == l_true);
SASSERT(ctx.get_assignment(lit) == l_true);
nlits.insert((~lit).index());
}
SASSERT(get_context().get_assignment(l) == l_undef);
SASSERT(get_context().get_assignment(c.lit()) == l_true);
SASSERT(ctx.get_assignment(l) == l_undef);
SASSERT(ctx.get_assignment(c.lit()) == l_true);
nlits.insert(l.index());
numeral sum = numeral::zero();
for (unsigned i = 0; i < c.size(); ++i) {
@ -2115,7 +2087,6 @@ namespace smt {
}
void theory_pb::validate_final_check(card& c) {
context& ctx = get_context();
if (ctx.get_assignment(c.lit()) == l_undef) {
TRACE("pb", display(tout << "is undef ", c, true););
return;
@ -2147,7 +2118,6 @@ namespace smt {
}
void theory_pb::validate_final_check(ineq& c) {
context& ctx = get_context();
if (ctx.get_assignment(c.lit()) == l_undef) {
TRACE("pb", tout << c.lit() << " is undef\n";);
@ -2182,7 +2152,6 @@ namespace smt {
}
bool theory_pb::validate_antecedents(literal_vector const& lits) {
context& ctx = get_context();
for (literal lit : lits) {
if (ctx.get_assignment(lit) != l_true) {
return false;
@ -2192,7 +2161,6 @@ namespace smt {
}
bool theory_pb::validate_unit_propagation(card const& c) {
context& ctx = get_context();
for (unsigned i = c.k(); i < c.size(); ++i) {
if (ctx.get_assignment(c.lit(i)) != l_false) {
return false;
@ -2202,13 +2170,11 @@ namespace smt {
}
app_ref theory_pb::literal2expr(literal lit) {
ast_manager& m = get_manager();
app_ref arg(m.mk_const(symbol((unsigned)lit.var()), m.mk_bool_sort()), m);
return app_ref(lit.sign() ? m.mk_not(arg) : arg, m);
}
app_ref theory_pb::active2expr() {
ast_manager& m = get_manager();
expr_ref_vector args(m);
vector<rational> coeffs;
normalize_active_coeffs();
@ -2225,7 +2191,6 @@ namespace smt {
// display methods
void theory_pb::display_resolved_lemma(std::ostream& out) const {
context& ctx = get_context();
out << "num marks: " << m_num_marks << "\n";
out << "conflict level: " << m_conflict_lvl << "\n";
for (literal r : m_resolved) {
@ -2264,12 +2229,10 @@ namespace smt {
}
std::ostream& theory_pb::display(std::ostream& out, arg_t const& c, bool values) const {
return c.display(get_context(), out, values);
return c.display(ctx, out, values);
}
std::ostream& theory_pb::display(std::ostream& out, ineq const& c, bool values) const {
ast_manager& m = get_manager();
context& ctx = get_context();
out << c.lit();
if (c.lit() != null_literal) {
if (values) {
@ -2389,7 +2352,6 @@ namespace smt {
}
model_value_proc * theory_pb::mk_value(enode * n, model_generator & mg) {
context& ctx = get_context();
app* a = n->get_owner();
pb_model_value_proc* p = alloc(pb_model_value_proc, a);
for (unsigned i = 0; i < a->get_num_args(); ++i) {