refactor(compiler): rename elim_rec to preprocess_rec
This commit is contained in:
parent
3d10c9daf8
commit
49a574dbbf
6 changed files with 50 additions and 25 deletions
|
@ -1 +1,2 @@
|
|||
add_library(compiler OBJECT rec_args.cpp eta_expansion.cpp simp_pr1_rec.cpp elim_rec.cpp)
|
||||
add_library(compiler OBJECT rec_args.cpp eta_expansion.cpp simp_pr1_rec.cpp preprocess_rec.cpp
|
||||
init_module.cpp)
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#pragma once
|
||||
#include "kernel/environment.h"
|
||||
|
||||
namespace lean {
|
||||
declaration elim_rec(environment const & env, declaration const & d, buffer<declaration> & aux_decls);
|
||||
}
|
|
@ -25,22 +25,24 @@ static expr expand_aux_recursors(environment const & env, expr const & e) {
|
|||
return normalize(*tc, e, cs);
|
||||
}
|
||||
|
||||
class elim_rec_fn {
|
||||
environment m_env;
|
||||
buffer<declaration> & m_aux_decls;
|
||||
static name * g_tmp_prefix = nullptr;
|
||||
|
||||
class preprocess_rec_fn {
|
||||
environment m_env;
|
||||
buffer<name> & m_aux_decls;
|
||||
|
||||
bool check(declaration const & d, expr const & v) {
|
||||
type_checker tc(m_env);
|
||||
expr t = tc.check(v, d.get_univ_params()).first;
|
||||
if (!tc.is_def_eq(d.get_type(), t).first)
|
||||
throw exception("elim_rec failed");
|
||||
throw exception("preprocess_rec failed");
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
elim_rec_fn(environment const & env, buffer<declaration> & aux_decls): m_env(env), m_aux_decls(aux_decls) {}
|
||||
preprocess_rec_fn(environment const & env, buffer<name> & aux_decls): m_env(env), m_aux_decls(aux_decls) {}
|
||||
|
||||
declaration operator()(declaration const & d) {
|
||||
environment operator()(declaration const & d) {
|
||||
expr v = d.get_value();
|
||||
v = expand_aux_recursors(m_env, v);
|
||||
v = eta_expand(m_env, v);
|
||||
|
@ -48,11 +50,19 @@ public:
|
|||
::pp(m_env, v);
|
||||
// TODO(Leo)
|
||||
check(d, v);
|
||||
return d;
|
||||
return m_env;
|
||||
}
|
||||
};
|
||||
|
||||
declaration elim_rec(environment const & env, declaration const & d, buffer<declaration> & aux_decls) {
|
||||
return elim_rec_fn(env, aux_decls)(d);
|
||||
environment preprocess_rec(environment const & env, declaration const & d, buffer<name> & aux_decls) {
|
||||
return preprocess_rec_fn(env, aux_decls)(d);
|
||||
}
|
||||
|
||||
void initialize_preprocess_rec() {
|
||||
g_tmp_prefix = new name(name::mk_internal_unique_name());
|
||||
}
|
||||
|
||||
void finalize_preprocess_rec() {
|
||||
delete g_tmp_prefix;
|
||||
}
|
||||
}
|
23
src/compiler/preprocess_rec.h
Normal file
23
src/compiler/preprocess_rec.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#pragma once
|
||||
#include "kernel/environment.h"
|
||||
|
||||
namespace lean {
|
||||
/** \brief Expand user-defined and auxiliary recursors, simplify declaration,
|
||||
put definition in eta-expanded normal form, and
|
||||
eliminate nested (recursive) recursor applications.
|
||||
Each nested recursive application becomes a new definition.
|
||||
|
||||
All new declarations are added to the resulting environment.
|
||||
\remark The new declaration corresponding to \c d is in the last one in \c new_decls.
|
||||
*/
|
||||
environment preprocess_rec(environment const & env, declaration const & d, buffer<name> & new_decls);
|
||||
|
||||
void initialize_preprocess_rec();
|
||||
void finalize_preprocess_rec();
|
||||
}
|
|
@ -35,7 +35,7 @@ Author: Leonardo de Moura
|
|||
#include "library/composition_manager.h"
|
||||
#include "library/definitional/projection.h"
|
||||
#include "library/simplifier/simp_rule_set.h"
|
||||
#include "compiler/elim_rec.h"
|
||||
#include "compiler/preprocess_rec.h"
|
||||
#include "frontends/lean/util.h"
|
||||
#include "frontends/lean/parser.h"
|
||||
#include "frontends/lean/calc.h"
|
||||
|
@ -1055,8 +1055,8 @@ static environment init_hits_cmd(parser & p) {
|
|||
static environment compile_cmd(parser & p) {
|
||||
name n = p.check_constant_next("invalid #compile command, constant expected");
|
||||
declaration d = p.env().get(n);
|
||||
buffer<declaration> aux_decls;
|
||||
elim_rec(p.env(), d, aux_decls);
|
||||
buffer<name> aux_decls;
|
||||
preprocess_rec(p.env(), d, aux_decls);
|
||||
return p.env();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ Author: Leonardo de Moura
|
|||
#include "library/tactic/init_module.h"
|
||||
#include "library/definitional/init_module.h"
|
||||
#include "library/print.h"
|
||||
#include "compiler/init_module.h"
|
||||
#include "frontends/lean/init_module.h"
|
||||
#include "frontends/lua/register_modules.h"
|
||||
#include "init/init.h"
|
||||
|
@ -37,12 +38,14 @@ void initialize() {
|
|||
initialize_tactic_module();
|
||||
initialize_simplifier_module();
|
||||
initialize_definitional_module();
|
||||
initialize_compiler_module();
|
||||
initialize_frontend_lean_module();
|
||||
register_modules();
|
||||
}
|
||||
void finalize() {
|
||||
run_thread_finalizers();
|
||||
finalize_frontend_lean_module();
|
||||
finalize_compiler_module();
|
||||
finalize_definitional_module();
|
||||
finalize_simplifier_module();
|
||||
finalize_tactic_module();
|
||||
|
|
Loading…
Reference in a new issue