feat(frontends/lean/elaborator): use tactic_hints for unsolved placeholders

This commit is contained in:
Leonardo de Moura 2014-09-25 17:54:10 -07:00
parent bb1c6d44ac
commit 318fec43a4

View file

@ -887,8 +887,11 @@ public:
/** \brief Try to instantiate meta-variable \c mvar (modulo its state ps) using the given tactic.
If it succeeds, then update subst with the solution.
Return true iff the metavariable \c mvar has been assigned.
If \c show_failure == true, then display reason for failure.
*/
bool try_using(substitution & subst, expr const & mvar, proof_state const & ps, tactic const & tac) {
bool try_using(substitution & subst, expr const & mvar, proof_state const & ps, tactic const & tac,
bool show_failure) {
lean_assert(length(ps.get_goals()) == 1);
// make sure ps is a really a proof state for mvar.
lean_assert(mlocal_name(get_app_fn(head(ps.get_goals()).get_meta())) == mlocal_name(mvar));
@ -897,10 +900,12 @@ public:
auto r = seq.pull();
if (!r) {
// tactic failed to produce any result
if (show_failure)
display_unsolved_proof_state(mvar, ps, "tactic failed");
return false;
} else if (!empty(r->first.get_goals())) {
// tactic contains unsolved subgoals
if (show_failure)
display_unsolved_proof_state(mvar, r->first, "unsolved subgoals");
return false;
} else {
@ -910,9 +915,11 @@ public:
return true;
}
} catch (tactic_exception & ex) {
if (show_failure) {
auto out = regular(env(), ios());
display_error_pos(out, pip(), ex.get_expr());
out << " tactic failed: " << ex.what() << "\n";
}
return false;
}
}
@ -921,7 +928,6 @@ public:
if (visited.contains(mlocal_name(mvar)))
return;
visited.insert(mlocal_name(mvar));
if (auto local_hint = get_local_tactic_hint(subst, mvar, visited)) {
auto meta = mvar_to_meta(mvar);
if (!meta)
return;
@ -931,7 +937,17 @@ public:
// first solve unassigned metavariables in type
type = solve_unassigned_mvars(subst, type, visited);
proof_state ps(goals(goal(*meta, type)), subst, m_ngen.mk_child());
try_using(subst, mvar, ps, *local_hint);
if (auto local_hint = get_local_tactic_hint(subst, mvar, visited)) {
// using user provided tactic
bool show_failure = true;
try_using(subst, mvar, ps, *local_hint, show_failure);
} else {
// using tactic_hints
for (tactic_hint_entry const & tentry : get_tactic_hints(env())) {
bool show_failure = false;
if (try_using(subst, mvar, ps, tentry.get_tactic(), show_failure))
return;
}
}
}