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:
parent
873a07d34c
commit
a1b5a8e50f
2 changed files with 61 additions and 46 deletions
|
@ -1076,7 +1076,8 @@ class parser::imp {
|
||||||
diagnostic(m_frontend) << "Proof state:\n" << s << endl;
|
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())
|
if (!stack.empty())
|
||||||
diagnostic(m_frontend) << "Backtracking...\n";
|
diagnostic(m_frontend) << "Backtracking...\n";
|
||||||
while (!stack.empty()) {
|
while (!stack.empty()) {
|
||||||
|
@ -1097,18 +1098,7 @@ class parser::imp {
|
||||||
throw exception("failed to synthesize proof object using tactics");
|
throw exception("failed to synthesize proof object using tactics");
|
||||||
}
|
}
|
||||||
|
|
||||||
expr parse_tactic(proof_state s) {
|
void tactic_apply(proof_state_seq_stack & stack, 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) {
|
|
||||||
auto tac_pos = pos();
|
auto tac_pos = pos();
|
||||||
tactic t;
|
tactic t;
|
||||||
if (curr() == scanner::token::ScriptBlock) {
|
if (curr() == scanner::token::ScriptBlock) {
|
||||||
|
@ -1134,27 +1124,49 @@ class parser::imp {
|
||||||
proof_state_seq::maybe_pair r;
|
proof_state_seq::maybe_pair r;
|
||||||
code_with_callbacks([&]() {
|
code_with_callbacks([&]() {
|
||||||
// t may have call-backs we should set ios in the script_state
|
// 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();
|
r = seq.pull();
|
||||||
});
|
});
|
||||||
if (r) {
|
if (r) {
|
||||||
s = r->first;
|
s = r->first;
|
||||||
stack.push_back(r->second);
|
stack.push_back(r->second);
|
||||||
} else {
|
} 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()) {
|
if (s.is_proof_final_state()) {
|
||||||
assignment a(s.get_menv());
|
assignment a(s.get_menv());
|
||||||
proof_map m;
|
proof_map m;
|
||||||
expr pr = s.get_proof_builder()(m, a);
|
expr pr = s.get_proof_builder()(m, a);
|
||||||
|
if (has_metavar(pr)) {
|
||||||
|
throw exception("synthesized proof object has unsolved metavars");
|
||||||
|
}
|
||||||
return pr;
|
return pr;
|
||||||
} else {
|
} else {
|
||||||
display_proof_state(s);
|
display_proof_state(s);
|
||||||
throw exception("failed to synthesize proof object using tactics");
|
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 {
|
} else {
|
||||||
throw parser_error(sstream() << "invalid tactical proof, unknown command '" << id << "'", p);
|
throw parser_error(sstream() << "invalid tactical proof, unknown command '" << id << "'", p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ format proof_state::pp(formatter const & fmt, options const & opts) const {
|
||||||
r += line();
|
r += line();
|
||||||
r += p.second.pp(fmt, opts);
|
r += p.second.pp(fmt, opts);
|
||||||
}
|
}
|
||||||
|
if (first) {
|
||||||
|
r = format("no goals");
|
||||||
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue