feat(frontends/lean,library/blast/forward/pattern): check whether patterns can be inferred at declaration time

This commit is contained in:
Leonardo de Moura 2015-12-02 22:36:10 -08:00
parent f84c6a6cfa
commit 028ef47c84
6 changed files with 19 additions and 6 deletions

View file

@ -234,14 +234,12 @@ static void print_metaclasses(parser const & p) {
static void print_patterns(parser & p, name const & n) { static void print_patterns(parser & p, name const & n) {
if (is_forward_lemma(p.env(), n)) { if (is_forward_lemma(p.env(), n)) {
blast::scope_debug scope(p.env(), p.ios());
// we regenerate the patterns to make sure they reflect the current set of reducible constants // we regenerate the patterns to make sure they reflect the current set of reducible constants
try { try {
auto lemma = blast::mk_hi_lemma(n, LEAN_FORWARD_LEMMA_DEFAULT_PRIORITY); if (auto mps = mk_multipatterns(p.env(), p.ios(), n)) {
if (lemma.m_multi_patterns) {
io_state_stream out = p.regular_stream(); io_state_stream out = p.regular_stream();
out << "(multi-)patterns:\n"; out << "(multi-)patterns:\n";
for (multi_pattern const & mp : lemma.m_multi_patterns) { for (multi_pattern const & mp : mps) {
out << "{"; out << "{";
bool first = true; bool first = true;
for (expr const & p : mp) { for (expr const & p : mp) {

View file

@ -241,6 +241,7 @@ environment decl_attributes::apply(environment env, io_state const & ios, name c
env = add_backward_rule(env, d, LEAN_BACKWARD_DEFAULT_PRIORITY, m_persistent); env = add_backward_rule(env, d, LEAN_BACKWARD_DEFAULT_PRIORITY, m_persistent);
} }
if (forward) { if (forward) {
mk_multipatterns(env, ios, d); // try to create patterns
if (m_priority) if (m_priority)
env = add_forward_lemma(env, d, *m_priority, m_persistent); env = add_forward_lemma(env, d, *m_priority, m_persistent);
else else

View file

@ -130,7 +130,7 @@ expr mk_pattern_hint(expr const & e) {
if (has_pattern_hints(e)) if (has_pattern_hints(e))
throw exception("invalid pattern hint, nested patterns hints are not allowed"); throw exception("invalid pattern hint, nested patterns hints are not allowed");
if (!is_app(e)) if (!is_app(e))
throw_generic_exception("invalid pattern hint, pattern must be applications", e); throw_generic_exception("invalid pattern hint, pattern hints must be applications", e);
return mk_annotation(*g_pattern_hint, e); return mk_annotation(*g_pattern_hint, e);
} }
@ -630,6 +630,13 @@ hi_lemma mk_hi_lemma(name const & c, unsigned priority) {
} }
} }
list<multi_pattern> mk_multipatterns(environment const & env, io_state const & ios, name const & c) {
blast::scope_debug scope(env, ios);
// we regenerate the patterns to make sure they reflect the current set of reducible constants
auto lemma = blast::mk_hi_lemma(c, LEAN_FORWARD_LEMMA_DEFAULT_PRIORITY);
return lemma.m_multi_patterns;
}
void initialize_pattern() { void initialize_pattern() {
g_name = new name("no_pattern"); g_name = new name("no_pattern");
g_key = new std::string("NOPAT"); g_key = new std::string("NOPAT");

View file

@ -48,6 +48,9 @@ struct hi_lemma_cmp {
int operator()(hi_lemma const & l1, hi_lemma const & l2) const { return expr_quick_cmp()(l1.m_prop, l2.m_prop); } int operator()(hi_lemma const & l1, hi_lemma const & l2) const { return expr_quick_cmp()(l1.m_prop, l2.m_prop); }
}; };
/** \brief Try to compute multipatterns for declaration \c c using the current environment configuration. */
list<multi_pattern> mk_multipatterns(environment const & env, io_state const & ios, name const & c);
namespace blast { namespace blast {
/** \brief Create a (local) heuristic instantiation lemma for \c H. /** \brief Create a (local) heuristic instantiation lemma for \c H.
The maximum number of steps is extracted from the blast config object. */ The maximum number of steps is extracted from the blast config object. */

View file

@ -16,3 +16,6 @@ reveal tst₀ tst₁ tst₃
print tst₀ print tst₀
print tst₁ print tst₁
print tst₃ print tst₃
definition tst₄ [forward] : ∀ x : nat, (: id x :) = x :=
λ x, rfl

View file

@ -1,4 +1,4 @@
bad_pattern.lean:9:33: error: invalid pattern hint, pattern must be applications bad_pattern.lean:9:33: error: invalid pattern hint, pattern hints must be applications
theorem tst₀ [forward] : ∀ (x : ), P x := theorem tst₀ [forward] : ∀ (x : ), P x :=
sorry sorry
(multi-)patterns: (multi-)patterns:
@ -11,3 +11,4 @@ theorem tst₃ [forward] : ∀ (x : ), P (:id x:) :=
sorry sorry
(multi-)patterns: (multi-)patterns:
{P ?M_1} {P ?M_1}
bad_pattern.lean:20:0: error: pattern inference failed for [forward] annotation, (solution: provide pattern hints using the notation '(: t :)' )