feat(library/simplifier): improve error message when simplifier is looping
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
72c607846a
commit
ee4344076e
4 changed files with 44 additions and 2 deletions
|
@ -1512,8 +1512,12 @@ public:
|
|||
set_ctx(ctx);
|
||||
m_num_steps = 0;
|
||||
m_depth = 0;
|
||||
auto r = simplify(e);
|
||||
return mk_pair(r.m_expr, get_proof(r));
|
||||
try {
|
||||
auto r = simplify(e);
|
||||
return mk_pair(r.m_expr, get_proof(r));
|
||||
} catch (stack_space_exception & ex) {
|
||||
throw simplifier_stack_space_exception();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1560,6 +1564,13 @@ expr_pair simplify(expr const & e, ro_environment const & env, context const & c
|
|||
return simplify(e, env, ctx, opts, num_ns, rules.data(), monitor);
|
||||
}
|
||||
|
||||
simplifier_stack_space_exception::simplifier_stack_space_exception():stack_space_exception("simplifier") {}
|
||||
char const * simplifier_stack_space_exception::what() const noexcept {
|
||||
return "deep recursion was detected at 'simplifier', this is probably due to a non-terminating set of rewrite rules, you may use a simplifier_monitor object to track the simplifier behavior (see the simplifier manual); if your problem is very big, you may try to increase stack space in your system";
|
||||
}
|
||||
exception * simplifier_stack_space_exception::clone() const { return new simplifier_stack_space_exception(); }
|
||||
void simplifier_stack_space_exception::rethrow() const { throw *this; }
|
||||
|
||||
DECL_UDATA(simplifier)
|
||||
DECL_UDATA(ro_simplifier)
|
||||
|
||||
|
|
|
@ -105,6 +105,14 @@ public:
|
|||
virtual void failed_abstraction_eh(ro_simplifier const & s, expr const & e, failure_kind k) = 0;
|
||||
};
|
||||
|
||||
class simplifier_stack_space_exception : public stack_space_exception {
|
||||
public:
|
||||
simplifier_stack_space_exception();
|
||||
virtual char const * what() const noexcept;
|
||||
virtual exception * clone() const;
|
||||
virtual void rethrow() const;
|
||||
};
|
||||
|
||||
expr_pair simplify(expr const & e, ro_environment const & env, context const & ctx, options const & pts,
|
||||
unsigned num_rs, rewrite_rule_set const * rs,
|
||||
std::shared_ptr<simplifier_monitor> const & monitor = std::shared_ptr<simplifier_monitor>());
|
||||
|
|
14
tests/lean/simp_loop.lean
Normal file
14
tests/lean/simp_loop.lean
Normal file
|
@ -0,0 +1,14 @@
|
|||
import tactic
|
||||
import macros
|
||||
|
||||
variable f : Nat → Nat
|
||||
variable g : Nat → Nat
|
||||
|
||||
axiom Ax1 (a : Nat) : f a = g a
|
||||
axiom Ax2 (a : Nat) : g a = f a
|
||||
|
||||
add_rewrite Ax1 Ax2
|
||||
|
||||
-- The following call to simp should produce a stack overflow
|
||||
theorem T : f 0 = 0
|
||||
:= by simp
|
9
tests/lean/simp_loop.lean.expected.out
Normal file
9
tests/lean/simp_loop.lean.expected.out
Normal file
|
@ -0,0 +1,9 @@
|
|||
Set: pp::colors
|
||||
Set: pp::unicode
|
||||
Imported 'tactic'
|
||||
Imported 'macros'
|
||||
Assumed: f
|
||||
Assumed: g
|
||||
Assumed: Ax1
|
||||
Assumed: Ax2
|
||||
simp_loop.lean:13:1: error: deep recursion was detected at 'simplifier', this is probably due to a non-terminating set of rewrite rules, you may use a simplifier_monitor object to track the simplifier behavior (see the simplifier manual); if your problem is very big, you may try to increase stack space in your system
|
Loading…
Add table
Reference in a new issue