fix(frontends/lean): check wheter the synthesized proof term has metavars or not

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-12-05 14:22:19 -08:00
parent 873a07d34c
commit a1b5a8e50f
2 changed files with 61 additions and 46 deletions

View file

@ -1076,7 +1076,8 @@ class parser::imp {
diagnostic(m_frontend) << "Proof state:\n" << s << endl;
}
void backtrack(std::vector<lazy_list<proof_state>> & stack, proof_state & s) {
typedef std::vector<proof_state_seq> proof_state_seq_stack;
void tactic_backtrack(proof_state_seq_stack & stack, proof_state & s) {
if (!stack.empty())
diagnostic(m_frontend) << "Backtracking...\n";
while (!stack.empty()) {
@ -1097,18 +1098,7 @@ class parser::imp {
throw exception("failed to synthesize proof object using tactics");
}
expr parse_tactic(proof_state s) {
proof_state ini = s;
std::vector<lazy_list<proof_state>> stack;
while (true) {
auto p = pos();
if (!curr_is_identifier()) {
display_proof_state(s);
throw parser_error("invalid tactic, identifier expected", p);
}
name id = curr_name();
next();
if (id == g_apply) {
void tactic_apply(proof_state_seq_stack & stack, proof_state & s) {
auto tac_pos = pos();
tactic t;
if (curr() == scanner::token::ScriptBlock) {
@ -1134,27 +1124,49 @@ class parser::imp {
proof_state_seq::maybe_pair r;
code_with_callbacks([&]() {
// t may have call-backs we should set ios in the script_state
lazy_list<proof_state> seq = t(m_frontend, m_frontend.get_state(), s);
proof_state_seq seq = t(m_frontend, m_frontend.get_state(), s);
r = seq.pull();
});
if (r) {
s = r->first;
stack.push_back(r->second);
} else {
backtrack(stack, s);
tactic_backtrack(stack, s);
}
} else if (id == g_back) {
backtrack(stack, s);
} else if (id == g_done) {
}
expr tactic_done(proof_state const & s) {
if (s.is_proof_final_state()) {
assignment a(s.get_menv());
proof_map m;
expr pr = s.get_proof_builder()(m, a);
if (has_metavar(pr)) {
throw exception("synthesized proof object has unsolved metavars");
}
return pr;
} else {
display_proof_state(s);
throw exception("failed to synthesize proof object using tactics");
}
}
expr parse_tactic(proof_state s) {
proof_state ini = s;
proof_state_seq_stack stack;
while (true) {
auto p = pos();
if (!curr_is_identifier()) {
display_proof_state(s);
throw parser_error("invalid tactic, identifier expected", p);
}
name id = curr_name();
next();
if (id == g_apply) {
tactic_apply(stack, s);
} else if (id == g_back) {
tactic_backtrack(stack, s);
} else if (id == g_done) {
return tactic_done(s);
} else {
throw parser_error(sstream() << "invalid tactical proof, unknown command '" << id << "'", p);
}

View file

@ -45,6 +45,9 @@ format proof_state::pp(formatter const & fmt, options const & opts) const {
r += line();
r += p.second.pp(fmt, opts);
}
if (first) {
r = format("no goals");
}
return r;
}