environment decl_attributes::apply(environment env, io_state const & ios, name const & d) const { if (m_is_instance) { if (m_priority) { #if defined(__GNUC__) && !defined(__CLANG__) #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif env = add_instance(env, d, *m_priority, m_persistent); } else { env = add_instance(env, d, m_persistent); } } if (m_is_trans_instance) { if (m_priority) { #if defined(__GNUC__) && !defined(__CLANG__) #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif env = add_trans_instance(env, d, *m_priority, m_persistent); } else { env = add_trans_instance(env, d, m_persistent); } } if (m_is_coercion) env = add_coercion(env, ios, d, m_persistent); auto decl = env.find(d); if (decl && decl->is_definition()) { if (m_is_reducible) env = set_reducible(env, d, reducible_status::Reducible, m_persistent); if (m_is_irreducible) env = set_reducible(env, d, reducible_status::Irreducible, m_persistent); if (m_is_semireducible) env = set_reducible(env, d, reducible_status::Semireducible, m_persistent); if (m_is_quasireducible) env = set_reducible(env, d, reducible_status::Quasireducible, m_persistent); if (m_unfold_hint) env = add_unfold_hint(env, d, m_unfold_hint, m_persistent); if (m_unfold_full_hint) env = add_unfold_full_hint(env, d, m_persistent); } if (m_constructor_hint) env = add_constructor_hint(env, d, m_persistent); if (m_symm) env = add_symm(env, d, m_persistent); if (m_refl) env = add_refl(env, d, m_persistent); if (m_trans) env = add_trans(env, d, m_persistent); if (m_subst) env = add_subst(env, d, m_persistent); if (m_recursor) env = add_user_recursor(env, d, m_recursor_major_pos, m_persistent); if (m_is_class) env = add_class(env, d, m_persistent); if (m_rewrite) env = add_rewrite_rule(env, d, m_persistent); if (m_has_multiple_instances) env = mark_multiple_instances(env, d, m_persistent); return env; }
name mk_fresh_name(environment const & env, name const & prefix, char const * suffix, unsigned & idx) { while (true) { name curr(prefix, suffix); curr = curr.append_after(idx); idx++; if (!env.find(curr) && !is_vm_function(env, curr)) return curr; } }
static name mk_fresh_name(environment const & env, buffer<name> const & names, name const & s) { unsigned i = 1; name c = s; while (true) { if (!env.find(c) && std::find(names.begin(), names.end(), c) == names.end()) return c; c = s.append_after(i); i++; } }
static unsigned get_max_height(environment const & env, expr const & v) { unsigned h = 0; for_each(v, [&](expr const & e, unsigned) { if (is_constant(e)) { auto d = env.find(const_name(e)); if (d && d->get_height() > h) h = d->get_height(); } return true; }); return h; }
name mk_name_for(expr const & e) { lean_assert(is_nested_declaration(e)); if (auto n = get_nested_declaration_name(e)) { return *n; } else { name ns = get_namespace(m_env); while (true) { name aux = m_dname.append_after(m_idx); m_idx++; if (!m_env.find(ns + aux)) return aux; } } }
/** \brief Return true iff the type of all declarations in deps still have the same hashcode stored in deps. */ bool definition_cache::check_dependencies(environment const & env, dependencies const & deps) { bool ok = true; deps.for_each([&](name const & n, unsigned h) { if (ok) { if (auto d = env.find(n)) { if (h != hash_bi(d->get_type())) ok = false; } else { ok = false; } } }); return ok; }
void definition_cache::collect_dependencies(environment const & env, expr const & e, dependencies & deps) { for_each(e, [&](expr const & e, unsigned) { if (!is_constant(e)) return true; name const & n = const_name(e); if (deps.contains(n)) return true; auto d = env.find(n); if (!d) return true; deps.insert(n, hash_bi(d->get_type())); return true; }); }
bool is_tactic_namespace_open(environment const & env) { for (name const & a : get_expr_aliases(env, "apply")) { if (a == get_tactic_apply_name()) { // make sure the type is the expected one if (auto d = env.find(a)) { expr t = d->get_type(); if (is_pi(t)) { expr b = binding_body(t); if (!is_constant(b) || const_name(b) != get_tactic_name()) throw exception("tactic namespace declarations have been modified, " "function 'tactic.apply' is expected to return a 'tactic'"); } } return true; } } return false; }
static void check_identifier(parser & p, environment const & env, name const & ns, name const & id) { name full_id = ns + id; if (!env.find(full_id)) throw parser_error(sstream() << "invalid 'using' command, unknown declaration '" << full_id << "'", p.pos()); }