Example #1
0
 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;
 }
static bool contains_untrusted_macro(unsigned trust_lvl, declaration const & d) {
    if (trust_lvl > LEAN_BELIEVER_TRUST_LEVEL)
        return false;
    if (contains_untrusted_macro(trust_lvl, d.get_type()))
        return true;
    return (d.is_definition() || d.is_theorem()) && contains_untrusted_macro(trust_lvl, d.get_value());
}
Example #3
0
static bool contains_untrusted_macro(unsigned trust_lvl, declaration const & d) {
#if defined(LEAN_ALL_MACROS_HAVE_SMALL_TRUST_LVL)
    if (trust_lvl > LEAN_BELIEVER_TRUST_LEVEL) return false;
#endif
    if (!d.is_trusted())
        return false;
    if (contains_untrusted_macro(trust_lvl, d.get_type()))
        return true;
    return (d.is_definition() || d.is_theorem()) && contains_untrusted_macro(trust_lvl, d.get_value());
}
Example #4
0
    void print_decl(declaration const & d) {
        format fn = compose_many({simple_pp(d.get_name()), space(), format(":"), space(), pp(d.get_type())});

        if (d.is_definition() && !d.is_theorem()) {
            m_out << compose_many({format("def"), space(), fn, space(), format(":="), line(), pp(d.get_value()), line()});
        } else {
            format cmd(d.is_theorem() ? "theorem" : (d.is_axiom() ? "axiom" : "constant"));
            m_out << compose_many({cmd, space(), fn, line()});
        }
    }
Example #5
0
bool match_pattern(type_checker & tc, expr const & pattern, declaration const & d, unsigned max_steps, bool cheap) {
    name_generator ngen = tc.mk_ngen();
     buffer<level> ls;
    unsigned num_ls = d.get_num_univ_params();
    for (unsigned i = 0; i < num_ls; i++)
        ls.push_back(mk_meta_univ(ngen.next()));
    expr dt        = instantiate_type_univ_params(d, to_list(ls.begin(), ls.end()));

    unsigned num_e = get_expect_num_args(tc, pattern);
    unsigned num_d = get_expect_num_args(tc, dt);
    if (num_e > num_d)
        return false;
    for (unsigned i = 0; i < num_d - num_e; i++) {
        dt         = tc.whnf(dt).first;
        expr local = mk_local(ngen.next(), binding_domain(dt));
        dt         = instantiate(binding_body(dt), local);
    }
    try {
        unifier_config cfg;
        cfg.m_max_steps            = max_steps;
        cfg.m_kind                 = cheap ? unifier_kind::Cheap : unifier_kind::Liberal;
        cfg.m_ignore_context_check = true;
        auto r = unify(tc.env(), pattern, dt, tc.mk_ngen(), substitution(), cfg);
        return static_cast<bool>(r.pull());
    } catch (exception&) {
        return false;
    }
}
Example #6
0
environment environment::add(declaration const & d) const {
    if (trust_lvl() == 0)
        throw_kernel_exception(*this, "environment trust level does not allow users to add declarations that were not type checked");
    name const & n = d.get_name();
    if (find(n))
        throw_already_declared(*this, n);
    return environment(m_header, m_id, insert(m_declarations, n, d), m_global_levels, m_extensions);
}
Example #7
0
// --------------------------------------------------------------------------------------------------------------------
member::member(const string name, const declaration& declaration, const char* usage)
: mName(move(name))
, mType(declaration.typeInfo())
, mUsage(usage)
, mDeclaration(declaration)
{
	mHashName = type_info::hash(this->name());
}
Example #8
0
    /* If type of d is a proposition or return a type, we don't need to compile it.
       We can just generate (fun args, neutral_expr)

       This procedure returns true if type of d is a proposition or return a type,
       and store the dummy code above in */
    bool compile_irrelevant(declaration const & d, buffer<procedure> & procs) {
        type_context ctx(m_env, transparency_mode::All);
        expr type = d.get_type();
        type_context::tmp_locals locals(ctx);
        while (true) {
            type = ctx.relaxed_whnf(type);
            if (!is_pi(type))
                break;
            expr local = locals.push_local_from_binding(type);
            type       = instantiate(binding_body(type), local);
        }
        if (ctx.is_prop(type) || is_sort(type)) {
            expr r = locals.mk_lambda(mk_neutral_expr());
            procs.emplace_back(d.get_name(), optional<pos_info>(), r);
            return true;
        } else {
            return false;
        }
    }
Example #9
0
 environment operator()(declaration const & d) {
     expr v = d.get_value();
     v = expand_aux_recursors(m_env, v);
     v = eta_expand(m_env, v);
     v = simp_pr1_rec(m_env, v);
     ::pp(m_env, v);
     // TODO(Leo)
     check(d, v);
     return m_env;
 }
Example #10
0
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);
    }
}
Example #11
0
declaration unfold_untrusted_macros(environment const & env, declaration const & d, unsigned trust_lvl) {
    if (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,
                              d.get_height());
        } 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_height(), d.use_conv_opt());
        } 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;
    }
}
Example #12
0
bool contains_untrusted_macro(unsigned trust_lvl, declaration const & d) {
    if (contains_untrusted_macro(trust_lvl, d.get_type()))
        return true;
    return (d.is_definition() || d.is_theorem()) && contains_untrusted_macro(trust_lvl, d.get_value());
}
Example #13
0
bool projection_converter::is_opaque(declaration const & d) const {
    return m_proj_info.find(d.get_name()) != nullptr;
}
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());
    }
}
Example #15
0
 void print_axioms(declaration const & decl) {
     print_axioms(decl.get_type());
     if (decl.is_definition()) print_axioms(decl.get_value());
 }