refactor(frontends/lean/builtin_cmds): cleanup 'check' command
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
5c51be4585
commit
195429611b
3 changed files with 25 additions and 13 deletions
|
@ -82,24 +82,15 @@ environment end_scoped_cmd(parser & p) {
|
||||||
|
|
||||||
environment check_cmd(parser & p) {
|
environment check_cmd(parser & p) {
|
||||||
expr e = p.parse_expr();
|
expr e = p.parse_expr();
|
||||||
buffer<expr> section_ps;
|
buffer<expr> locals;
|
||||||
expr_struct_set locals;
|
e = abstract_locals(e, p, locals);
|
||||||
collect_locals(e, locals);
|
|
||||||
sort_section_params(locals, p, section_ps);
|
|
||||||
e = p.lambda_abstract(section_ps, e);
|
|
||||||
level_param_names ls = to_level_param_names(collect_univ_params(e));
|
level_param_names ls = to_level_param_names(collect_univ_params(e));
|
||||||
level_param_names new_ls;
|
level_param_names new_ls;
|
||||||
std::tie(e, new_ls) = p.elaborate_relaxed(e);
|
std::tie(e, new_ls) = p.elaborate_relaxed(e);
|
||||||
auto tc = mk_type_checker_with_hints(p.env(), p.mk_ngen());
|
auto tc = mk_type_checker_with_hints(p.env(), p.mk_ngen());
|
||||||
expr type = tc->check(e, append(ls, new_ls));
|
expr type = tc->check(e, append(ls, new_ls));
|
||||||
// consume sections_ps introduced with mk_section_params
|
e = instantiate_locals(e, locals);
|
||||||
for (unsigned i = 0; i < section_ps.size(); i++) {
|
type = instantiate_locals(type, locals);
|
||||||
lean_assert(is_lambda(e));
|
|
||||||
lean_assert(is_pi(type));
|
|
||||||
expr local = section_ps[i];
|
|
||||||
e = instantiate(binding_body(e), local);
|
|
||||||
type = instantiate(binding_body(type), local);
|
|
||||||
}
|
|
||||||
auto reg = p.regular_stream();
|
auto reg = p.regular_stream();
|
||||||
formatter const & fmt = reg.get_formatter();
|
formatter const & fmt = reg.get_formatter();
|
||||||
options opts = p.ios().get_options();
|
options opts = p.ios().get_options();
|
||||||
|
|
|
@ -6,6 +6,8 @@ Author: Leonardo de Moura
|
||||||
*/
|
*/
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "util/sstream.h"
|
#include "util/sstream.h"
|
||||||
|
#include "kernel/abstract.h"
|
||||||
|
#include "kernel/instantiate.h"
|
||||||
#include "library/scoped_ext.h"
|
#include "library/scoped_ext.h"
|
||||||
#include "library/locals.h"
|
#include "library/locals.h"
|
||||||
#include "frontends/lean/parser.h"
|
#include "frontends/lean/parser.h"
|
||||||
|
@ -56,4 +58,19 @@ void collect_section_locals(expr const & type, expr const & value, parser const
|
||||||
collect_locals(value, ls);
|
collect_locals(value, ls);
|
||||||
sort_section_params(ls, p, section_ps);
|
sort_section_params(ls, p, section_ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expr abstract_locals(expr const & e, parser const & p, buffer<expr> & locals) {
|
||||||
|
expr_struct_set ls;
|
||||||
|
collect_locals(e, ls);
|
||||||
|
sort_section_params(ls, p, locals);
|
||||||
|
return Fun(locals, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
expr instantiate_locals(expr const & b, buffer<expr> & locals) {
|
||||||
|
expr _b = b;
|
||||||
|
unsigned sz = locals.size();
|
||||||
|
for (unsigned i = 0; i < sz; i++)
|
||||||
|
_b = binding_body(_b);
|
||||||
|
return instantiate_rev(_b, locals.size(), locals.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,4 +19,8 @@ levels collect_section_levels(level_param_names const & ls, parser & p);
|
||||||
void collect_section_locals(expr const & type, expr const & value, parser const & p, buffer<expr> & section_ps);
|
void collect_section_locals(expr const & type, expr const & value, parser const & p, buffer<expr> & section_ps);
|
||||||
/** \brief Copy the local parameters to \c section_ps, then sort \c section_ps (using the order in which they were declared). */
|
/** \brief Copy the local parameters to \c section_ps, then sort \c section_ps (using the order in which they were declared). */
|
||||||
void sort_section_params(expr_struct_set const & locals, parser const & p, buffer<expr> & section_ps);
|
void sort_section_params(expr_struct_set const & locals, parser const & p, buffer<expr> & section_ps);
|
||||||
|
/** \brief collect all locals in \c e and store and locals, and return Fun(locals, e) */
|
||||||
|
expr abstract_locals(expr const & e, parser const & p, buffer<expr> & locals);
|
||||||
|
/** \brief 'inverse' of \c abstract_locals, given a binding \c b instantiate it using locals */
|
||||||
|
expr instantiate_locals(expr const & b, buffer<expr> & locals);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue