Skip to content

Commit 9a299eb

Browse files
move mam to euf
1 parent 0e4c033 commit 9a299eb

File tree

6 files changed

+72
-56
lines changed

6 files changed

+72
-56
lines changed

src/sat/smt/q_mam.cpp renamed to src/ast/euf/euf_mam.cpp

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ Revision History:
3030
#include "ast/ast_smt2_pp.h"
3131
#include "ast/euf/euf_enode.h"
3232
#include "ast/euf/euf_egraph.h"
33-
#include "sat/smt/q_mam.h"
34-
#include "sat/smt/q_ematch.h"
35-
#include "sat/smt/euf_solver.h"
33+
#include "ast/euf/euf_mam.h"
3634

3735

3836

@@ -545,9 +543,9 @@ namespace q {
545543
return m_root;
546544
}
547545

548-
void add_candidate(euf::solver& ctx, enode * n) {
546+
void add_candidate(euf::mam_solver& ctx, enode * n) {
549547
m_candidates.push_back(n);
550-
ctx.push(push_back_trail<enode*, false>(m_candidates));
548+
ctx.get_trail().push(push_back_trail<enode*, false>(m_candidates));
551549
}
552550

553551
void unmark(unsigned head) {
@@ -570,8 +568,8 @@ namespace q {
570568
return m_qhead < m_candidates.size();
571569
}
572570

573-
void save_qhead(euf::solver& ctx) {
574-
ctx.push(value_trail<unsigned>(m_qhead));
571+
void save_qhead(euf::mam_solver& ctx) {
572+
ctx.get_trail().push(value_trail<unsigned>(m_qhead));
575573
}
576574

577575
enode* next_candidate() {
@@ -628,7 +626,7 @@ namespace q {
628626
// ------------------------------------
629627

630628
class code_tree_manager {
631-
euf::solver & ctx;
629+
euf::mam_solver & ctx;
632630
label_hasher & m_lbl_hasher;
633631
region & m_region;
634632

@@ -662,7 +660,7 @@ namespace q {
662660
}
663661

664662
public:
665-
code_tree_manager(label_hasher & h, euf::solver& ctx):
663+
code_tree_manager(label_hasher & h, euf::mam_solver& ctx):
666664
ctx(ctx),
667665
m_lbl_hasher(h),
668666
m_region(ctx.get_region()) {
@@ -787,20 +785,20 @@ namespace q {
787785
}
788786

789787
void set_next(instruction * instr, instruction * new_next) {
790-
ctx.push(mam_value_trail<instruction*>(instr->m_next));
788+
ctx.get_trail().push(mam_value_trail<instruction*>(instr->m_next));
791789
instr->m_next = new_next;
792790
}
793791

794792
void save_num_regs(code_tree * tree) {
795-
ctx.push(mam_value_trail<unsigned>(tree->m_num_regs));
793+
ctx.get_trail().push(mam_value_trail<unsigned>(tree->m_num_regs));
796794
}
797795

798796
void save_num_choices(code_tree * tree) {
799-
ctx.push(mam_value_trail<unsigned>(tree->m_num_choices));
797+
ctx.get_trail().push(mam_value_trail<unsigned>(tree->m_num_choices));
800798
}
801799

802800
void insert_new_lbl_hash(filter * instr, unsigned h) {
803-
ctx.push(mam_value_trail<approx_set>(instr->m_lbl_set));
801+
ctx.get_trail().push(mam_value_trail<approx_set>(instr->m_lbl_set));
804802
instr->m_lbl_set.insert(h);
805803
}
806804
};
@@ -1858,7 +1856,7 @@ namespace q {
18581856
typedef svector<backtrack_point> backtrack_stack;
18591857

18601858
class interpreter {
1861-
euf::solver& ctx;
1859+
euf::mam_solver& ctx;
18621860
ast_manager & m;
18631861
mam & m_mam;
18641862
bool m_use_filters;
@@ -1992,7 +1990,7 @@ namespace q {
19921990
#define INIT_ARGS_SIZE 16
19931991

19941992
public:
1995-
interpreter(euf::solver& ctx, mam & ma, bool use_filters):
1993+
interpreter(euf::mam_solver& ctx, mam & ma, bool use_filters):
19961994
ctx(ctx),
19971995
m(ctx.get_manager()),
19981996
m_mam(ma),
@@ -2019,7 +2017,7 @@ namespace q {
20192017
if (t->filter_candidates()) {
20202018
code_tree::scoped_unmark _unmark(t);
20212019
while ((app = t->next_candidate()) && !ctx.resource_limits_exceeded()) {
2022-
TRACE("trigger_bug", tout << "candidate\n" << ctx.bpp(app) << "\n";);
2020+
TRACE("trigger_bug", tout << "candidate\n" << ctx.get_egraph().bpp(app) << "\n";);
20232021
if (!app->is_marked3() && app->is_cgr()) {
20242022
execute_core(t, app);
20252023
app->mark3();
@@ -2028,7 +2026,7 @@ namespace q {
20282026
}
20292027
else {
20302028
while ((app = t->next_candidate()) && !ctx.resource_limits_exceeded()) {
2031-
TRACE("trigger_bug", tout << "candidate\n" << ctx.bpp(app) << "\n";);
2029+
TRACE("trigger_bug", tout << "candidate\n" << ctx.get_egraph().bpp(app) << "\n";);
20322030
if (app->is_cgr())
20332031
execute_core(t, app);
20342032
}
@@ -2820,7 +2818,7 @@ namespace q {
28202818
ast_manager & m;
28212819
compiler & m_compiler;
28222820
ptr_vector<code_tree> m_trees; // mapping: func_label -> tree
2823-
euf::solver& ctx;
2821+
euf::mam_solver& ctx;
28242822
#ifdef Z3DEBUG
28252823
egraph * m_egraph;
28262824
#endif
@@ -2837,7 +2835,7 @@ namespace q {
28372835
};
28382836

28392837
public:
2840-
code_tree_map(ast_manager & m, compiler & c, euf::solver& ctx):
2838+
code_tree_map(ast_manager & m, compiler & c, euf::mam_solver& ctx):
28412839
m(m),
28422840
m_compiler(c),
28432841
ctx(ctx) {
@@ -2871,7 +2869,7 @@ namespace q {
28712869
m_trees[lbl_id] = m_compiler.mk_tree(qa, mp, first_idx, false);
28722870
SASSERT(m_trees[lbl_id]->expected_num_args() == p->get_num_args());
28732871
DEBUG_CODE(m_trees[lbl_id]->set_egraph(m_egraph););
2874-
ctx.push(mk_tree_trail(m_trees, lbl_id));
2872+
ctx.get_trail().push(mk_tree_trail(m_trees, lbl_id));
28752873
}
28762874
else {
28772875
code_tree * tree = m_trees[lbl_id];
@@ -2884,7 +2882,7 @@ namespace q {
28842882
}
28852883
DEBUG_CODE(if (first_idx == 0) {
28862884
m_trees[lbl_id]->get_patterns().push_back(std::make_pair(qa, mp));
2887-
ctx.push(push_back_trail<std::pair<quantifier*, app*>, false>(m_trees[lbl_id]->get_patterns()));
2885+
ctx.get_trail().push(push_back_trail<std::pair<quantifier*, app*>, false>(m_trees[lbl_id]->get_patterns()));
28882886
});
28892887
TRACE("trigger_bug", tout << "after add_pattern, first_idx: " << first_idx << "\n"; m_trees[lbl_id]->display(tout););
28902888
}
@@ -3038,9 +3036,9 @@ namespace q {
30383036
//
30393037
// ------------------------------------
30403038
class mam_impl : public mam {
3041-
euf::solver& ctx;
3039+
euf::mam_solver& ctx;
30423040
egraph & m_egraph;
3043-
ematch & m_ematch;
3041+
euf::on_binding_callback & m_ematch;
30443042
ast_manager & m;
30453043
bool m_use_filters;
30463044
label_hasher m_lbl_hasher;
@@ -3095,9 +3093,9 @@ namespace q {
30953093
void add_candidate(code_tree * t, enode * app) {
30963094
if (!t)
30973095
return;
3098-
TRACE("q", tout << "candidate " << ctx.bpp(app) << "\n";);
3096+
TRACE("q", tout << "candidate " << ctx.get_egraph().bpp(app) << "\n";);
30993097
if (!t->has_candidates()) {
3100-
ctx.push(push_back_trail<code_tree*, false>(m_to_match));
3098+
ctx.get_trail().push(push_back_trail<code_tree*, false>(m_to_match));
31013099
m_to_match.push_back(t);
31023100
}
31033101
t->add_candidate(ctx, app);
@@ -3120,7 +3118,7 @@ namespace q {
31203118
void update_lbls(enode * n, unsigned elem) {
31213119
approx_set & r_lbls = n->get_root()->get_lbls();
31223120
if (!r_lbls.may_contain(elem)) {
3123-
ctx.push(mam_value_trail<approx_set>(r_lbls));
3121+
ctx.get_trail().push(mam_value_trail<approx_set>(r_lbls));
31243122
r_lbls.insert(elem);
31253123
}
31263124
}
@@ -3132,7 +3130,7 @@ namespace q {
31323130
TRACE("mam_bug", tout << "update_clbls: " << lbl->get_name() << " is already clbl: " << m_is_clbl[lbl_id] << "\n";);
31333131
if (m_is_clbl[lbl_id])
31343132
return;
3135-
ctx.push(set_bitvector_trail(m_is_clbl, lbl_id));
3133+
ctx.get_trail().push(set_bitvector_trail(m_is_clbl, lbl_id));
31363134
SASSERT(m_is_clbl[lbl_id]);
31373135
unsigned h = m_lbl_hasher(lbl);
31383136
for (enode* app : m_egraph.enodes_of(lbl)) {
@@ -3152,7 +3150,7 @@ namespace q {
31523150
enode * c = app->get_arg(i);
31533151
approx_set & r_plbls = c->get_root()->get_plbls();
31543152
if (!r_plbls.may_contain(elem)) {
3155-
ctx.push(mam_value_trail<approx_set>(r_plbls));
3153+
ctx.get_trail().push(mam_value_trail<approx_set>(r_plbls));
31563154
r_plbls.insert(elem);
31573155
TRACE("trigger_bug", tout << "updating plabels of:\n" << mk_ismt2_pp(c->get_root()->get_expr(), m) << "\n";
31583156
tout << "new_elem: " << static_cast<unsigned>(elem) << "\n";
@@ -3173,7 +3171,7 @@ namespace q {
31733171
TRACE("mam_bug", tout << "update_plbls: " << lbl->get_name() << " is already plbl: " << m_is_plbl[lbl_id] << "\n";);
31743172
if (m_is_plbl[lbl_id])
31753173
return;
3176-
ctx.push(set_bitvector_trail(m_is_plbl, lbl_id));
3174+
ctx.get_trail().push(set_bitvector_trail(m_is_plbl, lbl_id));
31773175
SASSERT(m_is_plbl[lbl_id]);
31783176
SASSERT(is_plbl(lbl));
31793177
unsigned h = m_lbl_hasher(lbl);
@@ -3220,7 +3218,7 @@ namespace q {
32203218
p = p->m_child;
32213219
}
32223220
curr->m_code = mk_code(qa, mp, pat_idx);
3223-
ctx.push(new_obj_trail<code_tree>(curr->m_code));
3221+
ctx.get_trail().push(new_obj_trail<code_tree>(curr->m_code));
32243222
return head;
32253223
}
32263224

@@ -3243,7 +3241,7 @@ namespace q {
32433241
insert_code(t, qa, mp, p->m_pattern_idx);
32443242
}
32453243
else {
3246-
ctx.push(set_ptr_trail<path_tree>(t->m_first_child));
3244+
ctx.get_trail().push(set_ptr_trail<path_tree>(t->m_first_child));
32473245
t->m_first_child = mk_path_tree(p->m_child, qa, mp);
32483246
}
32493247
}
@@ -3253,9 +3251,9 @@ namespace q {
32533251
insert_code(t, qa, mp, p->m_pattern_idx);
32543252
}
32553253
else {
3256-
ctx.push(set_ptr_trail<code_tree>(t->m_code));
3254+
ctx.get_trail().push(set_ptr_trail<code_tree>(t->m_code));
32573255
t->m_code = mk_code(qa, mp, p->m_pattern_idx);
3258-
ctx.push(new_obj_trail<code_tree>(t->m_code));
3256+
ctx.get_trail().push(new_obj_trail<code_tree>(t->m_code));
32593257
}
32603258
}
32613259
else {
@@ -3268,10 +3266,10 @@ namespace q {
32683266
prev_sibling = t;
32693267
t = t->m_sibling;
32703268
}
3271-
ctx.push(set_ptr_trail<path_tree>(prev_sibling->m_sibling));
3269+
ctx.get_trail().push(set_ptr_trail<path_tree>(prev_sibling->m_sibling));
32723270
prev_sibling->m_sibling = mk_path_tree(p, qa, mp);
32733271
if (!found_label) {
3274-
ctx.push(value_trail<approx_set>(head->m_filter));
3272+
ctx.get_trail().push(value_trail<approx_set>(head->m_filter));
32753273
head->m_filter.insert(m_lbl_hasher(p->m_label));
32763274
}
32773275
}
@@ -3281,7 +3279,7 @@ namespace q {
32813279
insert(m_pc[h1][h2], p, qa, mp);
32823280
}
32833281
else {
3284-
ctx.push(set_ptr_trail<path_tree>(m_pc[h1][h2]));
3282+
ctx.get_trail().push(set_ptr_trail<path_tree>(m_pc[h1][h2]));
32853283
m_pc[h1][h2] = mk_path_tree(p, qa, mp);
32863284
}
32873285
TRACE("mam_path_tree_updt",
@@ -3298,7 +3296,7 @@ namespace q {
32983296
insert(m_pp[h1][h2].first, p2, qa, mp);
32993297
}
33003298
else {
3301-
ctx.push(set_ptr_trail<path_tree>(m_pp[h1][h2].first));
3299+
ctx.get_trail().push(set_ptr_trail<path_tree>(m_pp[h1][h2].first));
33023300
m_pp[h1][h2].first = mk_path_tree(p1, qa, mp);
33033301
insert(m_pp[h1][h2].first, p2, qa, mp);
33043302
}
@@ -3316,8 +3314,8 @@ namespace q {
33163314
}
33173315
else {
33183316
SASSERT(m_pp[h1][h2].second == nullptr);
3319-
ctx.push(set_ptr_trail<path_tree>(m_pp[h1][h2].first));
3320-
ctx.push(set_ptr_trail<path_tree>(m_pp[h1][h2].second));
3317+
ctx.get_trail().push(set_ptr_trail<path_tree>(m_pp[h1][h2].first));
3318+
ctx.get_trail().push(set_ptr_trail<path_tree>(m_pp[h1][h2].second));
33213319
m_pp[h1][h2].first = mk_path_tree(p1, qa, mp);
33223320
m_pp[h1][h2].second = mk_path_tree(p2, qa, mp);
33233321
}
@@ -3462,7 +3460,7 @@ namespace q {
34623460
\brief Collect new E-matching candidates using the inverted path index t.
34633461
*/
34643462
void collect_parents(enode * r, path_tree * t) {
3465-
TRACE("mam", tout << ctx.bpp(r) << " " << t << "\n";);
3463+
TRACE("mam", tout << ctx.get_egraph().bpp(r) << " " << t << "\n";);
34663464
if (t == nullptr)
34673465
return;
34683466
#ifdef _PROFILE_PATH_TREE
@@ -3682,7 +3680,7 @@ namespace q {
36823680
void propagate_new_patterns() {
36833681
if (m_new_patterns_qhead >= m_new_patterns.size())
36843682
return;
3685-
ctx.push(value_trail<unsigned>(m_new_patterns_qhead));
3683+
ctx.get_trail().push(value_trail<unsigned>(m_new_patterns_qhead));
36863684

36873685
TRACE("mam_new_pat", tout << "matching new patterns:\n";);
36883686
m_tmp_trees_to_delete.reset();
@@ -3725,7 +3723,7 @@ namespace q {
37253723
}
37263724

37273725
public:
3728-
mam_impl(euf::solver & ctx, ematch& ematch, bool use_filters):
3726+
mam_impl(euf::mam_solver & ctx, euf::on_binding_callback& ematch, bool use_filters):
37293727
ctx(ctx),
37303728
m_egraph(ctx.get_egraph()),
37313729
m_ematch(ematch),
@@ -3754,7 +3752,7 @@ namespace q {
37543752
return; // ignore multi-pattern containing ground pattern.
37553753
update_filters(qa, mp);
37563754
m_new_patterns.push_back(qp_pair(qa, mp));
3757-
ctx.push(push_back_trail<qp_pair, false>(m_new_patterns));
3755+
ctx.get_trail().push(push_back_trail<qp_pair, false>(m_new_patterns));
37583756
// The matching abstract machine implements incremental
37593757
// e-matching. So, for a multi-pattern [ p_1, ..., p_n ],
37603758
// we have to make n insertions. In the i-th insertion,
@@ -3782,7 +3780,7 @@ namespace q {
37823780
void propagate_to_match() {
37833781
if (m_to_match_head >= m_to_match.size())
37843782
return;
3785-
ctx.push(value_trail<unsigned>(m_to_match_head));
3783+
ctx.get_trail().push(value_trail<unsigned>(m_to_match_head));
37863784
for (; m_to_match_head < m_to_match.size(); ++m_to_match_head)
37873785
m_interpreter.execute(m_to_match[m_to_match_head]);
37883786
}
@@ -3872,8 +3870,8 @@ namespace q {
38723870
approx_set other_lbls = other->get_lbls();
38733871
approx_set & root_lbls = root->get_lbls();
38743872

3875-
ctx.push(mam_value_trail<approx_set>(root_lbls));
3876-
ctx.push(mam_value_trail<approx_set>(root_plbls));
3873+
ctx.get_trail().push(mam_value_trail<approx_set>(root_lbls));
3874+
ctx.get_trail().push(mam_value_trail<approx_set>(root_plbls));
38773875
root_lbls |= other_lbls;
38783876
root_plbls |= other_plbls;
38793877
TRACE("mam_inc_bug",
@@ -3909,7 +3907,7 @@ namespace q {
39093907
}
39103908
}
39113909

3912-
mam* mam::mk(euf::solver& ctx, ematch& em) {
3910+
mam* mam::mk(euf::mam_solver& ctx, euf::on_binding_callback& em) {
39133911
return alloc(mam_impl, ctx, em, true);
39143912
}
39153913

src/sat/smt/q_mam.h renamed to src/ast/euf/euf_mam.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,23 @@ Module Name:
2222
#include <functional>
2323

2424
namespace euf {
25-
class solver;
25+
26+
class mam_solver {
27+
public:
28+
virtual ~mam_solver() = default;
29+
virtual trail_stack& get_trail() = 0;
30+
virtual region& get_region() = 0;
31+
virtual ast_manager& get_manager() = 0;
32+
virtual egraph& get_egraph() = 0;
33+
virtual bool is_relevant(euf::enode* n) const = 0;
34+
virtual bool resource_limits_exceeded() const = 0;
35+
};
36+
37+
class on_binding_callback {
38+
public:
39+
virtual ~on_binding_callback() = default;
40+
virtual void on_binding(quantifier* q, app* pat, euf::enode* const* binding, unsigned max_generation, unsigned min_gen, unsigned max_gen) = 0;
41+
};
2642
};
2743

2844
namespace q {
@@ -43,7 +59,7 @@ namespace q {
4359

4460
public:
4561

46-
static mam * mk(euf::solver& ctx, ematch& em);
62+
static mam * mk(euf::mam_solver& ctx, euf::on_binding_callback& em);
4763

4864
virtual ~mam() = default;
4965

src/sat/smt/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ z3_add_component(sat_smt
3636
q_clause.cpp
3737
q_ematch.cpp
3838
q_eval.cpp
39-
q_mam.cpp
4039
q_mbi.cpp
4140
q_model_fixer.cpp
4241
q_theory_checker.cpp

0 commit comments

Comments
 (0)