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()); } }
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("preprocess_rec failed"); return true; }
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; } }
declaration sanitize_level_params(declaration const & d) { name_set globals; collect_global_levels(d.get_type(), globals); if (d.is_definition()) collect_global_levels(d.get_value(), globals); if (globals.empty()) return d; name_map<name> param_name_map; level_param_names new_ls = sanitize_level_params(d.get_univ_params(), globals, param_name_map); if (param_name_map.empty()) return d; expr new_type = rename_param_levels(d.get_type(), param_name_map); if (d.is_constant_assumption()) { return update_declaration(d, new_ls, new_type); } else { expr new_value = rename_param_levels(d.get_value(), param_name_map); return update_declaration(d, new_ls, new_type, new_value); } }