static declaration update_declaration(declaration d, optional<level_param_names> const & ps,
                                      optional<expr> const & type, optional<expr> const & value) {
    level_param_names _ps = ps ? *ps : d.get_univ_params();
    expr _type = type ? *type : d.get_type();
    expr _value;
    if (d.is_definition()) {
        _value = value ? *value : d.get_value();
    } else {
        lean_assert(!value);
    }
    if (d.is_constant_assumption()) {
        if (is_eqp(d.get_type(), _type) && is_eqp(d.get_univ_params(), _ps))
            return d;
        if (d.is_axiom())
            return mk_axiom(d.get_name(), _ps, _type);
        else
            return mk_constant_assumption(d.get_name(), _ps, _type);
    } else {
        if (is_eqp(d.get_type(), _type) && is_eqp(d.get_value(), _value) && is_eqp(d.get_univ_params(), _ps))
            return d;
        if (d.is_theorem())
            return mk_theorem(d.get_name(), _ps, _type, _value, d.get_height());
        else
            return mk_definition(d.get_name(), _ps, _type, _value,
                                 d.get_height(), d.use_conv_opt());
    }
}
示例#2
0
declaration unfold_untrusted_macros(environment const & env, declaration const & d, optional<unsigned> const & trust_lvl) {
    if (!trust_lvl || contains_untrusted_macro(*trust_lvl, d)) {
        expr new_t = unfold_untrusted_macros(env, d.get_type(), trust_lvl);
        if (d.is_theorem()) {
            expr new_v = unfold_untrusted_macros(env, d.get_value(), trust_lvl);
            return mk_theorem(d.get_name(), d.get_univ_params(), new_t, new_v);
        } else if (d.is_definition()) {
            expr new_v = unfold_untrusted_macros(env, d.get_value(), trust_lvl);
            return mk_definition(d.get_name(), d.get_univ_params(), new_t, new_v,
                                 d.get_hints(), d.is_trusted());
        } else if (d.is_axiom()) {
            return mk_axiom(d.get_name(), d.get_univ_params(), new_t);
        } else if (d.is_constant_assumption()) {
            return mk_constant_assumption(d.get_name(), d.get_univ_params(), new_t);
        } else {
            lean_unreachable();
        }
    } else {
        return d;
    }
}
示例#3
0
 pair<environment, expr> operator()(name const & c, expr const & type, expr const & value, bool is_lemma, optional<bool> const & is_meta) {
     lean_assert(!is_lemma || is_meta);
     lean_assert(!is_lemma || *is_meta == false);
     expr new_type  = collect(m_ctx.instantiate_mvars(type));
     expr new_value = collect(m_ctx.instantiate_mvars(value));
     buffer<expr> norm_params;
     collect_and_normalize_dependencies(norm_params);
     new_type  = replace_locals(new_type, m_params, norm_params);
     new_value = replace_locals(new_value, m_params, norm_params);
     expr def_type  = m_ctx.mk_pi(norm_params, new_type);
     expr def_value = m_ctx.mk_lambda(norm_params, new_value);
     environment const & env = m_ctx.env();
     declaration d;
     if (is_lemma) {
         d = mk_theorem(c, to_list(m_level_params), def_type, def_value);
     } else if (is_meta) {
         bool use_self_opt = true;
         d = mk_definition(env, c, to_list(m_level_params), def_type, def_value, use_self_opt, !*is_meta);
     } else {
         bool use_self_opt = true;
         d = mk_definition_inferring_trusted(env, c, to_list(m_level_params), def_type, def_value, use_self_opt);
     }
     environment new_env = module::add(env, check(env, d, true));
     buffer<level> ls;
     for (name const & n : m_level_params) {
         if (level const * l = m_univ_meta_to_param_inv.find(n))
             ls.push_back(*l);
         else
             ls.push_back(mk_param_univ(n));
     }
     buffer<expr> ps;
     for (expr const & x : m_params) {
         if (expr const * m = m_meta_to_param_inv.find(mlocal_name(x)))
             ps.push_back(*m);
         else
             ps.push_back(x);
     }
     expr r = mk_app(mk_constant(c, to_list(ls)), ps);
     return mk_pair(new_env, r);
 }