Skip to content

Commit 1cd1622

Browse files
make rule processing fully incremental
1 parent 590b79d commit 1cd1622

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

src/ast/simplifiers/euf_completion.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ Delayed solver invocation
5151
Mam optimization?
5252
match(p, t, S) = suppose all variables in p are bound in S, check equality using canonization of p[S], otherwise prune instances from S.
5353
54-
55-
56-
57-
5854
--*/
5955

6056
#include "ast/ast_pp.h"
@@ -94,13 +90,6 @@ namespace euf {
9490
}
9591

9692
completion::~completion() {
97-
reset_rules();
98-
}
99-
100-
void completion::reset_rules() {
101-
for (auto r : m_rules)
102-
dealloc(r);
103-
m_rules.reset();
10493
}
10594

10695
void completion::reduce() {
@@ -113,7 +102,6 @@ namespace euf {
113102
read_egraph();
114103
IF_VERBOSE(11, verbose_stream() << "(euf.completion :rounds " << rounds << ")\n");
115104
}
116-
reset_rules();
117105
}
118106

119107
void completion::add_egraph() {
@@ -229,45 +217,44 @@ namespace euf {
229217
}
230218
}
231219
body.shrink(j);
232-
if (body.empty()) {
233-
add_constraint(head, d);
234-
return;
220+
if (body.empty())
221+
add_constraint(head, d);
222+
else {
223+
m_rules.push_back(alloc(ground_rule, body, head, d));
224+
get_trail().push(push_back_vector(m_rules));
235225
}
236-
m_rules.push_back(alloc(ground_rule, body, head, d));
237226
}
238227

239228
void completion::check_rules() {
240-
unsigned j = 0;
241229
for (auto& r : m_rules) {
230+
if (!r->m_active)
231+
continue;
242232
switch (check_rule(*r)) {
243233
case l_true:
244-
dealloc(r);
234+
get_trail().push(value_trail(r->m_active));
235+
r->m_active = false;
245236
break; // remove rule, it is activated
246237
case l_false:
247-
dealloc(r);
238+
get_trail().push(value_trail(r->m_active));
239+
r->m_active = false;
248240
break; // remove rule, premise is false
249241
case l_undef:
250-
m_rules[j++] = r;
251242
break;
252243
}
253244
}
254-
m_rules.shrink(j);
255245
}
256246

257247
lbool completion::check_rule(ground_rule& r) {
258-
unsigned j = 0;
259248
for (auto* f : r.m_body) {
260249
switch (eval_cond(f, r.m_dep)) {
261250
case l_true:
262251
break;
263252
case l_false:
264253
return l_false;
265254
default:
266-
r.m_body[j++] = f;
267255
break;
268256
}
269257
}
270-
r.m_body.shrink(j);
271258
if (r.m_body.empty()) {
272259
add_constraint(r.m_head, r.m_dep);
273260
return l_true;
@@ -650,6 +637,4 @@ namespace euf {
650637
}
651638
}
652639

653-
}
654-
655-
640+
}

src/ast/simplifiers/euf_completion.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ namespace euf {
3030
virtual ~side_condition_solver() = default;
3131
virtual void add_constraint(expr* f, expr_dependency* d) = 0;
3232
virtual bool is_true(expr* f, expr_dependency*& d) = 0;
33+
virtual void push() = 0;
34+
virtual void pop(unsigned n) = 0;
3335
};
3436

3537
class completion : public dependent_expr_simplifier, public on_binding_callback, public mam_solver {
@@ -44,6 +46,7 @@ namespace euf {
4446
expr_ref_vector m_body;
4547
expr_ref m_head;
4648
expr_dependency* m_dep;
49+
bool m_active = true;
4750
ground_rule(expr_ref_vector& b, expr_ref& h, expr_dependency* d) :
4851
m_body(b), m_head(h), m_dep(d) {}
4952
};
@@ -87,15 +90,15 @@ namespace euf {
8790
lbool check_rule(ground_rule& rule);
8891
void check_rules();
8992
void add_rule(expr* f, expr_dependency* d);
90-
void reset_rules();
9193

9294
bool is_gt(expr* a, expr* b) const;
9395
public:
9496
completion(ast_manager& m, dependent_expr_state& fmls);
9597
~completion() override;
96-
char const* name() const override { return "euf-reduce"; }
97-
void push() override { m_egraph.push(); dependent_expr_simplifier::push(); }
98-
void pop(unsigned n) override { dependent_expr_simplifier::pop(n); m_egraph.pop(n); }
98+
char const* name() const override { return "euf-completion"; }
99+
void push() override { if (m_side_condition_solver) m_side_condition_solver->push(); m_egraph.push(); dependent_expr_simplifier::push(); }
100+
void pop(unsigned n) override { dependent_expr_simplifier::pop(n); m_egraph.pop(n); if (m_side_condition_solver) m_side_condition_solver->pop(1);
101+
}
99102
void reduce() override;
100103
void collect_statistics(statistics& st) const override;
101104
void reset_statistics() override { m_stats.reset(); }

0 commit comments

Comments
 (0)