3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-14 06:45:25 +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

@ -29,11 +29,11 @@ Revision History:
namespace smt {
template<typename Ext>
theory_dense_diff_logic<Ext>::theory_dense_diff_logic(ast_manager & m, theory_arith_params & p):
theory(m.mk_family_id("arith")),
m_params(p),
m_autil(m),
m_arith_eq_adapter(*this, p, m_autil),
theory_dense_diff_logic<Ext>::theory_dense_diff_logic(context& ctx):
theory(ctx, ctx.get_manager().mk_family_id("arith")),
m_params(ctx.get_fparams()),
m_autil(ctx.get_manager()),
m_arith_eq_adapter(*this, m_autil),
m_non_diff_logic_exprs(false),
m_var_value_table(DEFAULT_HASHTABLE_INITIAL_CAPACITY, var_value_hash(*this), var_value_eq(*this)) {
m_edges.push_back(edge());
@ -41,12 +41,12 @@ namespace smt {
template<typename Ext>
theory* theory_dense_diff_logic<Ext>::mk_fresh(context * new_ctx) {
return alloc(theory_dense_diff_logic<Ext>, new_ctx->get_manager(), new_ctx->get_fparams());
return alloc(theory_dense_diff_logic<Ext>, *new_ctx);
}
template<typename Ext>
inline app * theory_dense_diff_logic<Ext>::mk_zero_for(expr * n) {
return m_autil.mk_numeral(rational(0), get_manager().get_sort(n));
return m_autil.mk_numeral(rational(0), m.get_sort(n));
}
template<typename Ext>
@ -66,13 +66,12 @@ namespace smt {
c.m_edge_id = self_edge_id;
c.m_distance.reset();
SASSERT(check_vector_sizes());
get_context().attach_th_var(n, this, v);
ctx.attach_th_var(n, this, v);
return v;
}
template<typename Ext>
theory_var theory_dense_diff_logic<Ext>::internalize_term_core(app * n) {
context & ctx = get_context();
if (ctx.e_internalized(n)) {
enode * e = ctx.get_enode(n);
if (is_attached_to_var(e))
@ -125,9 +124,9 @@ namespace smt {
template<typename Ext>
void theory_dense_diff_logic<Ext>::found_non_diff_logic_expr(expr * n) {
if (!m_non_diff_logic_exprs) {
TRACE("non_diff_logic", tout << "found non diff logic expression:\n" << mk_pp(n, get_manager()) << "\n";);
get_context().push_trail(value_trail<context, bool>(m_non_diff_logic_exprs));
IF_VERBOSE(0, verbose_stream() << "(smt.diff_logic: non-diff logic expression " << mk_pp(n, get_manager()) << ")\n";);
TRACE("non_diff_logic", tout << "found non diff logic expression:\n" << mk_pp(n, m) << "\n";);
ctx.push_trail(value_trail<context, bool>(m_non_diff_logic_exprs));
IF_VERBOSE(0, verbose_stream() << "(smt.diff_logic: non-diff logic expression " << mk_pp(n, m) << ")\n";);
m_non_diff_logic_exprs = true;
}
}
@ -138,8 +137,7 @@ namespace smt {
found_non_diff_logic_expr(n); // little hack... TODO: change to no_memory and return l_undef if SAT
return false;
}
TRACE("ddl", tout << "internalizing atom:\n" << mk_pp(n, get_manager()) << "\n";);
context & ctx = get_context();
TRACE("ddl", tout << "internalizing atom:\n" << mk_pp(n, m) << "\n";);
SASSERT(!ctx.b_internalized(n));
SASSERT(m_autil.is_le(n) || m_autil.is_ge(n));
theory_var source, target;
@ -170,15 +168,15 @@ namespace smt {
s = mk_zero_for(t);
}
else {
TRACE("ddl", tout << "failed to internalize:\n" << mk_pp(n, get_manager()) << "\n";);
TRACE("ddl", tout << "failed to internalize:\n" << mk_pp(n, m) << "\n";);
found_non_diff_logic_expr(n);
return false;
}
TRACE("arith", tout << expr_ref(lhs, get_manager()) << " " << expr_ref(s, get_manager()) << " " << expr_ref(t, get_manager()) << "\n";);
TRACE("arith", tout << expr_ref(lhs, m) << " " << expr_ref(s, m) << " " << expr_ref(t, m) << "\n";);
source = internalize_term_core(s);
target = internalize_term_core(t);
if (source == null_theory_var || target == null_theory_var) {
TRACE("ddl", tout << "failed to internalize:\n" << mk_pp(n, get_manager()) << "\n";);
TRACE("ddl", tout << "failed to internalize:\n" << mk_pp(n, m) << "\n";);
found_non_diff_logic_expr(n);
return false;
}
@ -195,18 +193,18 @@ namespace smt {
m_bv2atoms.setx(bv, a, 0);
m_matrix[source][target].m_occs.push_back(a);
m_matrix[target][source].m_occs.push_back(a);
TRACE("ddl", tout << "succeeded internalizing:\n" << mk_pp(n, get_manager()) << "\n";);
TRACE("ddl", tout << "succeeded internalizing:\n" << mk_pp(n, m) << "\n";);
return true;
}
template<typename Ext>
void theory_dense_diff_logic<Ext>::mk_clause(literal l1, literal l2) {
get_context().mk_th_axiom(get_id(), l1, l2);
ctx.mk_th_axiom(get_id(), l1, l2);
}
template<typename Ext>
void theory_dense_diff_logic<Ext>::mk_clause(literal l1, literal l2, literal l3) {
get_context().mk_th_axiom(get_id(), l1, l2, l3);
ctx.mk_th_axiom(get_id(), l1, l2, l3);
}
template<typename Ext>
@ -215,9 +213,9 @@ namespace smt {
found_non_diff_logic_expr(term); // little hack... TODO: change to no_memory and return l_undef if SAT
return false;
}
TRACE("ddl", tout << "internalizing term: " << mk_pp(term, get_manager()) << "\n";);
TRACE("ddl", tout << "internalizing term: " << mk_pp(term, m) << "\n";);
theory_var v = internalize_term_core(term);
TRACE("ddl", tout << mk_pp(term, get_manager()) << "\ninternalization result: " << (v != null_theory_var) << "\n";);
TRACE("ddl", tout << mk_pp(term, m) << "\ninternalization result: " << (v != null_theory_var) << "\n";);
if (v == null_theory_var)
found_non_diff_logic_expr(term);
return v != null_theory_var;
@ -225,10 +223,9 @@ namespace smt {
template<typename Ext>
void theory_dense_diff_logic<Ext>::internalize_eq_eh(app * atom, bool_var v) {
TRACE("ddl", tout << "eq-eh: " << mk_pp(atom, get_manager()) << "\n";);
TRACE("ddl", tout << "eq-eh: " << mk_pp(atom, m) << "\n";);
if (memory::above_high_watermark())
return;
context & ctx = get_context();
app * lhs = to_app(atom->get_arg(0));
app * rhs = to_app(atom->get_arg(1));
app * s;
@ -258,13 +255,13 @@ namespace smt {
template<typename Ext>
void theory_dense_diff_logic<Ext>::assign_eh(bool_var v, bool is_true) {
if (get_context().has_th_justification(v, get_id())) {
if (ctx.has_th_justification(v, get_id())) {
TRACE("ddl", tout << "ignoring atom propagated by the theory.\n";);
return;
}
atom * a = m_bv2atoms.get(v, 0);
if (!a) {
SASSERT(get_manager().is_eq(get_context().bool_var2expr(v)));
SASSERT(m.is_eq(ctx.bool_var2expr(v)));
return;
}
m_stats.m_num_assertions++;
@ -540,7 +537,6 @@ namespace smt {
template<typename Ext>
void theory_dense_diff_logic<Ext>::assign_literal(literal l, theory_var source, theory_var target) {
context & ctx = get_context();
literal_vector & antecedents = m_tmp_literals;
antecedents.reset();
get_antecedents(source, target, antecedents);
@ -553,7 +549,6 @@ namespace smt {
SASSERT(c.m_edge_id != null_edge_id);
numeral neg_dist = c.m_distance;
neg_dist.neg();
context & ctx = get_context();
typename atoms::const_iterator it = c.m_occs.begin();
typename atoms::const_iterator end = c.m_occs.end();
for (; it != end; ++it) {
@ -597,7 +592,6 @@ namespace smt {
get_antecedents(target, source, antecedents);
if (l != null_literal)
antecedents.push_back(l);
context & ctx = get_context();
region & r = ctx.get_region();
ctx.set_conflict(ctx.mk_justification(theory_conflict_justification(get_id(), r, antecedents.size(), antecedents.c_ptr())));
@ -698,7 +692,7 @@ namespace smt {
out.width(5);
out << std::left << get_enode(a->get_source())->get_owner_id() << " <= ";
out.width(10);
out << std::left << a->get_offset() << " assignment: " << get_context().get_assignment(a->get_bool_var()) << "\n";
out << std::left << a->get_offset() << " assignment: " << ctx.get_assignment(a->get_bool_var()) << "\n";
}
template<typename Ext>
@ -733,7 +727,7 @@ namespace smt {
TRACE("ddl_model",
tout << "ddl model\n";
for (theory_var v = 0; v < num_vars; v++) {
tout << "#" << mk_pp(get_enode(v)->get_owner(), get_manager()) << " = " << m_assignment[v] << "\n";
tout << "#" << mk_pp(get_enode(v)->get_owner(), m) << " = " << m_assignment[v] << "\n";
});
}
@ -811,11 +805,11 @@ namespace smt {
enode * n = get_enode(v);
if (m_autil.is_zero(n->get_owner()) && !m_assignment[v].is_zero()) {
numeral val = m_assignment[v];
sort * s = get_manager().get_sort(n->get_owner());
sort * s = m.get_sort(n->get_owner());
// adjust the value of all variables that have the same sort.
for (int v2 = 0; v2 < num_vars; ++v2) {
enode * n2 = get_enode(v2);
if (get_manager().get_sort(n2->get_owner()) == s) {
if (m.get_sort(n2->get_owner()) == s) {
m_assignment[v2] -= val;
}
}
@ -825,14 +819,14 @@ namespace smt {
TRACE("ddl_model",
tout << "ddl model\n";
for (theory_var v = 0; v < num_vars; v++) {
tout << "#" << mk_pp(get_enode(v)->get_owner(), get_manager()) << " = " << m_assignment[v] << "\n";
tout << "#" << mk_pp(get_enode(v)->get_owner(), m) << " = " << m_assignment[v] << "\n";
});
}
template<typename Ext>
void theory_dense_diff_logic<Ext>::init_model(model_generator & m) {
m_factory = alloc(arith_factory, get_manager());
m.register_factory(m_factory);
void theory_dense_diff_logic<Ext>::init_model(model_generator & mg) {
m_factory = alloc(arith_factory, m);
mg.register_factory(m_factory);
if (!m_assignment.empty()) {
fix_zero();
compute_epsilon();
@ -880,7 +874,6 @@ namespace smt {
return false;
}
else {
context& ctx = get_context();
enode * e = nullptr;
theory_var v = 0;
if (ctx.e_internalized(n)) {
@ -924,7 +917,6 @@ namespace smt {
template<typename Ext>
inf_eps_rational<inf_rational> theory_dense_diff_logic<Ext>::maximize(theory_var v, expr_ref& blocker, bool& has_shared) {
typedef simplex::simplex<simplex::mpq_ext> Simplex;
ast_manager& m = get_manager();
Simplex S(m.limit());
objective_term const& objective = m_objectives[v];
has_shared = false;
@ -1025,7 +1017,7 @@ namespace smt {
unsigned edge_id = v - num_nodes;
literal lit = m_edges[edge_id].m_justification;
if (lit != null_literal) {
get_context().literal2expr(lit, tmp);
ctx.literal2expr(lit, tmp);
core.push_back(tmp);
}
}
@ -1053,12 +1045,12 @@ namespace smt {
template<typename Ext>
theory_var theory_dense_diff_logic<Ext>::add_objective(app* term) {
TRACE("opt", tout << mk_pp(term, get_manager()) << "\n";);
TRACE("opt", tout << mk_pp(term, m) << "\n";);
objective_term objective;
theory_var result = m_objectives.size();
rational q(1), r(0);
expr_ref_vector vr(get_manager());
if (!is_linear(get_manager(), term)) {
expr_ref_vector vr(m);
if (!is_linear(m, term)) {
result = null_theory_var;
}
else if (internalize_objective(term, q, r, objective)) {
@ -1085,7 +1077,6 @@ namespace smt {
template<typename Ext>
expr_ref theory_dense_diff_logic<Ext>::mk_ineq(theory_var v, inf_eps const& val, bool is_strict) {
ast_manager& m = get_manager();
objective_term const& t = m_objectives[v];
expr_ref e(m), f(m), f2(m);
TRACE("opt", tout << "mk_ineq " << v << " " << val << "\n";);