From 5d3a4ee8050791ba23dacf6efe8ed7843445497b Mon Sep 17 00:00:00 2001 From: Nikolaj Bjorner Date: Wed, 25 Dec 2019 21:06:26 -0800 Subject: [PATCH] fix #2824 fix #2825 Signed-off-by: Nikolaj Bjorner --- src/ast/ast.cpp | 54 +++++++++++++-------------------- src/ast/ast.h | 1 + src/cmd_context/cmd_context.cpp | 5 ++- src/cmd_context/pdecl.cpp | 2 +- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 466e42bd8..fce725db8 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -2190,6 +2190,21 @@ bool ast_manager::coercion_needed(func_decl * decl, unsigned num_args, expr * co return false; } +expr* ast_manager::coerce_to(expr* e, sort* s) { + sort* se = get_sort(e); + if (s != se && s->get_family_id() == m_arith_family_id && se->get_family_id() == m_arith_family_id) { + if (s->get_decl_kind() == REAL_SORT) { + return mk_app(m_arith_family_id, OP_TO_REAL, e); + } + else { + return mk_app(m_arith_family_id, OP_TO_INT, e); + } + } + else { + return e; + } +} + app * ast_manager::mk_app_core(func_decl * decl, unsigned num_args, expr * const * args) { app * r = nullptr; app * new_node = nullptr; @@ -2198,35 +2213,9 @@ app * ast_manager::mk_app_core(func_decl * decl, unsigned num_args, expr * const try { if (m_int_real_coercions && coercion_needed(decl, num_args, args)) { expr_ref_buffer new_args(*this); - if (decl->is_associative()) { - sort * d = decl->get_domain(0); - for (unsigned i = 0; i < num_args; i++) { - sort * s = get_sort(args[i]); - if (d != s && d->get_family_id() == m_arith_family_id && s->get_family_id() == m_arith_family_id) { - if (d->get_decl_kind() == REAL_SORT) - new_args.push_back(mk_app(m_arith_family_id, OP_TO_REAL, args[i])); - else - new_args.push_back(mk_app(m_arith_family_id, OP_TO_INT, args[i])); - } - else { - new_args.push_back(args[i]); - } - } - } - else { - for (unsigned i = 0; i < num_args; i++) { - sort * d = decl->get_domain(i); - sort * s = get_sort(args[i]); - if (d != s && d->get_family_id() == m_arith_family_id && s->get_family_id() == m_arith_family_id) { - if (d->get_decl_kind() == REAL_SORT) - new_args.push_back(mk_app(m_arith_family_id, OP_TO_REAL, args[i])); - else - new_args.push_back(mk_app(m_arith_family_id, OP_TO_INT, args[i])); - } - else { - new_args.push_back(args[i]); - } - } + for (unsigned i = 0; i < num_args; i++) { + sort * d = decl->is_associative() ? decl->get_domain(0) : decl->get_domain(i); + new_args.push_back(coerce_to(args[i], d)); } check_args(decl, num_args, new_args.c_ptr()); SASSERT(new_args.size() == num_args); @@ -2446,10 +2435,9 @@ bool ast_manager::is_label_lit(expr const * n, buffer & names) const { } app * ast_manager::mk_pattern(unsigned num_exprs, app * const * exprs) { - DEBUG_CODE({ - for (unsigned i = 0; i < num_exprs; ++i) { - SASSERT(is_app(exprs[i])); - }}); + for (unsigned i = 0; i < num_exprs; ++i) { + if (!is_app(exprs[i])) throw default_exception("patterns cannot be variables or quantifiers"); + } return mk_app(m_pattern_family_id, OP_PATTERN, 0, nullptr, num_exprs, (expr*const*)exprs); } diff --git a/src/ast/ast.h b/src/ast/ast.h index 132113ff9..97c64ddd0 100644 --- a/src/ast/ast.h +++ b/src/ast/ast.h @@ -1578,6 +1578,7 @@ public: // Return true if s1 and s2 are equal, or coercions are enabled, and s1 and s2 are compatible. bool compatible_sorts(sort * s1, sort * s2) const; + expr* coerce_to(expr* e, sort* s); // For debugging purposes void display_free_ids(std::ostream & out) { m_expr_id_gen.display_free_ids(out); out << "\n"; m_decl_id_gen.display_free_ids(out); } diff --git a/src/cmd_context/cmd_context.cpp b/src/cmd_context/cmd_context.cpp index ebf51c794..61a0296c2 100644 --- a/src/cmd_context/cmd_context.cpp +++ b/src/cmd_context/cmd_context.cpp @@ -324,7 +324,7 @@ bool cmd_context::macros_find(symbol const& s, unsigned n, expr*const* args, exp if (d.m_domain.size() != n) continue; bool eq = true; for (unsigned i = 0; eq && i < n; ++i) { - eq = m().compatible_sorts(d.m_domain[i], m().get_sort(args[i])); + eq = d.m_domain[i] == m().get_sort(args[i]); } if (eq) { t = d.m_body; @@ -1077,7 +1077,7 @@ void cmd_context::mk_app(symbol const & s, unsigned num_args, expr * const * arg tout << "args:\n"; for (unsigned i = 0; i < num_args; i++) tout << mk_ismt2_pp(args[i], m()) << "\n" << mk_pp(m().get_sort(args[i]), m()) << "\n";); var_subst subst(m()); scoped_rlimit no_limit(m().limit(), 0); - result = subst(_t, num_args, args); + result = subst(_t, num_args, args); if (well_sorted_check_enabled() && !is_well_sorted(m(), result)) throw cmd_exception("invalid macro application, sort mismatch ", s); return; @@ -1085,7 +1085,6 @@ void cmd_context::mk_app(symbol const & s, unsigned num_args, expr * const * arg func_decls fs; if (!m_func_decls.find(s, fs)) { - builtin_decl d; if (m_builtin_decls.find(s, d)) { family_id fid = d.m_fid; diff --git a/src/cmd_context/pdecl.cpp b/src/cmd_context/pdecl.cpp index 8c88b1680..3324de900 100644 --- a/src/cmd_context/pdecl.cpp +++ b/src/cmd_context/pdecl.cpp @@ -300,7 +300,7 @@ psort_user_decl::psort_user_decl(unsigned id, unsigned num_params, pdecl_manager m_def(p) { m_psort_kind = PSORT_USER; m.inc_ref(p); - SASSERT(p == 0 || num_params == p->get_num_params()); +// SASSERT(p == 0 || num_params == p->get_num_params()); } void psort_user_decl::finalize(pdecl_manager & m) {