refactor(kernel/instantiate): add functions instantiate_value_univ_params and instantiate_type_univ_params

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-08-12 07:38:43 -07:00
parent 0ca0ccb77d
commit 562926e7ad
6 changed files with 27 additions and 8 deletions

View file

@ -206,7 +206,7 @@ struct default_converter : public converter {
if (is_constant(e)) {
if (auto d = m_env.find(const_name(e))) {
if (d->is_definition() && !is_opaque(*d) && d->get_weight() >= w)
return unfold_name_core(instantiate_univ_params(d->get_value(), d->get_univ_params(), const_levels(e)), w);
return unfold_name_core(instantiate_value_univ_params(*d, const_levels(e)), w);
}
}
return e;

View file

@ -8,6 +8,7 @@ Author: Leonardo de Moura
#include <limits>
#include "kernel/free_vars.h"
#include "kernel/replace_fn.h"
#include "kernel/declaration.h"
#include "kernel/instantiate.h"
namespace lean {
@ -170,4 +171,14 @@ expr instantiate_univ_params(expr const & e, level_param_names const & ps, level
}
});
}
expr instantiate_type_univ_params(declaration const & d, levels const & ls) {
lean_assert(length(d.get_univ_params()) == length(ls));
return instantiate_univ_params(d.get_type(), d.get_univ_params(), ls);
}
expr instantiate_value_univ_params(declaration const & d, levels const & ls) {
lean_assert(length(d.get_univ_params()) == length(ls));
return instantiate_univ_params(d.get_value(), d.get_univ_params(), ls);
}
}

View file

@ -26,10 +26,18 @@ bool is_head_beta(expr const & t);
expr head_beta_reduce(expr const & t);
expr beta_reduce(expr t);
/**
\brief Instantiate the universe level parameters \c ps occurring in \c e with the levels \c ls.
/** \brief Instantiate the universe level parameters \c ps occurring in \c e with the levels \c ls.
\pre length(ps) == length(ls)
*/
expr instantiate_univ_params(expr const & e, level_param_names const & ps, levels const & ls);
class declaration;
/** \brief Instantiate the universe level parameters of the type of the given declaration.
\pre length(d.get_univ_params()) == length(ls)
*/
expr instantiate_type_univ_params(declaration const & d, levels const & ls);
/** \brief Instantiate the universe level parameters of the value of the given declaration.
\pre length(d.get_univ_params()) == length(ls)
*/
expr instantiate_value_univ_params(declaration const & d, levels const & ls);
}

View file

@ -214,7 +214,7 @@ expr type_checker::infer_constant(expr const & e, bool infer_only) {
for (level const & l : ls)
check_level(l, e);
}
return instantiate_univ_params(d.get_type(), ps, ls);
return instantiate_type_univ_params(d, ls);
}
expr type_checker::infer_macro(expr const & e, bool infer_only) {

View file

@ -361,7 +361,7 @@ protected:
optional<declaration> d = m_env.find(const_name(c));
if (d && d->is_definition() && (!d->is_opaque() || d->get_module_idx() == 0)) {
m_unfolded = true;
return instantiate_univ_params(d->get_value(), d->get_univ_params(), const_levels(c));
return instantiate_value_univ_params(*d, const_levels(c));
} else {
return c;
}

View file

@ -1107,8 +1107,8 @@ struct unifier_fn {
justification a;
// add case_split for t =?= s
expr lhs_fn_val = instantiate_univ_params(d.get_value(), d.get_univ_params(), const_levels(lhs_fn));
expr rhs_fn_val = instantiate_univ_params(d.get_value(), d.get_univ_params(), const_levels(rhs_fn));
expr lhs_fn_val = instantiate_value_univ_params(d, const_levels(lhs_fn));
expr rhs_fn_val = instantiate_value_univ_params(d, const_levels(rhs_fn));
expr t = apply_beta(lhs_fn_val, lhs_args.size(), lhs_args.data());
expr s = apply_beta(rhs_fn_val, rhs_args.size(), rhs_args.data());
bool relax = relax_main_opaque(c);