3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-01 08:53:18 +00:00

avoid perf abyss for macros

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2021-07-20 20:07:06 -07:00
parent 574246ff7a
commit 0ba518b0c0
5 changed files with 22 additions and 21 deletions

View file

@ -209,6 +209,7 @@ namespace recfun {
void def::compute_cases(util& u,
replace& subst,
is_immediate_pred & is_i,
bool is_macro,
unsigned n_vars, var *const * vars, expr* rhs)
{
VERIFY(m_cases.empty() && "cases cannot already be computed");
@ -227,7 +228,7 @@ namespace recfun {
expr_ref_vector conditions(m);
// is the function a macro (unconditional body)?
if (n_vars == 0 || !contains_ite(u, rhs)) {
if (is_macro || n_vars == 0 || !contains_ite(u, rhs)) {
// constant function or trivial control flow, only one (dummy) case
add_case(name, 0, conditions, rhs);
return;
@ -336,9 +337,9 @@ namespace recfun {
}
void util::set_definition(replace& subst, promise_def & d, unsigned n_vars, var * const * vars, expr * rhs) {
void util::set_definition(replace& subst, promise_def & d, bool is_macro, unsigned n_vars, var * const * vars, expr * rhs) {
expr_ref rhs1 = get_plugin().redirect_ite(subst, n_vars, vars, rhs);
d.set_definition(subst, n_vars, vars, rhs1);
d.set_definition(subst, is_macro, n_vars, vars, rhs1);
}
app_ref util::mk_num_rounds_pred(unsigned d) {
@ -369,11 +370,11 @@ namespace recfun {
};
// set definition
void promise_def::set_definition(replace& r, unsigned n_vars, var * const * vars, expr * rhs) {
void promise_def::set_definition(replace& r, bool is_macro, unsigned n_vars, var * const * vars, expr * rhs) {
SASSERT(n_vars == d->get_arity());
is_imm_pred is_i(*u);
d->compute_cases(*u, r, is_i, n_vars, vars, rhs);
d->compute_cases(*u, r, is_i, is_macro, n_vars, vars, rhs);
}
namespace decl {
@ -426,8 +427,8 @@ namespace recfun {
}
}
void plugin::set_definition(replace& r, promise_def & d, unsigned n_vars, var * const * vars, expr * rhs) {
u().set_definition(r, d, n_vars, vars, rhs);
void plugin::set_definition(replace& r, promise_def & d, bool is_macro, unsigned n_vars, var * const * vars, expr * rhs) {
u().set_definition(r, d, is_macro, n_vars, vars, rhs);
for (case_def & c : d.get_def()->get_cases()) {
m_case_defs.insert(c.get_decl(), &c);
}
@ -437,12 +438,12 @@ namespace recfun {
return !m_case_defs.empty();
}
def* plugin::mk_def(replace& subst,
def* plugin::mk_def(replace& subst, bool is_macro,
symbol const& name, unsigned n, sort ** params, sort * range,
unsigned n_vars, var ** vars, expr * rhs) {
promise_def d = mk_def(name, n, params, range);
SASSERT(! m_defs.contains(d.get_def()->get_decl()));
set_definition(subst, d, n_vars, vars, rhs);
set_definition(subst, d, is_macro, n_vars, vars, rhs);
return d.get_def();
}
@ -520,7 +521,7 @@ namespace recfun {
auto pd = mk_def(fresh_name, n, domain.data(), max_expr->get_sort());
func_decl* f = pd.get_def()->get_decl();
expr_ref new_body(m().mk_app(f, n, args.data()), m());
set_definition(subst, pd, n, vars, max_expr);
set_definition(subst, pd, false, n, vars, max_expr);
subst.reset();
subst.insert(max_expr, new_body);
result = subst(result);

View file

@ -114,7 +114,7 @@ namespace recfun {
// compute cases for a function, given its RHS (possibly containing `ite`).
void compute_cases(util& u, replace& subst, is_immediate_pred &,
unsigned n_vars, var *const * vars, expr* rhs);
bool is_macro, unsigned n_vars, var *const * vars, expr* rhs);
void add_case(std::string & name, unsigned case_index, expr_ref_vector const& conditions, expr* rhs, bool is_imm = false);
bool contains_ite(util& u, expr* e); // expression contains a test over a def?
bool contains_def(util& u, expr* e); // expression contains a def
@ -138,7 +138,7 @@ namespace recfun {
friend class util;
util * u;
def * d;
void set_definition(replace& r, unsigned n_vars, var * const * vars, expr * rhs); // call only once
void set_definition(replace& r, bool is_macro, unsigned n_vars, var * const * vars, expr * rhs); // call only once
public:
promise_def(util * u, def * d) : u(u), d(d) {}
promise_def(promise_def const & from) : u(from.u), d(from.d) {}
@ -182,9 +182,9 @@ namespace recfun {
promise_def ensure_def(symbol const& name, unsigned n, sort *const * params, sort * range, bool is_generated = false);
void set_definition(replace& r, promise_def & d, unsigned n_vars, var * const * vars, expr * rhs);
void set_definition(replace& r, promise_def & d, bool is_macro, unsigned n_vars, var * const * vars, expr * rhs);
def* mk_def(replace& subst, symbol const& name, unsigned n, sort ** params, sort * range, unsigned n_vars, var ** vars, expr * rhs);
def* mk_def(replace& subst, bool is_macro, symbol const& name, unsigned n, sort ** params, sort * range, unsigned n_vars, var ** vars, expr * rhs);
void erase_def(func_decl* f);
@ -216,7 +216,7 @@ namespace recfun {
decl::plugin * m_plugin;
bool compute_is_immediate(expr * rhs);
void set_definition(replace& r, promise_def & d, unsigned n_vars, var * const * vars, expr * rhs);
void set_definition(replace& r, promise_def & d, bool is_macro, unsigned n_vars, var * const * vars, expr * rhs);
public:
util(ast_manager &m);