diff --git a/src/frontends/lean/builtin_cmds.cpp b/src/frontends/lean/builtin_cmds.cpp index dd3e7f318c..7b5194d16e 100644 --- a/src/frontends/lean/builtin_cmds.cpp +++ b/src/frontends/lean/builtin_cmds.cpp @@ -222,7 +222,7 @@ environment reduce_cmd(parser & p) { expr e; level_param_names ls; std::tie(e, ls) = parse_local_expr(p, "_reduce"); expr r; - type_context ctx(p.env(), p.get_options(), metavar_context(), local_context(), transparency_mode::All); + type_context_old ctx(p.env(), p.get_options(), metavar_context(), local_context(), transparency_mode::All); if (whnf) { r = ctx.whnf(e); } else { @@ -391,7 +391,7 @@ static environment init_quotient_cmd(parser & p) { /* Temporary procedure that converts metavariables in \c e to metavar_context metavariables. - After we convert the frontend to type_context, we will not need to use this procedure. + After we convert the frontend to type_context_old, we will not need to use this procedure. */ static expr convert_metavars(metavar_context & mctx, expr const & e) { expr_map cache; @@ -427,7 +427,7 @@ static environment unify_cmd(parser & p) { e2 = convert_metavars(mctx, e2); auto rep = p.mk_message(p.cmd_pos(), p.pos(), INFORMATION); rep << e1 << " =?= " << e2 << "\n"; - type_context ctx(env, p.get_options(), mctx, lctx, transparency_mode::Semireducible); + type_context_old ctx(env, p.get_options(), mctx, lctx, transparency_mode::Semireducible); bool success = ctx.is_def_eq(e1, e2); if (success) rep << ctx.instantiate_mvars(e1) << " =?= " << ctx.instantiate_mvars(e2) << "\n"; @@ -453,7 +453,7 @@ static environment eval_cmd(parser & p) { if (has_synthetic_sorry(e)) return p.env(); - type_context tc(p.env(), transparency_mode::All); + type_context_old tc(p.env(), transparency_mode::All); auto type = tc.infer(e); bool has_repr_inst = false; diff --git a/src/frontends/lean/definition_cmds.cpp b/src/frontends/lean/definition_cmds.cpp index 4cca7a12e4..52aad4debf 100644 --- a/src/frontends/lean/definition_cmds.cpp +++ b/src/frontends/lean/definition_cmds.cpp @@ -356,8 +356,8 @@ static void get_args_for_instantiating_lemma(unsigned arity, Then, copy the equation lemmas from d._main to d. */ static environment copy_equation_lemmas(environment const & env, buffer const & d_names) { - type_context ctx(env, transparency_mode::All); - type_context::tmp_locals locals(ctx); + type_context_old ctx(env, transparency_mode::All); + type_context_old::tmp_locals locals(ctx); level_param_names lps; levels ls; buffer vals; @@ -643,7 +643,7 @@ static expr elaborate_proof( bool is_rfl_lemma, expr const & final_type, metavar_context const & mctx, local_context const & lctx, parser_pos_provider pos_provider, bool use_info_manager, std::string const & file_name) { - auto tc = std::make_shared(decl_env, opts, mctx, lctx); + auto tc = std::make_shared(decl_env, opts, mctx, lctx); scope_trace_env scope2(decl_env, opts, *tc); scope_traces_as_messages scope2a(file_name, header_pos); scope_pos_info_provider scope3(pos_provider); @@ -681,7 +681,7 @@ static void check_example(environment const & decl_env, options const & opts, expr const & fn, expr const & val0, metavar_context const & mctx, local_context const & lctx, parser_pos_provider pos_provider, bool use_info_manager, std::string const & file_name) { - auto tc = std::make_shared(decl_env, opts, mctx, lctx); + auto tc = std::make_shared(decl_env, opts, mctx, lctx); scope_trace_env scope2(decl_env, opts, *tc); scope_traces_as_messages scope2a(file_name, pos_provider.get_some_pos()); scope_pos_info_provider scope3(pos_provider); diff --git a/src/frontends/lean/elaborator.cpp b/src/frontends/lean/elaborator.cpp index cc47920f0b..ec58b5711f 100644 --- a/src/frontends/lean/elaborator.cpp +++ b/src/frontends/lean/elaborator.cpp @@ -218,7 +218,7 @@ bool elaborator::try_report(std::exception const & ex, optional const & re auto pip = get_pos_info_provider(); if (!pip) return false; - auto tc = std::make_shared(m_env, m_opts, m_ctx.mctx(), m_ctx.lctx()); + auto tc = std::make_shared(m_env, m_opts, m_ctx.mctx(), m_ctx.lctx()); message_builder out(tc, m_env, get_global_ios(), pip->get_file_name(), ref ? pip->get_pos_info_or_some(*ref) : pip->get_some_pos(), ERROR); out.set_exception(ex); @@ -441,7 +441,7 @@ auto elaborator::use_elim_elab_core(name const & fn) -> optional { if (is_basic_aux_recursor(m_env, fn) || inductive::is_elim_rule(m_env, fn)) { return optional(get_elim_info_for_builtin(fn)); } - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); declaration d = m_env.get(fn); expr type = d.get_type(); while (is_pi(type)) { @@ -703,7 +703,7 @@ optional elaborator::mk_coercion(expr const & e, expr e_type, expr type, e } bool elaborator::is_def_eq(expr const & e1, expr const & e2) { - type_context::approximate_scope scope(m_ctx); + type_context_old::approximate_scope scope(m_ctx); try { return m_ctx.is_def_eq(e1, e2); } catch (exception &) { @@ -1585,7 +1585,7 @@ expr elaborator::visit_base_app_core(expr const & fn, arg_mask amask, buffer dont_recover(m_recover_from_errors, false); first_pass(fn, args, *expected_type, ref, info); } catch (elaborator_exception & ex1) { @@ -2127,7 +2127,7 @@ static expr instantiate_rev_locals(expr const & a, unsigned n, expr const * subs return replace(a, fn); } -static expr instantiate_rev_locals(expr const & e, type_context::tmp_locals const & locals) { +static expr instantiate_rev_locals(expr const & e, type_context_old::tmp_locals const & locals) { return instantiate_rev_locals(e, locals.as_buffer().size(), locals.as_buffer().data()); } @@ -2178,7 +2178,7 @@ expr elaborator::visit_convoy(expr const & e, optional const & expected_ty } } else { // User provided some typing information for the match - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr it = fn_type; for (unsigned i = 0; i < args.size(); i++) { if (!is_pi(it)) @@ -2310,7 +2310,7 @@ expr elaborator::mk_aux_meta_def(expr const & e, expr const & ref) { return new_c; } -static void mvar_dep_sort_aux(type_context & ctx, expr const & m, +static void mvar_dep_sort_aux(type_context_old & ctx, expr const & m, name_set const & mvar_names, name_set & visited, buffer & result) { if (visited.contains(mlocal_name(m))) return; @@ -2329,7 +2329,7 @@ static void mvar_dep_sort_aux(type_context & ctx, expr const & m, } /* Topological sort based on dependencies. */ -static void mvar_dep_sort(type_context & ctx, buffer & mvars) { +static void mvar_dep_sort(type_context_old & ctx, buffer & mvars) { name_set visited; buffer result; name_set mvar_names; @@ -2359,7 +2359,7 @@ class validate_and_collect_lhs_mvars : public replace_visitor { buffer & m_unassigned_mvars; name_set m_collected; - type_context & ctx() { return m_elab.m_ctx; } + type_context_old & ctx() { return m_elab.m_ctx; } environment const & env() { return m_elab.env(); } @@ -2368,7 +2368,7 @@ class validate_and_collect_lhs_mvars : public replace_visitor { of definitions compiled using the equation compiler */ { /* Try without use delta reduction */ - type_context::transparency_scope scope(ctx(), transparency_mode::None); + type_context_old::transparency_scope scope(ctx(), transparency_mode::None); expr new_e = ctx().whnf(e); if (new_e != e) return some_expr(new_e); } @@ -2517,7 +2517,7 @@ public: /* Similar to instantiate_mvars, but add an inaccessible pattern annotation around metavariables whose value has been fixed by type inference. */ -static expr instantiate_pattern_mvars(type_context & ctx, expr const & lhs) { +static expr instantiate_pattern_mvars(type_context_old & ctx, expr const & lhs) { return replace(lhs, [&](expr const & e, unsigned) { if (is_metavar_decl_ref(e) && ctx.is_assigned(e)) { expr v = ctx.instantiate_mvars(e); @@ -2533,7 +2533,7 @@ static expr instantiate_pattern_mvars(type_context & ctx, expr const & lhs) { expr elaborator::visit_equation(expr const & e, unsigned num_fns) { expr const & ref = e; - type_context::tmp_locals fns(m_ctx); + type_context_old::tmp_locals fns(m_ctx); expr it = e; for (unsigned i = 0; i < num_fns; i++) { if (!is_lambda(it)) @@ -2583,7 +2583,7 @@ expr elaborator::visit_equation(expr const & e, unsigned num_fns) { // sort using dependencies mvar_dep_sort(m_ctx, unassigned_mvars); // create local variables for each unassigned metavar - type_context::tmp_locals new_locals(m_ctx); + type_context_old::tmp_locals new_locals(m_ctx); for (expr & m : unassigned_mvars) { expr type = instantiate_mvars(m_ctx.infer(m)); expr new_local = new_locals.push_local(mlocal_pp_name(m), type, binder_info()); @@ -2705,7 +2705,7 @@ elaborator::field_resolution elaborator::field_to_decl(expr const & e, expr cons if (is_field_notation(e)) { auto lhs = macro_arg(e, 0); if (is_constant(lhs)) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr t = whnf(s_type); while (is_pi(t)) { t = whnf(instantiate(binding_body(t), locals.push_local_from_binding(t))); @@ -2809,7 +2809,7 @@ expr elaborator::visit_field(expr const & e, optional const & expected_typ class reduce_projections_visitor : public replace_visitor { private: - type_context & m_ctx; + type_context_old & m_ctx; protected: expr visit_app(expr const & e) override { expr e2 = replace_visitor::visit_app(e); @@ -2820,7 +2820,7 @@ protected: return e2; } public: - reduce_projections_visitor(type_context & ctx): m_ctx(ctx) {} + reduce_projections_visitor(type_context_old & ctx): m_ctx(ctx) {} }; /* Predicated variant of `lean::instantiate_mvars`. It does not support delayed abstractions or universe mvars. */ @@ -2846,7 +2846,7 @@ class visit_structure_instance_fn { elaborator & m_elab; // note: fields needed by trace macros environment & m_env = m_elab.m_env; - type_context & m_ctx = m_elab.m_ctx; + type_context_old & m_ctx = m_elab.m_ctx; // inputs expr m_e, m_ref = m_e; @@ -3362,7 +3362,7 @@ expr elaborator::visit_macro(expr const & e, optional const & expected_typ /* If the instance fingerprint has been set, then make sure `type` is not a local instance. Then, add a new local declaration to locals. */ -expr elaborator::push_local(type_context::tmp_locals & locals, +expr elaborator::push_local(type_context_old::tmp_locals & locals, name const & n, expr const & type, binder_info const & binfo, expr const & /* ref */) { #if 0 // TODO(Leo): the following check is too restrictive if (m_ctx.lctx().get_instance_fingerprint() && @@ -3374,7 +3374,7 @@ expr elaborator::push_local(type_context::tmp_locals & locals, } /* See method above */ -expr elaborator::push_let(type_context::tmp_locals & locals, +expr elaborator::push_let(type_context_old::tmp_locals & locals, name const & n, expr const & type, expr const & value, expr const & /* ref */) { #if 0 // TODO(Leo): the following check is too restrictive if (m_ctx.lctx().get_instance_fingerprint() && @@ -3386,7 +3386,7 @@ expr elaborator::push_let(type_context::tmp_locals & locals, } expr elaborator::visit_lambda(expr const & e, optional const & expected_type) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr it = e; expr ex; bool has_expected; @@ -3431,7 +3431,7 @@ expr elaborator::visit_lambda(expr const & e, optional const & expected_ty } expr elaborator::visit_pi(expr const & e) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr it = e; expr parent_it = e; while (is_pi(it)) { @@ -3465,7 +3465,7 @@ expr elaborator::visit_let(expr const & e, optional const & expected_type) new_type = instantiate_mvars(new_type); new_value = instantiate_mvars(new_value); ensure_no_unassigned_metavars(new_value); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr l = copy_tag(let_type(e), push_let(locals, let_name(e), new_type, new_value, ref)); save_identifier_info(l); expr body = instantiate_rev_locals(let_body(e), locals); @@ -3503,7 +3503,7 @@ expr elaborator::visit_have_expr(expr const & e, optional const & expected new_proof = enforce_type(new_proof, new_type, "invalid have-expression", proof); synthesize(); ensure_no_unassigned_metavars(new_proof); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr ref = binding_domain(lambda); push_local(locals, binding_name(lambda), new_type, binding_info(lambda), ref); expr body = instantiate_rev_locals(binding_body(lambda), locals); @@ -3524,7 +3524,7 @@ expr elaborator::visit_suffices_expr(expr const & e, optional const & expe expr new_type = visit(type, none_expr()); synthesize_no_tactics(); { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr ref = binding_domain(fn); push_local(locals, binding_name(fn), new_type, binding_info(fn), ref); expr body = instantiate_rev_locals(binding_body(fn), locals); @@ -3797,7 +3797,7 @@ void elaborator::synthesize() { void elaborator::report_error(tactic_state const & s, char const * state_header, char const * msg, expr const & ref) { - auto tc = std::make_shared(m_env, m_opts, m_ctx.mctx(), m_ctx.lctx()); + auto tc = std::make_shared(m_env, m_opts, m_ctx.mctx(), m_ctx.lctx()); auto pip = get_pos_info_provider(); if (!pip) return; message_builder out(tc, m_env, get_global_ios(), pip->get_file_name(), @@ -3857,7 +3857,7 @@ void elaborator::snapshot::restore(elaborator & e) { This class also transforms remaining universe metavariables into parameters */ struct sanitize_param_names_fn : public replace_visitor { - type_context & m_ctx; + type_context_old & m_ctx; name m_p{"u"}; name_set m_L; /* All parameter names in the input expression. */ unsigned m_idx{1}; @@ -3867,10 +3867,10 @@ struct sanitize_param_names_fn : public replace_visitor { theorem type. */ bool m_fixed; - sanitize_param_names_fn(type_context & ctx, buffer & new_lp_names): + sanitize_param_names_fn(type_context_old & ctx, buffer & new_lp_names): m_ctx(ctx), m_new_param_names(new_lp_names), m_fixed(false) {} - sanitize_param_names_fn(type_context & ctx, elaborator::theorem_finalization_info const & info, + sanitize_param_names_fn(type_context_old & ctx, elaborator::theorem_finalization_info const & info, buffer & new_lp_names): m_ctx(ctx), m_L(info.m_L), m_new_param_names(new_lp_names), m_fixed(true) {} @@ -3932,7 +3932,7 @@ struct sanitize_param_names_fn : public replace_visitor { } }; -/** When the output of the elaborator may contain meta-variables, we convert the type_context level meta-variables +/** When the output of the elaborator may contain meta-variables, we convert the type_context_old level meta-variables into regular kernel meta-variables. */ static expr replace_with_simple_metavars(metavar_context mctx, name_map & cache, expr const & e) { if (!has_expr_metavar(e)) return e; @@ -4280,7 +4280,7 @@ static vm_obj tactic_save_type_info(vm_obj const &, vm_obj const & _e, vm_obj co auto pos = get_pos_info_provider()->get_pos_info(to_expr(ref)); if (!pos) return tactic::mk_success(s); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); try { expr type = ctx.infer(e); get_global_info_manager()->add_type_info(*pos, type); diff --git a/src/frontends/lean/elaborator.h b/src/frontends/lean/elaborator.h index f3daa45643..ca373ee711 100644 --- a/src/frontends/lean/elaborator.h +++ b/src/frontends/lean/elaborator.h @@ -41,7 +41,7 @@ private: options m_opts; context_cache m_cache; name m_decl_name; - type_context m_ctx; + type_context_old m_ctx; info_manager m_info; unsigned m_aux_meta_idx = 1; bool m_recover_from_errors; @@ -121,9 +121,9 @@ private: bool is_uvar_assigned(level const & l) const { return m_ctx.is_assigned(l); } bool is_mvar_assigned(expr const & e) const { return m_ctx.is_assigned(e); } - expr push_local(type_context::tmp_locals & locals, name const & n, expr const & type, + expr push_local(type_context_old::tmp_locals & locals, name const & n, expr const & type, binder_info const & binfo, expr const & ref); - expr push_let(type_context::tmp_locals & locals, + expr push_let(type_context_old::tmp_locals & locals, name const & n, expr const & type, expr const & value, expr const & ref); level mk_univ_metavar(); diff --git a/src/frontends/lean/inductive_cmds.cpp b/src/frontends/lean/inductive_cmds.cpp index b626cb7e43..94cad6d35f 100644 --- a/src/frontends/lean/inductive_cmds.cpp +++ b/src/frontends/lean/inductive_cmds.cpp @@ -91,7 +91,7 @@ class inductive_cmd_fn { environment m_env; cmd_meta m_meta_info; buffer m_mut_attrs; - type_context m_ctx; + type_context_old m_ctx; buffer m_lp_names; pos_info m_pos; name_map m_implicit_infer_map; @@ -303,7 +303,7 @@ class inductive_cmd_fn { /** \brief Return the universe level of the given type, if it is not a sort, then raise an exception. */ level get_datatype_result_level(expr d_type) { d_type = m_ctx.relaxed_whnf(d_type); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); while (is_pi(d_type)) { d_type = instantiate(binding_body(d_type), locals.push_local_from_binding(d_type)); d_type = m_ctx.relaxed_whnf(d_type); @@ -325,7 +325,7 @@ class inductive_cmd_fn { } } - void unify_nested_occurrences(type_context & ctx, expr const & ir_type, buffer const & inds, level const & resultant_level) { + void unify_nested_occurrences(type_context_old & ctx, expr const & ir_type, buffer const & inds, level const & resultant_level) { expr ty = ir_type; while (is_pi(ty)) { expr arg_ty = binding_domain(ty); @@ -402,7 +402,7 @@ class inductive_cmd_fn { /* Apply beta and zeta reduction */ expr normalize(expr const & e) { - type_context::transparency_scope scope(m_ctx, transparency_mode::None); + type_context_old::transparency_scope scope(m_ctx, transparency_mode::None); return ::lean::normalize(m_ctx, e); } diff --git a/src/frontends/lean/info_manager.cpp b/src/frontends/lean/info_manager.cpp index fa9f0501c2..0a58b9cad6 100644 --- a/src/frontends/lean/info_manager.cpp +++ b/src/frontends/lean/info_manager.cpp @@ -59,7 +59,7 @@ public: #ifdef LEAN_JSON void hole_info_data::report(io_state_stream const & ios, json & record) const { - type_context ctx = mk_type_context_for(m_state); + type_context_old ctx = mk_type_context_for(m_state); interactive_report_type(ios.get_environment(), ios.get_options(), ctx.infer(m_state.main()), record); } #endif @@ -172,7 +172,7 @@ void info_manager::add_vm_obj_format_info(pos_info pos, environment const & env, #ifdef LEAN_JSON void info_manager::get_info_record(environment const & env, options const & o, io_state const & ios, pos_info pos, json & record, std::function pred) const { - type_context tc(env, o); + type_context_old tc(env, o); io_state_stream out = regular(env, ios, tc).update_options(o); get_line_info_set(pos.first).for_each([&](unsigned c, list const & ds) { if (c == pos.second) { diff --git a/src/frontends/lean/interactive.cpp b/src/frontends/lean/interactive.cpp index 875e8623dc..62b8625c6b 100644 --- a/src/frontends/lean/interactive.cpp +++ b/src/frontends/lean/interactive.cpp @@ -30,7 +30,7 @@ namespace lean { LEAN_THREAD_VALUE(break_at_pos_exception::token_context, g_context, break_at_pos_exception::token_context::none); void interactive_report_type(environment const & env, options const & opts, expr const & e, json & j) { - type_context tc(env); + type_context_old tc(env); if (g_context == break_at_pos_exception::token_context::interactive_tactic) { vm_state vm(env, options()); tactic_state s = mk_tactic_state_for(env, opts, "_interactive_report_type", local_context(), mk_true()); @@ -221,7 +221,7 @@ optional find_hole(module_info const & m_mod_info, } bool execute_hole_command(tactic_state s, name const & cmd_decl_name, expr const & args, json & j) { - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); options opts = s.get_options(); opts = opts.update_if_undef(get_pp_use_holes_name(), true); s = set_options(s, opts); diff --git a/src/frontends/lean/json.cpp b/src/frontends/lean/json.cpp index 6157aa5c8d..bef415d082 100644 --- a/src/frontends/lean/json.cpp +++ b/src/frontends/lean/json.cpp @@ -56,7 +56,7 @@ void add_source_info(environment const & env, name const & d, json & record) { json serialize_decl(name const & short_name, name const & long_name, environment const & env, options const & o) { declaration const & d = env.get(long_name); - type_context tc(env); + type_context_old tc(env); auto fmter = mk_pretty_formatter_factory()(env, o, tc); expr type = d.get_type(); if (LEAN_COMPLETE_CONSUME_IMPLICIT) { diff --git a/src/frontends/lean/parser.cpp b/src/frontends/lean/parser.cpp index 8faab1fcba..67bfd56311 100644 --- a/src/frontends/lean/parser.cpp +++ b/src/frontends/lean/parser.cpp @@ -2327,10 +2327,10 @@ expr parser::parse_expr_with_env(local_environment const & lenv, unsigned rbp) { class lazy_type_context : public abstract_type_context { environment m_env; options m_opts; - std::unique_ptr m_ctx; - type_context & ctx() { + std::unique_ptr m_ctx; + type_context_old & ctx() { if (!m_ctx) - m_ctx.reset(new type_context(m_env, m_opts)); + m_ctx.reset(new type_context_old(m_env, m_opts)); return *m_ctx; } public: @@ -2609,12 +2609,12 @@ char const * parser::get_file_name() const { } message_builder parser::mk_message(pos_info const &p, message_severity severity) const { - std::shared_ptr tc = std::make_shared(env(), get_options()); + std::shared_ptr tc = std::make_shared(env(), get_options()); return message_builder(tc, env(), ios(), get_file_name(), p, severity); } message_builder parser::mk_message(pos_info const & start_pos, pos_info const & end_pos, message_severity severity) const { - std::shared_ptr tc = std::make_shared(env(), get_options()); + std::shared_ptr tc = std::make_shared(env(), get_options()); message_builder b(tc, env(), ios(), get_file_name(), start_pos, severity); b.set_end_pos(end_pos); return b; diff --git a/src/frontends/lean/print_cmd.cpp b/src/frontends/lean/print_cmd.cpp index 203032ddf5..ddabc4e21e 100644 --- a/src/frontends/lean/print_cmd.cpp +++ b/src/frontends/lean/print_cmd.cpp @@ -82,7 +82,7 @@ static void print_axioms(parser & p, message_builder & out) { if (p.curr_is_identifier()) { name c = p.check_constant_next("invalid '#print axioms', constant expected"); auto env = p.env(); - type_context tc(env, p.get_options()); + type_context_old tc(env, p.get_options()); auto new_out = io_state_stream(env, p.ios(), tc, out.get_text_stream().get_channel()); print_axioms_deps(env, new_out)(c); } else { @@ -184,7 +184,7 @@ static void print_patterns(parser & p, name const & n) { options opts = p.get_options(); opts = opts.update_if_undef(get_pp_metavar_args_name(), true); io_state new_ios(p.ios(), opts); - type_context tc(p.env(), opts); + type_context_old tc(p.env(), opts); io_state_stream out = regular(p.env(), new_ios, tc); out << "(multi-)patterns:\n"; if (!is_nil(hi.m_mvars)) { diff --git a/src/frontends/lean/structure_cmd.cpp b/src/frontends/lean/structure_cmd.cpp index ce42669cb3..4085c337b9 100644 --- a/src/frontends/lean/structure_cmd.cpp +++ b/src/frontends/lean/structure_cmd.cpp @@ -258,7 +258,7 @@ struct structure_cmd_fn { parser & m_p; cmd_meta m_meta_info; environment m_env; - type_context m_ctx; + type_context_old m_ctx; name m_namespace; name m_name; name m_given_name; diff --git a/src/library/abstract_context_cache.cpp b/src/library/abstract_context_cache.cpp index 9fb29e32e8..24ba38941a 100644 --- a/src/library/abstract_context_cache.cpp +++ b/src/library/abstract_context_cache.cpp @@ -72,7 +72,7 @@ context_cacheless::context_cacheless(abstract_context_cache const & c, bool): m_class_instance_max_depth(c.get_class_instance_max_depth()) { } -bool context_cacheless::is_transparent(type_context & ctx, transparency_mode m, declaration const & d) { +bool context_cacheless::is_transparent(type_context_old & ctx, transparency_mode m, declaration const & d) { if (m == transparency_mode::None) return false; name const & n = d.get_name(); @@ -92,7 +92,7 @@ bool context_cacheless::is_transparent(type_context & ctx, transparency_mode m, return false; } -optional context_cacheless::get_decl(type_context & ctx, transparency_mode m, name const & n) { +optional context_cacheless::get_decl(type_context_old & ctx, transparency_mode m, name const & n) { if (auto d = ctx.env().find(n)) { if (d->is_definition() && is_transparent(ctx, m, *d)) { return d; @@ -101,15 +101,15 @@ optional context_cacheless::get_decl(type_context & ctx, transparen return optional(); } -projection_info const * context_cacheless::get_proj_info(type_context & ctx, name const & n) { +projection_info const * context_cacheless::get_proj_info(type_context_old & ctx, name const & n) { return get_projection_info(ctx.env(), n); } -bool context_cacheless::get_aux_recursor(type_context & ctx, name const & n) { +bool context_cacheless::get_aux_recursor(type_context_old & ctx, name const & n) { return ::lean::is_aux_recursor(ctx.env(), n); } -void context_cacheless::get_unification_hints(type_context & ctx, name const & f1, name const & f2, buffer & hints) { +void context_cacheless::get_unification_hints(type_context_old & ctx, name const & f1, name const & f2, buffer & hints) { return ::lean::get_unification_hints(ctx.env(), f1, f2, hints); } diff --git a/src/library/abstract_context_cache.h b/src/library/abstract_context_cache.h index 1ad788c003..4bf1570991 100644 --- a/src/library/abstract_context_cache.h +++ b/src/library/abstract_context_cache.h @@ -18,7 +18,7 @@ namespace lean { #define LEAN_NUM_TRANSPARENCY_MODES 5 enum class transparency_mode { All = 0, Semireducible, Instances, Reducible, None }; -class type_context; +class type_context_old; /* Auxiliary information that is cached by the app_builder module in the context_cache. */ @@ -57,12 +57,12 @@ struct app_builder_info { without the overhead of many caches. We use contextual caches for the operations performed in the following modules: - type_context, app_builder, fun_info and congr_lemma. - In the type_context, we cache inferred types, whnf, type class instances, + type_context_old, app_builder, fun_info and congr_lemma. + In the type_context_old, we cache inferred types, whnf, type class instances, to cite a few. - This class has been added to address problems with the former `type_context_cache_manager`. - The `type_context_cache_manager` objects were stored in thread local objects. + This class has been added to address problems with the former `type_context_old_cache_manager`. + The `type_context_old_cache_manager` objects were stored in thread local objects. The correctness of this cache relied on the fact we used to never reuse fresh names in the whole system. This is not true in the new name_generator refactoring (for addressing issue #1601). The caches for the modules app_builder, congr_lemma and fun_info have the same problem. @@ -73,7 +73,7 @@ struct app_builder_info { Here is a scenario that demonstrates the problem. Suppose we are executing the tactic `t1 <|> t2`. - First, we execute `t1`, and in the process, the type_context + First, we execute `t1`, and in the process, the type_context_old cache is populated with new local constants created by `t1`. Then `t1` fails and we execute `t2`. When, we execute `t2` on the initial `tactic_state` object. Thus, @@ -84,8 +84,8 @@ struct app_builder_info { Here are possible implementations of this API: - An "imperative" implementation using hashtables, and it is useful for modules - that own a type_context object (e.g., elaborator). - This implementation is also useful for the new type_context API we are going to expose in the `io` monad. + that own a type_context_old object (e.g., elaborator). + This implementation is also useful for the new type_context_old API we are going to expose in the `io` monad. - In principle, a "functional" implementation using rb_map and rb_tree is possible. Then, this version could be stored in the tactic_state or local_context objects. @@ -96,11 +96,11 @@ struct app_builder_info { * The token can be viewed as a reference to the cache. * tactic_state stores this token. * Thread local storage stores the "imperative" implementation and a token of its owner. - * When we create a type_context for a tactic_state we check whether the thread local + * When we create a type_context_old for a tactic_state we check whether the thread local storage contains the cache for the given tactic_state. If yes, we use it, and obtain a new token for it since we will perform destructive updates. Otherwise, we create a new one. - * When we finish using the type_context, we update the tactic_state with the new fresh token, + * When we finish using the type_context_old, we update the tactic_state with the new fresh token, and put the updated cache back into the thread local storage. Remark: the thread local storage may store more than one cache. @@ -135,8 +135,8 @@ struct app_builder_info { This is fine because we only use the "liberal" mode when elaborating the header of a declaration. 2) frozen: after elaborating the header of a declaration, we freeze the local instances that can be used to - elaborate its body. The freeze step is also useful to speedup the type_context initialization - (see comment in the type_context class). So, we just check if the frozen local instances are the same + elaborate its body. The freeze step is also useful to speedup the type_context_old initialization + (see comment in the type_context_old class). So, we just check if the frozen local instances are the same before starting each step. This check is performed in the method `init_local_instances`. Here are some benefits of the new approach: @@ -146,9 +146,9 @@ struct app_builder_info { cache. - We don't need to check whether the cache is valid or not when we create a new - type_context. + type_context_old. - - It is more efficient when creating temporary type_context objects for performing + - It is more efficient when creating temporary type_context_old objects for performing a single operation. In this kind of scenario, we can use the dummy cache implementation that doesn't cache anything. @@ -179,12 +179,12 @@ public: /* Operations for accessing environment data more efficiently. The default implementation provided by this class does not have any optimization. */ - virtual optional get_decl(type_context &, transparency_mode, name const &) = 0; - virtual projection_info const * get_proj_info(type_context &, name const &) = 0; - virtual bool get_aux_recursor(type_context &, name const &) = 0; - virtual void get_unification_hints(type_context &, name const & f1, name const & f2, buffer & hints) = 0; + virtual optional get_decl(type_context_old &, transparency_mode, name const &) = 0; + virtual projection_info const * get_proj_info(type_context_old &, name const &) = 0; + virtual bool get_aux_recursor(type_context_old &, name const &) = 0; + virtual void get_unification_hints(type_context_old &, name const & f1, name const & f2, buffer & hints) = 0; - /* Cache support for type_context module */ + /* Cache support for type_context_old module */ virtual optional get_infer(expr const &) = 0; virtual void set_infer(expr const &, expr const &) = 0; @@ -213,54 +213,54 @@ public: /* Cache support for fun_info module */ - virtual optional get_fun_info(type_context &, expr const &) = 0; - virtual void set_fun_info(type_context &, expr const &, fun_info const &) = 0; + virtual optional get_fun_info(type_context_old &, expr const &) = 0; + virtual void set_fun_info(type_context_old &, expr const &, fun_info const &) = 0; - virtual optional get_fun_info_nargs(type_context &, expr const &, unsigned) = 0; - virtual void set_fun_info_nargs(type_context &, expr const &, unsigned, fun_info const &) = 0; + virtual optional get_fun_info_nargs(type_context_old &, expr const &, unsigned) = 0; + virtual void set_fun_info_nargs(type_context_old &, expr const &, unsigned, fun_info const &) = 0; - virtual optional get_specialization_prefix_size(type_context &, expr const &, unsigned) = 0; - virtual void set_specialization_prefix_size(type_context &, expr const &, unsigned, unsigned) = 0; + virtual optional get_specialization_prefix_size(type_context_old &, expr const &, unsigned) = 0; + virtual void set_specialization_prefix_size(type_context_old &, expr const &, unsigned, unsigned) = 0; - virtual optional get_subsingleton_info(type_context &, expr const &) = 0; - virtual void set_subsingleton_info(type_context &, expr const &, ss_param_infos const &) = 0; + virtual optional get_subsingleton_info(type_context_old &, expr const &) = 0; + virtual void set_subsingleton_info(type_context_old &, expr const &, ss_param_infos const &) = 0; - virtual optional get_subsingleton_info_nargs(type_context &, expr const &, unsigned) = 0; - virtual void set_subsingleton_info_nargs(type_context &, expr const &, unsigned, ss_param_infos const &) = 0; + virtual optional get_subsingleton_info_nargs(type_context_old &, expr const &, unsigned) = 0; + virtual void set_subsingleton_info_nargs(type_context_old &, expr const &, unsigned, ss_param_infos const &) = 0; - virtual optional get_specialized_subsingleton_info_nargs(type_context &, expr const &, unsigned) = 0; - virtual void set_specialization_subsingleton_info_nargs(type_context &, expr const &, unsigned, ss_param_infos const &) = 0; + virtual optional get_specialized_subsingleton_info_nargs(type_context_old &, expr const &, unsigned) = 0; + virtual void set_specialization_subsingleton_info_nargs(type_context_old &, expr const &, unsigned, ss_param_infos const &) = 0; /* Cache support for congr_lemma module */ - virtual optional get_simp_congr_lemma(type_context &, expr const &, unsigned) = 0; - virtual void set_simp_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) = 0; + virtual optional get_simp_congr_lemma(type_context_old &, expr const &, unsigned) = 0; + virtual void set_simp_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) = 0; - virtual optional get_specialized_simp_congr_lemma(type_context &, expr const &, unsigned) = 0; - virtual void set_specialized_simp_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) = 0; + virtual optional get_specialized_simp_congr_lemma(type_context_old &, expr const &, unsigned) = 0; + virtual void set_specialized_simp_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) = 0; - virtual optional get_congr_lemma(type_context &, expr const &, unsigned) = 0; - virtual void set_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) = 0; + virtual optional get_congr_lemma(type_context_old &, expr const &, unsigned) = 0; + virtual void set_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) = 0; - virtual optional get_specialized_congr_lemma(type_context &, expr const &, unsigned) = 0; - virtual void set_specialized_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) = 0; + virtual optional get_specialized_congr_lemma(type_context_old &, expr const &, unsigned) = 0; + virtual void set_specialized_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) = 0; - virtual optional get_hcongr_lemma(type_context &, expr const &, unsigned) = 0; - virtual void set_hcongr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) = 0; + virtual optional get_hcongr_lemma(type_context_old &, expr const &, unsigned) = 0; + virtual void set_hcongr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) = 0; /* Cache support for app_builder */ - virtual optional get_app_builder_info(type_context &, expr const &, unsigned) = 0; - virtual void set_app_builder_info(type_context &, expr const &, unsigned, app_builder_info const &) = 0; + virtual optional get_app_builder_info(type_context_old &, expr const &, unsigned) = 0; + virtual void set_app_builder_info(type_context_old &, expr const &, unsigned, app_builder_info const &) = 0; - virtual optional get_app_builder_info(type_context &, expr const &, list const &) = 0; - virtual void set_app_builder_info(type_context &, expr const &, list const &, app_builder_info const &) = 0; + virtual optional get_app_builder_info(type_context_old &, expr const &, list const &) = 0; + virtual void set_app_builder_info(type_context_old &, expr const &, list const &, app_builder_info const &) = 0; }; /* Dummy implementation of the abstract_context_cache interface that does not do cache anything but configuration options. */ class context_cacheless : public abstract_context_cache { protected: - bool is_transparent(type_context & ctx, transparency_mode m, declaration const & d); + bool is_transparent(type_context_old & ctx, transparency_mode m, declaration const & d); private: options m_options; bool m_unfold_lemmas; @@ -295,12 +295,12 @@ public: /* Operations for accessing environment data more efficiently. The default implementation provided by this class does not have any optimization. */ - virtual optional get_decl(type_context &, transparency_mode, name const &) override; - virtual projection_info const * get_proj_info(type_context &, name const &) override; - virtual bool get_aux_recursor(type_context &, name const &) override; - virtual void get_unification_hints(type_context &, name const & f1, name const & f2, buffer & hints) override; + virtual optional get_decl(type_context_old &, transparency_mode, name const &) override; + virtual projection_info const * get_proj_info(type_context_old &, name const &) override; + virtual bool get_aux_recursor(type_context_old &, name const &) override; + virtual void get_unification_hints(type_context_old &, name const & f1, name const & f2, buffer & hints) override; - /* Cache support for type_context module */ + /* Cache support for type_context_old module */ virtual optional get_infer(expr const &) override { return none_expr(); } virtual void set_infer(expr const &, expr const &) override {} @@ -324,48 +324,48 @@ public: /* Cache support for fun_info module */ - virtual optional get_fun_info(type_context &, expr const &) override { return optional(); } - virtual void set_fun_info(type_context &, expr const &, fun_info const &) override {} + virtual optional get_fun_info(type_context_old &, expr const &) override { return optional(); } + virtual void set_fun_info(type_context_old &, expr const &, fun_info const &) override {} - virtual optional get_fun_info_nargs(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_fun_info_nargs(type_context &, expr const &, unsigned, fun_info const &) override {} + virtual optional get_fun_info_nargs(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_fun_info_nargs(type_context_old &, expr const &, unsigned, fun_info const &) override {} - virtual optional get_specialization_prefix_size(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_specialization_prefix_size(type_context &, expr const &, unsigned, unsigned) override {} + virtual optional get_specialization_prefix_size(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_specialization_prefix_size(type_context_old &, expr const &, unsigned, unsigned) override {} - virtual optional get_subsingleton_info(type_context &, expr const &) override { return optional(); } - virtual void set_subsingleton_info(type_context &, expr const &, ss_param_infos const &) override {} + virtual optional get_subsingleton_info(type_context_old &, expr const &) override { return optional(); } + virtual void set_subsingleton_info(type_context_old &, expr const &, ss_param_infos const &) override {} - virtual optional get_subsingleton_info_nargs(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_subsingleton_info_nargs(type_context &, expr const &, unsigned, ss_param_infos const &) override {} + virtual optional get_subsingleton_info_nargs(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_subsingleton_info_nargs(type_context_old &, expr const &, unsigned, ss_param_infos const &) override {} - virtual optional get_specialized_subsingleton_info_nargs(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_specialization_subsingleton_info_nargs(type_context &, expr const &, unsigned, ss_param_infos const &) override {} + virtual optional get_specialized_subsingleton_info_nargs(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_specialization_subsingleton_info_nargs(type_context_old &, expr const &, unsigned, ss_param_infos const &) override {} /* Cache support for congr_lemma module */ - virtual optional get_simp_congr_lemma(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_simp_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override {} + virtual optional get_simp_congr_lemma(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_simp_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override {} - virtual optional get_specialized_simp_congr_lemma(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_specialized_simp_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override {} + virtual optional get_specialized_simp_congr_lemma(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_specialized_simp_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override {} - virtual optional get_congr_lemma(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override {} + virtual optional get_congr_lemma(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override {} - virtual optional get_specialized_congr_lemma(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_specialized_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override {} + virtual optional get_specialized_congr_lemma(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_specialized_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override {} - virtual optional get_hcongr_lemma(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_hcongr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override {} + virtual optional get_hcongr_lemma(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_hcongr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override {} /* Cache support for app_builder */ - virtual optional get_app_builder_info(type_context &, expr const &, unsigned) override { return optional(); } - virtual void set_app_builder_info(type_context &, expr const &, unsigned, app_builder_info const &) override {} + virtual optional get_app_builder_info(type_context_old &, expr const &, unsigned) override { return optional(); } + virtual void set_app_builder_info(type_context_old &, expr const &, unsigned, app_builder_info const &) override {} - virtual optional get_app_builder_info(type_context &, expr const &, list const &) override { return optional(); } - virtual void set_app_builder_info(type_context &, expr const &, list const &, app_builder_info const &) override {} + virtual optional get_app_builder_info(type_context_old &, expr const &, list const &) override { return optional(); } + virtual void set_app_builder_info(type_context_old &, expr const &, list const &, app_builder_info const &) override {} }; void initialize_abstract_context_cache(); diff --git a/src/library/ac_match.h b/src/library/ac_match.h index cbc9d414e6..76786a7bf9 100644 --- a/src/library/ac_match.h +++ b/src/library/ac_match.h @@ -12,8 +12,8 @@ Author: Leonardo de Moura The simplifier will be the main consumer of this module. The simplifier will use AC matching for any simp lemma marked with the [ac_match] attribute. -If AC matching fails, we use the matching procedure provided by type_context. -The AC matching procedure implemented here does not subsume the matching procedure at type_context, +If AC matching fails, we use the matching procedure provided by type_context_old. +The AC matching procedure implemented here does not subsume the matching procedure at type_context_old, which performs matching modulo CIC reduction rules and has support for higher-order patterns. By default, all simp lemmas derived from the local context will have the [ac_match] attribute. The simplifier will have an option for disabling all AC matching support. @@ -26,7 +26,7 @@ The AC matching procedure uses backtracking. The state is a tuple (Y, U, U_p, U_ - Y is a set of auxiliary temporary metavariables - U is a set of (unsolved) matching constraints: p =?= t, p may contain temporary metavariables, but t doesn't - U_p is a set of unsolved and postponed matching constraints. We use this set for storing matching constraints that should - be solved using using type_context full force is_def_eq procedure. + be solved using using type_context_old full force is_def_eq procedure. - U_u is a set of (unsolved) universe matching constraints: p =?= u, p may contain temporary universe metavariables, but u doesn't. - P (partial solutions) is a mapping from temporary metavariable to a triple (op, y, t) where op is an AC operator, y is in Y, and t is a term and the head of t is not op. @@ -36,15 +36,15 @@ The AC matching procedure uses backtracking. The state is a tuple (Y, U, U_p, U_ - S_u (universe solutions) is a mapping from temporary universe metavariable to an universe term u. u does not contain temporary metavariables. -We implement the mappings P and S using arrays. We use a similar approach in type_context. +We implement the mappings P and S using arrays. We use a similar approach in type_context_old. We implement U as a queue. The queue is an array and index qidx (queue head). This module ignores the fact that the universe operator `max` is associative and commutative. -Non trival universe constraints are just postponed like in the type_context class. +Non trival universe constraints are just postponed like in the type_context_old class. This module does not use AC matching for implicit arguments. Matching constraints for implicit arguments -are stored at U_p. When U is empty, we just use full force type_context is_def_eq to process the constraints -at U_p. Note that the type_context must have access to S and S_u. -We address this requirement by using the type_context m_eassignment and m_uassignment +are stored at U_p. When U is empty, we just use full force type_context_old is_def_eq to process the constraints +at U_p. Note that the type_context_old must have access to S and S_u. +We address this requirement by using the type_context_old m_eassignment and m_uassignment to implement S and S_u. Similarly, we use m_postponed to implement U_u. Here are the rules for processing U elements @@ -150,7 +150,7 @@ Remark: we use + and * to denote arbitrary AC operators ==> replace with p =?= s[x/t] -After we don't have more elements in U to process using the rules above, we process U_p and U_u constraints using type_context is_def_eq with full force. +After we don't have more elements in U to process using the rules above, we process U_p and U_u constraints using type_context_old is_def_eq with full force. Remark: in the rules above we do not have support for Pi and lambda-terms containing temporary metavariables. We will treat macros and (A -> B) as applications. Here (A -> B) denotes a non dependent Pi-term. diff --git a/src/library/app_builder.cpp b/src/library/app_builder.cpp index d41e045471..bc9f74d7c2 100644 --- a/src/library/app_builder.cpp +++ b/src/library/app_builder.cpp @@ -119,11 +119,11 @@ typedef cache_compatibility_helper app_builder_cache_helper; MK_THREAD_LOCAL_GET_DEF(app_builder_cache_helper, get_abch); /** Return an app_builder_cache for the transparency_mode in ctx, and compatible with the environment. */ -app_builder_cache & get_app_builder_cache_for(type_context const & ctx) { +app_builder_cache & get_app_builder_cache_for(type_context_old const & ctx) { return get_abch().get_cache_for(ctx); } -static level get_level_ap(type_context & ctx, expr const & A) { +static level get_level_ap(type_context_old & ctx, expr const & A) { try { return get_level(ctx, A); } catch (exception &) { @@ -147,7 +147,7 @@ static level get_level_ap(type_context & ctx, expr const & A) { rel.{1 2} nat (fun n : nat, vec real n) f g */ class app_builder { - type_context & m_ctx; + type_context_old & m_ctx; app_builder_cache & m_cache; typedef app_builder_cache::key key; typedef app_builder_cache::entry entry; @@ -307,7 +307,7 @@ class app_builder { } public: - app_builder(type_context & ctx):m_ctx(ctx), m_cache(get_app_builder_cache_for(ctx)) {} + app_builder(type_context_old & ctx):m_ctx(ctx), m_cache(get_app_builder_cache_for(ctx)) {} level get_level(expr const & A) { return get_level_ap(m_ctx, A); @@ -315,7 +315,7 @@ public: expr mk_app(name const & c, unsigned nargs, expr const * args) { lean_assert(std::all_of(args, args + nargs, [](expr const & arg) { return !has_idx_metavar(arg); })) - type_context::tmp_mode_scope scope(m_ctx); + type_context_old::tmp_mode_scope scope(m_ctx); optional e = get_entry(c, nargs); if (!e) { trace_failure(c, "failed to retrieve declaration"); @@ -358,7 +358,7 @@ public: } expr mk_app(name const & c, unsigned mask_sz, bool const * mask, expr const * args) { - type_context::tmp_mode_scope scope(m_ctx); + type_context_old::tmp_mode_scope scope(m_ctx); unsigned nargs = get_nargs(mask_sz, mask); optional e = get_entry(c, mask_sz, mask); if (!e) { @@ -683,7 +683,7 @@ public: lean_app_builder_trace(tout() << "failed to build lift_of_eq equality proof expected:\n" << H << "\n";); throw app_builder_exception(); } - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr x = locals.push_local(name("A"), A); // motive := fun x : A, a ~ x expr motive = locals.mk_lambda(mk_rel(R, a, x)); @@ -823,117 +823,117 @@ public: } }; -expr mk_app(type_context & ctx, name const & c, unsigned nargs, expr const * args, optional const & md) { +expr mk_app(type_context_old & ctx, name const & c, unsigned nargs, expr const * args, optional const & md) { if (md) { - type_context::transparency_scope _s1(ctx, *md); - type_context::zeta_scope _s2(ctx, true); + type_context_old::transparency_scope _s1(ctx, *md); + type_context_old::zeta_scope _s2(ctx, true); return app_builder(ctx).mk_app(c, nargs, args); } else if (!is_at_least_semireducible(ctx.mode())) { - type_context::transparency_scope _s1(ctx, transparency_mode::Semireducible); - type_context::zeta_scope _s2(ctx, true); + type_context_old::transparency_scope _s1(ctx, transparency_mode::Semireducible); + type_context_old::zeta_scope _s2(ctx, true); return app_builder(ctx).mk_app(c, nargs, args); } else { return app_builder(ctx).mk_app(c, nargs, args); } } -expr mk_app(type_context & ctx, name const & c, unsigned mask_sz, bool const * mask, expr const * args) { +expr mk_app(type_context_old & ctx, name const & c, unsigned mask_sz, bool const * mask, expr const * args) { return app_builder(ctx).mk_app(c, mask_sz, mask, args); } -expr mk_app(type_context & ctx, name const & c, unsigned total_nargs, unsigned expl_nargs, expr const * expl_args) { +expr mk_app(type_context_old & ctx, name const & c, unsigned total_nargs, unsigned expl_nargs, expr const * expl_args) { return app_builder(ctx).mk_app(c, total_nargs, expl_nargs, expl_args); } -expr mk_rel(type_context & ctx, name const & n, expr const & lhs, expr const & rhs) { +expr mk_rel(type_context_old & ctx, name const & n, expr const & lhs, expr const & rhs) { return app_builder(ctx).mk_rel(n, lhs, rhs); } -expr mk_eq(type_context & ctx, expr const & lhs, expr const & rhs) { +expr mk_eq(type_context_old & ctx, expr const & lhs, expr const & rhs) { return app_builder(ctx).mk_eq(lhs, rhs); } -expr mk_iff(type_context & ctx, expr const & lhs, expr const & rhs) { +expr mk_iff(type_context_old & ctx, expr const & lhs, expr const & rhs) { return app_builder(ctx).mk_iff(lhs, rhs); } -expr mk_heq(type_context & ctx, expr const & lhs, expr const & rhs) { +expr mk_heq(type_context_old & ctx, expr const & lhs, expr const & rhs) { return app_builder(ctx).mk_heq(lhs, rhs); } -expr mk_refl(type_context & ctx, name const & relname, expr const & a) { +expr mk_refl(type_context_old & ctx, name const & relname, expr const & a) { return app_builder(ctx).mk_refl(relname, a); } -expr mk_eq_refl(type_context & ctx, expr const & a) { +expr mk_eq_refl(type_context_old & ctx, expr const & a) { return app_builder(ctx).mk_eq_refl(a); } -expr mk_iff_refl(type_context & ctx, expr const & a) { +expr mk_iff_refl(type_context_old & ctx, expr const & a) { return app_builder(ctx).mk_iff_refl(a); } -expr mk_heq_refl(type_context & ctx, expr const & a) { +expr mk_heq_refl(type_context_old & ctx, expr const & a) { return app_builder(ctx).mk_heq_refl(a); } -expr mk_symm(type_context & ctx, name const & relname, expr const & H) { +expr mk_symm(type_context_old & ctx, name const & relname, expr const & H) { return app_builder(ctx).mk_symm(relname, H); } -expr mk_eq_symm(type_context & ctx, expr const & H) { +expr mk_eq_symm(type_context_old & ctx, expr const & H) { return app_builder(ctx).mk_eq_symm(H); } -expr mk_eq_symm(type_context & ctx, expr const & a, expr const & b, expr const & H) { +expr mk_eq_symm(type_context_old & ctx, expr const & a, expr const & b, expr const & H) { return app_builder(ctx).mk_eq_symm(a, b, H); } -expr mk_iff_symm(type_context & ctx, expr const & H) { +expr mk_iff_symm(type_context_old & ctx, expr const & H) { return app_builder(ctx).mk_iff_symm(H); } -expr mk_heq_symm(type_context & ctx, expr const & H) { +expr mk_heq_symm(type_context_old & ctx, expr const & H) { return app_builder(ctx).mk_heq_symm(H); } -expr mk_trans(type_context & ctx, name const & relname, expr const & H1, expr const & H2) { +expr mk_trans(type_context_old & ctx, name const & relname, expr const & H1, expr const & H2) { return app_builder(ctx).mk_trans(relname, H1, H2); } -expr mk_eq_trans(type_context & ctx, expr const & H1, expr const & H2) { +expr mk_eq_trans(type_context_old & ctx, expr const & H1, expr const & H2) { return app_builder(ctx).mk_eq_trans(H1, H2); } -expr mk_eq_trans(type_context & ctx, expr const & a, expr const & b, expr const & c, expr const & H1, expr const & H2) { +expr mk_eq_trans(type_context_old & ctx, expr const & a, expr const & b, expr const & c, expr const & H1, expr const & H2) { return app_builder(ctx).mk_eq_trans(a, b, c, H1, H2); } -expr mk_iff_trans(type_context & ctx, expr const & H1, expr const & H2) { +expr mk_iff_trans(type_context_old & ctx, expr const & H1, expr const & H2) { return app_builder(ctx).mk_iff_trans(H1, H2); } -expr mk_heq_trans(type_context & ctx, expr const & H1, expr const & H2) { +expr mk_heq_trans(type_context_old & ctx, expr const & H1, expr const & H2) { return app_builder(ctx).mk_heq_trans(H1, H2); } -expr mk_eq_rec(type_context & ctx, expr const & C, expr const & H1, expr const & H2) { +expr mk_eq_rec(type_context_old & ctx, expr const & C, expr const & H1, expr const & H2) { return app_builder(ctx).mk_eq_rec(C, H1, H2); } -expr mk_eq_drec(type_context & ctx, expr const & C, expr const & H1, expr const & H2) { +expr mk_eq_drec(type_context_old & ctx, expr const & C, expr const & H1, expr const & H2) { return app_builder(ctx).mk_eq_drec(C, H1, H2); } -expr mk_eq_of_heq(type_context & ctx, expr const & H) { +expr mk_eq_of_heq(type_context_old & ctx, expr const & H) { return app_builder(ctx).mk_eq_of_heq(H); } -expr mk_heq_of_eq(type_context & ctx, expr const & H) { +expr mk_heq_of_eq(type_context_old & ctx, expr const & H) { return app_builder(ctx).mk_heq_of_eq(H); } -expr mk_congr_arg(type_context & ctx, expr const & f, expr const & H, bool skip_arrow_test) { +expr mk_congr_arg(type_context_old & ctx, expr const & f, expr const & H, bool skip_arrow_test) { expr eq = ctx.relaxed_whnf(ctx.infer(H)); expr pi = ctx.relaxed_whnf(ctx.infer(f)); expr A, B, lhs, rhs; @@ -956,7 +956,7 @@ expr mk_congr_arg(type_context & ctx, expr const & f, expr const & H, bool skip_ return mk_app({mk_constant(get_congr_arg_name(), {lvl_1, lvl_2}), A, B, lhs, rhs, f, H}); } -expr mk_congr_fun(type_context & ctx, expr const & H, expr const & a) { +expr mk_congr_fun(type_context_old & ctx, expr const & H, expr const & a) { expr eq = ctx.relaxed_whnf(ctx.infer(H)); expr pi, lhs, rhs; if (!is_eq(eq, pi, lhs, rhs)) { @@ -975,7 +975,7 @@ expr mk_congr_fun(type_context & ctx, expr const & H, expr const & a) { return mk_app({mk_constant(get_congr_fun_name(), {lvl_1, lvl_2}), A, B, lhs, rhs, H, a}); } -expr mk_congr(type_context & ctx, expr const & H1, expr const & H2, bool skip_arrow_test) { +expr mk_congr(type_context_old & ctx, expr const & H1, expr const & H2, bool skip_arrow_test) { expr eq1 = ctx.relaxed_whnf(ctx.infer(H1)); expr eq2 = ctx.relaxed_whnf(ctx.infer(H2)); expr pi, lhs1, rhs1; @@ -1006,47 +1006,47 @@ expr mk_congr(type_context & ctx, expr const & H1, expr const & H2, bool skip_ar return mk_app({mk_constant(get_congr_name(), {lvl_1, lvl_2}), A, B, lhs1, rhs1, lhs2, rhs2, H1, H2}); } -expr mk_funext(type_context & ctx, expr const & lam_pf) { +expr mk_funext(type_context_old & ctx, expr const & lam_pf) { // TODO(dhs): efficient version return mk_app(ctx, get_funext_name(), lam_pf); } -expr lift_from_eq(type_context & ctx, name const & R, expr const & H) { +expr lift_from_eq(type_context_old & ctx, name const & R, expr const & H) { return app_builder(ctx).lift_from_eq(R, H); } -expr mk_iff_false_intro(type_context & ctx, expr const & H) { +expr mk_iff_false_intro(type_context_old & ctx, expr const & H) { // TODO(Leo): implement custom version if bottleneck. return mk_app(ctx, get_iff_false_intro_name(), {H}); } -expr mk_iff_true_intro(type_context & ctx, expr const & H) { +expr mk_iff_true_intro(type_context_old & ctx, expr const & H) { // TODO(Leo): implement custom version if bottleneck. return mk_app(ctx, get_iff_true_intro_name(), {H}); } -expr mk_eq_false_intro(type_context & ctx, expr const & H) { +expr mk_eq_false_intro(type_context_old & ctx, expr const & H) { return app_builder(ctx).mk_eq_false_intro(H); } -expr mk_eq_true_intro(type_context & ctx, expr const & H) { +expr mk_eq_true_intro(type_context_old & ctx, expr const & H) { return app_builder(ctx).mk_eq_true_intro(H); } -expr mk_not_of_eq_false(type_context & ctx, expr const & H) { +expr mk_not_of_eq_false(type_context_old & ctx, expr const & H) { return app_builder(ctx).mk_not_of_eq_false(H); } -expr mk_of_eq_true(type_context & ctx, expr const & H) { +expr mk_of_eq_true(type_context_old & ctx, expr const & H) { return app_builder(ctx).mk_of_eq_true(H); } -expr mk_neq_of_not_iff(type_context & ctx, expr const & H) { +expr mk_neq_of_not_iff(type_context_old & ctx, expr const & H) { // TODO(Leo): implement custom version if bottleneck. return mk_app(ctx, get_neq_of_not_iff_name(), {H}); } -expr mk_not_of_iff_false(type_context & ctx, expr const & H) { +expr mk_not_of_iff_false(type_context_old & ctx, expr const & H) { if (is_constant(get_app_fn(H), get_iff_false_intro_name())) { // not_of_iff_false (iff_false_intro H) == H return app_arg(H); @@ -1055,7 +1055,7 @@ expr mk_not_of_iff_false(type_context & ctx, expr const & H) { return mk_app(ctx, get_not_of_iff_false_name(), 2, {H}); } -expr mk_of_iff_true(type_context & ctx, expr const & H) { +expr mk_of_iff_true(type_context_old & ctx, expr const & H) { if (is_constant(get_app_fn(H), get_iff_true_intro_name())) { // of_iff_true (iff_true_intro H) == H return app_arg(H); @@ -1064,79 +1064,79 @@ expr mk_of_iff_true(type_context & ctx, expr const & H) { return mk_app(ctx, get_of_iff_true_name(), {H}); } -expr mk_false_of_true_iff_false(type_context & ctx, expr const & H) { +expr mk_false_of_true_iff_false(type_context_old & ctx, expr const & H) { // TODO(Leo): implement custom version if bottleneck. return mk_app(ctx, get_false_of_true_iff_false_name(), {H}); } -expr mk_false_of_true_eq_false(type_context & ctx, expr const & H) { +expr mk_false_of_true_eq_false(type_context_old & ctx, expr const & H) { // TODO(Leo): implement custom version if bottleneck. return mk_app(ctx, get_false_of_true_eq_false_name(), {H}); } -expr mk_not(type_context & ctx, expr const & H) { +expr mk_not(type_context_old & ctx, expr const & H) { // TODO(dhs): implement custom version if bottleneck. return mk_app(ctx, get_not_name(), {H}); } -expr mk_absurd(type_context & ctx, expr const & Hp, expr const & Hnp, expr const & b) { +expr mk_absurd(type_context_old & ctx, expr const & Hp, expr const & Hnp, expr const & b) { return mk_app(ctx, get_absurd_name(), {b, Hp, Hnp}); } -expr mk_partial_add(type_context & ctx, expr const & A) { +expr mk_partial_add(type_context_old & ctx, expr const & A) { return app_builder(ctx).mk_partial_add(A); } -expr mk_partial_mul(type_context & ctx, expr const & A) { +expr mk_partial_mul(type_context_old & ctx, expr const & A) { return app_builder(ctx).mk_partial_mul(A); } -expr mk_zero(type_context & ctx, expr const & A) { +expr mk_zero(type_context_old & ctx, expr const & A) { return app_builder(ctx).mk_zero(A); } -expr mk_one(type_context & ctx, expr const & A) { +expr mk_one(type_context_old & ctx, expr const & A) { return app_builder(ctx).mk_one(A); } -expr mk_partial_left_distrib(type_context & ctx, expr const & A) { +expr mk_partial_left_distrib(type_context_old & ctx, expr const & A) { return app_builder(ctx).mk_partial_left_distrib(A); } -expr mk_partial_right_distrib(type_context & ctx, expr const & A) { +expr mk_partial_right_distrib(type_context_old & ctx, expr const & A) { return app_builder(ctx).mk_partial_right_distrib(A); } -expr mk_ss_elim(type_context & ctx, expr const & A, expr const & ss_inst, expr const & old_e, expr const & new_e) { +expr mk_ss_elim(type_context_old & ctx, expr const & A, expr const & ss_inst, expr const & old_e, expr const & new_e) { return app_builder(ctx).mk_ss_elim(A, ss_inst, old_e, new_e); } -expr mk_false_rec(type_context & ctx, expr const & c, expr const & H) { +expr mk_false_rec(type_context_old & ctx, expr const & c, expr const & H) { return app_builder(ctx).mk_false_rec(c, H); } -expr mk_ite(type_context & ctx, expr const & c, expr const & t, expr const & e) { +expr mk_ite(type_context_old & ctx, expr const & c, expr const & t, expr const & e) { bool mask[5] = {true, false, false, true, true}; expr args[3] = {c, t, e}; return mk_app(ctx, get_ite_name(), 5, mask, args); } -expr mk_id(type_context & ctx, expr const & type, expr const & h) { +expr mk_id(type_context_old & ctx, expr const & type, expr const & h) { level lvl = get_level_ap(ctx, type); return mk_app(mk_constant(get_id_name(), {lvl}), type, h); } -expr mk_id(type_context & ctx, expr const & h) { +expr mk_id(type_context_old & ctx, expr const & h) { return mk_id(ctx, ctx.infer(h), h); } -expr mk_id_rhs(type_context & ctx, expr const & h) { +expr mk_id_rhs(type_context_old & ctx, expr const & h) { expr type = ctx.infer(h); level lvl = get_level_ap(ctx, type); return mk_app(mk_constant(get_id_rhs_name(), {lvl}), type, h); } -expr mk_id_delta(type_context & ctx, expr const & h) { +expr mk_id_delta(type_context_old & ctx, expr const & h) { expr type = ctx.infer(h); level lvl = get_level_ap(ctx, type); return mk_app(mk_constant(get_id_delta_name(), {lvl}), type, h); @@ -1170,7 +1170,7 @@ static bool is_eq_self_iff_true(expr const & h, expr & t) { } } -expr mk_eq_mpr(type_context & ctx, expr const & h1, expr const & h2) { +expr mk_eq_mpr(type_context_old & ctx, expr const & h1, expr const & h2) { /* eq.mpr (eq.trans H (propext (@eq_self_iff_true t))) h2 ==> @@ -1185,15 +1185,15 @@ expr mk_eq_mpr(type_context & ctx, expr const & h1, expr const & h2) { return mk_app(ctx, get_eq_mpr_name(), h1, h2); } -expr mk_iff_mpr(type_context & ctx, expr const & h1, expr const & h2) { +expr mk_iff_mpr(type_context_old & ctx, expr const & h1, expr const & h2) { return mk_app(ctx, get_iff_mpr_name(), h1, h2); } -expr mk_eq_mp(type_context & ctx, expr const & h1, expr const & h2) { +expr mk_eq_mp(type_context_old & ctx, expr const & h1, expr const & h2) { return mk_app(ctx, get_eq_mp_name(), h1, h2); } -expr mk_iff_mp(type_context & ctx, expr const & h1, expr const & h2) { +expr mk_iff_mp(type_context_old & ctx, expr const & h1, expr const & h2) { return mk_app(ctx, get_iff_mp_name(), h1, h2); } diff --git a/src/library/app_builder.h b/src/library/app_builder.h index 9bf4745820..b17e79022e 100644 --- a/src/library/app_builder.h +++ b/src/library/app_builder.h @@ -33,78 +33,78 @@ public: \remark if the transparency mode is not provided, then mk_app will use Semireducible if the ctx.mode() is Reducible or None. */ -expr mk_app(type_context & ctx, name const & c, unsigned nargs, expr const * args, +expr mk_app(type_context_old & ctx, name const & c, unsigned nargs, expr const * args, optional const & md = optional()); -inline expr mk_app(type_context & ctx, name const & c, std::initializer_list const & args, +inline expr mk_app(type_context_old & ctx, name const & c, std::initializer_list const & args, optional const & md = optional()) { return mk_app(ctx, c, args.size(), args.begin(), md); } -inline expr mk_app(type_context & ctx, name const & c, expr const & a1) { +inline expr mk_app(type_context_old & ctx, name const & c, expr const & a1) { return mk_app(ctx, c, {a1}); } -inline expr mk_app(type_context & ctx, name const & c, expr const & a1, expr const & a2) { +inline expr mk_app(type_context_old & ctx, name const & c, expr const & a1, expr const & a2) { return mk_app(ctx, c, {a1, a2}); } -inline expr mk_app(type_context & ctx, name const & c, expr const & a1, expr const & a2, expr const & a3) { +inline expr mk_app(type_context_old & ctx, name const & c, expr const & a1, expr const & a2, expr const & a3) { return mk_app(ctx, c, {a1, a2, a3}); } -inline expr mk_app(type_context & ctx, name const & c, expr const & a1, expr const & a2, expr const & a3, expr const & a4) { +inline expr mk_app(type_context_old & ctx, name const & c, expr const & a1, expr const & a2, expr const & a3, expr const & a4) { return mk_app(ctx, c, {a1, a2, a3, a4}); } -expr mk_app(type_context & ctx, name const & c, unsigned mask_sz, bool const * mask, expr const * args); +expr mk_app(type_context_old & ctx, name const & c, unsigned mask_sz, bool const * mask, expr const * args); /** \brief Shortcut for mk_app(c, total_nargs, mask, expl_nargs), where \c mask starts with total_nargs - expl_nargs false's followed by expl_nargs true's \pre total_nargs >= expl_nargs */ -expr mk_app(type_context & ctx, name const & c, unsigned total_nargs, unsigned expl_nargs, expr const * expl_args); +expr mk_app(type_context_old & ctx, name const & c, unsigned total_nargs, unsigned expl_nargs, expr const * expl_args); -inline expr mk_app(type_context & ctx, name const & c, unsigned total_nargs, std::initializer_list const & args) { +inline expr mk_app(type_context_old & ctx, name const & c, unsigned total_nargs, std::initializer_list const & args) { return mk_app(ctx, c, total_nargs, args.size(), args.begin()); } -inline expr mk_app(type_context & ctx, name const & c, unsigned total_nargs, expr const & a1) { +inline expr mk_app(type_context_old & ctx, name const & c, unsigned total_nargs, expr const & a1) { return mk_app(ctx, c, total_nargs, {a1}); } -inline expr mk_app(type_context & ctx, name const & c, unsigned total_nargs, expr const & a1, expr const & a2) { +inline expr mk_app(type_context_old & ctx, name const & c, unsigned total_nargs, expr const & a1, expr const & a2) { return mk_app(ctx, c, total_nargs, {a1, a2}); } -inline expr mk_app(type_context & ctx, name const & c, unsigned total_nargs, expr const & a1, expr const & a2, expr const & a3) { +inline expr mk_app(type_context_old & ctx, name const & c, unsigned total_nargs, expr const & a1, expr const & a2, expr const & a3) { return mk_app(ctx, c, total_nargs, {a1, a2, a3}); } /** \brief Similar to mk_app(n, lhs, rhs), but handles eq and iff more efficiently. */ -expr mk_rel(type_context & ctx, name const & n, expr const & lhs, expr const & rhs); -expr mk_eq(type_context & ctx, expr const & lhs, expr const & rhs); -expr mk_iff(type_context & ctx, expr const & lhs, expr const & rhs); -expr mk_heq(type_context & ctx, expr const & lhs, expr const & rhs); +expr mk_rel(type_context_old & ctx, name const & n, expr const & lhs, expr const & rhs); +expr mk_eq(type_context_old & ctx, expr const & lhs, expr const & rhs); +expr mk_iff(type_context_old & ctx, expr const & lhs, expr const & rhs); +expr mk_heq(type_context_old & ctx, expr const & lhs, expr const & rhs); /** \brief Similar a reflexivity proof for the given relation */ -expr mk_refl(type_context & ctx, name const & relname, expr const & a); -expr mk_eq_refl(type_context & ctx, expr const & a); -expr mk_iff_refl(type_context & ctx, expr const & a); -expr mk_heq_refl(type_context & ctx, expr const & a); +expr mk_refl(type_context_old & ctx, name const & relname, expr const & a); +expr mk_eq_refl(type_context_old & ctx, expr const & a); +expr mk_iff_refl(type_context_old & ctx, expr const & a); +expr mk_heq_refl(type_context_old & ctx, expr const & a); /** \brief Similar a symmetry proof for the given relation */ -expr mk_symm(type_context & ctx, name const & relname, expr const & H); -expr mk_eq_symm(type_context & ctx, expr const & H); -expr mk_eq_symm(type_context & ctx, expr const & a, expr const & b, expr const & H); -expr mk_iff_symm(type_context & ctx, expr const & H); -expr mk_heq_symm(type_context & ctx, expr const & H); +expr mk_symm(type_context_old & ctx, name const & relname, expr const & H); +expr mk_eq_symm(type_context_old & ctx, expr const & H); +expr mk_eq_symm(type_context_old & ctx, expr const & a, expr const & b, expr const & H); +expr mk_iff_symm(type_context_old & ctx, expr const & H); +expr mk_heq_symm(type_context_old & ctx, expr const & H); /** \brief Similar a transitivity proof for the given relation */ -expr mk_trans(type_context & ctx, name const & relname, expr const & H1, expr const & H2); -expr mk_eq_trans(type_context & ctx, expr const & H1, expr const & H2); -expr mk_eq_trans(type_context & ctx, expr const & a, expr const & b, expr const & c, expr const & H1, expr const & H2); -expr mk_iff_trans(type_context & ctx, expr const & H1, expr const & H2); -expr mk_heq_trans(type_context & ctx, expr const & H1, expr const & H2); +expr mk_trans(type_context_old & ctx, name const & relname, expr const & H1, expr const & H2); +expr mk_eq_trans(type_context_old & ctx, expr const & H1, expr const & H2); +expr mk_eq_trans(type_context_old & ctx, expr const & a, expr const & b, expr const & c, expr const & H1, expr const & H2); +expr mk_iff_trans(type_context_old & ctx, expr const & H1, expr const & H2); +expr mk_heq_trans(type_context_old & ctx, expr const & H1, expr const & H2); /** \brief Create a (non-dependent) eq.rec application. C is the motive. The expected types for C, H1 and H2 are @@ -113,7 +113,7 @@ expr mk_heq_trans(type_context & ctx, expr const & H1, expr const & H2); H2 : a = b The resultant application is @eq.rec A a C H1 b H2 */ -expr mk_eq_rec(type_context & ctx, expr const & C, expr const & H1, expr const & H2); +expr mk_eq_rec(type_context_old & ctx, expr const & C, expr const & H1, expr const & H2); /** \brief Create a (dependent) eq.drec application. C is the motive. The expected types for C, H1 and H2 are @@ -122,79 +122,79 @@ expr mk_eq_rec(type_context & ctx, expr const & C, expr const & H1, expr const & H2 : a = b The resultant application is @eq.drec A a C H1 b H2 */ -expr mk_eq_drec(type_context & ctx, expr const & C, expr const & H1, expr const & H2); +expr mk_eq_drec(type_context_old & ctx, expr const & C, expr const & H1, expr const & H2); -expr mk_eq_of_heq(type_context & ctx, expr const & H); -expr mk_heq_of_eq(type_context & ctx, expr const & H); +expr mk_eq_of_heq(type_context_old & ctx, expr const & H); +expr mk_heq_of_eq(type_context_old & ctx, expr const & H); -expr mk_congr_arg(type_context & ctx, expr const & f, expr const & H, bool skip_arrow_test = false); -expr mk_congr_fun(type_context & ctx, expr const & H, expr const & a); -expr mk_congr(type_context & ctx, expr const & H1, expr const & H2, bool skip_arrow_test = false); +expr mk_congr_arg(type_context_old & ctx, expr const & f, expr const & H, bool skip_arrow_test = false); +expr mk_congr_fun(type_context_old & ctx, expr const & H, expr const & a); +expr mk_congr(type_context_old & ctx, expr const & H1, expr const & H2, bool skip_arrow_test = false); -expr mk_funext(type_context & ctx, expr const & lam_pf); +expr mk_funext(type_context_old & ctx, expr const & lam_pf); /** \brief Given a reflexive relation R, and a proof H : a = b, build a proof for (R a b) */ -expr lift_from_eq(type_context & ctx, name const & R, expr const & H); +expr lift_from_eq(type_context_old & ctx, name const & R, expr const & H); /** \brief not p -> (p <-> false) */ -expr mk_iff_false_intro(type_context & ctx, expr const & H); +expr mk_iff_false_intro(type_context_old & ctx, expr const & H); /** \brief p -> (p <-> true) */ -expr mk_iff_true_intro(type_context & ctx, expr const & H); +expr mk_iff_true_intro(type_context_old & ctx, expr const & H); /** \brief (p <-> false) -> not p */ -expr mk_not_of_iff_false(type_context & ctx, expr const & H); +expr mk_not_of_iff_false(type_context_old & ctx, expr const & H); /** \brief (p <-> true) -> p */ -expr mk_of_iff_true(type_context & ctx, expr const & H); +expr mk_of_iff_true(type_context_old & ctx, expr const & H); /** \brief (true <-> false) -> false */ -expr mk_false_of_true_iff_false(type_context & ctx, expr const & H); +expr mk_false_of_true_iff_false(type_context_old & ctx, expr const & H); /** \brief (true = false) -> false */ -expr mk_false_of_true_eq_false(type_context & ctx, expr const & H); +expr mk_false_of_true_eq_false(type_context_old & ctx, expr const & H); /** \brief not p -> (p = false) */ -expr mk_eq_false_intro(type_context & ctx, expr const & H); +expr mk_eq_false_intro(type_context_old & ctx, expr const & H); /** \brief p -> (p = true) */ -expr mk_eq_true_intro(type_context & ctx, expr const & H); +expr mk_eq_true_intro(type_context_old & ctx, expr const & H); /** not(p <-> q) -> not(p = q) */ -expr mk_neq_of_not_iff(type_context & ctx, expr const & H); +expr mk_neq_of_not_iff(type_context_old & ctx, expr const & H); -expr mk_of_eq_true(type_context & ctx, expr const & H); -expr mk_not_of_eq_false(type_context & ctx, expr const & H); +expr mk_of_eq_true(type_context_old & ctx, expr const & H); +expr mk_not_of_eq_false(type_context_old & ctx, expr const & H); -expr mk_not(type_context & ctx, expr const & H); +expr mk_not(type_context_old & ctx, expr const & H); /** p -> not p -> b */ -expr mk_absurd(type_context & ctx, expr const & Hp, expr const & Hnp, expr const & b); +expr mk_absurd(type_context_old & ctx, expr const & Hp, expr const & Hnp, expr const & b); -expr mk_partial_add(type_context & ctx, expr const & A); -expr mk_partial_mul(type_context & ctx, expr const & A); -expr mk_zero(type_context & ctx, expr const & A); -expr mk_one(type_context & ctx, expr const & A); -expr mk_partial_left_distrib(type_context & ctx, expr const & A); -expr mk_partial_right_distrib(type_context & ctx, expr const & A); +expr mk_partial_add(type_context_old & ctx, expr const & A); +expr mk_partial_mul(type_context_old & ctx, expr const & A); +expr mk_zero(type_context_old & ctx, expr const & A); +expr mk_one(type_context_old & ctx, expr const & A); +expr mk_partial_left_distrib(type_context_old & ctx, expr const & A); +expr mk_partial_right_distrib(type_context_old & ctx, expr const & A); -expr mk_ss_elim(type_context & ctx, expr const & A, expr const & ss_inst, expr const & old_e, expr const & new_e); +expr mk_ss_elim(type_context_old & ctx, expr const & A, expr const & ss_inst, expr const & old_e, expr const & new_e); /** \brief False elimination */ -expr mk_false_rec(type_context & ctx, expr const & c, expr const & H); +expr mk_false_rec(type_context_old & ctx, expr const & c, expr const & H); /* (if c then t else e) */ -expr mk_ite(type_context & ctx, expr const & c, expr const & t, expr const & e); +expr mk_ite(type_context_old & ctx, expr const & c, expr const & t, expr const & e); /* (@id type h) */ -expr mk_id(type_context & ctx, expr const & type, expr const & h); +expr mk_id(type_context_old & ctx, expr const & type, expr const & h); /* (id h) */ -expr mk_id(type_context & ctx, expr const & h); +expr mk_id(type_context_old & ctx, expr const & h); /* (id_rhs h) */ -expr mk_id_rhs(type_context & ctx, expr const & h); +expr mk_id_rhs(type_context_old & ctx, expr const & h); /* (id_delta h) */ -expr mk_id_delta(type_context & ctx, expr const & h); +expr mk_id_delta(type_context_old & ctx, expr const & h); -expr mk_iff_mp(type_context & ctx, expr const & h1, expr const & h2); -expr mk_iff_mpr(type_context & ctx, expr const & h1, expr const & h2); -expr mk_eq_mp(type_context & ctx, expr const & h1, expr const & h2); -expr mk_eq_mpr(type_context & ctx, expr const & h1, expr const & h2); +expr mk_iff_mp(type_context_old & ctx, expr const & h1, expr const & h2); +expr mk_iff_mpr(type_context_old & ctx, expr const & h1, expr const & h2); +expr mk_eq_mp(type_context_old & ctx, expr const & h1, expr const & h2); +expr mk_eq_mpr(type_context_old & ctx, expr const & h1, expr const & h2); void initialize_app_builder(); void finalize_app_builder(); diff --git a/src/library/arith_instance.cpp b/src/library/arith_instance.cpp index ad13c90731..72910ab89c 100644 --- a/src/library/arith_instance.cpp +++ b/src/library/arith_instance.cpp @@ -17,10 +17,10 @@ arith_instance_info_ptr mk_arith_instance_info(expr const & type, level const & return std::make_shared(type, lvl); } -arith_instance::arith_instance(type_context & ctx, expr const & type, level const & level): +arith_instance::arith_instance(type_context_old & ctx, expr const & type, level const & level): m_ctx(&ctx), m_info(mk_arith_instance_info(type, level)) {} -arith_instance::arith_instance(type_context & ctx, expr const & type): +arith_instance::arith_instance(type_context_old & ctx, expr const & type): m_ctx(&ctx) { set_type(type); } diff --git a/src/library/arith_instance.h b/src/library/arith_instance.h index 1af2f2877e..79df151591 100644 --- a/src/library/arith_instance.h +++ b/src/library/arith_instance.h @@ -70,7 +70,7 @@ typedef std::shared_ptr arith_instance_info_ptr; arith_instance_info_ptr mk_arith_instance_info(expr const & type, level const & lvl); class arith_instance { - type_context * m_ctx; + type_context_old * m_ctx; arith_instance_info_ptr m_info; expr mk_structure(name const & s, optional & r); @@ -79,11 +79,11 @@ class arith_instance { expr mk_pos_num(mpz const & n); public: - arith_instance(type_context & ctx, arith_instance_info_ptr const & info):m_ctx(&ctx), m_info(info) {} - arith_instance(type_context & ctx, expr const & type, level const & level); - arith_instance(type_context & ctx, expr const & type); + arith_instance(type_context_old & ctx, arith_instance_info_ptr const & info):m_ctx(&ctx), m_info(info) {} + arith_instance(type_context_old & ctx, expr const & type, level const & level); + arith_instance(type_context_old & ctx, expr const & type); arith_instance(arith_instance_info_ptr const & info):m_ctx(nullptr), m_info(info) {} - arith_instance(type_context & ctx):m_ctx(&ctx) {} + arith_instance(type_context_old & ctx):m_ctx(&ctx) {} void set_info(arith_instance_info_ptr const & info) { m_info = info; } /* The following method creates a fresh `arith_instance_info` for the given type. diff --git a/src/library/aux_definition.cpp b/src/library/aux_definition.cpp index dca02c382b..360d1c7e5c 100644 --- a/src/library/aux_definition.cpp +++ b/src/library/aux_definition.cpp @@ -150,7 +150,7 @@ buffer const & closure_helper::get_norm_closure_params() const { } struct mk_aux_definition_fn : public closure_helper { - mk_aux_definition_fn(type_context & ctx):closure_helper(ctx) {} + mk_aux_definition_fn(type_context_old & ctx):closure_helper(ctx) {} pair operator()(name const & c, expr const & type, expr const & value, bool is_lemma, optional const & is_meta) { lean_assert(!is_lemma || is_meta); @@ -189,14 +189,14 @@ struct mk_aux_definition_fn : public closure_helper { pair mk_aux_definition(environment const & env, metavar_context const & mctx, local_context const & lctx, name const & c, expr const & type, expr const & value, optional const & is_meta) { - type_context ctx(env, options(), mctx, lctx, transparency_mode::All); + type_context_old ctx(env, options(), mctx, lctx, transparency_mode::All); bool is_lemma = false; return mk_aux_definition_fn(ctx)(c, type, value, is_lemma, is_meta); } pair mk_aux_definition(environment const & env, metavar_context const & mctx, local_context const & lctx, name const & c, expr const & value, optional const & is_meta) { - type_context ctx(env, options(), mctx, lctx, transparency_mode::All); + type_context_old ctx(env, options(), mctx, lctx, transparency_mode::All); expr type = ctx.infer(value); bool is_lemma = false; return mk_aux_definition_fn(ctx)(c, type, value, is_lemma, is_meta); @@ -204,7 +204,7 @@ pair mk_aux_definition(environment const & env, metavar_conte pair mk_aux_lemma(environment const & env, metavar_context const & mctx, local_context const & lctx, name const & c, expr const & type, expr const & value) { - type_context ctx(env, options(), mctx, lctx, transparency_mode::All); + type_context_old ctx(env, options(), mctx, lctx, transparency_mode::All); bool is_lemma = true; optional is_meta(false); return mk_aux_definition_fn(ctx)(c, type, value, is_lemma, is_meta); @@ -214,7 +214,7 @@ struct abstract_nested_proofs_fn : public replace_visitor_with_tc { name m_base_name; unsigned m_idx{1}; - abstract_nested_proofs_fn(type_context & ctx, name const & b): + abstract_nested_proofs_fn(type_context_old & ctx, name const & b): replace_visitor_with_tc(ctx), m_base_name(b, "_proof") { } @@ -284,7 +284,7 @@ struct abstract_nested_proofs_fn : public replace_visitor_with_tc { }; pair abstract_nested_proofs(environment const & env, metavar_context const & mctx, local_context const & lctx, name const & base_name, expr const & e) { - type_context ctx(env, options(), mctx, lctx, transparency_mode::Semireducible); + type_context_old ctx(env, options(), mctx, lctx, transparency_mode::Semireducible); return abstract_nested_proofs_fn(ctx, base_name)(e); } diff --git a/src/library/aux_definition.h b/src/library/aux_definition.h index ce177d8d5b..c3ab02c4c0 100644 --- a/src/library/aux_definition.h +++ b/src/library/aux_definition.h @@ -28,7 +28,7 @@ namespace lean { All new parameters are sorted based on dependencies. */ class closure_helper { - type_context & m_ctx; + type_context_old & m_ctx; name m_prefix; unsigned m_next_idx; name_set m_found_univ_params; @@ -43,12 +43,12 @@ class closure_helper { buffer m_norm_params; public: - closure_helper(type_context & ctx): + closure_helper(type_context_old & ctx): m_ctx(ctx), m_prefix("_aux_param"), m_next_idx(0) {} - type_context & ctx() { return m_ctx; } + type_context_old & ctx() { return m_ctx; } /* \pre finalize_collection has not been invoked */ level collect(level const & l); diff --git a/src/library/cache_helper.h b/src/library/cache_helper.h index 1da06fef63..b2a3eabbdf 100644 --- a/src/library/cache_helper.h +++ b/src/library/cache_helper.h @@ -23,7 +23,7 @@ public: return *m_cache_ptr[midx].get(); } - Cache & get_cache_for(type_context const & ctx) { + Cache & get_cache_for(type_context_old const & ctx) { return get_cache_for(ctx.env(), ctx.mode()); } diff --git a/src/library/check.cpp b/src/library/check.cpp index 4a97b7c34e..51af1bc022 100644 --- a/src/library/check.cpp +++ b/src/library/check.cpp @@ -11,7 +11,7 @@ Author: Leonardo de Moura namespace lean { struct check_fn { - type_context & m_ctx; + type_context_old & m_ctx; expr_struct_set m_visited; void visit_constant(expr const & e) { @@ -44,7 +44,7 @@ struct check_fn { } void visit_binding(expr const & e, bool is_pi) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr it = e; while (it.kind() == e.kind()) { expr d = instantiate_rev(binding_domain(it), locals.size(), locals.data()); @@ -78,7 +78,7 @@ struct check_fn { "(use 'set_option trace.check true' for additional details)"); } /* Improve performance if bottleneck */ - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr local = locals.push_local_from_let(e); visit(instantiate(let_body(e), local)); } @@ -130,11 +130,11 @@ struct check_fn { } public: - check_fn(type_context & ctx):m_ctx(ctx) {} + check_fn(type_context_old & ctx):m_ctx(ctx) {} void operator()(expr const & e) { return visit(e); } }; -void check(type_context & ctx, expr const & e) { +void check(type_context_old & ctx, expr const & e) { metavar_context mctx = ctx.mctx(); check_fn checker(ctx); checker(e); diff --git a/src/library/check.h b/src/library/check.h index f57194a601..e9e02f2f02 100644 --- a/src/library/check.h +++ b/src/library/check.h @@ -14,7 +14,7 @@ namespace lean { This procedure is use to check the proof-term produced by tactics such as rewrite. */ -void check(type_context & ctx, expr const & e); +void check(type_context_old & ctx, expr const & e); void initialize_check(); void finalize_check(); } diff --git a/src/library/class.cpp b/src/library/class.cpp index 574210f6cf..fb8e28ba1c 100644 --- a/src/library/class.cpp +++ b/src/library/class.cpp @@ -254,9 +254,9 @@ bool has_class_out_params(environment const & env, name const & c) { environment add_instance_core(environment const & env, name const & n, unsigned priority, bool persistent) { declaration d = env.get(n); expr type = d.get_type(); - type_context ctx(env, transparency_mode::All); + type_context_old ctx(env, transparency_mode::All); class_state S = class_ext::get_state(env); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); while (true) { type = ctx.whnf_head_pred(type, [&](expr const & e) { expr const & fn = get_app_fn(e); diff --git a/src/library/comp_val.cpp b/src/library/comp_val.cpp index e07fa0c5c4..765441bcae 100644 --- a/src/library/comp_val.cpp +++ b/src/library/comp_val.cpp @@ -311,7 +311,7 @@ optional mk_int_val_ne_proof(expr const & a, expr const & b) { } } -optional mk_val_ne_proof(type_context & ctx, expr const & a, expr const & b) { +optional mk_val_ne_proof(type_context_old & ctx, expr const & a, expr const & b) { expr type = ctx.infer(a); if (ctx.is_def_eq(type, mk_nat_type())) return mk_nat_val_ne_proof(a, b); diff --git a/src/library/comp_val.h b/src/library/comp_val.h index acb40d17ac..7b338231cb 100644 --- a/src/library/comp_val.h +++ b/src/library/comp_val.h @@ -51,7 +51,7 @@ optional mk_int_val_pos_proof(expr const & a); optional mk_int_val_ne_proof(expr const & a, expr const & b); /* Return a proof for a != b, a/b has type nat/int/char/string, and they are distinct values. */ -optional mk_val_ne_proof(type_context & ctx, expr const & a, expr const & b); +optional mk_val_ne_proof(type_context_old & ctx, expr const & a, expr const & b); void initialize_comp_val(); void finalize_comp_val(); diff --git a/src/library/compiler/comp_irrelevant.h b/src/library/compiler/comp_irrelevant.h index cbf4ba1e24..6ad90c1a34 100644 --- a/src/library/compiler/comp_irrelevant.h +++ b/src/library/compiler/comp_irrelevant.h @@ -8,7 +8,7 @@ Author: Leonardo de Moura #include "kernel/environment.h" namespace lean { -class type_context; +class type_context_old; class abstract_context_cache; /** \brief Mark sub-expressions of \c e that are computationally irrelevant. */ expr mark_comp_irrelevant_subterms(environment const & env, abstract_context_cache & cache, expr const & e); @@ -17,7 +17,7 @@ expr mark_comp_irrelevant(expr const & e); /** \brief Return true iff \c e is annotated with the comp-irrelevant annotation */ bool is_marked_as_comp_irrelevant(expr const & e); /** \brief Return true iff the type of \c e is a sort or a proposition */ -bool is_comp_irrelevant(type_context & ctx, expr const & e); +bool is_comp_irrelevant(type_context_old & ctx, expr const & e); void initialize_comp_irrelevant(); void finalize_comp_irrelevant(); } diff --git a/src/library/compiler/compiler_step_visitor.cpp b/src/library/compiler/compiler_step_visitor.cpp index a473515355..47deda4efd 100644 --- a/src/library/compiler/compiler_step_visitor.cpp +++ b/src/library/compiler/compiler_step_visitor.cpp @@ -28,7 +28,7 @@ compiler_step_visitor::~compiler_step_visitor() { } expr compiler_step_visitor::visit_lambda_let(expr const & e) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr t = e; while (true) { /* Types are ignored in compilation steps. So, we do not invoke visit for d. */ diff --git a/src/library/compiler/compiler_step_visitor.h b/src/library/compiler/compiler_step_visitor.h index 660fbb8205..d88130fefb 100644 --- a/src/library/compiler/compiler_step_visitor.h +++ b/src/library/compiler/compiler_step_visitor.h @@ -14,7 +14,7 @@ namespace lean { class compiler_step_visitor : public replace_visitor { protected: environment m_env; - type_context m_ctx; + type_context_old m_ctx; expr visit_lambda_let(expr const & e); protected: @@ -22,7 +22,7 @@ protected: virtual ~compiler_step_visitor(); environment const & env() const { return m_env; } - type_context & ctx() { return m_ctx; } + type_context_old & ctx() { return m_ctx; } virtual expr visit_macro(expr const & e) override; @@ -32,7 +32,7 @@ protected: } virtual expr visit_local(expr const & e) override { - /* We don't need to visit the type since we are using type_context. */ + /* We don't need to visit the type since we are using type_context_old. */ return e; } diff --git a/src/library/compiler/cse.cpp b/src/library/compiler/cse.cpp index e11707f6e6..23c6ea7725 100644 --- a/src/library/compiler/cse.cpp +++ b/src/library/compiler/cse.cpp @@ -159,10 +159,10 @@ class cse_fn : public compiler_step_visitor { unsigned & m_counter; expr_struct_set const & m_common_subexprs; expr_struct_map m_common_subexpr_to_local; - type_context::tmp_locals m_all_locals; /* new local declarations, it also include let-decls for common-subexprs */ + type_context_old::tmp_locals m_all_locals; /* new local declarations, it also include let-decls for common-subexprs */ local_context const & m_lctx; - cse_processor(unsigned & counter, type_context & ctx, expr_struct_set const & s): + cse_processor(unsigned & counter, type_context_old & ctx, expr_struct_set const & s): m_counter(counter), m_common_subexprs(s), m_all_locals(ctx), @@ -197,10 +197,10 @@ class cse_fn : public compiler_step_visitor { /* Similar to cse_processor, but has support for binding exprs (lambda and let) */ struct cse_processor_for_binding : public cse_processor { - type_context::tmp_locals const & m_locals; + type_context_old::tmp_locals const & m_locals; buffer m_new_locals; - cse_processor_for_binding(unsigned & counter, type_context & ctx, type_context::tmp_locals const & locals, expr_struct_set const & s): + cse_processor_for_binding(unsigned & counter, type_context_old & ctx, type_context_old::tmp_locals const & locals, expr_struct_set const & s): cse_processor(counter, ctx, s), m_locals(locals) { } @@ -228,7 +228,7 @@ class cse_fn : public compiler_step_visitor { }; expr visit_lambda_let(expr const & e) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr t = e; buffer let_values; while (true) { diff --git a/src/library/compiler/elim_recursors.cpp b/src/library/compiler/elim_recursors.cpp index 90813353f0..6f533fcf8f 100644 --- a/src/library/compiler/elim_recursors.cpp +++ b/src/library/compiler/elim_recursors.cpp @@ -81,7 +81,7 @@ protected: } } - expr consume_lambdas(type_context::tmp_locals & locals, expr e) { + expr consume_lambdas(type_context_old::tmp_locals & locals, expr e) { while (true) { expr new_e = ctx().whnf(e); if (is_lambda(new_e)) { @@ -118,7 +118,7 @@ protected: /* Create new locals for aux. The operating abstract_locals creates a lambda-abstraction around aux if it uses local constants. */ - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); buffer aux_decl_params; /* "fixed" parameters of the auxiliary recursive declaration. */ expr aux_body = aux; while (is_lambda(aux_body)) { @@ -175,7 +175,7 @@ protected: unsigned carity = get_constructor_arity(env(), cnames[i]); expr minor = aux_body_args[first_minor_idx + i]; // tout() << ">> minor: " << minor << "\n"; - type_context::tmp_locals minor_locals(m_ctx); + type_context_old::tmp_locals minor_locals(m_ctx); buffer minor_recs; /* "recursive calls" */ lean_assert(carity >= nparams); buffer rec_mask; @@ -186,7 +186,7 @@ protected: expr minor_local = minor_locals.push_local_from_binding(minor); minor = instantiate(binding_body(minor), minor_local); /* Check if minor_local is recursive data */ - type_context::tmp_locals aux_locals(m_ctx); + type_context_old::tmp_locals aux_locals(m_ctx); expr minor_local_type = ctx().whnf(ctx().infer(minor_local)); // tout() << ">>> minor_local_type: " << minor_local_type << "\n"; while (is_pi(minor_local_type)) { diff --git a/src/library/compiler/elim_unused_lets.cpp b/src/library/compiler/elim_unused_lets.cpp index 49673e3787..19086342ad 100644 --- a/src/library/compiler/elim_unused_lets.cpp +++ b/src/library/compiler/elim_unused_lets.cpp @@ -12,7 +12,7 @@ Author: Leonardo de Moura namespace lean { class elim_unused_lets_fn : public compiler_step_visitor { virtual expr visit_lambda(expr const & e) override { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr t = e; while (is_lambda(t)) { expr d = instantiate_rev(binding_domain(t), locals.size(), locals.data()); @@ -25,7 +25,7 @@ class elim_unused_lets_fn : public compiler_step_visitor { } virtual expr visit_let(expr const & e) override { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); collected_locals used_locals; expr t = e; while (is_let(t)) { diff --git a/src/library/compiler/erase_irrelevant.cpp b/src/library/compiler/erase_irrelevant.cpp index 2cd7c87477..b7c808b6cc 100644 --- a/src/library/compiler/erase_irrelevant.cpp +++ b/src/library/compiler/erase_irrelevant.cpp @@ -159,7 +159,7 @@ class erase_irrelevant_fn : public compiler_step_visitor { unsigned carity = get_constructor_arity(env(), cnames[i]); lean_assert(carity >= nparams); unsigned data_sz = carity - nparams; - type_context::tmp_locals locals(ctx()); + type_context_old::tmp_locals locals(ctx()); expr new_minor = minors[i]; for (unsigned j = 0; j < data_sz; j++) { if (!is_lambda(new_minor)) @@ -242,7 +242,7 @@ class erase_irrelevant_fn : public compiler_step_visitor { return add_args(major, 6, args); } - expr consume_lambdas(type_context::tmp_locals & locals, expr e) { + expr consume_lambdas(type_context_old::tmp_locals & locals, expr e) { while (true) { if (is_lambda(e)) { expr local = locals.push_local_from_binding(e); @@ -272,7 +272,7 @@ class erase_irrelevant_fn : public compiler_step_visitor { return *g_unreachable_expr; lean_assert(args.size() >= basic_arity + 1); expr major = args[nparams + nindices + 4]; - type_context::tmp_locals locals(ctx()); + type_context_old::tmp_locals locals(ctx()); major = consume_lambdas(locals, major); major = visit(major); major = erase_lambda_let_types(locals.mk_lambda(major)); diff --git a/src/library/compiler/eta_expansion.cpp b/src/library/compiler/eta_expansion.cpp index 07a7db5c62..83f1882fe7 100644 --- a/src/library/compiler/eta_expansion.cpp +++ b/src/library/compiler/eta_expansion.cpp @@ -42,7 +42,7 @@ class eta_expand_fn : public compiler_step_visitor { expr type = ctx().relaxed_whnf(ctx().infer(e)); if (!is_pi(type)) return false; - type_context::tmp_locals locals(ctx()); + type_context_old::tmp_locals locals(ctx()); while (is_pi(type)) { expr local = locals.push_local_from_binding(type); type = ctx().relaxed_whnf(instantiate(binding_body(type), local)); diff --git a/src/library/compiler/inliner.cpp b/src/library/compiler/inliner.cpp index b9936bb3ad..a063d7c180 100644 --- a/src/library/compiler/inliner.cpp +++ b/src/library/compiler/inliner.cpp @@ -125,7 +125,7 @@ class inline_simple_definitions_fn : public compiler_step_visitor { optional reduce_projection(expr const & e) { /* When trying to reduce a projection, we should only unfold reducible constants. */ - type_context::transparency_scope _(ctx(), transparency_mode::Instances); + type_context_old::transparency_scope _(ctx(), transparency_mode::Instances); return ctx().reduce_projection(e); } diff --git a/src/library/compiler/lambda_lifting.cpp b/src/library/compiler/lambda_lifting.cpp index efe6f15ec8..2ec33b5e99 100644 --- a/src/library/compiler/lambda_lifting.cpp +++ b/src/library/compiler/lambda_lifting.cpp @@ -55,7 +55,7 @@ class lambda_lifting_fn : public compiler_step_visitor { } expr visit_lambda_core(expr const & e) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr t = e; while (is_lambda(t)) { lean_assert(is_neutral_expr(binding_domain(t)) || closed(binding_domain(t))); @@ -135,7 +135,7 @@ class lambda_lifting_fn : public compiler_step_visitor { } virtual expr visit_let(expr const & e) override { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr t = e; while (is_let(t)) { lean_assert(is_neutral_expr(let_type(t)) || closed(let_type(t))); @@ -149,7 +149,7 @@ class lambda_lifting_fn : public compiler_step_visitor { } expr visit_cases_on_minor(unsigned data_sz, expr e) { - type_context::tmp_locals locals(ctx()); + type_context_old::tmp_locals locals(ctx()); for (unsigned i = 0; i < data_sz; i++) { if (is_lambda(e)) { expr l = locals.push_local_from_binding(e); diff --git a/src/library/compiler/nat_value.cpp b/src/library/compiler/nat_value.cpp index 3c3dd4992d..17d3e7cb2f 100644 --- a/src/library/compiler/nat_value.cpp +++ b/src/library/compiler/nat_value.cpp @@ -81,7 +81,7 @@ mpz const & get_nat_value_value(expr const & e) { return static_cast(macro_def(e).raw())->get_value(); } -optional to_nat_value(type_context & ctx, expr const & e) { +optional to_nat_value(type_context_old & ctx, expr const & e) { if (optional v = to_num(e)) { expr type = ctx.whnf(ctx.infer(e)); if (is_nat_type(type)) { @@ -98,11 +98,11 @@ class find_nat_values_fn : public replace_visitor_with_tc { return replace_visitor_with_tc::visit_app(e); } public: - find_nat_values_fn(type_context & ctx):replace_visitor_with_tc(ctx) {} + find_nat_values_fn(type_context_old & ctx):replace_visitor_with_tc(ctx) {} }; expr find_nat_values(environment const & env, expr const & e) { - type_context ctx(env, transparency_mode::All); + type_context_old ctx(env, transparency_mode::All); return find_nat_values_fn(ctx)(e); } diff --git a/src/library/compiler/nat_value.h b/src/library/compiler/nat_value.h index c921b5d46c..1f7df82613 100644 --- a/src/library/compiler/nat_value.h +++ b/src/library/compiler/nat_value.h @@ -21,7 +21,7 @@ bool is_nat_value(expr const & e); mpz const & get_nat_value_value(expr const & e); /** \brief If \c e encodes a nat numeral, then convert it into a nat_value macro */ -optional to_nat_value(type_context & ctx, expr const & e); +optional to_nat_value(type_context_old & ctx, expr const & e); void initialize_nat_value(); void finalize_nat_value(); diff --git a/src/library/compiler/preprocess.cpp b/src/library/compiler/preprocess.cpp index 9402913a22..1749baa9f8 100644 --- a/src/library/compiler/preprocess.cpp +++ b/src/library/compiler/preprocess.cpp @@ -65,7 +65,7 @@ class expand_aux_fn : public compiler_step_visitor { expr visit_cases_on(expr const & e) { /* Try to reduce cases_on. Remark: we only unfold reducible constants. */ - type_context::transparency_scope scope(ctx(), transparency_mode::Reducible); + type_context_old::transparency_scope scope(ctx(), transparency_mode::Reducible); if (auto r1 = ctx().reduce_aux_recursor(e)) { if (auto r2 = ctx().norm_ext(*r1)) { return compiler_step_visitor::visit(*r2); @@ -113,7 +113,7 @@ class expand_aux_fn : public compiler_step_visitor { } virtual expr visit_constant(expr const & e) override { - type_context::nozeta_scope scope(ctx()); + type_context_old::nozeta_scope scope(ctx()); if (should_unfold(e)) return visit(unfold(e)); else @@ -121,14 +121,14 @@ class expand_aux_fn : public compiler_step_visitor { } virtual expr visit_app(expr const & e) override { - type_context::nozeta_scope scope(ctx()); + type_context_old::nozeta_scope scope(ctx()); switch (get_recursor_app_kind(e)) { case recursor_kind::NotRecursor: { if (should_unfold(e)) return visit(unfold(e)); expr new_e; { - type_context::transparency_scope scope(ctx(), transparency_mode::Reducible); + type_context_old::transparency_scope scope(ctx(), transparency_mode::Reducible); new_e = copy_tag(e, ctx().whnf_head_pred(e, [&](expr const &) { return false; })); } if (is_eqp(new_e, e)) @@ -141,7 +141,7 @@ class expand_aux_fn : public compiler_step_visitor { case recursor_kind::Aux: expr new_e; { - type_context::transparency_scope scope(ctx(), transparency_mode::Reducible); + type_context_old::transparency_scope scope(ctx(), transparency_mode::Reducible); new_e = copy_tag(e, ctx().whnf_head_pred(e, [&](expr const & e) { return is_aux_recursor(e); })); } return compiler_step_visitor::visit(new_e); @@ -210,9 +210,9 @@ class preprocess_fn { 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 & procs) { - type_context ctx(m_env, transparency_mode::All); + type_context_old ctx(m_env, transparency_mode::All); expr type = d.get_type(); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); while (true) { type = ctx.relaxed_whnf(type); if (!is_pi(type)) diff --git a/src/library/compiler/simp_inductive.cpp b/src/library/compiler/simp_inductive.cpp index c29b5e58eb..d5d90805f9 100644 --- a/src/library/compiler/simp_inductive.cpp +++ b/src/library/compiler/simp_inductive.cpp @@ -87,7 +87,7 @@ class simp_inductive_core_fn : public compiler_step_visitor { protected: /* Return new minor premise and a flag indicating whether the body is unreachable or not */ pair visit_minor_premise(expr e, buffer const & rel_fields) { - type_context::tmp_locals locals(ctx()); + type_context_old::tmp_locals locals(ctx()); for (unsigned i = 0; i < rel_fields.size(); i++) { lean_assert(is_lambda(e)); if (rel_fields[i]) { @@ -251,7 +251,7 @@ class simp_inductive_fn : public simp_inductive_core_fn { for (unsigned i = 0; i < cnames.size(); i++) { unsigned carity = get_constructor_arity(env(), cnames[i]); unsigned data_sz = carity - nparams; - type_context::tmp_locals locals(ctx()); + type_context_old::tmp_locals locals(ctx()); expr new_minor = args[i+1]; for (unsigned j = 0; j < data_sz; j++) { if (!is_lambda(new_minor)) diff --git a/src/library/compiler/util.cpp b/src/library/compiler/util.cpp index 60ab91b140..d99841a0b9 100644 --- a/src/library/compiler/util.cpp +++ b/src/library/compiler/util.cpp @@ -33,7 +33,7 @@ name mk_compiler_unused_name(environment const & env, name const & prefix, char } } -bool is_comp_irrelevant(type_context & ctx, expr const & e) { +bool is_comp_irrelevant(type_context_old & ctx, expr const & e) { expr type = ctx.whnf(ctx.infer(e)); return is_sort(type) || ctx.is_prop(type); } diff --git a/src/library/compiler/util.h b/src/library/compiler/util.h index e5e8573772..4d7c09a27d 100644 --- a/src/library/compiler/util.h +++ b/src/library/compiler/util.h @@ -7,13 +7,13 @@ Author: Leonardo de Moura #pragma once #include "kernel/environment.h" namespace lean { -class type_context; +class type_context_old; /** \brief Create a new name of the form prefix.suffix_idx that is not the name of a declaration and/or VM function. It also updates the index idx. */ name mk_compiler_unused_name(environment const & env, name const & prefix, char const * suffix, unsigned & idx); /** \brief Return true iff \c e is computationally irrelevant */ -bool is_comp_irrelevant(type_context & ctx, expr const & e); +bool is_comp_irrelevant(type_context_old & ctx, expr const & e); /** \brief Given an inductive datatype \c n, store in \c r a "bitvector" s.t. r[i][j] is true iff the j-th argument of the i-th minor premise of the recursor \c n.rec diff --git a/src/library/congr_lemma.cpp b/src/library/congr_lemma.cpp index e973693b2e..85a68ecc95 100644 --- a/src/library/congr_lemma.cpp +++ b/src/library/congr_lemma.cpp @@ -41,17 +41,17 @@ typedef cache_compatibility_helper congr_lemma_cache_helper; /* CACHE_RESET: YES */ MK_THREAD_LOCAL_GET_DEF(congr_lemma_cache_helper, get_clch); -congr_lemma_cache & get_congr_lemma_cache_for(type_context const & ctx) { +congr_lemma_cache & get_congr_lemma_cache_for(type_context_old const & ctx) { return get_clch().get_cache_for(ctx); } struct congr_lemma_manager { typedef expr_unsigned key; typedef congr_lemma result; - type_context & m_ctx; + type_context_old & m_ctx; congr_lemma_cache & m_cache; - congr_lemma_manager(type_context & ctx): + congr_lemma_manager(type_context_old & ctx): m_ctx(ctx), m_cache(get_congr_lemma_cache_for(ctx)) {} expr infer(expr const & e) { return m_ctx.infer(e); } @@ -179,7 +179,7 @@ struct congr_lemma_manager { how the resulting term looks like. */ optional mk_congr_simp(expr const & fn, buffer const & pinfos, buffer const & kinds) { try { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr fn_type = relaxed_whnf(infer(fn)); name e_name("e"); buffer lhss; @@ -253,7 +253,7 @@ struct congr_lemma_manager { optional mk_congr(expr const & fn, optional const & simp_lemma, buffer const & pinfos, buffer const & kinds) { try { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr fn_type1 = whnf(infer(fn)); expr fn_type2 = fn_type1; name e_name("e"); @@ -484,7 +484,7 @@ struct congr_lemma_manager { } else if (is_heq(type, A, a, B, b)) { return mk_heq_refl(m_ctx, a); } else { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); lean_assert(is_pi(type) && is_pi(binding_body(type)) && is_pi(binding_body(binding_body(type)))); expr a = locals.push_local_from_binding(type); type = instantiate(binding_body(type), a); @@ -506,7 +506,7 @@ struct congr_lemma_manager { optional mk_hcongr_core(expr const & fn, unsigned nargs) { try { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr fn_type_lhs = relaxed_whnf(infer(fn)); expr fn_type_rhs = fn_type_lhs; name e_name("e"); @@ -618,35 +618,35 @@ struct congr_lemma_manager { } }; -optional mk_congr_simp(type_context & ctx, expr const & fn) { +optional mk_congr_simp(type_context_old & ctx, expr const & fn) { return congr_lemma_manager(ctx).mk_congr_simp(fn); } -optional mk_congr_simp(type_context & ctx, expr const & fn, unsigned nargs) { +optional mk_congr_simp(type_context_old & ctx, expr const & fn, unsigned nargs) { return congr_lemma_manager(ctx).mk_congr_simp(fn, nargs); } -optional mk_specialized_congr_simp(type_context & ctx, expr const & a) { +optional mk_specialized_congr_simp(type_context_old & ctx, expr const & a) { return congr_lemma_manager(ctx).mk_specialized_congr_simp(a); } -optional mk_congr(type_context & ctx, expr const & fn) { +optional mk_congr(type_context_old & ctx, expr const & fn) { return congr_lemma_manager(ctx).mk_congr(fn); } -optional mk_congr(type_context & ctx, expr const & fn, unsigned nargs) { +optional mk_congr(type_context_old & ctx, expr const & fn, unsigned nargs) { return congr_lemma_manager(ctx).mk_congr(fn, nargs); } -optional mk_specialized_congr(type_context & ctx, expr const & a) { +optional mk_specialized_congr(type_context_old & ctx, expr const & a) { return congr_lemma_manager(ctx).mk_specialized_congr(a); } -optional mk_hcongr(type_context & ctx, expr const & fn) { +optional mk_hcongr(type_context_old & ctx, expr const & fn) { return congr_lemma_manager(ctx).mk_hcongr(fn); } -optional mk_hcongr(type_context & ctx, expr const & fn, unsigned nargs) { +optional mk_hcongr(type_context_old & ctx, expr const & fn, unsigned nargs) { return congr_lemma_manager(ctx).mk_hcongr(fn, nargs); } diff --git a/src/library/congr_lemma.h b/src/library/congr_lemma.h index 125b5e96aa..0ea50fad51 100644 --- a/src/library/congr_lemma.h +++ b/src/library/congr_lemma.h @@ -8,7 +8,7 @@ Author: Leonardo de Moura #include "kernel/expr.h" namespace lean { -class type_context; +class type_context_old; enum class congr_arg_kind { /* It is a parameter for the congruence lemma, the parameter occurs in the left and right hand sides. */ @@ -40,18 +40,18 @@ public: bool all_eq_kind() const; }; -optional mk_congr_simp(type_context & ctx, expr const & fn); -optional mk_congr_simp(type_context & ctx, expr const & fn, unsigned nargs); +optional mk_congr_simp(type_context_old & ctx, expr const & fn); +optional mk_congr_simp(type_context_old & ctx, expr const & fn, unsigned nargs); /* Create a specialized theorem using (a prefix of) the arguments of the given application. */ -optional mk_specialized_congr_simp(type_context & ctx, expr const & a); +optional mk_specialized_congr_simp(type_context_old & ctx, expr const & a); -optional mk_congr(type_context & ctx, expr const & fn); -optional mk_congr(type_context & ctx, expr const & fn, unsigned nargs); +optional mk_congr(type_context_old & ctx, expr const & fn); +optional mk_congr(type_context_old & ctx, expr const & fn, unsigned nargs); /* Create a specialized theorem using (a prefix of) the arguments of the given application. */ -optional mk_specialized_congr(type_context & ctx, expr const & a); +optional mk_specialized_congr(type_context_old & ctx, expr const & a); -optional mk_hcongr(type_context & ctx, expr const & fn); -optional mk_hcongr(type_context & ctx, expr const & fn, unsigned nargs); +optional mk_hcongr(type_context_old & ctx, expr const & fn); +optional mk_hcongr(type_context_old & ctx, expr const & fn, unsigned nargs); void initialize_congr_lemma(); void finalize_congr_lemma(); diff --git a/src/library/constructions/constructor.cpp b/src/library/constructions/constructor.cpp index 0ad1246ab9..e3c8b5ef4f 100644 --- a/src/library/constructions/constructor.cpp +++ b/src/library/constructions/constructor.cpp @@ -11,7 +11,7 @@ Author: Leonardo de Moura #include "library/inductive_compiler/ginductive.h" namespace lean { -optional mk_constructor_eq_constructor_inconsistency_proof(type_context & ctx, expr const & e1, expr const & e2, expr const & h) { +optional mk_constructor_eq_constructor_inconsistency_proof(type_context_old & ctx, expr const & e1, expr const & e2, expr const & h) { environment const & env = ctx.env(); optional c1 = is_gintro_rule_app(env, e1); if (!c1) return none_expr(); @@ -28,8 +28,8 @@ optional mk_constructor_eq_constructor_inconsistency_proof(type_context & return some_expr(pr); } -optional mk_constructor_ne_constructor_proof(type_context & ctx, expr const & e1, expr const & e2) { - type_context::tmp_locals locals(ctx); +optional mk_constructor_ne_constructor_proof(type_context_old & ctx, expr const & e1, expr const & e2) { + type_context_old::tmp_locals locals(ctx); expr h = locals.push_local("_h", mk_eq(ctx, e1, e2)); if (optional pr = mk_constructor_eq_constructor_inconsistency_proof(ctx, e1, e2, h)) return some_expr(locals.mk_lambda(*pr)); @@ -37,7 +37,7 @@ optional mk_constructor_ne_constructor_proof(type_context & ctx, expr cons return none_expr(); } -optional mk_constructor_eq_constructor_implied_core(type_context & ctx, expr const & e1, expr const & e2, expr const & h, buffer & implied_pairs) { +optional mk_constructor_eq_constructor_implied_core(type_context_old & ctx, expr const & e1, expr const & e2, expr const & h, buffer & implied_pairs) { // TODO(Leo, Daniel): add support for generalized inductive datatypes // TODO(Leo): add a definition for this proof at inductive datatype declaration time? environment const & env = ctx.env(); @@ -88,7 +88,7 @@ optional mk_constructor_eq_constructor_implied_core(type_context & ctx, ex expr nct = ctx.relaxed_whnf(mk_app(ctx, nct_name, motive, e1, e2)); if (!is_pi(nct)) return none_expr(); expr it = binding_domain(nct); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); buffer eq_proofs; for (unsigned i = 0; i < num_new_eqs; i++) { /* Remark: some of the hypotheses are heterogeneous, we should convert them @@ -113,7 +113,7 @@ optional mk_constructor_eq_constructor_implied_core(type_context & ctx, ex return some_expr(mk_app(result_prefix, fun)); } -bool mk_constructor_eq_constructor_implied_eqs(type_context & ctx, expr const & e1, expr const & e2, expr const & h, buffer> & result) { +bool mk_constructor_eq_constructor_implied_eqs(type_context_old & ctx, expr const & e1, expr const & e2, expr const & h, buffer> & result) { buffer implied_pairs; optional conj_pr = mk_constructor_eq_constructor_implied_core(ctx, e1, e2, h, implied_pairs); if (!conj_pr) return false; diff --git a/src/library/constructions/constructor.h b/src/library/constructions/constructor.h index 28d89a8261..89ddc723ec 100644 --- a/src/library/constructions/constructor.h +++ b/src/library/constructions/constructor.h @@ -8,15 +8,15 @@ Author: Leonardo de Moura namespace lean { /* If e1 and e2 are constructor applications, the constructors are different, and (h : e1 = e2), then return a proof for false. */ -optional mk_constructor_eq_constructor_inconsistency_proof(type_context & ctx, expr const & e1, expr const & e2, expr const & h); +optional mk_constructor_eq_constructor_inconsistency_proof(type_context_old & ctx, expr const & e1, expr const & e2, expr const & h); /* If e1 and e2 are constructor applications, the constructors are different, then return a proof for not (e1 = e2). */ -optional mk_constructor_ne_constructor_proof(type_context & ctx, expr const & e1, expr const & e2); +optional mk_constructor_ne_constructor_proof(type_context_old & ctx, expr const & e1, expr const & e2); /* If e1 and e2 are constructor applications for the same constructor, and (h : e1 = e2), then return true, and store the triples (a_i, b_i, hab_i) at result, where (hab_i : a_i = b_i) and a_i (b_i) are constructor fields of e1 (e2). */ -bool mk_constructor_eq_constructor_implied_eqs(type_context & ctx, expr const & e1, expr const & e2, expr const & h, +bool mk_constructor_eq_constructor_implied_eqs(type_context_old & ctx, expr const & e1, expr const & e2, expr const & h, buffer> & result); } diff --git a/src/library/constructions/has_sizeof.cpp b/src/library/constructions/has_sizeof.cpp index 6b0966d8a7..71fa245da9 100644 --- a/src/library/constructions/has_sizeof.cpp +++ b/src/library/constructions/has_sizeof.cpp @@ -66,13 +66,13 @@ class mk_has_sizeof_fn { return mk_local(m_ngen.next(), n, ty, binder_info()); } - optional mk_has_sizeof(type_context & ctx, expr const & type) { + optional mk_has_sizeof(type_context_old & ctx, expr const & type) { level l = get_level(ctx, type); expr inst_type = mk_app(mk_constant(get_has_sizeof_name(), {l}), type); return ctx.mk_class_instance(inst_type); } - optional build_has_sizeof_argument_type(type_context & ctx, expr const & param) { + optional build_has_sizeof_argument_type(type_context_old & ctx, expr const & param) { expr ty = ctx.relaxed_whnf(ctx.infer(param)); buffer locals; while (is_pi(ty)) { @@ -87,7 +87,7 @@ class mk_has_sizeof_fn { mk_app(param, locals)))); } - optional is_recursive_arg(type_context & ctx, expr const & arg_ty, buffer & arg_args) { + optional is_recursive_arg(type_context_old & ctx, expr const & arg_ty, buffer & arg_args) { expr it = ctx.relaxed_whnf(arg_ty); while (is_pi(it)) { expr arg_arg = mk_local_for(it); @@ -102,7 +102,7 @@ class mk_has_sizeof_fn { } void define_instance() { - type_context ctx(m_env); + type_context_old ctx(m_env); auto odecls = inductive::is_inductive_decl(m_env, m_ind_name); if (!odecls) @@ -123,7 +123,7 @@ class mk_has_sizeof_fn { name has_sizeof_name = mk_has_sizeof_name(m_ind_name); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); buffer params; buffer param_insts; @@ -159,7 +159,7 @@ class mk_has_sizeof_fn { { // Create a new type context so that the [has_sizeof] instances are available for type class resolution local_context lctx = ctx.lctx(); - type_context ctx(m_env, options(), lctx); + type_context_old ctx(m_env, options(), lctx); expr motive; { @@ -268,9 +268,9 @@ class mk_has_sizeof_fn { m_env = add_protected(m_env, has_sizeof_name); { - /* Create new type_context with new environment */ + /* Create new type_context_old with new environment */ local_context lctx = ctx.lctx(); - type_context ctx(m_env, options(), lctx); + type_context_old ctx(m_env, options(), lctx); expr c_has_sizeof = mk_app(mk_app(mk_constant(has_sizeof_name, lvls), params), used_param_insts); // Defeq simp lemmas @@ -289,7 +289,7 @@ class mk_has_sizeof_fn { expr local = mk_local_for(ir_ty); locals.push_back(local); expr candidate = mk_app(ctx, get_sizeof_name(), local); - type_context stctx(m_env, options(), ctx.lctx(), transparency_mode::Semireducible); + type_context_old stctx(m_env, options(), ctx.lctx(), transparency_mode::Semireducible); if (!stctx.is_def_eq(candidate, mk_constant(get_nat_zero_name()))) rhs = mk_nat_add(rhs, candidate); ir_ty = ctx.relaxed_whnf(instantiate(binding_body(ir_ty), local)); diff --git a/src/library/constructions/injective.cpp b/src/library/constructions/injective.cpp index eacf4f6ed3..da2a2ac356 100644 --- a/src/library/constructions/injective.cpp +++ b/src/library/constructions/injective.cpp @@ -23,7 +23,7 @@ Author: Daniel Selsam, Leonardo de Moura namespace lean { -static void collect_args(type_context & tctx, expr const & type, unsigned num_params, +static void collect_args(type_context_old & tctx, expr const & type, unsigned num_params, buffer & params, buffer & args1, buffer & args2, buffer & new_args) { expr ty = tctx.relaxed_whnf(type); @@ -60,7 +60,7 @@ static void collect_args(type_context & tctx, expr const & type, unsigned num_pa expr mk_injective_type_core(environment const & env, name const & ir_name, expr const & ir_type, unsigned num_params, level_param_names const & lp_names, bool use_eq) { // The transparency needs to match the kernel since we need to be consistent with the no_confusion construction. - type_context ctx(env, transparency_mode::All); + type_context_old ctx(env, transparency_mode::All); buffer params, args1, args2, new_args; collect_args(ctx, ir_type, num_params, params, args1, args2, new_args); expr c_ir_params = mk_app(mk_constant(ir_name, param_names_to_levels(lp_names)), params); @@ -103,7 +103,7 @@ expr mk_injective_eq_type(environment const & env, name const & ir_name, expr co return mk_injective_type_core(env, ir_name, ir_type, num_params, lp_names, true); } -expr prove_by_assumption(type_context & tctx, expr const & ty, expr const & eq) { +expr prove_by_assumption(type_context_old & tctx, expr const & ty, expr const & eq) { if (is_eq(ty) && is_heq(tctx.infer(eq))) { return mk_eq_of_heq(tctx, eq); } else { @@ -111,7 +111,7 @@ expr prove_by_assumption(type_context & tctx, expr const & ty, expr const & eq) } } -expr prove_conjuncts_core(type_context & tctx, expr const & ty, buffer const & eqs, unsigned idx) { +expr prove_conjuncts_core(type_context_old & tctx, expr const & ty, buffer const & eqs, unsigned idx) { if (idx == eqs.size() - 1) { lean_assert(!is_and(ty)); return prove_by_assumption(tctx, ty, eqs[idx]); @@ -124,12 +124,12 @@ expr prove_conjuncts_core(type_context & tctx, expr const & ty, buffer con } } -expr prove_conjuncts(type_context & tctx, expr const & ty, buffer const & eqs) { +expr prove_conjuncts(type_context_old & tctx, expr const & ty, buffer const & eqs) { return prove_conjuncts_core(tctx, ty, eqs, 0); } expr prove_injective(environment const & env, expr const & inj_type, name const & ind_name) { - type_context tctx(env); + type_context_old tctx(env); expr ty = inj_type; buffer args; @@ -182,7 +182,7 @@ expr prove_injective(environment const & env, expr const & inj_type, name const } expr prove_injective_arrow(environment const & env, expr const & inj_arrow_type, name const & inj_name, level_param_names const & inj_lp_names) { - type_context tctx(env); + type_context_old tctx(env); expr ty = inj_arrow_type; buffer args; @@ -209,7 +209,7 @@ expr prove_injective_arrow(environment const & env, expr const & inj_arrow_type, environment mk_injective_arrow(environment const & env, name const & ir_name) { declaration d = env.get(mk_injective_name(ir_name)); - type_context tctx(env); + type_context_old tctx(env); name P_lp_name = mk_fresh_lp_name(d.get_univ_params()); expr P = tctx.push_local(name("P"), mk_sort(mk_param_univ(P_lp_name)), mk_strict_implicit_binder_info()); @@ -249,7 +249,7 @@ environment mk_injective_arrow(environment const & env, name const & ir_name) { expr prove_injective_eq(environment const & env, expr const & inj_eq_type, name const & inj_eq_name) { try { - type_context ctx(env, transparency_mode::Semireducible); + type_context_old ctx(env, transparency_mode::Semireducible); expr dummy_ref; tactic_state s = mk_tactic_state_for(env, options(), inj_eq_name, metavar_context(), local_context(), inj_eq_type); vm_obj r = tactic_evaluator(ctx, options(), dummy_ref)(mk_constant(get_tactic_mk_inj_eq_name()), s); diff --git a/src/library/context_cache.cpp b/src/library/context_cache.cpp index 7fc89fcba9..5304e0da23 100644 --- a/src/library/context_cache.cpp +++ b/src/library/context_cache.cpp @@ -19,7 +19,7 @@ context_cache::context_cache(options const & o): context_cache::~context_cache() { } -optional context_cache::get_decl(type_context & ctx, transparency_mode m, name const & n) { +optional context_cache::get_decl(type_context_old & ctx, transparency_mode m, name const & n) { auto & cache = m_transparency_cache[static_cast(m)]; auto it = cache.find(n); if (it != cache.end()) { @@ -30,12 +30,12 @@ optional context_cache::get_decl(type_context & ctx, transparency_m return r; } -projection_info const * context_cache::get_proj_info(type_context & ctx, name const & n) { +projection_info const * context_cache::get_proj_info(type_context_old & ctx, name const & n) { // TODO(Leo): check if we really need a cache for get_proj_info return context_cacheless::get_proj_info(ctx, n); } -bool context_cache::get_aux_recursor(type_context & ctx, name const & n) { +bool context_cache::get_aux_recursor(type_context_old & ctx, name const & n) { auto it = m_aux_recursor_cache.find(n); if (it != m_aux_recursor_cache.end()) return it->second; @@ -44,7 +44,7 @@ bool context_cache::get_aux_recursor(type_context & ctx, name const & n) { return r; } -void context_cache::get_unification_hints(type_context & ctx, name const & f1, name const & f2, buffer & hints) { +void context_cache::get_unification_hints(type_context_old & ctx, name const & f1, name const & f2, buffer & hints) { if (!m_uhints) m_uhints = ::lean::get_unification_hints(ctx.env()); ::lean::get_unification_hints(*m_uhints, f1, f2, hints); diff --git a/src/library/context_cache.h b/src/library/context_cache.h index 2369ef59d0..0856eaa162 100644 --- a/src/library/context_cache.h +++ b/src/library/context_cache.h @@ -27,7 +27,7 @@ class context_cache : public context_cacheless { cached value for (fun {A : Type} (a : A), a) when inferring the type of (fun (A : Type) (a : A), a). This is wasteful in modules such as the tactic framework. - So, when we create a type_context_cache object we can specify whether this extra + So, when we create a type_context_old_cache object we can specify whether this extra level of precision is required or not. */ typedef expr_cond_bi_struct_map infer_cache; typedef expr_struct_map whnf_cache; @@ -50,9 +50,9 @@ class context_cache : public context_cacheless { \remark In Semireducible, Instances and Reducible modes, projections and theorems are considered opaque independently of annotations. Actually, theorems will not be treated as opaque - IF option `type_context.unfold_lemmas` is set to true. + IF option `type_context_old.unfold_lemmas` is set to true. In All mode, projections are still considered opaque, - this is not a problem since type_context implements a custom reduction rule for projections. + this is not a problem since type_context_old implements a custom reduction rule for projections. The All mode is used for type inference where it is unacceptable to fail to infer a type. The Semireducible mode is used for scenarios where an `is_def_eq` is expected to succeed @@ -68,19 +68,19 @@ class context_cache : public context_cacheless { /* We use the following approach for caching type class instances. - Whenever a type_context object is initialized with a local_context lctx + Whenever a type_context_old object is initialized with a local_context lctx 1) If lctx has an instance_fingerprint, then we compare with the instance_fingerprint stored in this cache, if they are equal, we keep m_local_instances, m_instance_cache and m_subsingleton_cache. - New local instances added using methods type_context::push_local and type_context::push_let will + New local instances added using methods type_context_old::push_local and type_context_old::push_let will be ignored. 2) If lctx doesn't have one, we clear m_local_instances, m_instance_cache and m_subsingleton_cache. We also traverse lctx and collect the local instances. - The methods type_context::push_local and type_context::push_let will flush the cache + The methods type_context_old::push_local and type_context_old::push_let will flush the cache whenever new local instances are pushed into the local context. m_instance_cache and m_subsingleton_cache are flushed before the cache is returned to the @@ -99,12 +99,12 @@ public: context_cache & operator=(context_cache const &) = delete; context_cache & operator=(context_cache &&) = default; - virtual optional get_decl(type_context &, transparency_mode, name const &) override; - virtual projection_info const * get_proj_info(type_context &, name const &) override; - virtual bool get_aux_recursor(type_context &, name const &) override; - virtual void get_unification_hints(type_context &, name const & f1, name const & f2, buffer & hints) override; + virtual optional get_decl(type_context_old &, transparency_mode, name const &) override; + virtual projection_info const * get_proj_info(type_context_old &, name const &) override; + virtual bool get_aux_recursor(type_context_old &, name const &) override; + virtual void get_unification_hints(type_context_old &, name const & f1, name const & f2, buffer & hints) override; - /* Cache support for type_context module */ + /* Cache support for type_context_old module */ virtual optional get_infer(expr const &) override; virtual void set_infer(expr const &, expr const &) override; diff --git a/src/library/defeq_canonizer.cpp b/src/library/defeq_canonizer.cpp index 275d8b3bd2..240d5e43c6 100644 --- a/src/library/defeq_canonizer.cpp +++ b/src/library/defeq_canonizer.cpp @@ -12,7 +12,7 @@ Author: Leonardo de Moura #include "library/defeq_canonizer.h" namespace lean { -defeq_canonizer::defeq_canonizer(type_context & ctx, state & s): +defeq_canonizer::defeq_canonizer(type_context_old & ctx, state & s): m_ctx(ctx), m_state(s) { } @@ -22,7 +22,7 @@ optional defeq_canonizer::get_head_symbol(expr type) { if (is_constant(fn)) { return optional(const_name(fn)); } else if (is_pi(type)) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr l = locals.push_local_from_binding(type); return get_head_symbol(instantiate(binding_body(type), l)); } else { @@ -99,12 +99,12 @@ expr defeq_canonizer::canonize_core(expr const & e) { } } -static void trace(type_context & ctx, expr const & e, expr const & r) { +static void trace(type_context_old & ctx, expr const & e, expr const & r) { lean_trace("defeq_canonizer", scope_trace_env _(ctx.env(), ctx); tout() << "\n" << e << "\n==>\n" << r << "\n";); } expr defeq_canonizer::canonize(expr const & e, bool & updated) { - type_context::transparency_scope scope(m_ctx, transparency_mode::Instances); + type_context_old::transparency_scope scope(m_ctx, transparency_mode::Instances); m_updated = &updated; expr r = canonize_core(e); trace(m_ctx, e, r); @@ -112,7 +112,7 @@ expr defeq_canonizer::canonize(expr const & e, bool & updated) { } expr defeq_canonizer::canonize(expr const & e) { - type_context::transparency_scope scope(m_ctx, transparency_mode::Instances); + type_context_old::transparency_scope scope(m_ctx, transparency_mode::Instances); m_updated = nullptr; expr r = canonize_core(e); trace(m_ctx, e, r); diff --git a/src/library/defeq_canonizer.h b/src/library/defeq_canonizer.h index a04222d0b5..01374369ec 100644 --- a/src/library/defeq_canonizer.h +++ b/src/library/defeq_canonizer.h @@ -38,7 +38,7 @@ public: name_map> m_M; }; private: - type_context & m_ctx; + type_context_old & m_ctx; state & m_state; bool * m_updated{nullptr}; @@ -51,7 +51,7 @@ private: expr canonize_core(expr const & e); public: - defeq_canonizer(type_context & ctx, state & s); + defeq_canonizer(type_context_old & ctx, state & s); expr canonize(expr const & e, bool & updated); expr canonize(expr const & e); diff --git a/src/library/discr_tree.cpp b/src/library/discr_tree.cpp index 9fd8ea6159..aa38cdffb5 100644 --- a/src/library/discr_tree.cpp +++ b/src/library/discr_tree.cpp @@ -138,7 +138,7 @@ int discr_tree::node_cmp::operator()(node const & n1, node const & n2) const { } } -auto discr_tree::insert_erase_atom(type_context & ctx, node && n, edge const & e, buffer> & todo, +auto discr_tree::insert_erase_atom(type_context_old & ctx, node && n, edge const & e, buffer> & todo, expr const & v, buffer> & skip, bool ins) -> node { node new_n = ensure_unshared(n.steal()); if (auto child = new_n.m_ptr->m_children.find(e)) { @@ -154,14 +154,14 @@ auto discr_tree::insert_erase_atom(type_context & ctx, node && n, edge const & e } } -auto discr_tree::insert_erase_star(type_context & ctx, node && n, buffer> & todo, expr const & v, +auto discr_tree::insert_erase_star(type_context_old & ctx, node && n, buffer> & todo, expr const & v, buffer> & skip, bool ins) -> node { node new_n = ensure_unshared(n.steal()); new_n.m_ptr->m_star_child = insert_erase(ctx, new_n.m_ptr->m_star_child.steal(), false, todo, v, skip, ins); return new_n; } -auto discr_tree::insert_erase_app(type_context & ctx, +auto discr_tree::insert_erase_app(type_context_old & ctx, node && n, bool is_root, expr const & e, buffer> & todo, expr const & v, buffer> & skip, bool ins) -> node { lean_assert(is_app(e)); @@ -199,7 +199,7 @@ auto discr_tree::insert_erase_app(type_context & ctx, } } -auto discr_tree::insert_erase(type_context & ctx, +auto discr_tree::insert_erase(type_context_old & ctx, node && n, bool is_root, buffer> & todo, expr const & v, buffer> & skip, bool ins) -> node { if (todo.empty()) { @@ -241,7 +241,7 @@ auto discr_tree::insert_erase(type_context & ctx, lean_unreachable(); } -void discr_tree::insert_erase(type_context & ctx, expr const & k, expr const & v, bool ins) { +void discr_tree::insert_erase(type_context_old & ctx, expr const & k, expr const & v, bool ins) { // insert & erase operations. // The erase operation is not optimal because it does not eliminate dead branches from the tree. // If this becomes an issue, we can remove dead branches from time to time and/or reconstruct @@ -253,7 +253,7 @@ void discr_tree::insert_erase(type_context & ctx, expr const & k, expr const & v lean_trace("discr_tree", tout() << "\n"; trace();); } -bool discr_tree::find_atom(type_context & ctx, node const & n, edge const & e, list> todo, std::function const & fn) { // NOLINT +bool discr_tree::find_atom(type_context_old & ctx, node const & n, edge const & e, list> todo, std::function const & fn) { // NOLINT if (auto child = n.m_ptr->m_children.find(e)) { return find(ctx, *child, todo, fn); } else { @@ -261,7 +261,7 @@ bool discr_tree::find_atom(type_context & ctx, node const & n, edge const & e, l } } -bool discr_tree::find_star(type_context & ctx, node const & n, list> todo, std::function const & fn) { // NOLINT +bool discr_tree::find_star(type_context_old & ctx, node const & n, list> todo, std::function const & fn) { // NOLINT bool cont = true; n.m_ptr->m_skip.for_each([&](node const & skip_child) { if (cont && !find(ctx, skip_child, todo, fn)) @@ -277,7 +277,7 @@ bool discr_tree::find_star(type_context & ctx, node const & n, list> todo, std::function const & fn) { // NOLINT +bool discr_tree::find_app(type_context_old & ctx, node const & n, expr const & e, list> todo, std::function const & fn) { // NOLINT lean_assert(is_app(e)); buffer args; expr const & f = get_app_args(e, args); @@ -303,7 +303,7 @@ bool discr_tree::find_app(type_context & ctx, node const & n, expr const & e, li } } -bool discr_tree::find(type_context & ctx, node const & n, list> todo, std::function const & fn) { // NOLINT +bool discr_tree::find(type_context_old & ctx, node const & n, list> todo, std::function const & fn) { // NOLINT if (!todo) { bool cont = true; n.m_ptr->m_values.for_each([&](expr const & v) { @@ -338,12 +338,12 @@ bool discr_tree::find(type_context & ctx, node const & n, list> lean_unreachable(); } -void discr_tree::find(type_context & ctx, expr const & e, std::function const & fn) const { // NOLINT +void discr_tree::find(type_context_old & ctx, expr const & e, std::function const & fn) const { // NOLINT if (m_root) find(ctx, m_root, to_list(mk_pair(e, false)), fn); } -void discr_tree::collect(type_context & ctx, expr const & e, buffer & r) const { +void discr_tree::collect(type_context_old & ctx, expr const & e, buffer & r) const { find(ctx, e, [&](expr const & v) { r.push_back(v); return true; }); } diff --git a/src/library/discr_tree.h b/src/library/discr_tree.h index 771b92646d..cbb21b919b 100644 --- a/src/library/discr_tree.h +++ b/src/library/discr_tree.h @@ -47,28 +47,28 @@ private: }; static void swap(node & n1, node & n2); static node ensure_unshared(node && n); - static node insert_erase_atom(type_context & ctx, node && n, edge const & e, buffer> & todo, expr const & v, buffer> & skip, bool ins); - static node insert_erase_star(type_context & ctx, node && n, buffer> & todo, expr const & v, buffer> & skip, bool ins); - static node insert_erase_app(type_context & ctx, node && n, bool is_root, expr const & e, buffer> & todo, expr const & v, + static node insert_erase_atom(type_context_old & ctx, node && n, edge const & e, buffer> & todo, expr const & v, buffer> & skip, bool ins); + static node insert_erase_star(type_context_old & ctx, node && n, buffer> & todo, expr const & v, buffer> & skip, bool ins); + static node insert_erase_app(type_context_old & ctx, node && n, bool is_root, expr const & e, buffer> & todo, expr const & v, buffer> & skip, bool ins); - static node insert_erase(type_context & ctx, node && n, bool is_root, buffer> & todo, + static node insert_erase(type_context_old & ctx, node && n, bool is_root, buffer> & todo, expr const & v, buffer> & skip, bool ins); - void insert_erase(type_context & ctx, expr const & k, expr const & v, bool ins); + void insert_erase(type_context_old & ctx, expr const & k, expr const & v, bool ins); - static bool find_atom(type_context & ctx, node const & n, edge const & e, list> todo, std::function const & fn); // NOLINT - static bool find_star(type_context & ctx, node const & n, list> todo, std::function const & fn); // NOLINT - static bool find_app(type_context & ctx, node const & n, expr const & e, list> todo, std::function const & fn); // NOLINT - static bool find(type_context & ctx, node const & n, list> todo, std::function const & fn); // NOLINT + static bool find_atom(type_context_old & ctx, node const & n, edge const & e, list> todo, std::function const & fn); // NOLINT + static bool find_star(type_context_old & ctx, node const & n, list> todo, std::function const & fn); // NOLINT + static bool find_app(type_context_old & ctx, node const & n, expr const & e, list> todo, std::function const & fn); // NOLINT + static bool find(type_context_old & ctx, node const & n, list> todo, std::function const & fn); // NOLINT node m_root; public: - void insert(type_context & ctx, expr const & k, expr const & v) { insert_erase(ctx, k, v, true); } - void insert(type_context & ctx, expr const & k) { insert(ctx, k, k); } - void erase(type_context & ctx, expr const & k, expr const & v) { insert_erase(ctx, k, v, false); } - void erase(type_context & ctx, expr const & k) { erase(ctx, k, k); } + void insert(type_context_old & ctx, expr const & k, expr const & v) { insert_erase(ctx, k, v, true); } + void insert(type_context_old & ctx, expr const & k) { insert(ctx, k, k); } + void erase(type_context_old & ctx, expr const & k, expr const & v) { insert_erase(ctx, k, v, false); } + void erase(type_context_old & ctx, expr const & k) { erase(ctx, k, k); } - void find(type_context & ctx, expr const & e, std::function const & fn) const; // NOLINT - void collect(type_context & ctx, expr const & e, buffer & r) const; + void find(type_context_old & ctx, expr const & e, std::function const & fn) const; // NOLINT + void collect(type_context_old & ctx, expr const & e, buffer & r) const; void trace() const; }; diff --git a/src/library/equations_compiler/compiler.cpp b/src/library/equations_compiler/compiler.cpp index 771dc0fc51..b653d9e394 100644 --- a/src/library/equations_compiler/compiler.cpp +++ b/src/library/equations_compiler/compiler.cpp @@ -30,7 +30,7 @@ static bool has_nested_rec(expr const & eqns) { } static eqn_compiler_result compile_equations_core(environment & env, elaborator & elab, metavar_context & mctx, local_context const & lctx, expr const & eqns) { - type_context ctx(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); + type_context_old ctx(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); trace_compiler(tout() << "compiling\n" << eqns << "\n";); trace_compiler(tout() << "recursive: " << is_recursive_eqns(ctx, eqns) << "\n";); trace_compiler(tout() << "nested recursion: " << has_nested_rec(eqns) << "\n";); @@ -103,8 +103,8 @@ struct pull_nested_rec_fn : public replace_visitor { local_context & lctx() { return m_lctx_stack.back(); } - type_context mk_type_context(local_context const & lctx) { - return type_context(m_env, m_mctx, lctx, m_elab.get_cache(), transparency_mode::Semireducible); + type_context_old mk_type_context(local_context const & lctx) { + return type_context_old(m_env, m_mctx, lctx, m_elab.get_cache(), transparency_mode::Semireducible); } expr visit_lambda_pi_let(bool is_lam, expr const & e) { @@ -132,7 +132,7 @@ struct pull_nested_rec_fn : public replace_visitor { } t = instantiate_rev(t, locals.size(), locals.data()); t = visit(t); - type_context ctx = mk_type_context(lctx()); + type_context_old ctx = mk_type_context(lctx()); t = is_lam ? ctx.mk_lambda(locals, t) : ctx.mk_pi(locals, t); m_mctx = ctx.mctx(); m_lctx_stack.pop_back(); @@ -209,7 +209,7 @@ struct pull_nested_rec_fn : public replace_visitor { if the recursive call will be defined using well founded recursion. */ void collect_local_props(name_set & found, buffer & R) { - type_context ctx = mk_type_context(lctx()); + type_context_old ctx = mk_type_context(lctx()); lctx().for_each([&](local_decl const & d) { if (!base_lctx().find_local_decl(d.get_name()) && !found.contains(d.get_name()) && @@ -273,7 +273,7 @@ struct pull_nested_rec_fn : public replace_visitor { get_app_args(e, args); buffer local_deps; collect_locals(e, local_deps); - type_context ctx = mk_type_context(lctx()); + type_context_old ctx = mk_type_context(lctx()); expr val = ctx.mk_lambda(local_deps, e); expr val_type = ctx.infer(val); name fn_aux = name("_f").append_after(m_new_locals.size() + 1); @@ -299,7 +299,7 @@ struct pull_nested_rec_fn : public replace_visitor { lean_assert(m_lctx_stack.size() == 1); local_context new_lctx = m_lctx_stack[0]; auto r = compile_equations_core(m_env, m_elab, m_mctx, new_lctx, new_e); - type_context ctx = mk_type_context(new_lctx); + type_context_old ctx = mk_type_context(new_lctx); r.m_fns = map(r.m_fns, [&] (expr const & fn) { return replace_locals(fn, m_new_locals, m_new_values); }); m_mctx = ctx.mctx(); return r; @@ -345,7 +345,7 @@ static expr compile_equations_main(environment & env, elaborator & elab, expr compile_equations(environment & env, elaborator & elab, metavar_context & mctx, local_context const & lctx, expr const & eqns) { equations_header const & header = get_equations_header(eqns); - type_context ctx(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); + type_context_old ctx(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); if (!header.m_is_meta && !header.m_is_lemma && !header.m_is_noncomputable && @@ -354,7 +354,7 @@ expr compile_equations(environment & env, elaborator & elab, metavar_context & m /* We compile non-meta recursive definitions as meta definitions first. The motivations are: - Clear execution cost semantics for recursive functions. - - Auxiliary meta definition may assist recursive definition unfolding in the type_context object. + - Auxiliary meta definition may assist recursive definition unfolding in the type_context_old object. */ equations_header aux_header = header; aux_header.m_is_meta = true; diff --git a/src/library/equations_compiler/elim_match.cpp b/src/library/equations_compiler/elim_match.cpp index bf92832ecf..a090271ef2 100644 --- a/src/library/equations_compiler/elim_match.cpp +++ b/src/library/equations_compiler/elim_match.cpp @@ -191,15 +191,15 @@ struct elim_match_fn { return true; } - type_context mk_type_context(local_context const & lctx) { - return type_context(m_env, m_mctx, lctx, m_elab.get_cache(), transparency_mode::Semireducible); + type_context_old mk_type_context(local_context const & lctx) { + return type_context_old(m_env, m_mctx, lctx, m_elab.get_cache(), transparency_mode::Semireducible); } - type_context mk_type_context(expr const & mvar) { + type_context_old mk_type_context(expr const & mvar) { return mk_type_context(get_local_context(mvar)); } - type_context mk_type_context(problem const & P) { + type_context_old mk_type_context(problem const & P) { return mk_type_context(get_local_context(P)); } @@ -208,7 +208,7 @@ struct elim_match_fn { std::function mk_pp_ctx(local_context const & lctx) { options opts = get_options(); opts = opts.update(get_pp_beta_name(), false); - type_context ctx = mk_type_context(lctx); + type_context_old ctx = mk_type_context(lctx); return ::lean::mk_pp_ctx(ctx); } @@ -235,7 +235,7 @@ struct elim_match_fn { format pp_problem(problem const & P) { format r; auto pp = mk_pp_ctx(P); - type_context ctx = mk_type_context(P); + type_context_old ctx = mk_type_context(P); r += format("match") + space() + format(P.m_fn_name) + space() + format(":") + space() + pp(ctx.infer(P.m_goal)); format v; bool first = true; @@ -264,7 +264,7 @@ struct elim_match_fn { if (!is_constant(e)) return optional(); return is_constructor(const_name(e)); } - optional is_constructor_app(type_context & ctx, expr const & e) const { + optional is_constructor_app(type_context_old & ctx, expr const & e) const { if (auto ind_type = is_constructor(get_app_fn(e))) { // Check that e is not a partially applied constructor. auto e_type = whnf_ginductive(ctx, ctx.infer(e)); @@ -321,7 +321,7 @@ struct elim_match_fn { return result; } - bool is_value(type_context & ctx, expr const & e) { + bool is_value(type_context_old & ctx, expr const & e) { try { if (!m_use_ite) return false; if (is_nat_int_char_string_name_value(ctx, e)) return true; @@ -333,7 +333,7 @@ struct elim_match_fn { } } - bool is_finite_value(type_context & ctx, expr const & e) { + bool is_finite_value(type_context_old & ctx, expr const & e) { lean_assert(is_value(ctx, e)); return is_char_value(ctx, e); } @@ -355,7 +355,7 @@ struct elim_match_fn { unsigned get_inductive_num_params(expr const & I) const { return get_inductive_num_params(const_name(I)); } /* Normalize until head is constructor or value */ - expr whnf_pattern(type_context & ctx, expr const & e) { + expr whnf_pattern(type_context_old & ctx, expr const & e) { if (is_inaccessible(e)) { return e; } else if (is_value(ctx, e)) { @@ -374,14 +374,14 @@ struct elim_match_fn { } /* Normalize until head is constructor */ - expr whnf_constructor(type_context & ctx, expr const & e) { + expr whnf_constructor(type_context_old & ctx, expr const & e) { return ctx.whnf_head_pred(e, [&](expr const & e) { return !is_constructor_app(ctx, e); }); } /* Normalize until head is an inductive datatype */ - expr whnf_inductive(type_context & ctx, expr const & e) { + expr whnf_inductive(type_context_old & ctx, expr const & e) { return ctx.whnf_head_pred(e, [&](expr const & e) { return !is_inductive_app(e); }); @@ -391,7 +391,7 @@ struct elim_match_fn { expr it = eqn; it = binding_body(it); /* consume fn header */ if (is_no_equation(it)) return optional(); - type_context ctx = mk_type_context(lctx); + type_context_old ctx = mk_type_context(lctx); buffer locals; while (is_lambda(it)) { expr type = instantiate_rev(binding_domain(it), locals); @@ -443,7 +443,7 @@ struct elim_match_fn { unsigned get_eqns_arity(local_context const & lctx, expr const & eqns) { /* Naive way to retrieve the arity of the function being defined */ lean_assert(is_equations(eqns)); - type_context ctx = mk_type_context(lctx); + type_context_old ctx = mk_type_context(lctx); unpack_eqns ues(ctx, eqns); return ues.get_arity_of(0); } @@ -507,7 +507,7 @@ struct elim_match_fn { bool is_constructor_transition(problem const & P) { return all_equations(P, [&](equation const & eqn) { expr const & p = head(eqn.m_patterns); - type_context ctx = mk_type_context(eqn.m_lctx); + type_context_old ctx = mk_type_context(eqn.m_lctx); if (is_constructor_app(ctx, p)) return true; return is_value(ctx, p); @@ -541,7 +541,7 @@ struct elim_match_fn { if (is_local(p)) { has_variable = true; return true; } - type_context ctx = mk_type_context(eqn.m_lctx); + type_context_old ctx = mk_type_context(eqn.m_lctx); if (is_constructor_app(ctx, p)) { has_constructor = true; return true; } @@ -569,7 +569,7 @@ struct elim_match_fn { if (is_local(p)) { has_variable = true; return true; } else { - type_context ctx = mk_type_context(eqn.m_lctx); + type_context_old ctx = mk_type_context(eqn.m_lctx); if (is_value(ctx, p)) { has_value = true; if (is_finite_value(ctx, p)) @@ -584,7 +584,7 @@ struct elim_match_fn { return false; if (!has_variable && has_finite_value) return false; - type_context ctx = mk_type_context(P); + type_context_old ctx = mk_type_context(P); /* Check whether other variables on the variable stack depend on the head. */ expr const & v = head(P.m_var_stack); if (depends_on(ctx.infer(P.m_goal), v)) { @@ -692,7 +692,7 @@ struct elim_match_fn { buffer R; for (equation const & eqn : eqns) { lean_assert(eqn.m_patterns); - type_context ctx = mk_type_context(eqn.m_lctx); + type_context_old ctx = mk_type_context(eqn.m_lctx); /* Remark: reverted bcf44f7020, see issue #1739 */ /* expr pattern = whnf_constructor(ctx, head(eqn.m_patterns)); */ /* We use ctx.relaxed_whnf to make sure we expose the kernel constructor */ @@ -740,7 +740,7 @@ struct elim_match_fn { equation new_eqn = eqn; new_eqn.m_subst = apply(eqn.m_subst, new_subst); /* Update patterns */ - type_context ctx = mk_type_context(eqn.m_lctx); + type_context_old ctx = mk_type_context(eqn.m_lctx); for (unsigned i = nparams; i < pattern_args.size(); i++) pattern_args[i] = whnf_pattern(ctx, pattern_args[i]); new_eqn.m_patterns = to_list(pattern_args.begin() + nparams, pattern_args.end(), tail(eqn.m_patterns)); @@ -752,7 +752,7 @@ struct elim_match_fn { optional> process_constructor_core(problem const & P, bool fail_if_subgoals) { trace_match(tout() << "step: constructors only\n";); lean_assert(is_constructor_transition(P)); - type_context ctx = mk_type_context(P); + type_context_old ctx = mk_type_context(P); expr x = head(P.m_var_stack); /* Remark: reverted bcf44f7020, see issue #1739 */ /* expr x_type = whnf_inductive(ctx, ctx.infer(x)); */ @@ -823,7 +823,7 @@ struct elim_match_fn { bool is_last = !tail(P.m_var_stack); expr x = head(P.m_var_stack); local_context lctx = get_local_context(P.m_goal); - type_context ctx = mk_type_context(P); + type_context_old ctx = mk_type_context(P); expr goal_type = ctx.infer(P.m_goal); expr else_goal = ctx.mk_metavar_decl(lctx, goal_type); buffer values; @@ -868,7 +868,7 @@ struct elim_match_fn { if (is_last) break; } else if (is_local(p)) { /* Replace variable `p` with `val` in this equation */ - type_context ctx = mk_type_context(eqn.m_lctx); + type_context_old ctx = mk_type_context(eqn.m_lctx); buffer from; buffer to; buffer new_vars; @@ -918,7 +918,7 @@ struct elim_match_fn { equation new_eqn = eqn; new_eqn.m_patterns = tail(new_eqn.m_patterns); new_eqn.m_subst = add_subst(eqn.m_subst, p, x); - type_context ctx = mk_type_context(eqn.m_lctx); + type_context_old ctx = mk_type_context(eqn.m_lctx); new_eqn.m_hs = eqn.m_hs; unsigned idx = length(eqn.m_hs) + 1; for (unsigned i = 0; i < values.size(); i++) { @@ -949,7 +949,7 @@ struct elim_match_fn { for (equation const & eqn : P.m_equations) { expr const & pattern = head(eqn.m_patterns); if (is_local(pattern)) { - type_context ctx = mk_type_context(eqn.m_lctx); + type_context_old ctx = mk_type_context(eqn.m_lctx); for_each_compatible_constructor(ctx, pattern, [&](expr const & c, buffer const & new_c_vars) { expr var = pattern; @@ -983,7 +983,7 @@ struct elim_match_fn { if (!is_next_var(P)) { return process_variable(P); } else { - type_context ctx = mk_type_context(P); + type_context_old ctx = mk_type_context(P); expr x = head(P.m_var_stack); expr arg_type = ctx.infer(x); if (is_below_type(arg_type)) { @@ -1015,7 +1015,7 @@ struct elim_match_fn { list process_non_variable(problem const & P) { expr p = head(P.m_var_stack); lean_assert(!is_local(p)); - type_context ctx = mk_type_context(P); + type_context_old ctx = mk_type_context(P); if (all_inaccessible(P)) { trace_match(tout() << "step: skip inaccessible patterns\n";); problem new_P; @@ -1063,7 +1063,7 @@ struct elim_match_fn { /* Create (f ... x) with the given arity, where the other arguments are inferred using type inference */ - expr mk_app_with_arity(type_context & ctx, name const & f, unsigned arity, expr const & x) { + expr mk_app_with_arity(type_context_old & ctx, name const & f, unsigned arity, expr const & x) { buffer mask; mask.resize(arity - 1, false); mask.push_back(true); @@ -1138,7 +1138,7 @@ struct elim_match_fn { expr M_1 = revert(m_env, get_options(), m_mctx, P.m_goal, to_revert, preserve_to_revert_order); /* Step 2 */ - type_context ctx1 = mk_type_context(M_1); + type_context_old ctx1 = mk_type_context(M_1); expr M_1_type = ctx1.relaxed_whnf(ctx1.infer(M_1)); lean_assert(is_pi(M_1_type)); expr x1 = ctx1.push_local(binding_name(M_1_type), binding_domain(M_1_type)); @@ -1232,9 +1232,9 @@ struct elim_match_fn { t =?= s - Remark: we also use `id_rhs` to implement "smart reduction" at type_context. + Remark: we also use `id_rhs` to implement "smart reduction" at type_context_old. */ - type_context ctx = mk_type_context(P); + type_context_old ctx = mk_type_context(P); rhs = mk_id_rhs(ctx, rhs); } m_mctx.assign(P.m_goal, rhs); @@ -1299,7 +1299,7 @@ struct elim_match_fn { expr finalize_lemma(expr const & fn, lemma const & L) { buffer args; to_buffer(L.m_lhs_args, args); - type_context ctx = mk_type_context(L.m_lctx); + type_context_old ctx = mk_type_context(L.m_lctx); expr lhs = mk_app(fn, args); expr eq = mk_eq(ctx, lhs, L.m_rhs); buffer locals; @@ -1368,7 +1368,7 @@ struct elim_match_fn { elim_match_result operator()(local_context const & lctx, expr const & eqns) { lean_assert(equations_num_fns(eqns) == 1); DEBUG_CODE({ - type_context ctx = mk_type_context(lctx); + type_context_old ctx = mk_type_context(lctx); lean_assert(!is_recursive_eqns(ctx, eqns)); }); m_aux_lemmas = get_equations_header(eqns).m_aux_lemmas; @@ -1438,7 +1438,7 @@ eqn_compiler_result mk_nonrec(environment & env, elaborator & elab, metavar_cont auto counter_examples = map2(R.m_counter_examples, [&] (list const & e) { return mk_app(fn, e); }); return { {R.m_fn}, counter_examples }; } - type_context ctx1(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); + type_context_old ctx1(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); /* We should use the type specified at eqns instead of m_ctx.infer(R.m_fn). These two types must be definitionally equal, but the shape of @@ -1455,9 +1455,9 @@ eqn_compiler_result mk_nonrec(environment & env, elaborator & elab, metavar_cont std::tie(env, fn) = mk_aux_definition(env, elab.get_options(), mctx, lctx, header, fn_name, fn_actual_name, fn_type, R.m_fn); unsigned eqn_idx = 1; - type_context ctx2(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); + type_context_old ctx2(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); for (expr type : R.m_lemmas) { - type_context::tmp_locals locals(ctx2); + type_context_old::tmp_locals locals(ctx2); type = ctx2.relaxed_whnf(type); while (is_pi(type)) { expr local = locals.push_local_from_binding(type); diff --git a/src/library/equations_compiler/pack_domain.cpp b/src/library/equations_compiler/pack_domain.cpp index 709ad4d4c6..318e2df1ef 100644 --- a/src/library/equations_compiler/pack_domain.cpp +++ b/src/library/equations_compiler/pack_domain.cpp @@ -16,15 +16,15 @@ Author: Leonardo de Moura namespace lean { struct sigma_packer_fn { - type_context & m_ctx; - sigma_packer_fn(type_context & ctx):m_ctx(ctx) {} + type_context_old & m_ctx; + sigma_packer_fn(type_context_old & ctx):m_ctx(ctx) {} expr_pair mk_sigma_domain(expr const & pi_type, buffer & out_locals, unsigned n) { expr type = pi_type; if (!is_pi(type)) type = m_ctx.relaxed_whnf(type); if (!is_pi(type)) throw_ill_formed_eqns(); expr const & A = binding_domain(type); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr a = locals.push_local_from_binding(type); out_locals.push_back(a); expr next_pi_type = instantiate(binding_body(type), a); @@ -49,7 +49,7 @@ struct sigma_packer_fn { buffer locals; expr domain, pre_codomain; std::tie(domain, pre_codomain) = mk_sigma_domain(pi_type, locals, n); - type_context::tmp_locals plocal(m_ctx); + type_context_old::tmp_locals plocal(m_ctx); expr p = plocal.push_local("_p", domain); expr codomain = mk_codomain(pre_codomain, p, locals, n); return plocal.mk_pi(codomain); @@ -123,7 +123,7 @@ struct sigma_packer_fn { } public: - update_apps_fn(type_context & ctx, buffer const & old_fns, unpack_eqns const & ues): + update_apps_fn(type_context_old & ctx, buffer const & old_fns, unpack_eqns const & ues): replace_visitor_with_tc(ctx), m_old_fns(old_fns), m_ues(ues) {} }; @@ -154,7 +154,7 @@ struct sigma_packer_fn { } }; -expr pack_domain(type_context & ctx, expr const & e) { +expr pack_domain(type_context_old & ctx, expr const & e) { return sigma_packer_fn(ctx)(e); } } diff --git a/src/library/equations_compiler/pack_domain.h b/src/library/equations_compiler/pack_domain.h index dd0799749e..857c971f70 100644 --- a/src/library/equations_compiler/pack_domain.h +++ b/src/library/equations_compiler/pack_domain.h @@ -9,5 +9,5 @@ Author: Leonardo de Moura namespace lean { /** \brief Create a new equations object where all functions being defined are unary. The trick is to pack multiple arguments using a Sigma type. */ -expr pack_domain(type_context & ctx, expr const & e); +expr pack_domain(type_context_old & ctx, expr const & e); } diff --git a/src/library/equations_compiler/pack_mutual.cpp b/src/library/equations_compiler/pack_mutual.cpp index f8714b86a2..2f35b84d97 100644 --- a/src/library/equations_compiler/pack_mutual.cpp +++ b/src/library/equations_compiler/pack_mutual.cpp @@ -18,7 +18,7 @@ Author: Leonardo de Moura namespace lean { #define trace_debug_mutual(Code) lean_trace(name({"debug", "eqn_compiler", "mutual"}), scope_trace_env _scope(m_ctx.env(), m_ctx); Code) -static expr mk_mutual_arg(type_context & ctx, expr const & e, unsigned fidx, unsigned num_fns, +static expr mk_mutual_arg(type_context_old & ctx, expr const & e, unsigned fidx, unsigned num_fns, expr psum_type, unsigned i) { if (i == num_fns - 1) { return e; @@ -36,14 +36,14 @@ static expr mk_mutual_arg(type_context & ctx, expr const & e, unsigned fidx, uns } } -expr mk_mutual_arg(type_context & ctx, expr const & e, unsigned fidx, unsigned num_fns, expr const & psum_type) { +expr mk_mutual_arg(type_context_old & ctx, expr const & e, unsigned fidx, unsigned num_fns, expr const & psum_type) { return mk_mutual_arg(ctx, e, fidx, num_fns, psum_type, 0); } struct pack_mutual_fn { - type_context & m_ctx; + type_context_old & m_ctx; - pack_mutual_fn(type_context & ctx):m_ctx(ctx) {} + pack_mutual_fn(type_context_old & ctx):m_ctx(ctx) {} expr mk_new_domain(buffer const & domains) { unsigned i = domains.size(); @@ -76,7 +76,7 @@ struct pack_mutual_fn { /* Add major */ cases_on = mk_app(cases_on, x); /* Add minors */ - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr y_1 = locals.push_local("_s", args[0]); expr m_1 = m_ctx.mk_lambda(y_1, instantiate(codomains[i], y_1)); expr y_2 = locals.push_local("_s", args[1]); @@ -91,7 +91,7 @@ struct pack_mutual_fn { expr m_new_fn; expr m_new_domain; - replace_fns(type_context & ctx, unpack_eqns const & ues, expr const & new_fn): + replace_fns(type_context_old & ctx, unpack_eqns const & ues, expr const & new_fn): replace_visitor_with_tc(ctx), m_ues(ues), m_new_fn(new_fn) { @@ -147,7 +147,7 @@ struct pack_mutual_fn { f : Pi (x : psum A_1 ... (psum A_{n-1} A_n)), psum.cases_on x (fun y, B_1 y) (... (fun y, B_n y) ...) remark: this module assumes the B_i's are in the same universe. */ - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); buffer domains; buffer codomains; level codomains_lvl; @@ -218,7 +218,7 @@ struct pack_mutual_fn { } }; -expr pack_mutual(type_context & ctx, expr const & e) { +expr pack_mutual(type_context_old & ctx, expr const & e) { return pack_mutual_fn(ctx)(e); } diff --git a/src/library/equations_compiler/pack_mutual.h b/src/library/equations_compiler/pack_mutual.h index dcfddcd18c..83a1967a53 100644 --- a/src/library/equations_compiler/pack_mutual.h +++ b/src/library/equations_compiler/pack_mutual.h @@ -9,9 +9,9 @@ Author: Leonardo de Moura namespace lean { /** \brief Create a new equations object containing a single function. The functions must be unary. */ -expr pack_mutual(type_context & ctx, expr const & eqns); +expr pack_mutual(type_context_old & ctx, expr const & eqns); -expr mk_mutual_arg(type_context & ctx, expr const & e, unsigned fidx, unsigned num_fns, expr const & psum_type); +expr mk_mutual_arg(type_context_old & ctx, expr const & e, unsigned fidx, unsigned num_fns, expr const & psum_type); void initialize_pack_mutual(); void finalize_pack_mutual(); diff --git a/src/library/equations_compiler/structural_rec.cpp b/src/library/equations_compiler/structural_rec.cpp index d0164ee779..a654aee685 100644 --- a/src/library/equations_compiler/structural_rec.cpp +++ b/src/library/equations_compiler/structural_rec.cpp @@ -22,9 +22,9 @@ Author: Leonardo de Moura #include "frontends/lean/elaborator.h" namespace lean { -#define trace_struct(Code) lean_trace(name({"eqn_compiler", "structural_rec"}), type_context ctx = mk_type_context(); scope_trace_env _scope1(m_env, ctx); Code) +#define trace_struct(Code) lean_trace(name({"eqn_compiler", "structural_rec"}), type_context_old ctx = mk_type_context(); scope_trace_env _scope1(m_env, ctx); Code) #define trace_struct_aux(Code) lean_trace(name({"eqn_compiler", "structural_rec"}), scope_trace_env _scope1(m_ctx.env(), m_ctx); Code) -#define trace_debug_struct(Code) lean_trace(name({"debug", "eqn_compiler", "structural_rec"}), type_context ctx = mk_type_context(); scope_trace_env _scope1(m_env, ctx); Code) +#define trace_debug_struct(Code) lean_trace(name({"debug", "eqn_compiler", "structural_rec"}), type_context_old ctx = mk_type_context(); scope_trace_env _scope1(m_env, ctx); Code) #define trace_debug_struct_aux(Code) lean_trace(name({"debug", "eqn_compiler", "structural_rec"}), scope_trace_env _scope1(m_ctx.env(), m_ctx); Code) struct structural_rec_fn { @@ -56,8 +56,8 @@ struct structural_rec_fn { throw generic_exception(m_ref, strm); } - type_context mk_type_context() { - return type_context(m_env, m_mctx, m_lctx, m_elab.get_cache(), transparency_mode::Semireducible); + type_context_old mk_type_context() { + return type_context_old(m_env, m_mctx, m_lctx, m_elab.get_cache(), transparency_mode::Semireducible); } environment const & env() const { return m_env; } @@ -66,13 +66,13 @@ struct structural_rec_fn { /** \brief Auxiliary object for checking whether recursive application are structurally smaller or not */ struct check_rhs_fn { - type_context & m_ctx; + type_context_old & m_ctx; expr m_lhs; expr m_fn; expr m_pattern; unsigned m_arg_idx; - check_rhs_fn(type_context & ctx, expr const & lhs, expr const & fn, expr const & pattern, unsigned arg_idx): + check_rhs_fn(type_context_old & ctx, expr const & lhs, expr const & fn, expr const & pattern, unsigned arg_idx): m_ctx(ctx), m_lhs(lhs), m_fn(fn), m_pattern(pattern), m_arg_idx(arg_idx) {} bool is_constructor(expr const & e) const { @@ -160,7 +160,7 @@ struct structural_rec_fn { if (!check_rhs(let_value(e))) { return false; } else { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); return check_rhs(instantiate(let_body(e), locals.push_local_from_let(e))); } case expr_kind::Lambda: @@ -168,7 +168,7 @@ struct structural_rec_fn { if (!check_rhs(binding_domain(e))) { return false; } else { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); return check_rhs(instantiate(binding_body(e), locals.push_local_from_binding(e))); } } @@ -180,19 +180,19 @@ struct structural_rec_fn { } }; - bool check_rhs(type_context & ctx, expr const & lhs, expr const & fn, expr pattern, unsigned arg_idx, expr const & rhs) { + bool check_rhs(type_context_old & ctx, expr const & lhs, expr const & fn, expr pattern, unsigned arg_idx, expr const & rhs) { pattern = ctx.whnf(pattern); return check_rhs_fn(ctx, lhs, fn, pattern, arg_idx)(rhs); } - bool check_eq(type_context & ctx, expr const & eqn, unsigned arg_idx) { + bool check_eq(type_context_old & ctx, expr const & eqn, unsigned arg_idx) { unpack_eqn ue(ctx, eqn); buffer args; expr const & fn = get_app_args(ue.lhs(), args); return check_rhs(ctx, ue.lhs(), fn, args[arg_idx], arg_idx, ue.rhs()); } - static bool depends_on_locals(expr const & e, type_context::tmp_locals const & locals) { + static bool depends_on_locals(expr const & e, type_context_old::tmp_locals const & locals) { return depends_on_any(e, locals.as_buffer().size(), locals.as_buffer().data()); } @@ -200,9 +200,9 @@ struct structural_rec_fn { If the argument type is an indexed family, we store the position of the indices (in the function being defined) at m_indices_pos. This method also updates m_reflexive (true iff the inductive datatype is reflexive). */ - bool check_arg_type(type_context & ctx, unpack_eqns const & ues, unsigned arg_idx) { + bool check_arg_type(type_context_old & ctx, unpack_eqns const & ues, unsigned arg_idx) { m_indices_pos.clear(); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); /* We can only use structural recursion on arg_idx IF 1- Type is an inductive datatype with support for the brec_on construction. 2- Type parameters do not depend on other arguments of the function being defined. */ @@ -311,7 +311,7 @@ struct structural_rec_fn { If the result is true, then m_arg_pos will contain the position of the argument, and m_indices_pos the position of its indices (when the type of the argument is an indexed family). */ - bool find_rec_arg(type_context & ctx, unpack_eqns const & ues) { + bool find_rec_arg(type_context_old & ctx, unpack_eqns const & ues) { buffer const & eqns = ues.get_eqns_of(0); unsigned arity = ues.get_arity_of(0); for (unsigned i = 0; i < arity; i++) { @@ -334,8 +334,8 @@ struct structural_rec_fn { /* Return the type of the new function. It also sets the m_motive_type field. */ - expr mk_new_fn_motive_types(type_context & ctx, unpack_eqns const & ues) { - type_context::tmp_locals locals(ctx); + expr mk_new_fn_motive_types(type_context_old & ctx, unpack_eqns const & ues) { + type_context_old::tmp_locals locals(ctx); expr fn = ues.get_fn(0); expr fn_type = ctx.infer(fn); unsigned arity = ues.get_arity_of(0); @@ -419,7 +419,7 @@ struct structural_rec_fn { expr m_F; expr m_C; - elim_rec_apps_fn(type_context & ctx, expr const & fn, + elim_rec_apps_fn(type_context_old & ctx, expr const & fn, unsigned arg_pos, buffer const & indices_pos, expr const & F, expr const & C): replace_visitor_with_tc(ctx), m_fn(fn), m_arg_pos(arg_pos), m_indices_pos(indices_pos), m_F(F), m_C(C) {} @@ -522,7 +522,7 @@ struct structural_rec_fn { 2) W have an equation (second) where the recursive argument is a variable (flag incomplete). */ - bool must_complete_rec_arg(type_context & ctx, unpack_eqns const & ues) { + bool must_complete_rec_arg(type_context_old & ctx, unpack_eqns const & ues) { if (m_arg_pos == 0) return false; buffer const & eqns = ues.get_eqns_of(0); bool has_case_analysis_before = false; @@ -550,7 +550,7 @@ struct structural_rec_fn { return false; } - void update_eqs(type_context & ctx, unpack_eqns & ues, expr const & fn, expr const & new_fn) { + void update_eqs(type_context_old & ctx, unpack_eqns & ues, expr const & fn, expr const & new_fn) { /* C is a temporary "abstract" motive, we use it to access the "brec_on dictionary". The "brec_on dictionary is an element of type below, and it is the last argument of the new function. */ expr C = mk_local(ctx.next_name(), "_C", m_motive_type, binder_info()); @@ -579,7 +579,7 @@ struct structural_rec_fn { expr new_lhs = mk_app(new_fn, new_lhs_args); expr type = ctx.whnf(ctx.infer(new_lhs)); lean_assert(is_pi(type)); - type_context::tmp_locals extra(ctx); + type_context_old::tmp_locals extra(ctx); expr F = extra.push_local(binding_name(type), binding_domain(type)); new_vars.push_back(F); new_lhs = mk_app(new_lhs, F); @@ -606,7 +606,7 @@ struct structural_rec_fn { } optional elim_recursion(expr const & e) { - type_context ctx = mk_type_context(); + type_context_old ctx = mk_type_context(); unpack_eqns ues(ctx, e); if (ues.get_num_fns() != 1) { trace_struct(tout() << "structural recursion is not supported for mutually recursive functions:"; @@ -640,7 +640,7 @@ struct structural_rec_fn { return some_expr(new_eqns); } - expr whnf_upto_below(type_context & ctx, name const & I_name, expr const & below_type) { + expr whnf_upto_below(type_context_old & ctx, name const & I_name, expr const & below_type) { name below_name(I_name, "below"); name ibelow_name(I_name, "ibelow"); return ctx.whnf_head_pred(below_type, [&](expr const & e) { @@ -654,8 +654,8 @@ struct structural_rec_fn { } expr mk_function(expr const & aux_fn) { - type_context ctx = mk_type_context(); - type_context::tmp_locals locals(ctx); + type_context_old ctx = mk_type_context(); + type_context_old::tmp_locals locals(ctx); buffer fn_args; expr aux_fn_type = ctx.infer(aux_fn); for (unsigned i = 0; i < m_arity + 1 /* below argument */; i++) { @@ -723,7 +723,7 @@ struct structural_rec_fn { unsigned m_arg_pos; buffer const & m_indices_pos; public: - mk_lemma_rhs_fn(type_context & ctx, expr const & fn, expr const & F, expr const & rec_arg, + mk_lemma_rhs_fn(type_context_old & ctx, expr const & fn, expr const & F, expr const & rec_arg, unsigned arg_pos, buffer const & indices_pos): replace_visitor_with_tc(ctx), m_fn(fn), m_F(F), m_lhs_rec_arg(rec_arg), m_arg_pos(arg_pos), m_indices_pos(indices_pos) {} @@ -924,15 +924,15 @@ struct structural_rec_fn { } }; - expr mk_lemma_rhs(type_context & ctx, expr const & fn, expr const & F, expr const & rec_arg, expr const & rhs) { + expr mk_lemma_rhs(type_context_old & ctx, expr const & fn, expr const & F, expr const & rec_arg, expr const & rhs) { return mk_lemma_rhs_fn(ctx, fn, F, rec_arg, m_arg_pos, m_indices_pos)(rhs); } void mk_lemmas(expr const & fn, list const & lemmas) { unsigned eqn_idx = 1; - type_context ctx = mk_type_context(); + type_context_old ctx = mk_type_context(); for (expr type : lemmas) { - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); type = ctx.relaxed_whnf(type); while (is_pi(type)) { expr local = locals.push_local_from_binding(type); diff --git a/src/library/equations_compiler/unbounded_rec.cpp b/src/library/equations_compiler/unbounded_rec.cpp index e1167048d4..6db15bd9c2 100644 --- a/src/library/equations_compiler/unbounded_rec.cpp +++ b/src/library/equations_compiler/unbounded_rec.cpp @@ -22,7 +22,7 @@ Author: Leonardo de Moura #include "frontends/lean/elaborator.h" namespace lean { -static expr replace_rec_apps(type_context & ctx, expr const & e) { +static expr replace_rec_apps(type_context_old & ctx, expr const & e) { equations_header const & header = get_equations_header(e); list actual_names = header.m_fn_actual_names; unpack_eqns ues(ctx, e); @@ -48,7 +48,7 @@ static expr replace_rec_apps(type_context & ctx, expr const & e) { return r; } -static void split_rec_fns(type_context & ctx, expr const & e, buffer & result) { +static void split_rec_fns(type_context_old & ctx, expr const & e, buffer & result) { equations_header const & header = get_equations_header(e); unpack_eqns ues(ctx, e); list fn_names = header.m_fn_names; @@ -87,7 +87,7 @@ static expr fix_rec_apps(expr const & e, name_map const & name2new_type, eqn_compiler_result unbounded_rec(environment & env, elaborator & elab, metavar_context & mctx, local_context const & lctx, expr const & e) { - type_context ctx(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); + type_context_old ctx(env, mctx, lctx, elab.get_cache(), transparency_mode::Semireducible); /* Replace recursive application with macro, and split mutual definition in n definitions. */ expr e1 = replace_rec_apps(ctx, e); diff --git a/src/library/equations_compiler/util.cpp b/src/library/equations_compiler/util.cpp index caaac15e6f..e0f6315bb8 100644 --- a/src/library/equations_compiler/util.cpp +++ b/src/library/equations_compiler/util.cpp @@ -83,7 +83,7 @@ static expr consume_fn_prefix(expr eq, buffer const & fns) { return instantiate_rev(eq, fns); } -unpack_eqns::unpack_eqns(type_context & ctx, expr const & e): +unpack_eqns::unpack_eqns(type_context_old & ctx, expr const & e): m_locals(ctx) { lean_assert(is_equations(e)); m_src = e; @@ -128,7 +128,7 @@ unpack_eqns::unpack_eqns(type_context & ctx, expr const & e): } } else { /* noequation, guess arity using type of function */ - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); expr type = ctx.relaxed_whnf(ctx.infer(m_fns[fidx])); unsigned arity = 0; while (is_pi(type)) { @@ -161,7 +161,7 @@ expr unpack_eqns::repack() { return update_equations(m_src, new_eqs); } -unpack_eqn::unpack_eqn(type_context & ctx, expr const & eqn): +unpack_eqn::unpack_eqn(type_context_old & ctx, expr const & eqn): m_src(eqn), m_locals(ctx) { expr it = eqn; while (is_lambda(it)) { @@ -191,7 +191,7 @@ expr unpack_eqn::repack() { return copy_tag(m_src, m_locals.ctx().mk_lambda(m_vars, new_eq)); } -bool is_recursive_eqns(type_context & ctx, expr const & e) { +bool is_recursive_eqns(type_context_old & ctx, expr const & e) { unpack_eqns ues(ctx, e); for (unsigned fidx = 0; fidx < ues.get_num_fns(); fidx++) { buffer const & eqns = ues.get_eqns_of(fidx); @@ -314,8 +314,8 @@ pair mk_aux_definition(environment const & env, options const static pair abstract_rhs_nested_proofs(environment const & env, metavar_context const & mctx, local_context const & lctx, name const & base_name, expr const & e) { - type_context ctx(env, options(), mctx, lctx, transparency_mode::Semireducible); - type_context::tmp_locals locals(ctx); + type_context_old ctx(env, options(), mctx, lctx, transparency_mode::Semireducible); + type_context_old::tmp_locals locals(ctx); expr t = e; while (is_pi(t)) { expr d = instantiate_rev(binding_domain(t), locals.size(), locals.data()); @@ -368,7 +368,7 @@ static environment add_equation_lemma(environment const & env, options const & o return new_env; } -static expr whnf_ite(type_context & ctx, expr const & e) { +static expr whnf_ite(type_context_old & ctx, expr const & e) { /* We use id_rhs as a "marker" to decide when to stop the whnf computation. */ return ctx.whnf_head_pred(e, [&](expr const & e) { expr const & fn = get_app_fn(e); @@ -383,8 +383,8 @@ static bool is_ite_eq(expr const & lhs, buffer & ite_args) { return is_constant(fn, get_ite_name()) && ite_args.size() == 5 && is_eq(ite_args[0]); } -static bool conservative_is_def_eq(type_context & ctx, expr const & a, expr const & b) { - type_context::transparency_scope scope(ctx, transparency_mode::Reducible); +static bool conservative_is_def_eq(type_context_old & ctx, expr const & a, expr const & b) { + type_context_old::transparency_scope scope(ctx, transparency_mode::Reducible); return ctx.is_def_eq(a, b); } @@ -409,7 +409,7 @@ static lbool compare_values(expr const & a, expr const & b) { return l_undef; } -static bool quick_is_def_eq_when_values(type_context & ctx, expr const & a, expr const & b) { +static bool quick_is_def_eq_when_values(type_context_old & ctx, expr const & a, expr const & b) { if (!is_local(a) && !is_local(b)) { if (compare_values(a, b) == l_true) return true; @@ -418,7 +418,7 @@ static bool quick_is_def_eq_when_values(type_context & ctx, expr const & a, expr } /* Try to find (H : not (c_lhs = c_rhs)) at Hs */ -static optional find_if_neg_hypothesis(type_context & ctx, expr const & c_lhs, expr const & c_rhs, +static optional find_if_neg_hypothesis(type_context_old & ctx, expr const & c_lhs, expr const & c_rhs, buffer const & Hs) { for (expr const & H : Hs) { expr H_type = ctx.infer(H); @@ -458,7 +458,7 @@ static optional find_if_neg_hypothesis(type_context & ctx, expr const & c_ (eq.symm (g_f_eq a)) (f_g_eq a) */ -static optional prove_eq_rec_invertible_aux(type_context & ctx, expr const & e) { +static optional prove_eq_rec_invertible_aux(type_context_old & ctx, expr const & e) { buffer rec_args; expr rec_fn = get_app_args(e, rec_args); if (!is_constant(rec_fn, get_eq_rec_name()) || rec_args.size() != 6) return optional(); @@ -502,7 +502,7 @@ static optional prove_eq_rec_invertible_aux(type_context & ctx, expr expr f_a_eq_f_a = mk_eq(ctx, f_a, f_a); /* (fun H : f a = f a, eq.refl (h a)) */ expr pr_minor = mk_lambda("_H", f_a_eq_f_a, refl_h_a); - type_context::tmp_locals aux_locals(ctx); + type_context_old::tmp_locals aux_locals(ctx); expr x = aux_locals.push_local("_x", A); /* Remark: we cannot use mk_app(f, x) in the following line. Reason: f may have implicit arguments. So, app_fn(f_x) is not equal to f in general, @@ -549,7 +549,7 @@ static optional prove_eq_rec_invertible_aux(type_context & ctx, expr We build an auxiliary proof for (F = h a) using prove_eq_rec_invertible_aux. Then, we use congr_fun to build the final proof if n > 0 */ -static optional prove_eq_rec_invertible(type_context & ctx, expr const & e) { +static optional prove_eq_rec_invertible(type_context_old & ctx, expr const & e) { buffer args; expr const & fn = get_app_args(e, args); if (args.size() == 6) { @@ -582,7 +582,7 @@ static optional prove_eq_rec_invertible(type_context & ctx, expr cons } } -static expr prove_eqn_lemma_core(type_context & ctx, buffer const & Hs, expr const & lhs, expr const & rhs, bool root) { +static expr prove_eqn_lemma_core(type_context_old & ctx, buffer const & Hs, expr const & lhs, expr const & rhs, bool root) { buffer ite_args; expr new_lhs = whnf_ite(ctx, lhs); if (is_ite_eq(new_lhs, ite_args)) { @@ -711,7 +711,7 @@ static expr prove_eqn_lemma_core(type_context & ctx, buffer const & Hs, ex while building the proof. However, the performance problem described in Option 2 may happen. */ if (root) { - /* Remark: type_context currently does not have support for id_delta. + /* Remark: type_context_old currently does not have support for id_delta. So, we unfold lhs before invoking ctx.is_def_eq. */ expr lhs_body = lhs; if (auto b = unfold_term(ctx.env(), lhs)) @@ -731,8 +731,8 @@ static expr prove_eqn_lemma_core(type_context & ctx, buffer const & Hs, ex "disable lemma generation using `set_option eqn_compiler.lemmas false`)"); } -static expr prove_eqn_lemma(type_context & ctx, buffer const & Hs, expr const & lhs, expr const & rhs) { - type_context::smart_unfolding_scope S(ctx, false); +static expr prove_eqn_lemma(type_context_old & ctx, buffer const & Hs, expr const & lhs, expr const & rhs) { + type_context_old::smart_unfolding_scope S(ctx, false); if (auto new_lhs = unfold_app(ctx.env(), lhs)) { buffer args; expr fn = get_app_args(*new_lhs, args); @@ -805,7 +805,7 @@ environment mk_equation_lemma(environment const & env, options const & opts, met name const & f_name, name const & f_actual_name, unsigned eqn_idx, bool is_private, buffer const & Hs, expr const & lhs, expr const & rhs) { if (!get_eqn_compiler_lemmas(opts)) return env; - type_context ctx(env, opts, mctx, lctx, transparency_mode::Semireducible); + type_context_old ctx(env, opts, mctx, lctx, transparency_mode::Semireducible); expr proof = prove_eqn_lemma(ctx, Hs, lhs, rhs); expr new_rhs = cleanup_equation_rhs(rhs); expr type = ctx.mk_pi(Hs, mk_eq(ctx, lhs, new_rhs)); @@ -818,11 +818,11 @@ environment mk_simple_equation_lemma_for(environment const & env, options const if (!env.find(get_eq_name())) return env; if (!get_eqn_compiler_lemmas(opts)) return env; declaration d = env.get(c_actual); - type_context ctx(env, transparency_mode::All); + type_context_old ctx(env, transparency_mode::All); expr type = d.get_type(); expr value = d.get_value(); expr lhs = mk_constant(c_actual, param_names_to_levels(d.get_univ_params())); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); for (unsigned i = 0; i < arity; i++) { type = ctx.relaxed_whnf(type); value = ctx.relaxed_whnf(value); @@ -853,7 +853,7 @@ bool is_name_value(expr const & e) { return false; } -bool is_nat_int_char_string_name_value(type_context & ctx, expr const & e) { +bool is_nat_int_char_string_name_value(type_context_old & ctx, expr const & e) { if (is_char_value(ctx, e) || is_string_value(e) || is_name_value(e)) return true; if (is_signed_num(e)) { expr type = ctx.infer(e); @@ -868,7 +868,7 @@ static bool is_inductive(environment const & env, expr const & e) { } /* Normalize until head is an inductive datatype */ -static expr whnf_inductive(type_context & ctx, expr const & e) { +static expr whnf_inductive(type_context_old & ctx, expr const & e) { return ctx.whnf_head_pred(e, [&](expr const & e) { return !is_inductive(ctx.env(), get_app_fn(e)); }); @@ -883,7 +883,7 @@ static void get_constructors_of(environment const & env, name const & n, buffer< where new_vars are fresh variables and are arguments of (c A ...) which have not been fixed by typing constraints. Moreover, fn is only invoked if the type of (c A ...) matches (I A idx). */ -void for_each_compatible_constructor(type_context & ctx, expr const & var, +void for_each_compatible_constructor(type_context_old & ctx, expr const & var, std::function &)> const & fn) { lean_assert(is_local(var)); expr var_type = whnf_inductive(ctx, ctx.infer(var)); @@ -903,7 +903,7 @@ void for_each_compatible_constructor(type_context & ctx, expr const & var, expr c = mk_app(mk_constant(c_name, I_ls), I_params); expr it = whnf_inductive(ctx, ctx.infer(c)); { - type_context::tmp_mode_scope scope(ctx); + type_context_old::tmp_mode_scope scope(ctx); while (is_pi(it)) { expr new_arg = ctx.mk_tmp_mvar(binding_domain(it)); c_vars.push_back(new_arg); @@ -952,7 +952,7 @@ void for_each_compatible_constructor(type_context & ctx, expr const & var, \remark The set of variables in t is a subset of {x_1, ..., x_{i-1}} union {y_1, ..., y_k} */ -void update_telescope(type_context & ctx, buffer const & vars, expr const & var, +void update_telescope(type_context_old & ctx, buffer const & vars, expr const & var, expr const & t, buffer const & t_vars, buffer & new_vars, buffer & from, buffer & to) { /* We are replacing `var` with `c` */ @@ -1021,11 +1021,11 @@ struct replace_rec_fn_macro_fn : public replace_visitor { }; environment mk_smart_unfolding_definition(environment const & env, options const & o, name const & n) { - type_context ctx(env, o, metavar_context(), local_context()); + type_context_old ctx(env, o, metavar_context(), local_context()); declaration const & d = env.get(n); expr val = d.get_value(); levels ls = param_names_to_levels(d.get_univ_params()); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); while (is_lambda(val)) { val = instantiate(binding_body(val), locals.push_local_from_binding(val)); } diff --git a/src/library/equations_compiler/util.h b/src/library/equations_compiler/util.h index 5fc6344ef3..d0f702838b 100644 --- a/src/library/equations_compiler/util.h +++ b/src/library/equations_compiler/util.h @@ -22,7 +22,7 @@ bool get_eqn_compiler_zeta(options const & o); TODO(Leo): as soon as we remove the legacy code from Lean2, this class will be much simpler. */ class unpack_eqns { - type_context::tmp_locals m_locals; + type_context_old::tmp_locals m_locals; expr m_src; buffer m_fns; /* m_arity[i] contains the number of arguments for each equation lhs @@ -36,7 +36,7 @@ class unpack_eqns { public: /** \brief Extract the data stored in the equations-expression \c e. \pre is_equations(e) */ - unpack_eqns(type_context & ctx, expr const & e); + unpack_eqns(type_context_old & ctx, expr const & e); /** \brief Re-build an equations-expression using the information stored at m_fns and m_eqs. */ expr repack(); @@ -55,7 +55,7 @@ public: /** \brief Helper class for unpacking a single equation nested in a equations expression. */ class unpack_eqn { expr m_src; - type_context::tmp_locals m_locals; + type_context_old::tmp_locals m_locals; bool m_modified_vars{false}; buffer m_vars; expr m_nested_src; @@ -63,7 +63,7 @@ class unpack_eqn { expr m_rhs; bool m_ignore_if_unused; public: - unpack_eqn(type_context & ctx, expr const & eqn); + unpack_eqn(type_context_old & ctx, expr const & eqn); expr add_var(name const & n, expr const & type); buffer & get_vars() { return m_vars; } expr & lhs() { return m_lhs; } @@ -76,7 +76,7 @@ public: /** \brief Return true iff \c e is recursive. That is, some equation in the rhs has a reference to a function being defined by the equations. */ -bool is_recursive_eqns(type_context & ctx, expr const & e); +bool is_recursive_eqns(type_context_old & ctx, expr const & e); expr erase_inaccessible_annotations(expr const & e); list erase_inaccessible_annotations(list const & es); @@ -118,14 +118,14 @@ environment mk_simple_equation_lemma_for(environment const & env, options const name mk_equation_name(name const & f_name, unsigned eqn_idx); /* Return true iff e is a nat, int, char or string value. */ -bool is_nat_int_char_string_name_value(type_context & ctx, expr const & e); +bool is_nat_int_char_string_name_value(type_context_old & ctx, expr const & e); /* Given a variable (x : I A idx), where (I A idx) is an inductive datatype, for each constructor c of (I A idx), this function invokes fn(t, new_vars) where t is of the form (c A ...), where new_vars are fresh variables and are arguments of (c A ...) which have not been fixed by typing constraints. Moreover, fn is only invoked if the type of (c A ...) matches (I A idx). */ -void for_each_compatible_constructor(type_context & ctx, expr const & var, +void for_each_compatible_constructor(type_context_old & ctx, expr const & var, std::function &)> const & fn); /* Given the telescope vars [x_1, ..., x_i, ..., x_n] and var := x_i, @@ -140,12 +140,12 @@ void for_each_compatible_constructor(type_context & ctx, expr const & var, The replacement will suppress entries x_j => T(x_j) if T(x_j) is equal to x_j. */ -void update_telescope(type_context & ctx, buffer const & vars, expr const & var, +void update_telescope(type_context_old & ctx, buffer const & vars, expr const & var, expr const & t, buffer const & t_vars, buffer & new_vars, buffer & from, buffer & to); /* Create auxiliary definition for unfolding declaration `n`. - See smart unfolding comment at type_context. */ + See smart unfolding comment at type_context_old. */ environment mk_smart_unfolding_definition(environment const & env, options const & o, name const & n); struct eqn_compiler_result { diff --git a/src/library/equations_compiler/wf_rec.cpp b/src/library/equations_compiler/wf_rec.cpp index 766687f968..00d852b6f2 100644 --- a/src/library/equations_compiler/wf_rec.cpp +++ b/src/library/equations_compiler/wf_rec.cpp @@ -25,8 +25,8 @@ Author: Leonardo de Moura #include "library/equations_compiler/util.h" namespace lean { -#define trace_wf(Code) lean_trace(name({"eqn_compiler", "wf_rec"}), type_context ctx = mk_type_context(); scope_trace_env _scope1(m_env, ctx); Code) -#define trace_debug_wf(Code) lean_trace(name({"debug", "eqn_compiler", "wf_rec"}), type_context ctx = mk_type_context(); scope_trace_env _scope1(m_env, ctx); Code) +#define trace_wf(Code) lean_trace(name({"eqn_compiler", "wf_rec"}), type_context_old ctx = mk_type_context(); scope_trace_env _scope1(m_env, ctx); Code) +#define trace_debug_wf(Code) lean_trace(name({"debug", "eqn_compiler", "wf_rec"}), type_context_old ctx = mk_type_context(); scope_trace_env _scope1(m_env, ctx); Code) #define trace_debug_wf_aux(Code) lean_trace(name({"debug", "eqn_compiler", "wf_rec"}), scope_trace_env _scope1(m_env, ctx); Code) struct wf_rec_fn { @@ -48,11 +48,11 @@ struct wf_rec_fn { m_env(env), m_elab(elab), m_mctx(mctx), m_lctx(lctx) { } - type_context mk_type_context(local_context const & lctx) { - return type_context(m_env, m_mctx, lctx, m_elab.get_cache(), transparency_mode::Semireducible); + type_context_old mk_type_context(local_context const & lctx) { + return type_context_old(m_env, m_mctx, lctx, m_elab.get_cache(), transparency_mode::Semireducible); } - type_context mk_type_context() { + type_context_old mk_type_context() { return mk_type_context(m_lctx); } @@ -61,7 +61,7 @@ struct wf_rec_fn { } expr pack_domain(expr const & eqns) { - type_context ctx = mk_type_context(); + type_context_old ctx = mk_type_context(); expr r = ::lean::pack_domain(ctx, eqns); m_env = ctx.env(); m_mctx = ctx.mctx(); @@ -69,7 +69,7 @@ struct wf_rec_fn { } expr pack_mutual(expr const & eqns) { - type_context ctx = mk_type_context(); + type_context_old ctx = mk_type_context(); expr r = ::lean::pack_mutual(ctx, eqns); m_env = ctx.env(); m_mctx = ctx.mctx(); @@ -78,7 +78,7 @@ struct wf_rec_fn { void mk_wf_relation(expr const & eqns, expr const & rel_tac) { lean_assert(get_equations_header(eqns).m_num_fns == 1); - type_context ctx = mk_type_context(); + type_context_old ctx = mk_type_context(); unpack_eqns ues(ctx, eqns); name fn_name = head(get_equations_header(eqns).m_fn_names); vm_obj vm_fn = to_obj(ues.get_fn(0)); @@ -119,8 +119,8 @@ struct wf_rec_fn { } /* Return the type of the functional. */ - expr mk_new_fn_type(type_context & ctx, unpack_eqns const & ues) { - type_context::tmp_locals locals(ctx); + expr mk_new_fn_type(type_context_old & ctx, unpack_eqns const & ues) { + type_context_old::tmp_locals locals(ctx); expr fn = ues.get_fn(0); expr fn_type = ctx.relaxed_whnf(ctx.infer(fn)); lean_assert(ues.get_arity_of(0) == 1); @@ -141,7 +141,7 @@ struct wf_rec_fn { expr m_x; expr m_F; - elim_rec_apps_fn(wf_rec_fn & parent, type_context & ctx, name const & fn_name, expr const & fn, expr const & x, expr const & F): + elim_rec_apps_fn(wf_rec_fn & parent, type_context_old & ctx, name const & fn_name, expr const & fn, expr const & x, expr const & F): replace_visitor_with_tc(ctx), m_parent(parent), m_fn_name(fn_name), m_fn(fn), m_x(x), m_F(F) {} virtual expr visit_local(expr const & e) { @@ -215,7 +215,7 @@ struct wf_rec_fn { } }; - void update_eqs(type_context & ctx, name const & fn_name, unpack_eqns & ues, expr const & fn, expr const & new_fn) { + void update_eqs(type_context_old & ctx, name const & fn_name, unpack_eqns & ues, expr const & fn, expr const & new_fn) { buffer & eqns = ues.get_eqns_of(0); buffer new_eqns; for (expr const & eqn : eqns) { @@ -229,7 +229,7 @@ struct wf_rec_fn { expr type = ctx.whnf(ctx.infer(new_lhs)); lean_assert(is_pi(type)); ue.lhs() = new_lhs; - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); expr F = locals.push_local_from_binding(type); ue.rhs() = ctx.mk_lambda(F, elim_rec_apps_fn(*this, ctx, fn_name, fn, lhs_args[0], F)(rhs)); new_eqns.push_back(ue.repack()); @@ -238,7 +238,7 @@ struct wf_rec_fn { } expr elim_recursion(expr const & eqns) { - type_context ctx = mk_type_context(); + type_context_old ctx = mk_type_context(); unpack_eqns ues(ctx, eqns); lean_assert(ues.get_num_fns() == 1); expr fn = ues.get_fn(0); @@ -255,8 +255,8 @@ struct wf_rec_fn { } expr mk_fix(expr const & aux_fn) { - type_context ctx = mk_type_context(); - type_context::tmp_locals locals(ctx); + type_context_old ctx = mk_type_context(); + type_context_old::tmp_locals locals(ctx); buffer fn_args; expr it = ctx.relaxed_whnf(ctx.infer(aux_fn)); lean_assert(is_pi(it)); @@ -274,7 +274,7 @@ struct wf_rec_fn { } expr mk_fix_aux_function(equations_header const & header, expr fn) { - type_context ctx = mk_type_context(); + type_context_old ctx = mk_type_context(); fn = mk_fix(fn); expr fn_type = ctx.infer(fn); expr r; @@ -288,7 +288,7 @@ struct wf_rec_fn { expr m_fn; expr m_F; - mk_lemma_rhs_fn(type_context & ctx, expr const & fn, expr const & F): + mk_lemma_rhs_fn(type_context_old & ctx, expr const & fn, expr const & F): replace_visitor_with_tc(ctx), m_fn(fn), m_F(F) {} virtual expr visit_local(expr const & e) override { @@ -308,10 +308,10 @@ struct wf_rec_fn { } }; - expr mk_lemma_rhs(type_context & ctx, expr const & fn, expr rhs) { + expr mk_lemma_rhs(type_context_old & ctx, expr const & fn, expr rhs) { rhs = ctx.relaxed_whnf(rhs); lean_assert(is_lambda(rhs)); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); expr F = locals.push_local_from_binding(rhs); rhs = instantiate(binding_body(rhs), F); return mk_lemma_rhs_fn(ctx, fn, F)(rhs); @@ -320,9 +320,9 @@ struct wf_rec_fn { void mk_lemmas(name const & fn_name, expr const & fn, list const & lemmas) { name const & fn_prv_name = const_name(get_app_fn(fn)); unsigned eqn_idx = 1; - type_context ctx = mk_type_context(); + type_context_old ctx = mk_type_context(); for (expr type : lemmas) { - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); type = ctx.relaxed_whnf(type); while (is_pi(type)) { expr local = locals.push_local_from_binding(type); @@ -341,7 +341,7 @@ struct wf_rec_fn { m_mctx = ctx.mctx(); } - expr_pair mk_sigma(type_context & ctx, unsigned i, buffer const & args) { + expr_pair mk_sigma(type_context_old & ctx, unsigned i, buffer const & args) { lean_assert(args.size() > 0); if (i == args.size() - 1) { return mk_pair(args[i], ctx.infer(args[i])); @@ -412,7 +412,7 @@ struct wf_rec_fn { unpack_eqns const & m_ues; buffer const & m_result_fns; - unpack_apps_fn(type_context & ctx, name const & packed_name, unsigned packed_num_params, + unpack_apps_fn(type_context_old & ctx, name const & packed_name, unsigned packed_num_params, unpack_eqns const & ues, buffer const & result_fns): replace_visitor_with_tc(ctx), m_packed_name(packed_name), m_packed_num_params(packed_num_params), m_ues(ues), m_result_fns(result_fns) { @@ -432,7 +432,7 @@ struct wf_rec_fn { equations_header const & header = get_equations_header(eqns_before_pack); list fn_names = header.m_fn_names; list fn_actual_names = header.m_fn_actual_names; - type_context ctx = mk_type_context(); + type_context_old ctx = mk_type_context(); buffer result_fns; expr packed_fn_type = ctx.relaxed_whnf(ctx.infer(packed_fn)); expr packed_domain = binding_domain(packed_fn_type); @@ -441,7 +441,7 @@ struct wf_rec_fn { for (unsigned fidx = 0; fidx < num_fns; fidx++) { unsigned arity = ues.get_arity_of(fidx); expr fn_type = ctx.infer(ues.get_fn(fidx)); - type_context::tmp_locals args(ctx); + type_context_old::tmp_locals args(ctx); expr it = fn_type; for (unsigned i = 0; i < arity; i++) { it = ctx.relaxed_whnf(it); @@ -477,7 +477,7 @@ struct wf_rec_fn { if (!packed_eqn_decl) break; list packed_eqn_levels = param_names_to_levels(packed_eqn_decl->get_univ_params()); expr packed_eqn_type = instantiate_type_univ_params(*packed_eqn_decl, packed_eqn_levels); - type_context::tmp_locals args(ctx); + type_context_old::tmp_locals args(ctx); expr packed_eqn = packed_eqn_type; while (true) { packed_eqn = ctx.relaxed_whnf(packed_eqn); diff --git a/src/library/eval_helper.h b/src/library/eval_helper.h index 5ff51a47a6..f04b8bb1ab 100644 --- a/src/library/eval_helper.h +++ b/src/library/eval_helper.h @@ -17,7 +17,7 @@ namespace lean { class eval_helper { environment m_env; options m_opts; - type_context m_tc; + type_context_old m_tc; buffer m_args; vm_state m_vms; vm_state::profiler m_prof; diff --git a/src/library/fun_info.cpp b/src/library/fun_info.cpp index 17c2b7aabf..84cd89d178 100644 --- a/src/library/fun_info.cpp +++ b/src/library/fun_info.cpp @@ -48,7 +48,7 @@ typedef cache_compatibility_helper fun_info_cache_helper; /* CACHE_RESET: YES */ MK_THREAD_LOCAL_GET_DEF(fun_info_cache_helper, get_fich); -fun_info_cache & get_fun_info_cache_for(type_context const & ctx) { +fun_info_cache & get_fun_info_cache_for(type_context_old const & ctx) { return get_fich().get_cache_for(ctx); } @@ -89,11 +89,11 @@ static list collect_deps(expr const & type, buffer const & local } /* Store parameter info for fn in \c pinfos and return the dependencies of the resulting type. */ -static list get_core(type_context & ctx, +static list get_core(type_context_old & ctx, expr const & fn, buffer & pinfos, unsigned max_args) { expr type = ctx.relaxed_try_to_pi(ctx.infer(fn)); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); unsigned i = 0; while (is_pi(type)) { if (i == max_args) @@ -112,7 +112,7 @@ static list get_core(type_context & ctx, return collect_deps(type, locals.as_buffer(), pinfos); } -fun_info get_fun_info(type_context & ctx, expr const & e) { +fun_info get_fun_info(type_context_old & ctx, expr const & e) { fun_info_cache & cache = get_fun_info_cache_for(ctx); auto it = cache.m_cache_get.find(e); if (it != cache.m_cache_get.end()) @@ -124,7 +124,7 @@ fun_info get_fun_info(type_context & ctx, expr const & e) { return r; } -fun_info get_fun_info(type_context & ctx, expr const & e, unsigned nargs) { +fun_info get_fun_info(type_context_old & ctx, expr const & e, unsigned nargs) { fun_info_cache & cache = get_fun_info_cache_for(ctx); expr_unsigned key(e, nargs); auto it = cache.m_cache_get_nargs.find(key); @@ -138,10 +138,10 @@ fun_info get_fun_info(type_context & ctx, expr const & e, unsigned nargs) { } /* Store subsingleton parameter info for fn in \c ssinfos */ -static void get_ss_core(type_context & ctx, expr const & fn, buffer & ssinfos, +static void get_ss_core(type_context_old & ctx, expr const & fn, buffer & ssinfos, unsigned max_args) { expr type = ctx.relaxed_try_to_pi(ctx.infer(fn)); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); unsigned i = 0; while (is_pi(type)) { if (i == max_args) @@ -162,7 +162,7 @@ static void get_ss_core(type_context & ctx, expr const & fn, buffer const & p return false; } -static void trace_if_unsupported(type_context & ctx, expr const & fn, +static void trace_if_unsupported(type_context_old & ctx, expr const & fn, buffer const & args, unsigned prefix_sz, ss_param_infos const & result) { lean_assert(args.size() >= length(result)); if (!is_fun_info_trace_enabled()) @@ -248,7 +248,7 @@ static void trace_if_unsupported(type_context & ctx, expr const & fn, } } -unsigned get_specialization_prefix_size(type_context & ctx, expr const & fn, unsigned nargs) { +unsigned get_specialization_prefix_size(type_context_old & ctx, expr const & fn, unsigned nargs) { /* We say a function is "cheap" if it is of the form: @@ -306,7 +306,7 @@ unsigned get_specialization_prefix_size(type_context & ctx, expr const & fn, uns return prefix_sz; } -ss_param_infos get_specialized_subsingleton_info(type_context & ctx, expr const & a) { +ss_param_infos get_specialized_subsingleton_info(type_context_old & ctx, expr const & a) { lean_assert(is_app(a)); buffer args; expr const & fn = get_app_args(a, args); diff --git a/src/library/fun_info.h b/src/library/fun_info.h index 50070a5698..47cc7a4d04 100644 --- a/src/library/fun_info.h +++ b/src/library/fun_info.h @@ -8,7 +8,7 @@ Author: Leonardo de Moura #include "kernel/expr.h" namespace lean { -class type_context; +class type_context_old; /** \brief Function parameter information. */ class param_info { @@ -43,10 +43,10 @@ public: list const & get_result_deps() const { return m_result_deps; } }; -fun_info get_fun_info(type_context & ctx, expr const & fn); +fun_info get_fun_info(type_context_old & ctx, expr const & fn); /** \brief Return information assuming the function has only nargs. \pre nargs <= get_fun_info(ctx, fn).get_arity() */ -fun_info get_fun_info(type_context & ctx, expr const & fn, unsigned nargs); +fun_info get_fun_info(type_context_old & ctx, expr const & fn, unsigned nargs); /** \brief Subsingleton parameter information */ class subsingleton_param_info { @@ -84,8 +84,8 @@ public: typedef subsingleton_param_info ss_param_info; typedef list ss_param_infos; -list get_subsingleton_info(type_context & ctx, expr const & fn); -list get_subsingleton_info(type_context & ctx, expr const & fn, unsigned nargs); +list get_subsingleton_info(type_context_old & ctx, expr const & fn); +list get_subsingleton_info(type_context_old & ctx, expr const & fn, unsigned nargs); /** \brief Return subsingleton parameter information for the function application. This is more precise than \c get_subsingleton_info for dependent functions. @@ -99,8 +99,8 @@ list get_subsingleton_info(type_context & ctx, expr const & fn, u The second argument is marked as subsingleton only because the resulting information is taking into account the first argument. */ -list get_specialized_subsingleton_info(type_context & ctx, expr const & app); -unsigned get_specialization_prefix_size(type_context & ctx, expr const & fn, unsigned nargs); +list get_specialized_subsingleton_info(type_context_old & ctx, expr const & app); +unsigned get_specialization_prefix_size(type_context_old & ctx, expr const & fn, unsigned nargs); /** Clear thread local cache */ void clear_fun_info_cache(); diff --git a/src/library/inductive_compiler/ginductive.cpp b/src/library/inductive_compiler/ginductive.cpp index a26ae5c7b9..f97c0930b3 100644 --- a/src/library/inductive_compiler/ginductive.cpp +++ b/src/library/inductive_compiler/ginductive.cpp @@ -22,7 +22,7 @@ optional is_gintro_rule_app(environment const & env, expr const & e) { return optional(const_name(fn)); } -expr whnf_ginductive(type_context & ctx, expr const & e) { +expr whnf_ginductive(type_context_old & ctx, expr const & e) { return ctx.whnf_head_pred(e, [&](expr const & e) { expr const & fn = get_app_fn(e); if (!is_constant(fn)) return true; @@ -30,13 +30,13 @@ expr whnf_ginductive(type_context & ctx, expr const & e) { }); } -expr whnf_gintro_rule(type_context & ctx, expr const & e) { +expr whnf_gintro_rule(type_context_old & ctx, expr const & e) { return ctx.whnf_head_pred(e, [&](expr const & e) { return !is_gintro_rule_app(ctx.env(), e); }); } -expr whnf_ginductive_gintro_rule(type_context & ctx, expr const & e) { +expr whnf_ginductive_gintro_rule(type_context_old & ctx, expr const & e) { return ctx.whnf_head_pred(e, [&](expr const & e) { expr const & fn = get_app_fn(e); if (!is_constant(fn)) return true; diff --git a/src/library/inductive_compiler/ginductive.h b/src/library/inductive_compiler/ginductive.h index 4e36f1a538..3a97bf8a57 100644 --- a/src/library/inductive_compiler/ginductive.h +++ b/src/library/inductive_compiler/ginductive.h @@ -33,14 +33,14 @@ unsigned get_ginductive_num_indices(environment const & env, name const & ind_na list get_ginductive_mut_ind_names(environment const & env, name const & ind_name); /* Normalize \c e until it is in weak head normal form OR the head is a ginductive datatype. */ -expr whnf_ginductive(type_context & ctx, expr const & e); +expr whnf_ginductive(type_context_old & ctx, expr const & e); /* Normalize \c e until it is in weak head normal form OR the head is a ginductive intro rule (aka constructor) */ -expr whnf_gintro_rule(type_context & ctx, expr const & e); +expr whnf_gintro_rule(type_context_old & ctx, expr const & e); /* Normalize \c e until it is in weak head normal form OR the head is a ginductive intro rule (aka constructor) or generalized inductive datatype. */ -expr whnf_ginductive_gintro_rule(type_context & ctx, expr const & e); +expr whnf_ginductive_gintro_rule(type_context_old & ctx, expr const & e); /* Similar to is_constructor_app, but takes generalized introduction rules into account. */ optional is_gintro_rule_app(environment const & env, expr const & e); diff --git a/src/library/inductive_compiler/mutual.cpp b/src/library/inductive_compiler/mutual.cpp index 82d5c5e6f4..202c541651 100644 --- a/src/library/inductive_compiler/mutual.cpp +++ b/src/library/inductive_compiler/mutual.cpp @@ -44,7 +44,7 @@ class add_mutual_inductive_decl_fn { name m_basic_ind_name; name m_basic_prefix; - type_context m_tctx; + type_context_old m_tctx; buffer m_index_types; expr m_full_index_type; @@ -317,7 +317,7 @@ class add_mutual_inductive_decl_fn { name basic_has_sizeof_name = mk_has_sizeof_name(mlocal_name(m_basic_decl.get_ind(0))); for (unsigned ind_idx = 0; ind_idx < m_mut_decl.get_inds().size(); ++ind_idx) { - type_context tctx_synth(m_env, m_opts, lctx); + type_context_old tctx_synth(m_env, m_opts, lctx); expr const & ind = m_mut_decl.get_ind(ind_idx); name sizeof_name = mk_sizeof_name(mlocal_name(ind)); @@ -377,7 +377,7 @@ class add_mutual_inductive_decl_fn { void define_sizeof_specs(local_context const & lctx, buffer const & param_insts) { for (unsigned ind_idx = 0; ind_idx < m_mut_decl.get_inds().size(); ++ind_idx) { - type_context tctx_synth(m_env, m_opts, lctx); + type_context_old tctx_synth(m_env, m_opts, lctx); expr const & ind = m_mut_decl.get_ind(ind_idx); name sizeof_name = mk_sizeof_name(mlocal_name(ind)); @@ -403,7 +403,7 @@ class add_mutual_inductive_decl_fn { expr local = mk_local_for(ir_ty); locals.push_back(local); expr candidate = mk_app(m_tctx, get_sizeof_name(), local); - type_context stctx(m_env, options(), m_tctx.lctx(), transparency_mode::Semireducible); + type_context_old stctx(m_env, options(), m_tctx.lctx(), transparency_mode::Semireducible); if (!stctx.is_def_eq(candidate, mk_constant(get_nat_zero_name()))) rhs = mk_nat_add(rhs, candidate); ir_ty = tctx_synth.whnf(instantiate(binding_body(ir_ty), local)); diff --git a/src/library/inductive_compiler/nested.cpp b/src/library/inductive_compiler/nested.cpp index 1a1276bdb5..b0a6fc7015 100644 --- a/src/library/inductive_compiler/nested.cpp +++ b/src/library/inductive_compiler/nested.cpp @@ -90,7 +90,7 @@ class add_nested_inductive_decl_fn { bool m_is_trusted; ginductive_decl m_inner_decl; - type_context m_tctx; + type_context_old m_tctx; expr m_nested_occ; @@ -227,7 +227,7 @@ class add_nested_inductive_decl_fn { return is_constant(fn) && const_name(fn).is_string() && const_name(fn).get_string() == std::string("sizeof"); } - static optional unfold_sizeof(type_context & tctx, expr const & e) { + static optional unfold_sizeof(type_context_old & tctx, expr const & e) { buffer args; expr fn = get_app_args(e, args); @@ -235,7 +235,7 @@ class add_nested_inductive_decl_fn { if (args.size() == 3 && is_constant(fn) && const_name(fn) == get_sizeof_name()) { // Note(dhs): *.sizeof is irreducible, and *.sizeof_inst are reduced when using transparency_mode::Instances // Here we want to reduce only sizeof_inst to expose the basic *.sizeof application. - type_context::transparency_scope scope(tctx, transparency_mode::Instances); + type_context_old::transparency_scope scope(tctx, transparency_mode::Instances); expr inst = tctx.whnf(args[1]); if (is_app(inst) && is_sizeof_app(app_arg(inst))) { expr new_e = mk_app(app_arg(tctx.whnf(args[1])), args[2]); @@ -248,7 +248,7 @@ class add_nested_inductive_decl_fn { return none_expr(); } - expr force_unfold_sizeof(type_context & ctx, expr const & e) { + expr force_unfold_sizeof(type_context_old & ctx, expr const & e) { if (auto r = unfold_sizeof(ctx, e)) { return *r; } else { @@ -256,7 +256,7 @@ class add_nested_inductive_decl_fn { } } - expr safe_whnf(type_context & tctx, expr const & e) { + expr safe_whnf(type_context_old & tctx, expr const & e) { expr r = tctx.whnf_head_pred(e, [&](expr const & t) { expr fn = get_app_fn(t); if (!is_constant(fn)) @@ -317,7 +317,7 @@ class add_nested_inductive_decl_fn { } expr mk_pack_injective_type(name const & pack_name, optional pack_arity = optional()) { - type_context::tmp_locals locals(m_tctx); + type_context_old::tmp_locals locals(m_tctx); buffer all_args; expr full_ty = m_tctx.infer(mk_constant(pack_name, m_nested_decl.get_levels())); expr ty = full_ty; @@ -771,7 +771,7 @@ class add_nested_inductive_decl_fn { initialize_synth_lctx(); if (!m_has_sizeof) return; for (unsigned ind_idx = 0; ind_idx < m_nested_decl.get_num_inds(); ++ind_idx) { - type_context tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx); + type_context_old tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx); expr const & ind = m_nested_decl.get_ind(ind_idx); name inner_sizeof_name = mk_sizeof_name(mlocal_name(m_inner_decl.get_ind(ind_idx))); @@ -837,7 +837,7 @@ class add_nested_inductive_decl_fn { expr c_inner_sizeof = mk_app(mk_app(mk_constant(inner_sizeof_name, m_nested_decl.get_levels()), m_inner_decl.get_params()), m_param_insts); for (unsigned ir_idx = 0; ir_idx < m_nested_decl.get_num_intro_rules(ind_idx); ++ir_idx) { - type_context tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx); + type_context_old tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx); expr ty = tctx_synth.whnf(mlocal_type(ind)); buffer indices; @@ -862,7 +862,7 @@ class add_nested_inductive_decl_fn { expr local = mk_local_for(ir_ty); locals.push_back(local); expr candidate = mk_app(tctx_synth, get_sizeof_name(), local); - type_context stctx(m_env, options(), tctx_synth.lctx(), transparency_mode::Semireducible); + type_context_old stctx(m_env, options(), tctx_synth.lctx(), transparency_mode::Semireducible); if (!stctx.is_def_eq(candidate, mk_constant(get_nat_zero_name()))) rhs = mk_nat_add(rhs, candidate); ir_ty = tctx_synth.whnf(instantiate(binding_body(ir_ty), local)); @@ -880,7 +880,7 @@ class add_nested_inductive_decl_fn { expr lhs_alt; { - type_context ntctx(m_env, options(), tctx_synth.lctx(), transparency_mode::None); + type_context_old ntctx(m_env, options(), tctx_synth.lctx(), transparency_mode::None); lhs_alt = mk_app(tctx_synth, get_sizeof_name(), ntctx.whnf(mk_app(mk_app(d_c_ir.get_value(), m_inner_decl.get_params()), locals))); } @@ -1457,7 +1457,7 @@ class add_nested_inductive_decl_fn { } simp_result force_eq_rec(expr const & rec_fn, buffer const & rec_args) { - // See comments above prove_eq_rec_invertible(type_context & ctx, expr const & e) at equation_compiler/util.cpp. + // See comments above prove_eq_rec_invertible(type_context_old & ctx, expr const & e) at equation_compiler/util.cpp. lean_assert(is_constant(rec_fn, get_eq_rec_name()) && rec_args.size() == 6); expr B = rec_args[0]; expr from = rec_args[1]; /* (f (g (f a))) */ @@ -1495,7 +1495,7 @@ class add_nested_inductive_decl_fn { expr f_a_eq_f_a = mk_eq(m_tctx, f_a, f_a); /* (fun H : f a = f a, eq.refl (h a)) */ expr pr_minor = mk_lambda("_H", f_a_eq_f_a, refl_h_a); - type_context::tmp_locals aux_locals(m_tctx); + type_context_old::tmp_locals aux_locals(m_tctx); expr x = aux_locals.push_local("_x", A); /* Remark: we cannot use mk_app(f, x) in the following line. Reason: f may have implicit arguments. So, app_fn(f_x) is not equal to f in general, @@ -1542,7 +1542,7 @@ class add_nested_inductive_decl_fn { return simplify_fn::post(e, parent); } public: - sizeof_simplify_fn(type_context & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, simp_config const & cfg): + sizeof_simplify_fn(type_context_old & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, simp_config const & cfg): simplify_fn(ctx, dcs, slss, list(), cfg) {} }; @@ -1563,8 +1563,8 @@ class add_nested_inductive_decl_fn { environment env = set_reducible(m_env, get_sizeof_name(), reducible_status::Irreducible, false); env = set_reducible(env, get_has_add_add_name(), reducible_status::Irreducible, false); - type_context tctx(env, m_tctx.get_options(), lctx, transparency_mode::Semireducible); - type_context tctx_whnf(env, m_tctx.get_options(), lctx, transparency_mode::None); + type_context_old tctx(env, m_tctx.get_options(), lctx, transparency_mode::Semireducible); + type_context_old tctx_whnf(env, m_tctx.get_options(), lctx, transparency_mode::None); simp_lemmas all_lemmas = use_sizeof ? join(m_lemmas, m_nested_decl.get_sizeof_lemmas()) : m_lemmas; for (expr const & H : Hs) { expr H_type = tctx_whnf.infer(H); @@ -1590,9 +1590,9 @@ class add_nested_inductive_decl_fn { lean_trace(name({"inductive_compiler", "nested", "prove"}), tout() << "[goal]: " << thm << "\n";); expr ty = thm; - // Note: type_context only used to manage locals and abstract at the end - type_context ctx(m_env, m_tctx.get_options(), use_sizeof ? m_synth_lctx : local_context()); - type_context::tmp_locals locals(ctx); + // Note: type_context_old only used to manage locals and abstract at the end + type_context_old ctx(m_env, m_tctx.get_options(), use_sizeof ? m_synth_lctx : local_context()); + type_context_old::tmp_locals locals(ctx); while (is_pi(ty)) { expr l = locals.push_local_from_binding(ty); @@ -1644,7 +1644,7 @@ class add_nested_inductive_decl_fn { void prove_primitive_pack_sizeof(buffer const & index_locals) { name n = mk_primitive_name(fn_type::SIZEOF_PACK); - type_context tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx, transparency_mode::Semireducible); + type_context_old tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx, transparency_mode::Semireducible); expr x_unpacked = mk_local_pp("x_unpacked", mk_app(m_nested_occ, index_locals)); expr lhs = force_unfold_sizeof(tctx_synth, mk_app(tctx_synth, get_sizeof_name(), mk_app(mk_app(m_primitive_pack, index_locals), x_unpacked))); @@ -1698,7 +1698,7 @@ class add_nested_inductive_decl_fn { void prove_nested_pack_sizeof(expr const & start, expr const & /* end */, expr const & nested_pack, buffer const & index_locals, unsigned nest_idx) { name n = mk_nested_name(fn_type::SIZEOF_PACK, nest_idx); - type_context tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx); + type_context_old tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx); expr x_unpacked = mk_local_pp("x_unpacked", mk_app(start, index_locals)); expr lhs = force_unfold_sizeof(tctx_synth, mk_app(tctx_synth, get_sizeof_name(), mk_app(mk_app(nested_pack, index_locals), x_unpacked))); @@ -1732,7 +1732,7 @@ class add_nested_inductive_decl_fn { lean_assert(is_constant(fn) && const_name(fn) == get_eq_name()); buffer pi_args; - type_context tctx(m_env, m_tctx.get_options(), transparency_mode::Semireducible); + type_context_old tctx(m_env, m_tctx.get_options(), transparency_mode::Semireducible); expr ty = safe_whnf(tctx, args[0]); while (is_pi(ty)) { @@ -1782,7 +1782,7 @@ class add_nested_inductive_decl_fn { void prove_pi_pack_sizeof(expr const & pi_pack, buffer const & ldeps, expr const & nested_pack_fn, expr const & arg_ty) { name n = mk_pi_name(fn_type::SIZEOF_PACK); - type_context tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx, transparency_mode::Semireducible); + type_context_old tctx_synth(m_env, m_tctx.get_options(), m_synth_lctx, transparency_mode::Semireducible); expr x_unpacked = mk_local_pp("x_unpacked", arg_ty); expr lhs = force_unfold_sizeof(tctx_synth, mk_app(tctx_synth, get_sizeof_name(), mk_app(pi_pack, x_unpacked))); @@ -2081,11 +2081,11 @@ class add_nested_inductive_decl_fn { } } public: - assumption_simplify_fn(type_context & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, simp_config const & cfg): + assumption_simplify_fn(type_context_old & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, simp_config const & cfg): simplify_fn(ctx, dcs, slss, list(), cfg) {} }; - expr intros_simp_prove_conjuncts(type_context & tctx, simp_lemmas const & slss, expr const & tgt) { + expr intros_simp_prove_conjuncts(type_context_old & tctx, simp_lemmas const & slss, expr const & tgt) { simp_config cfg = get_simp_config(); defeq_can_state dcs; @@ -2117,7 +2117,7 @@ class add_nested_inductive_decl_fn { expr prove_nested_injective(expr const & inj_type, simp_lemmas const & slss, name const & inj_arrow_name) { lean_trace(name({"inductive_compiler", "nested", "injective"}), tout() << "[try to prove]: " << inj_type << "\n";); - type_context tctx(m_env, m_opts); + type_context_old tctx(m_env, m_opts); buffer hyps; expr ty = inj_type; @@ -2144,7 +2144,7 @@ class add_nested_inductive_decl_fn { buffer new_hyps; while (optional o_s = intron(1, s, new_hyps, true)) { s = *o_s; - type_context tctx = mk_type_context_for(s); + type_context_old tctx = mk_type_context_for(s); local_decl hyp_decl = tctx.lctx().get_local_decl(new_hyps.back()); expr A, lhs, B, rhs; @@ -2168,7 +2168,7 @@ class add_nested_inductive_decl_fn { buffer new_hyps; s = *intron(1, s, new_hyps, true); - type_context tctx = mk_type_context_for(s); + type_context_old tctx = mk_type_context_for(s); local_decl hyp_decl = tctx.lctx().get_local_decl(new_hyps.back()); expr A, lhs, B, rhs; @@ -2182,7 +2182,7 @@ class add_nested_inductive_decl_fn { } if (is_heq(s.get_main_goal_decl()->get_type(), A, lhs, B, rhs)) { - type_context tctx = mk_type_context_for(s); + type_context_old tctx = mk_type_context_for(s); lean_assert(tctx.is_def_eq(A, B)); expr e = mk_app(tctx, get_heq_of_eq_name(), 3, A, lhs, rhs); s = *apply(tctx, false, false, e, s); @@ -2192,12 +2192,12 @@ class add_nested_inductive_decl_fn { unsigned arity = get_app_num_args(lhs); { - type_context tctx = mk_type_context_for(s); + type_context_old tctx = mk_type_context_for(s); name H_unpack_name({"H_unpack"}); expr H_unpack_type = mk_eq(tctx, mk_app(tctx, unpack_name, arity, lhs), mk_app(tctx, unpack_name, arity, rhs)); s = *tactic::is_success(assert_define_core(true, H_unpack_name, H_unpack_type, s)); { - type_context tctx = mk_type_context_for(s); + type_context_old tctx = mk_type_context_for(s); simp_config cfg = get_simp_config(); defeq_can_state dcs; simp_lemmas slss; @@ -2209,7 +2209,7 @@ class add_nested_inductive_decl_fn { s = *intron(1, s, new_hyps, true); { - type_context tctx = mk_type_context_for(s); + type_context_old tctx = mk_type_context_for(s); local_decl H_unpack_decl = tctx.lctx().get_local_decl(new_hyps.back()); slss = simp_lemmas(); @@ -2225,7 +2225,7 @@ class add_nested_inductive_decl_fn { tactic_state prove_pack_injective_easy_direction(tactic_state const & s0) { buffer new_hyps; tactic_state s = *intron(1, s0, new_hyps, true); - type_context tctx = mk_type_context_for(s); + type_context_old tctx = mk_type_context_for(s); local_decl hyp_decl = tctx.lctx().get_local_decl(new_hyps.back()); expr A, lhs, B, rhs; @@ -2239,7 +2239,7 @@ class add_nested_inductive_decl_fn { } expr goal_type = s.get_main_goal_decl()->get_type(); { - type_context tctx = mk_type_context_for(s); + type_context_old tctx = mk_type_context_for(s); simp_config cfg = get_simp_config(); defeq_can_state dcs; simp_lemmas slss; @@ -2265,7 +2265,7 @@ class add_nested_inductive_decl_fn { vm_state vms(m_env, m_opts); scope_vm_state vms_scope(vms); tactic_state s = intros_and_subst(pack_inj_name, pack_inj_type); - type_context tctx = mk_type_context_for(s); + type_context_old tctx = mk_type_context_for(s); s = *apply(tctx, false, false, mk_constant(get_iff_intro_name()), s); s = prove_pack_injective_hard_direction(s, unpack_name, unpack_pack_name); s = prove_pack_injective_easy_direction(s); diff --git a/src/library/inductive_compiler/util.cpp b/src/library/inductive_compiler/util.cpp index ec68afd1d5..63757eec50 100644 --- a/src/library/inductive_compiler/util.cpp +++ b/src/library/inductive_compiler/util.cpp @@ -26,10 +26,10 @@ implicit_infer_kind get_implicit_infer_kind(name_map const unsigned get_num_indices(environment const & env, expr const & ind) { unsigned num_indices = 0; - type_context tctx(env); + type_context_old tctx(env); lean_assert(is_local(ind)); expr ind_type = tctx.relaxed_whnf(mlocal_type(ind)); - type_context::tmp_locals locals(tctx); + type_context_old::tmp_locals locals(tctx); while (is_pi(ind_type)) { ind_type = instantiate(binding_body(ind_type), locals.push_local_from_binding(ind_type)); ind_type = tctx.relaxed_whnf(ind_type); @@ -39,9 +39,9 @@ unsigned get_num_indices(environment const & env, expr const & ind) { return num_indices; } -expr get_ind_result_type(type_context & tctx, expr const & ind) { +expr get_ind_result_type(type_context_old & tctx, expr const & ind) { expr ind_type = tctx.relaxed_whnf(tctx.infer(ind)); - type_context::tmp_locals locals(tctx); + type_context_old::tmp_locals locals(tctx); while (is_pi(ind_type)) { ind_type = instantiate(binding_body(ind_type), locals.push_local_from_binding(ind_type)); ind_type = tctx.relaxed_whnf(ind_type); diff --git a/src/library/inductive_compiler/util.h b/src/library/inductive_compiler/util.h index db286c8c92..979cbb2652 100644 --- a/src/library/inductive_compiler/util.h +++ b/src/library/inductive_compiler/util.h @@ -13,7 +13,7 @@ namespace lean { implicit_infer_kind get_implicit_infer_kind(name_map const & implicit_infer_map, name const & n); unsigned get_num_indices(environment const & env, expr const & ind); -expr get_ind_result_type(type_context & tctx, expr const & ind); +expr get_ind_result_type(type_context_old & tctx, expr const & ind); void assert_def_eq(environment const & env, expr const & e1, expr const & e2); void assert_type_correct(environment const & env, expr const & e); void assert_no_locals(name const & n, expr const & e); diff --git a/src/library/local_context.h b/src/library/local_context.h index 886ee48df1..54ce7fdae0 100644 --- a/src/library/local_context.h +++ b/src/library/local_context.h @@ -89,7 +89,7 @@ class local_context { name_map m_user_name2idxs; idx2local_decl m_idx2local_decl; optional m_local_instances; - friend class type_context; + friend class type_context_old; void insert_user_name(local_decl const &d); void erase_user_name(local_decl const &d); diff --git a/src/library/message_builder.cpp b/src/library/message_builder.cpp index 9ba7fda7e1..ca87546a1c 100644 --- a/src/library/message_builder.cpp +++ b/src/library/message_builder.cpp @@ -21,7 +21,7 @@ message_builder::message_builder(std::shared_ptr const & message_builder::message_builder(environment const & env, io_state const & ios, std::string const & file_name, pos_info const & pos, message_severity severity) : - message_builder(std::make_shared(env, ios.get_options()), + message_builder(std::make_shared(env, ios.get_options()), env, ios, file_name, pos, severity) {} message message_builder::build() { diff --git a/src/library/norm_num.h b/src/library/norm_num.h index 1a76a438cf..287fad24cd 100644 --- a/src/library/norm_num.h +++ b/src/library/norm_num.h @@ -15,7 +15,7 @@ Author: Robert Y. Lewis namespace lean { class norm_num_context { - type_context & m_ctx; + type_context_old & m_ctx; arith_instance m_ainst; pair mk_norm_add(expr const &, expr const &); @@ -83,12 +83,12 @@ class norm_num_context { expr mk_norm_eq(expr const &, expr const &); public: - norm_num_context(type_context & ctx): m_ctx(ctx), m_ainst(ctx) {} + norm_num_context(type_context_old & ctx): m_ctx(ctx), m_ainst(ctx) {} pair mk_norm(expr const & e); }; -inline pair mk_norm_num(type_context & ctx, expr const & e) { +inline pair mk_norm_num(type_context_old & ctx, expr const & e) { return norm_num_context(ctx).mk_norm(e); } } diff --git a/src/library/persistent_context_cache.cpp b/src/library/persistent_context_cache.cpp index b05ed38e23..255db2ace9 100644 --- a/src/library/persistent_context_cache.cpp +++ b/src/library/persistent_context_cache.cpp @@ -51,19 +51,19 @@ unsigned persistent_context_cache::get_class_instance_max_depth() const { return m_cache_ptr->get_class_instance_max_depth(); } -optional persistent_context_cache::get_decl(type_context & ctx, transparency_mode m, name const & n) { +optional persistent_context_cache::get_decl(type_context_old & ctx, transparency_mode m, name const & n) { return m_cache_ptr->get_decl(ctx, m, n); } -projection_info const * persistent_context_cache::get_proj_info(type_context & ctx, name const & n) { +projection_info const * persistent_context_cache::get_proj_info(type_context_old & ctx, name const & n) { return m_cache_ptr->get_proj_info(ctx, n); } -bool persistent_context_cache::get_aux_recursor(type_context & ctx, name const & n) { +bool persistent_context_cache::get_aux_recursor(type_context_old & ctx, name const & n) { return m_cache_ptr->get_aux_recursor(ctx, n); } -void persistent_context_cache::get_unification_hints(type_context & ctx, name const & f1, name const & f2, buffer & hints) { +void persistent_context_cache::get_unification_hints(type_context_old & ctx, name const & f1, name const & f2, buffer & hints) { return m_cache_ptr->get_unification_hints(ctx, f1, f2, hints); } @@ -131,108 +131,108 @@ optional persistent_context_cache::get_frozen_local_instances() return m_cache_ptr->get_frozen_local_instances(); } -optional persistent_context_cache::get_fun_info(type_context & ctx, expr const & e) { +optional persistent_context_cache::get_fun_info(type_context_old & ctx, expr const & e) { return m_cache_ptr->get_fun_info(ctx, e); } -void persistent_context_cache::set_fun_info(type_context & ctx, expr const & e, fun_info const & r) { +void persistent_context_cache::set_fun_info(type_context_old & ctx, expr const & e, fun_info const & r) { return m_cache_ptr->set_fun_info(ctx, e, r); } -optional persistent_context_cache::get_fun_info_nargs(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_fun_info_nargs(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_fun_info_nargs(ctx, e, k); } -void persistent_context_cache::set_fun_info_nargs(type_context & ctx, expr const & e, unsigned k, fun_info const & r) { +void persistent_context_cache::set_fun_info_nargs(type_context_old & ctx, expr const & e, unsigned k, fun_info const & r) { return m_cache_ptr->set_fun_info_nargs(ctx, e, k, r); } -optional persistent_context_cache::get_specialization_prefix_size(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_specialization_prefix_size(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_specialization_prefix_size(ctx, e, k); } -void persistent_context_cache::set_specialization_prefix_size(type_context & ctx, expr const & e, unsigned k, unsigned r) { +void persistent_context_cache::set_specialization_prefix_size(type_context_old & ctx, expr const & e, unsigned k, unsigned r) { return m_cache_ptr->set_specialization_prefix_size(ctx, e, k, r); } -optional persistent_context_cache::get_subsingleton_info(type_context & ctx, expr const & e) { +optional persistent_context_cache::get_subsingleton_info(type_context_old & ctx, expr const & e) { return m_cache_ptr->get_subsingleton_info(ctx, e); } -void persistent_context_cache::set_subsingleton_info(type_context & ctx, expr const & e, ss_param_infos const & r) { +void persistent_context_cache::set_subsingleton_info(type_context_old & ctx, expr const & e, ss_param_infos const & r) { return m_cache_ptr->set_subsingleton_info(ctx, e, r); } -optional persistent_context_cache::get_subsingleton_info_nargs(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_subsingleton_info_nargs(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_subsingleton_info_nargs(ctx, e, k); } -void persistent_context_cache::set_subsingleton_info_nargs(type_context & ctx, expr const & e, unsigned k, ss_param_infos const & r) { +void persistent_context_cache::set_subsingleton_info_nargs(type_context_old & ctx, expr const & e, unsigned k, ss_param_infos const & r) { return m_cache_ptr->set_subsingleton_info_nargs(ctx, e, k, r); } -optional persistent_context_cache::get_specialized_subsingleton_info_nargs(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_specialized_subsingleton_info_nargs(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_specialized_subsingleton_info_nargs(ctx, e, k); } -void persistent_context_cache::set_specialization_subsingleton_info_nargs(type_context & ctx, expr const & e, unsigned k, ss_param_infos const & r) { +void persistent_context_cache::set_specialization_subsingleton_info_nargs(type_context_old & ctx, expr const & e, unsigned k, ss_param_infos const & r) { return m_cache_ptr->set_specialization_subsingleton_info_nargs(ctx, e, k, r); } -optional persistent_context_cache::get_simp_congr_lemma(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_simp_congr_lemma(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_simp_congr_lemma(ctx, e, k); } -void persistent_context_cache::set_simp_congr_lemma(type_context & ctx, expr const & e, unsigned k, congr_lemma const & r) { +void persistent_context_cache::set_simp_congr_lemma(type_context_old & ctx, expr const & e, unsigned k, congr_lemma const & r) { return m_cache_ptr->set_simp_congr_lemma(ctx, e, k, r); } -optional persistent_context_cache::get_specialized_simp_congr_lemma(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_specialized_simp_congr_lemma(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_specialized_simp_congr_lemma(ctx, e, k); } -void persistent_context_cache::set_specialized_simp_congr_lemma(type_context & ctx, expr const & e, unsigned k, congr_lemma const & r) { +void persistent_context_cache::set_specialized_simp_congr_lemma(type_context_old & ctx, expr const & e, unsigned k, congr_lemma const & r) { return m_cache_ptr->set_specialized_simp_congr_lemma(ctx, e, k, r); } -optional persistent_context_cache::get_congr_lemma(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_congr_lemma(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_congr_lemma(ctx, e, k); } -void persistent_context_cache::set_congr_lemma(type_context & ctx, expr const & e, unsigned k, congr_lemma const & r) { +void persistent_context_cache::set_congr_lemma(type_context_old & ctx, expr const & e, unsigned k, congr_lemma const & r) { return m_cache_ptr->set_congr_lemma(ctx, e, k, r); } -optional persistent_context_cache::get_specialized_congr_lemma(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_specialized_congr_lemma(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_specialized_congr_lemma(ctx, e, k); } -void persistent_context_cache::set_specialized_congr_lemma(type_context & ctx, expr const & e, unsigned k, congr_lemma const & r) { +void persistent_context_cache::set_specialized_congr_lemma(type_context_old & ctx, expr const & e, unsigned k, congr_lemma const & r) { return m_cache_ptr->set_specialized_congr_lemma(ctx, e, k, r); } -optional persistent_context_cache::get_hcongr_lemma(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_hcongr_lemma(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_hcongr_lemma(ctx, e, k); } -void persistent_context_cache::set_hcongr_lemma(type_context & ctx, expr const & e, unsigned k, congr_lemma const & r) { +void persistent_context_cache::set_hcongr_lemma(type_context_old & ctx, expr const & e, unsigned k, congr_lemma const & r) { return m_cache_ptr->set_hcongr_lemma(ctx, e, k, r); } -optional persistent_context_cache::get_app_builder_info(type_context & ctx, expr const & e, unsigned k) { +optional persistent_context_cache::get_app_builder_info(type_context_old & ctx, expr const & e, unsigned k) { return m_cache_ptr->get_app_builder_info(ctx, e, k); } -void persistent_context_cache::set_app_builder_info(type_context & ctx, expr const & e, unsigned k, app_builder_info const & r) { +void persistent_context_cache::set_app_builder_info(type_context_old & ctx, expr const & e, unsigned k, app_builder_info const & r) { return m_cache_ptr->set_app_builder_info(ctx, e, k, r); } -optional persistent_context_cache::get_app_builder_info(type_context & ctx, expr const & e, list const & m) { +optional persistent_context_cache::get_app_builder_info(type_context_old & ctx, expr const & e, list const & m) { return m_cache_ptr->get_app_builder_info(ctx, e, m); } -void persistent_context_cache::set_app_builder_info(type_context & ctx, expr const & e, list const & m, app_builder_info const & r) { +void persistent_context_cache::set_app_builder_info(type_context_old & ctx, expr const & e, list const & m, app_builder_info const & r) { return m_cache_ptr->set_app_builder_info(ctx, e, m, r); } diff --git a/src/library/persistent_context_cache.h b/src/library/persistent_context_cache.h index e6018bd639..555c5cf236 100644 --- a/src/library/persistent_context_cache.h +++ b/src/library/persistent_context_cache.h @@ -43,12 +43,12 @@ public: /* Operations for accessing environment data more efficiently. The default implementation provided by this class does not have any optimization. */ - virtual optional get_decl(type_context &, transparency_mode, name const &) override; - virtual projection_info const * get_proj_info(type_context &, name const &) override; - virtual bool get_aux_recursor(type_context &, name const &) override; - virtual void get_unification_hints(type_context &, name const & f1, name const & f2, buffer & hints) override; + virtual optional get_decl(type_context_old &, transparency_mode, name const &) override; + virtual projection_info const * get_proj_info(type_context_old &, name const &) override; + virtual bool get_aux_recursor(type_context_old &, name const &) override; + virtual void get_unification_hints(type_context_old &, name const & f1, name const & f2, buffer & hints) override; - /* Cache support for type_context module */ + /* Cache support for type_context_old module */ virtual optional get_infer(expr const &) override; virtual void set_infer(expr const &, expr const &) override; @@ -77,47 +77,47 @@ public: /* Cache support for fun_info module */ - virtual optional get_fun_info(type_context &, expr const &) override; - virtual void set_fun_info(type_context &, expr const &, fun_info const &) override; + virtual optional get_fun_info(type_context_old &, expr const &) override; + virtual void set_fun_info(type_context_old &, expr const &, fun_info const &) override; - virtual optional get_fun_info_nargs(type_context &, expr const &, unsigned) override; - virtual void set_fun_info_nargs(type_context &, expr const &, unsigned, fun_info const &) override; + virtual optional get_fun_info_nargs(type_context_old &, expr const &, unsigned) override; + virtual void set_fun_info_nargs(type_context_old &, expr const &, unsigned, fun_info const &) override; - virtual optional get_specialization_prefix_size(type_context &, expr const &, unsigned) override; - virtual void set_specialization_prefix_size(type_context &, expr const &, unsigned, unsigned) override; + virtual optional get_specialization_prefix_size(type_context_old &, expr const &, unsigned) override; + virtual void set_specialization_prefix_size(type_context_old &, expr const &, unsigned, unsigned) override; - virtual optional get_subsingleton_info(type_context &, expr const &) override; - virtual void set_subsingleton_info(type_context &, expr const &, ss_param_infos const &) override; + virtual optional get_subsingleton_info(type_context_old &, expr const &) override; + virtual void set_subsingleton_info(type_context_old &, expr const &, ss_param_infos const &) override; - virtual optional get_subsingleton_info_nargs(type_context &, expr const &, unsigned) override; - virtual void set_subsingleton_info_nargs(type_context &, expr const &, unsigned, ss_param_infos const &) override; + virtual optional get_subsingleton_info_nargs(type_context_old &, expr const &, unsigned) override; + virtual void set_subsingleton_info_nargs(type_context_old &, expr const &, unsigned, ss_param_infos const &) override; - virtual optional get_specialized_subsingleton_info_nargs(type_context &, expr const &, unsigned) override; - virtual void set_specialization_subsingleton_info_nargs(type_context &, expr const &, unsigned, ss_param_infos const &) override; + virtual optional get_specialized_subsingleton_info_nargs(type_context_old &, expr const &, unsigned) override; + virtual void set_specialization_subsingleton_info_nargs(type_context_old &, expr const &, unsigned, ss_param_infos const &) override; /* Cache support for congr_lemma module */ - virtual optional get_simp_congr_lemma(type_context &, expr const &, unsigned) override; - virtual void set_simp_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override; + virtual optional get_simp_congr_lemma(type_context_old &, expr const &, unsigned) override; + virtual void set_simp_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override; - virtual optional get_specialized_simp_congr_lemma(type_context &, expr const &, unsigned) override; - virtual void set_specialized_simp_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override; + virtual optional get_specialized_simp_congr_lemma(type_context_old &, expr const &, unsigned) override; + virtual void set_specialized_simp_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override; - virtual optional get_congr_lemma(type_context &, expr const &, unsigned) override; - virtual void set_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override; + virtual optional get_congr_lemma(type_context_old &, expr const &, unsigned) override; + virtual void set_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override; - virtual optional get_specialized_congr_lemma(type_context &, expr const &, unsigned) override; - virtual void set_specialized_congr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override; + virtual optional get_specialized_congr_lemma(type_context_old &, expr const &, unsigned) override; + virtual void set_specialized_congr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override; - virtual optional get_hcongr_lemma(type_context &, expr const &, unsigned) override; - virtual void set_hcongr_lemma(type_context &, expr const &, unsigned, congr_lemma const &) override; + virtual optional get_hcongr_lemma(type_context_old &, expr const &, unsigned) override; + virtual void set_hcongr_lemma(type_context_old &, expr const &, unsigned, congr_lemma const &) override; /* Cache support for app_builder */ - virtual optional get_app_builder_info(type_context &, expr const &, unsigned) override; - virtual void set_app_builder_info(type_context &, expr const &, unsigned, app_builder_info const &) override; + virtual optional get_app_builder_info(type_context_old &, expr const &, unsigned) override; + virtual void set_app_builder_info(type_context_old &, expr const &, unsigned, app_builder_info const &) override; - virtual optional get_app_builder_info(type_context &, expr const &, list const &) override; - virtual void set_app_builder_info(type_context &, expr const &, list const &, app_builder_info const &) override; + virtual optional get_app_builder_info(type_context_old &, expr const &, list const &) override; + virtual void set_app_builder_info(type_context_old &, expr const &, list const &, app_builder_info const &) override; }; } diff --git a/src/library/replace_visitor_with_tc.cpp b/src/library/replace_visitor_with_tc.cpp index 6c0d7c9e32..52a3f83d51 100644 --- a/src/library/replace_visitor_with_tc.cpp +++ b/src/library/replace_visitor_with_tc.cpp @@ -8,7 +8,7 @@ Author: Leonardo de Moura #include "library/replace_visitor_with_tc.h" namespace lean { expr replace_visitor_with_tc::visit_lambda_pi_let(bool is_lam, expr const & e) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr t = e; while (true) { if ((is_lam && is_lambda(t)) || (!is_lam && is_pi(t))) { diff --git a/src/library/replace_visitor_with_tc.h b/src/library/replace_visitor_with_tc.h index 0d0449d898..ac799daf65 100644 --- a/src/library/replace_visitor_with_tc.h +++ b/src/library/replace_visitor_with_tc.h @@ -8,10 +8,10 @@ Author: Leonardo de Moura #include "library/replace_visitor.h" #include "library/type_context.h" namespace lean { -/** \brief Version of replace_visitor with a nested type_context object. */ +/** \brief Version of replace_visitor with a nested type_context_old object. */ class replace_visitor_with_tc : public replace_visitor { protected: - type_context & m_ctx; + type_context_old & m_ctx; expr visit_lambda_pi_let(bool is_lam, expr const & e); virtual expr visit_lambda(expr const & e) override { return visit_lambda_pi_let(true, e); @@ -24,6 +24,6 @@ protected: } virtual expr visit_app(expr const & e) override; public: - replace_visitor_with_tc(type_context & ctx):m_ctx(ctx) {} + replace_visitor_with_tc(type_context_old & ctx):m_ctx(ctx) {} }; } diff --git a/src/library/tactic/ac_tactics.cpp b/src/library/tactic/ac_tactics.cpp index 50e041da54..14faf06bb3 100644 --- a/src/library/tactic/ac_tactics.cpp +++ b/src/library/tactic/ac_tactics.cpp @@ -38,7 +38,7 @@ static ac_manager_old::cache_ptr get_cache(environment const & env) { return std::make_shared(env); } -ac_manager_old::ac_manager_old(type_context & ctx): +ac_manager_old::ac_manager_old(type_context_old & ctx): m_ctx(ctx), m_cache_ptr(get_cache(ctx.env())) { } @@ -652,7 +652,7 @@ expr mk_perm_ac_macro(abstract_type_context & ctx, expr const & assoc, expr cons vm_obj tactic_flat_assoc(vm_obj const & op, vm_obj const & assoc, vm_obj const & e, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); pair p = flat_assoc_fn(ctx, to_expr(op), to_expr(assoc)).flat(to_expr(e)); return tactic::mk_success(mk_vm_pair(to_obj(p.first), to_obj(p.second)), tactic::to_state(s)); CATCH; @@ -660,7 +660,7 @@ vm_obj tactic_flat_assoc(vm_obj const & op, vm_obj const & assoc, vm_obj const & vm_obj tactic_perm_ac(vm_obj const & op, vm_obj const & assoc, vm_obj const & comm, vm_obj const & e1, vm_obj const & e2, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); expr H = perm_ac_fn(ctx, to_expr(op), to_expr(assoc), to_expr(comm)).perm(to_expr(e1), to_expr(e2)); return tactic::mk_success(to_obj(H), tactic::to_state(s)); CATCH; diff --git a/src/library/tactic/ac_tactics.h b/src/library/tactic/ac_tactics.h index 4dc504553e..2b46d1c0de 100644 --- a/src/library/tactic/ac_tactics.h +++ b/src/library/tactic/ac_tactics.h @@ -66,10 +66,10 @@ public: struct cache; typedef std::shared_ptr cache_ptr; private: - type_context & m_ctx; + type_context_old & m_ctx; cache_ptr m_cache_ptr; public: - ac_manager_old(type_context & ctx); + ac_manager_old(type_context_old & ctx); ~ac_manager_old(); /* If e is of the form (op a b), and op is associative (i.e., there is an instance (is_associative _ op)), then return proof term for forall x y z, op (op x y) z = op x (op y z) */ diff --git a/src/library/tactic/algebraic_normalizer.cpp b/src/library/tactic/algebraic_normalizer.cpp index 1f0ed42535..ada02d0df4 100644 --- a/src/library/tactic/algebraic_normalizer.cpp +++ b/src/library/tactic/algebraic_normalizer.cpp @@ -15,7 +15,7 @@ static name * g_algebra = nullptr; MK_THREAD_LOCAL_GET_DEF(algebraic_info_manager::data_ptr, get_alg_info_data); -algebraic_info_manager::algebraic_info_manager(type_context & ctx): +algebraic_info_manager::algebraic_info_manager(type_context_old & ctx): m_ctx(ctx) { data_ptr p = get_alg_info_data(); if (p && @@ -49,7 +49,7 @@ algebraic_info_ref algebraic_info_manager::get_info(expr const & op) { vm_obj tactic_trace_algebra_info(vm_obj const & op, vm_obj const & _s) { tactic_state const & s = tactic::to_state(_s); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); algebraic_info_manager m(ctx); if (m.get_info(to_expr(op))) { tout() << "operator has algebraic info\n"; diff --git a/src/library/tactic/algebraic_normalizer.h b/src/library/tactic/algebraic_normalizer.h index b5ad5204d4..6026f731c5 100644 --- a/src/library/tactic/algebraic_normalizer.h +++ b/src/library/tactic/algebraic_normalizer.h @@ -98,13 +98,13 @@ public: typedef std::shared_ptr data_ptr; private: - type_context & m_ctx; + type_context_old & m_ctx; data_ptr m_data; public: - algebraic_info_manager(type_context & ctx); + algebraic_info_manager(type_context_old & ctx); ~algebraic_info_manager(); - type_context & ctx() const { return m_ctx; } + type_context_old & ctx() const { return m_ctx; } algebraic_info_ref get_info(expr const & op); }; diff --git a/src/library/tactic/app_builder_tactics.cpp b/src/library/tactic/app_builder_tactics.cpp index d73213ad21..c4f3e6ee0b 100644 --- a/src/library/tactic/app_builder_tactics.cpp +++ b/src/library/tactic/app_builder_tactics.cpp @@ -16,7 +16,7 @@ namespace lean { vm_obj tactic_mk_app(vm_obj const & c, vm_obj const & as, vm_obj const & tmode, vm_obj const & _s) { tactic_state const & s = tactic::to_state(_s); try { - type_context ctx = mk_type_context_for(s, to_transparency_mode(tmode)); + type_context_old ctx = mk_type_context_for(s, to_transparency_mode(tmode)); buffer args; to_buffer_expr(as, args); expr r = mk_app(ctx, to_name(c), args.size(), args.data()); @@ -29,7 +29,7 @@ vm_obj tactic_mk_app(vm_obj const & c, vm_obj const & as, vm_obj const & tmode, #define MK_APP(CODE) { \ tactic_state const & s = tactic::to_state(_s); \ try { \ - type_context ctx = mk_type_context_for(s); \ + type_context_old ctx = mk_type_context_for(s); \ expr r = CODE; \ return tactic::mk_success(to_obj(r), s); \ } catch (exception & ex) { \ @@ -72,7 +72,7 @@ vm_obj tactic_mk_eq_mp(vm_obj const & h1, vm_obj const & h2, vm_obj const & _s) vm_obj tactic_mk_mapp(vm_obj const & c, vm_obj const & as, vm_obj const & tmode, vm_obj const & _s) { tactic_state const & s = tactic::to_state(_s); try { - type_context ctx = mk_type_context_for(s, to_transparency_mode(tmode)); + type_context_old ctx = mk_type_context_for(s, to_transparency_mode(tmode)); buffer mask; buffer args; vm_obj it = as; diff --git a/src/library/tactic/apply_tactic.cpp b/src/library/tactic/apply_tactic.cpp index eb1d0c8b63..b93b8bf7f0 100644 --- a/src/library/tactic/apply_tactic.cpp +++ b/src/library/tactic/apply_tactic.cpp @@ -37,8 +37,8 @@ apply_cfg::apply_cfg(vm_obj const & cfg): Compute the number of expected arguments and whether the result type is of the form (?m ...) where ?m is an unassigned metavariable. */ -static pair get_expected_num_args_ho_result(type_context & ctx, expr e) { - type_context::tmp_locals locals(ctx); +static pair get_expected_num_args_ho_result(type_context_old & ctx, expr e) { + type_context_old::tmp_locals locals(ctx); unsigned r = 0; while (true) { e = ctx.relaxed_whnf(e); @@ -54,11 +54,11 @@ static pair get_expected_num_args_ho_result(type_context & ctx, } } -static unsigned get_expected_num_args(type_context & ctx, expr e) { +static unsigned get_expected_num_args(type_context_old & ctx, expr e) { return get_expected_num_args_ho_result(ctx, e).first; } -static bool try_instance(type_context & ctx, expr const & meta, tactic_state const & s, vm_obj * out_error_obj, char const * tac_name) { +static bool try_instance(type_context_old & ctx, expr const & meta, tactic_state const & s, vm_obj * out_error_obj, char const * tac_name) { if (ctx.is_assigned(meta)) return true; expr meta_type = ctx.instantiate_mvars(ctx.infer(meta)); @@ -90,7 +90,7 @@ static bool try_instance(type_context & ctx, expr const & meta, tactic_state con return true; } -bool synth_instances(type_context & ctx, buffer const & metas, buffer const & is_instance, +bool synth_instances(type_context_old & ctx, buffer const & metas, buffer const & is_instance, tactic_state const & s, vm_obj * out_error_obj, char const * tac_name) { unsigned i = is_instance.size(); while (i > 0) { @@ -105,7 +105,7 @@ bool synth_instances(type_context & ctx, buffer const & metas, buffer(?m_1 ...) (?m_2 ... ) ... (?m_k ...), we say ?m_i is "redundant" if it occurs in the type of some ?m_j. This procedure removes from metas any redundant element. */ -static void remove_dep_goals(type_context & ctx, buffer & metas) { +static void remove_dep_goals(type_context_old & ctx, buffer & metas) { unsigned k = 0; for (unsigned i = 0; i < metas.size(); i++) { bool found = false; @@ -125,7 +125,7 @@ static void remove_dep_goals(type_context & ctx, buffer & metas) { metas.shrink(k); } -static void reorder_non_dep_first(type_context & ctx, buffer & metas) { +static void reorder_non_dep_first(type_context_old & ctx, buffer & metas) { buffer non_dep, dep; for (unsigned i = 0; i < metas.size(); i++) { bool found = false; @@ -148,7 +148,7 @@ static void reorder_non_dep_first(type_context & ctx, buffer & metas) { metas.append(dep); } -void collect_new_goals(type_context & ctx, new_goals_kind k, buffer const & metas, buffer & new_goals) { +void collect_new_goals(type_context_old & ctx, new_goals_kind k, buffer const & metas, buffer & new_goals) { for (auto m : metas) { if (!ctx.is_assigned(m)) { ctx.instantiate_mvars_at_type_of(m); @@ -167,7 +167,7 @@ void collect_new_goals(type_context & ctx, new_goals_kind k, buffer const } } -static optional apply(type_context & ctx, expr e, apply_cfg const & cfg, tactic_state const & s, +static optional apply(type_context_old & ctx, expr e, apply_cfg const & cfg, tactic_state const & s, vm_obj * out_error_obj, vm_obj * new_metas) { optional g = s.get_main_goal_decl(); lean_assert(g); @@ -243,11 +243,11 @@ static optional apply(type_context & ctx, expr e, apply_cfg const to_list(new_goals.begin(), new_goals.end(), tail(s.goals())))); } -optional apply(type_context & ctx, expr const & e, apply_cfg const & cfg, tactic_state const & s) { +optional apply(type_context_old & ctx, expr const & e, apply_cfg const & cfg, tactic_state const & s) { return apply(ctx, e, cfg, s, nullptr, nullptr); } -optional apply(type_context & ctx, bool all, bool use_instances, expr const & e, tactic_state const & s) { +optional apply(type_context_old & ctx, bool all, bool use_instances, expr const & e, tactic_state const & s) { apply_cfg cfg; cfg.m_new_goals = all ? new_goals_kind::All : new_goals_kind::NonDepOnly; cfg.m_instances = use_instances; @@ -260,8 +260,8 @@ vm_obj tactic_apply_core(vm_obj const & e, vm_obj const & cfg0, vm_obj const & s optional g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(cfg.m_mode); - type_context::approximate_scope _(ctx, cfg.m_approx); + type_context_old ctx = cache.mk_type_context(cfg.m_mode); + type_context_old::approximate_scope _(ctx, cfg.m_approx); try { vm_obj error_obj; vm_obj new_metas; diff --git a/src/library/tactic/apply_tactic.h b/src/library/tactic/apply_tactic.h index ebbc8b92bc..c808ec1b5d 100644 --- a/src/library/tactic/apply_tactic.h +++ b/src/library/tactic/apply_tactic.h @@ -33,14 +33,14 @@ struct apply_cfg { apply_cfg() {} apply_cfg(vm_obj const & cfg); }; -optional apply(type_context & ctx, expr const & e, apply_cfg const & cfg, tactic_state const & s); +optional apply(type_context_old & ctx, expr const & e, apply_cfg const & cfg, tactic_state const & s); /* For backward compatibility */ -optional apply(type_context & ctx, bool all, bool use_instances, expr const & e, tactic_state const & s); +optional apply(type_context_old & ctx, bool all, bool use_instances, expr const & e, tactic_state const & s); /* Helper functions */ -bool synth_instances(type_context & ctx, buffer const & metas, buffer const & is_instance, +bool synth_instances(type_context_old & ctx, buffer const & metas, buffer const & is_instance, tactic_state const & s, vm_obj * out_error_obj, char const * tac_name); -void collect_new_goals(type_context & ctx, new_goals_kind k, buffer const & metas, buffer & new_goals); +void collect_new_goals(type_context_old & ctx, new_goals_kind k, buffer const & metas, buffer & new_goals); void initialize_apply_tactic(); void finalize_apply_tactic(); diff --git a/src/library/tactic/assert_tactic.cpp b/src/library/tactic/assert_tactic.cpp index 8e5eed0309..064115ad73 100644 --- a/src/library/tactic/assert_tactic.cpp +++ b/src/library/tactic/assert_tactic.cpp @@ -14,7 +14,7 @@ namespace lean { vm_obj assert_define_core(bool is_assert, name const & n, expr const & t, tactic_state const & s) { optional g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); if (!is_sort(ctx.whnf(ctx.infer(t)))) { format msg("invalid "); if (is_assert) msg += format("assert"); else msg += format("define"); @@ -50,7 +50,7 @@ vm_obj tactic_define_core(vm_obj const & n, vm_obj const & t, vm_obj const & s) vm_obj assertv_definev_core(bool is_assert, name const & n, expr const & t, expr const & v, tactic_state const & s) { optional g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); expr v_type = ctx.infer(v); if (!ctx.is_def_eq(t, v_type)) { auto thunk = [=]() { diff --git a/src/library/tactic/backward/backward_chaining.cpp b/src/library/tactic/backward/backward_chaining.cpp index 645d594c39..0abac350d9 100644 --- a/src/library/tactic/backward/backward_chaining.cpp +++ b/src/library/tactic/backward/backward_chaining.cpp @@ -29,7 +29,7 @@ unsigned get_backward_chaining_max_depth(options const & o) { struct back_chaining_fn { tactic_state m_initial_state; - type_context m_ctx; + type_context_old m_ctx; bool m_use_instances; unsigned m_max_depth; vm_obj m_pre_tactic; diff --git a/src/library/tactic/backward/backward_lemmas.cpp b/src/library/tactic/backward/backward_lemmas.cpp index 70d1c26f25..08c0ead35c 100644 --- a/src/library/tactic/backward/backward_lemmas.cpp +++ b/src/library/tactic/backward/backward_lemmas.cpp @@ -21,8 +21,8 @@ Author: Leonardo de Moura #include "library/tactic/backward/backward_lemmas.h" namespace lean { -static optional get_backward_target(type_context & ctx, expr type) { - type_context::tmp_locals locals(ctx); +static optional get_backward_target(type_context_old & ctx, expr type) { + type_context_old::tmp_locals locals(ctx); while (is_pi(type)) { expr local = locals.push_local_from_binding(type); type = ctx.try_to_pi(instantiate(binding_body(type), local)); @@ -34,7 +34,7 @@ static optional get_backward_target(type_context & ctx, expr type) { return optional(); } -static optional get_backward_target(type_context & ctx, name const & c) { +static optional get_backward_target(type_context_old & ctx, name const & c) { declaration const & d = ctx.env().get(c); list us = param_names_to_levels(d.get_univ_params()); expr type = ctx.try_to_pi(instantiate_type_univ_params(d, us)); @@ -92,7 +92,7 @@ unsigned backward_lemma_prio_fn::operator()(backward_lemma const & r) const { return LEAN_DEFAULT_PRIORITY; } -backward_lemma_index::backward_lemma_index(type_context & ctx): +backward_lemma_index::backward_lemma_index(type_context_old & ctx): m_index(get_intro_attribute().get_instances_by_prio(ctx.env())) { buffer lemmas; get_intro_attribute().get_instances(ctx.env(), lemmas); @@ -109,14 +109,14 @@ backward_lemma_index::backward_lemma_index(type_context & ctx): } } -void backward_lemma_index::insert(type_context & ctx, expr const & href) { +void backward_lemma_index::insert(type_context_old & ctx, expr const & href) { expr href_type = ctx.infer(href); if (optional target = get_backward_target(ctx, href_type)) { m_index.insert(*target, backward_lemma(gexpr(href))); } } -void backward_lemma_index::erase(type_context & ctx, expr const & href) { +void backward_lemma_index::erase(type_context_old & ctx, expr const & href) { expr href_type = ctx.infer(href); if (optional target = get_backward_target(ctx, href_type)) { m_index.erase(*target, backward_lemma(gexpr(href))); @@ -149,12 +149,12 @@ vm_obj to_obj(backward_lemma_index const & idx) { } vm_obj tactic_mk_backward_lemmas(vm_obj const & m, vm_obj const & s) { - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); return tactic::mk_success(to_obj(backward_lemma_index(ctx)), tactic::to_state(s)); } vm_obj tactic_backward_lemmas_insert(vm_obj const & m, vm_obj const & lemmas, vm_obj const & lemma, vm_obj const & s) { - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); backward_lemma_index new_lemmas = to_backward_lemmas(lemmas); new_lemmas.insert(ctx, to_expr(lemma)); return tactic::mk_success(to_obj(new_lemmas), tactic::to_state(s)); @@ -174,7 +174,7 @@ void initialize_backward_lemmas() { auto const & data = *get_intro_attribute().get(env, c); if (data.m_eager) return env; // FIXME: support old blast attributes - type_context ctx(env, ios.get_options()); + type_context_old ctx(env, ios.get_options()); auto index = get_backward_target(ctx, c); if (!index || index->kind() != expr_kind::Constant) throw exception( diff --git a/src/library/tactic/backward/backward_lemmas.h b/src/library/tactic/backward/backward_lemmas.h index 37f575b385..5bd3d31536 100644 --- a/src/library/tactic/backward/backward_lemmas.h +++ b/src/library/tactic/backward/backward_lemmas.h @@ -30,9 +30,9 @@ struct backward_lemma_prio_fn { class backward_lemma_index { head_map_prio m_index; public: - backward_lemma_index(type_context & ctx); - void insert(type_context & ctx, expr const & href); - void erase(type_context & ctx, expr const & href); + backward_lemma_index(type_context_old & ctx); + void insert(type_context_old & ctx, expr const & href); + void erase(type_context_old & ctx, expr const & href); list find(head_index const & h) const; }; diff --git a/src/library/tactic/cases_tactic.cpp b/src/library/tactic/cases_tactic.cpp index 4f8491be20..898d40dc29 100644 --- a/src/library/tactic/cases_tactic.cpp +++ b/src/library/tactic/cases_tactic.cpp @@ -56,11 +56,11 @@ struct cases_tactic_fn { declaration m_I_decl; declaration m_cases_on_decl; - type_context mk_type_context_for(metavar_decl const & g) { + type_context_old mk_type_context_for(metavar_decl const & g) { return ::lean::mk_type_context_for(m_env, m_opts, m_mctx, g.get_context(), m_mode); } - type_context mk_type_context_for(expr const & mvar) { + type_context_old mk_type_context_for(expr const & mvar) { return mk_type_context_for(m_mctx.get_metavar_decl(mvar)); } @@ -77,7 +77,7 @@ struct cases_tactic_fn { throw cases_tactic_exception { mk_tactic_state(mvar), [=] { return format(msg); } }; } - #define lean_cases_trace(MVAR, CODE) lean_trace(name({"tactic", "cases"}), type_context TMP_CTX = mk_type_context_for(MVAR); scope_trace_env _scope1(m_env, TMP_CTX); CODE) + #define lean_cases_trace(MVAR, CODE) lean_trace(name({"tactic", "cases"}), type_context_old TMP_CTX = mk_type_context_for(MVAR); scope_trace_env _scope1(m_env, TMP_CTX); CODE) void init_inductive_info(name const & n) { m_nindices = get_ginductive_num_indices(m_env, n); @@ -89,7 +89,7 @@ struct cases_tactic_fn { m_cases_on_decl = m_env.get(get_dep_cases_on(m_env, n)); } - expr whnf_inductive(type_context & ctx, expr const & e) { + expr whnf_inductive(type_context_old & ctx, expr const & e) { if (m_unfold_ginductive) return ctx.relaxed_whnf(e); else @@ -109,7 +109,7 @@ struct cases_tactic_fn { } bool is_cases_applicable(expr const & mvar, expr const & H) { - type_context ctx = mk_type_context_for(mvar); + type_context_old ctx = mk_type_context_for(mvar); expr t = whnf_inductive(ctx, ctx.infer(H)); buffer args; expr const & fn = get_app_args(t, args); @@ -137,7 +137,7 @@ struct cases_tactic_fn { lean_assert(is_local(h)); if (m_nindices == 0) return true; - type_context ctx = mk_type_context_for(g); + type_context_old ctx = mk_type_context_for(g); expr h_type = whnf_inductive(ctx, ctx.infer(h)); buffer args; get_app_args(h_type, args); @@ -164,9 +164,9 @@ struct cases_tactic_fn { return ok; } - pair mk_eq(type_context & ctx, expr const & lhs, expr const & rhs) { + pair mk_eq(type_context_old & ctx, expr const & lhs, expr const & rhs) { // make sure we don't assign regular metavars at is_def_eq - type_context::tmp_mode_scope scope(ctx); + type_context_old::tmp_mode_scope scope(ctx); expr lhs_type = ctx.infer(lhs); expr rhs_type = ctx.infer(rhs); level l = get_level(ctx, lhs_type); @@ -197,7 +197,7 @@ struct cases_tactic_fn { The original goal is solved if we can solve the produced goal. */ expr generalize_indices(expr const & mvar, expr const & h, buffer & new_indices_H, unsigned & num_eqs) { metavar_decl g = m_mctx.get_metavar_decl(mvar); - type_context ctx = mk_type_context_for(g); + type_context_old ctx = mk_type_context_for(g); expr h_type = whnf_inductive(ctx, ctx.infer(h)); buffer I_args; expr const & I = get_app_args(h_type, I_args); @@ -311,7 +311,7 @@ struct cases_tactic_fn { /* Create (f ... x) with the given arity, where the other arguments are inferred using type inference */ - expr mk_inverse(type_context & ctx, inverse_info const & inv, expr const & x) { + expr mk_inverse(type_context_old & ctx, inverse_info const & inv, expr const & x) { buffer mask; mask.resize(inv.m_arity - 1, false); mask.push_back(true); @@ -338,7 +338,7 @@ struct cases_tactic_fn { expr target = g.get_type(); lean_assert(is_pi(target) && is_arrow(target)); if (is_eq(binding_domain(target), lhs, rhs)) { - type_context ctx = mk_type_context_for(mvar); + type_context_old ctx = mk_type_context_for(mvar); expr lhs_n = whnf_gintro_rule(ctx, lhs); expr rhs_n = whnf_gintro_rule(ctx, rhs); if (lhs != lhs_n || rhs != rhs_n) { @@ -358,7 +358,7 @@ struct cases_tactic_fn { local_decl H_decl = g1.get_context().get_last_local_decl(); expr H_type = H_decl.get_type(); expr H = H_decl.mk_ref(); - type_context ctx = mk_type_context_for(*mvar1); + type_context_old ctx = mk_type_context_for(*mvar1); if (is_heq(H_type, A, lhs, B, rhs)) { if (!ctx.is_def_eq(A, B)) { throw_exception(mvar, "cases tactic failed, when processing auxiliary heterogeneous equality"); diff --git a/src/library/tactic/change_tactic.cpp b/src/library/tactic/change_tactic.cpp index c8d9a6ac12..756a53d0e8 100644 --- a/src/library/tactic/change_tactic.cpp +++ b/src/library/tactic/change_tactic.cpp @@ -16,7 +16,7 @@ vm_obj change_core(expr const & e, bool check, tactic_state const & s) { optional g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); if (e == g->get_type()) return tactic::mk_success(s); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); if (!check || ctx.is_def_eq(e, g->get_type())) { expr new_e = ctx.instantiate_mvars(e); expr new_M = ctx.mk_metavar_decl(g->get_context(), new_e); diff --git a/src/library/tactic/congr_lemma_tactics.cpp b/src/library/tactic/congr_lemma_tactics.cpp index a597680df5..33707f8390 100644 --- a/src/library/tactic/congr_lemma_tactics.cpp +++ b/src/library/tactic/congr_lemma_tactics.cpp @@ -42,7 +42,7 @@ static vm_obj mk_result(optional const & l, vm_obj const & s) { vm_obj tactic_mk_congr_lemma_simp(vm_obj const & fn, vm_obj const & nargs, vm_obj const & m, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); if (is_none(nargs)) { return mk_result(mk_congr_simp(ctx, to_expr(fn)), s); } else { @@ -53,14 +53,14 @@ vm_obj tactic_mk_congr_lemma_simp(vm_obj const & fn, vm_obj const & nargs, vm_ob vm_obj tactic_mk_specialized_congr_lemma_simp(vm_obj const & a, vm_obj const & m, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); return mk_result(mk_specialized_congr_simp(ctx, to_expr(a)), s); CATCH; } vm_obj tactic_mk_congr_lemma(vm_obj const & fn, vm_obj const & nargs, vm_obj const & m, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); if (is_none(nargs)) { return mk_result(mk_congr(ctx, to_expr(fn)), s); } else { @@ -71,14 +71,14 @@ vm_obj tactic_mk_congr_lemma(vm_obj const & fn, vm_obj const & nargs, vm_obj con vm_obj tactic_mk_specialized_congr_lemma(vm_obj const & a, vm_obj const & m, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); return mk_result(mk_specialized_congr(ctx, to_expr(a)), s); CATCH; } vm_obj tactic_mk_hcongr_lemma(vm_obj const & fn, vm_obj const & nargs, vm_obj const & m, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); if (is_none(nargs)) { return mk_result(mk_hcongr(ctx, to_expr(fn)), s); } else { diff --git a/src/library/tactic/destruct_tactic.cpp b/src/library/tactic/destruct_tactic.cpp index 4153c5a039..b8b21a48c5 100644 --- a/src/library/tactic/destruct_tactic.cpp +++ b/src/library/tactic/destruct_tactic.cpp @@ -12,7 +12,7 @@ Author: Leonardo de Moura #include "library/tactic/tactic_state.h" namespace lean { -static void add_minors(type_context & ctx, unsigned nminors, expr & cases, buffer & new_goals) { +static void add_minors(type_context_old & ctx, unsigned nminors, expr & cases, buffer & new_goals) { expr cases_type = ctx.infer(cases); for (unsigned i = 0; i < nminors; i++) { cases_type = ctx.relaxed_whnf(cases_type); @@ -30,7 +30,7 @@ tactic_state destruct(transparency_mode md, expr const & e, tactic_state const & if (!s.goals()) throw exception("destruct tactic failed, there are no goals to be solved"); - type_context ctx = mk_type_context_for(s, md); + type_context_old ctx = mk_type_context_for(s, md); environment const & env = ctx.env(); expr target = s.get_main_goal_decl()->get_type(); level target_lvl = get_level(ctx, target); @@ -76,7 +76,7 @@ tactic_state destruct(transparency_mode md, expr const & e, tactic_state const & /* add motive */ buffer refls; /* refl proof for indices and major */ { - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); buffer js; buffer eqs; expr I_A = mk_app(I, I_args.size() - nindices, I_args.data()); @@ -128,7 +128,7 @@ tactic_state destruct(transparency_mode md, expr const & e, tactic_state const & lean_assert(!dep_elim); /* add motive */ { - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); if (nindices > 0) { expr I_A = mk_app(I, I_args.size() - nindices, I_args.data()); expr I_A_type = ctx.infer(I_A); diff --git a/src/library/tactic/dsimplify.cpp b/src/library/tactic/dsimplify.cpp index 6f658c7acd..e40a672027 100644 --- a/src/library/tactic/dsimplify.cpp +++ b/src/library/tactic/dsimplify.cpp @@ -26,7 +26,7 @@ Author: Leonardo de Moura #endif namespace lean { -expr reduce_beta_eta_proj_iota(type_context & ctx, expr e, bool beta, bool eta, bool proj, bool iota) { +expr reduce_beta_eta_proj_iota(type_context_old & ctx, expr e, bool beta, bool eta, bool proj, bool iota) { bool p; do { p = false; @@ -60,7 +60,7 @@ expr reduce_beta_eta_proj_iota(type_context & ctx, expr e, bool beta, bool eta, return e; } -optional unfold_step(type_context & ctx, expr const & e, name_set const & to_unfold, bool unfold_reducible) { +optional unfold_step(type_context_old & ctx, expr const & e, name_set const & to_unfold, bool unfold_reducible) { if (!unfold_reducible && to_unfold.empty()) return none_expr(); if (!is_app(e) && !is_constant(e)) @@ -77,7 +77,7 @@ optional unfold_step(type_context & ctx, expr const & e, name_set const & if (is_projection(ctx.env(), const_name(fn))) { if (in_to_unfold) { - type_context::transparency_scope scope(ctx, transparency_mode::Instances); + type_context_old::transparency_scope scope(ctx, transparency_mode::Instances); return ctx.reduce_projection(e); } else { return none_expr(); @@ -85,7 +85,7 @@ optional unfold_step(type_context & ctx, expr const & e, name_set const & } else if (in_to_unfold) { return unfold_term(ctx.env(), e); } else if (unfold_reducible && is_reducible(ctx.env(), fn_name)) { - type_context::transparency_scope scope(ctx, transparency_mode::Reducible); + type_context_old::transparency_scope scope(ctx, transparency_mode::Reducible); return unfold_term(ctx.env(), e); } else { return none_expr(); @@ -140,7 +140,7 @@ expr dsimplify_core_fn::visit_macro(expr const & e) { expr dsimplify_core_fn::visit_binding(expr const & e) { expr_kind k = e.kind(); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr b = e; bool modified = false; while (b.kind() == k) { @@ -163,7 +163,7 @@ expr dsimplify_core_fn::visit_let(expr const & e) { if (m_cfg.m_zeta) { return visit(instantiate(let_body(e), let_value(e))); } else { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr b = e; bool modified = false; while (is_let(b)) { @@ -297,7 +297,7 @@ expr dsimplify_core_fn::visit(expr const & e) { return curr_e; } -dsimplify_core_fn::dsimplify_core_fn(type_context & ctx, defeq_canonizer::state & dcs, dsimp_config const & cfg): +dsimplify_core_fn::dsimplify_core_fn(type_context_old & ctx, defeq_canonizer::state & dcs, dsimp_config const & cfg): m_ctx(ctx), m_defeq_canonizer(ctx, dcs), m_num_steps(0), m_need_restart(false), m_cfg(cfg) {} expr dsimplify_core_fn::operator()(expr e) { @@ -319,7 +319,7 @@ expr dsimplify_fn::reduce(expr const & e) { } optional> dsimplify_fn::pre(expr const & e) { - type_context::transparency_scope s(m_ctx, m_cfg.m_md); + type_context_old::transparency_scope s(m_ctx, m_cfg.m_md); expr new_e = reduce(e); if (new_e != e) { lean_dsimp_trace(m_ctx, "dsimplify", tout() << "reduce\n" << e << "\n==>\n" << new_e << "\n";); @@ -334,7 +334,7 @@ optional> dsimplify_fn::post(expr const & e) { return optional>(*r, true); expr curr_e; { - type_context::transparency_scope s(m_ctx, m_cfg.m_md); + type_context_old::transparency_scope s(m_ctx, m_cfg.m_md); curr_e = reduce(e); if (curr_e != e) { lean_dsimp_trace(m_ctx, "dsimplify", tout() << "reduce\n" << e << "\n==>\n" << curr_e << "\n";); @@ -370,7 +370,7 @@ optional> dsimplify_fn::post(expr const & e) { return optional>(curr_e, true); } -dsimplify_fn::dsimplify_fn(type_context & ctx, defeq_canonizer::state & dcs, simp_lemmas_for const & lemmas, +dsimplify_fn::dsimplify_fn(type_context_old & ctx, defeq_canonizer::state & dcs, simp_lemmas_for const & lemmas, list const & to_unfold, dsimp_config const & cfg): dsimplify_core_fn(ctx, dcs, cfg), m_simp_lemmas(lemmas), @@ -410,7 +410,7 @@ class tactic_dsimplify_fn : public dsimplify_core_fn { } public: - tactic_dsimplify_fn(type_context & ctx, defeq_canonizer::state & dcs, + tactic_dsimplify_fn(type_context_old & ctx, defeq_canonizer::state & dcs, vm_obj const & a, vm_obj const & pre, vm_obj const & post, tactic_state const & s, dsimp_config const & cfg): dsimplify_core_fn(ctx, dcs, cfg), @@ -430,7 +430,7 @@ vm_obj tactic_dsimplify_core(vm_obj const &, vm_obj const & a, dsimp_config cfg(_cfg); try { tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(cfg.m_md); + type_context_old ctx = cache.mk_type_context(cfg.m_md); defeq_can_state dcs = s.dcs(); tactic_dsimplify_fn F(ctx, dcs, a, pre, post, s, cfg); expr new_e = F(to_expr(e)); @@ -450,7 +450,7 @@ vm_obj simp_lemmas_dsimplify(vm_obj const & lemmas, vm_obj const & u, vm_obj con dsimp_config cfg(_cfg); try { tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(cfg.m_md); + type_context_old ctx = cache.mk_type_context(cfg.m_md); defeq_can_state dcs = s.dcs(); list to_unfold = to_list_name(u); simp_lemmas_for dlemmas; diff --git a/src/library/tactic/dsimplify.h b/src/library/tactic/dsimplify.h index ea289c9b5a..a5d53d33c8 100644 --- a/src/library/tactic/dsimplify.h +++ b/src/library/tactic/dsimplify.h @@ -46,7 +46,7 @@ struct dsimp_config { class dsimplify_core_fn { protected: - type_context & m_ctx; + type_context_old & m_ctx; defeq_canonizer m_defeq_canonizer; expr_struct_map m_cache; unsigned m_num_steps; @@ -65,7 +65,7 @@ protected: expr visit(expr const & e); public: - dsimplify_core_fn(type_context & ctx, defeq_canonizer::state & s, dsimp_config const & cfg); + dsimplify_core_fn(type_context_old & ctx, defeq_canonizer::state & s, dsimp_config const & cfg); expr operator()(expr e); metavar_context const & mctx() const; }; @@ -77,12 +77,12 @@ class dsimplify_fn : public dsimplify_core_fn { virtual optional> pre(expr const & e) override; virtual optional> post(expr const & e) override; public: - dsimplify_fn(type_context & ctx, defeq_canonizer::state & s, + dsimplify_fn(type_context_old & ctx, defeq_canonizer::state & s, simp_lemmas_for const & lemmas, list const & to_unfold, dsimp_config const & cfg); }; -expr reduce_beta_eta_proj_iota(type_context & ctx, expr e, bool beta, bool eta, bool proj, bool iota); -optional unfold_step(type_context & ctx, expr const & e, name_set const & to_unfold, bool unfold_reducible); +expr reduce_beta_eta_proj_iota(type_context_old & ctx, expr e, bool beta, bool eta, bool proj, bool iota); +optional unfold_step(type_context_old & ctx, expr const & e, name_set const & to_unfold, bool unfold_reducible); void initialize_dsimplify(); void finalize_dsimplify(); diff --git a/src/library/tactic/eqn_lemmas.cpp b/src/library/tactic/eqn_lemmas.cpp index 69ea731e55..8d313adba0 100644 --- a/src/library/tactic/eqn_lemmas.cpp +++ b/src/library/tactic/eqn_lemmas.cpp @@ -40,7 +40,7 @@ static environment update(environment const & env, eqn_lemmas_ext const & ext) { } environment add_eqn_lemma_core(environment const & env, name const & eqn_lemma) { - type_context ctx(env, transparency_mode::None); + type_context_old ctx(env, transparency_mode::None); simp_lemmas lemmas = add(ctx, simp_lemmas(), eqn_lemma, LEAN_DEFAULT_PRIORITY); optional new_lemma; lemmas.for_each([&](name const & r, simp_lemma const & sl) { diff --git a/src/library/tactic/eval.cpp b/src/library/tactic/eval.cpp index 8fa6587b56..f301b8e7de 100644 --- a/src/library/tactic/eval.cpp +++ b/src/library/tactic/eval.cpp @@ -22,7 +22,7 @@ static vm_obj eval(expr const & A, expr a, tactic_state const & s) { if (has_local(a) || !closed(a)) return tactic::mk_exception("invalid eval_expr, expression must be closed", s); if (is_constant(a)) { - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); if (!ctx.is_def_eq(A, ctx.infer(a))) return tactic::mk_exception("invalid eval_expr, type mismatch", s); vm_obj r = get_vm_state().get_constant(const_name(a)); diff --git a/src/library/tactic/exact_tactic.cpp b/src/library/tactic/exact_tactic.cpp index 794d8c915a..342e8d146e 100644 --- a/src/library/tactic/exact_tactic.cpp +++ b/src/library/tactic/exact_tactic.cpp @@ -15,7 +15,7 @@ static vm_obj exact(expr const & e, transparency_mode const & m, tactic_state s) optional g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(m); + type_context_old ctx = cache.mk_type_context(m); expr mvar = head(s.goals()); if (is_metavar(e) && mlocal_name(mvar) == mlocal_name(e)) { return tactic::mk_exception("invalid exact tactic, trying to solve goal using itself", s); @@ -37,7 +37,7 @@ static vm_obj exact(expr const & e, transparency_mode const & m, tactic_state s) auto thunk = [=]() { format r("exact tactic failed, failed to assign "); formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); - type_context ctx = mk_cacheless_type_context_for(s, transparency_mode::All); + type_context_old ctx = mk_cacheless_type_context_for(s, transparency_mode::All); formatter fmt = fmtf(s.env(), s.get_options(), ctx); unsigned indent = get_pp_indent(s.get_options()); r += nest(indent, line() + fmt(e)); diff --git a/src/library/tactic/fun_info_tactics.cpp b/src/library/tactic/fun_info_tactics.cpp index 7e34904627..e2e24bacbd 100644 --- a/src/library/tactic/fun_info_tactics.cpp +++ b/src/library/tactic/fun_info_tactics.cpp @@ -62,7 +62,7 @@ static vm_obj mk_result(list const & info, vm_obj const & s) { vm_obj tactic_get_fun_info(vm_obj const & fn, vm_obj const & n, vm_obj const & m, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); if (is_none(n)) { return mk_result(get_fun_info(ctx, to_expr(fn)), s); } else { @@ -73,7 +73,7 @@ vm_obj tactic_get_fun_info(vm_obj const & fn, vm_obj const & n, vm_obj const & m vm_obj tactic_get_subsingleton_info(vm_obj const & fn, vm_obj const & n, vm_obj const & m, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); if (is_none(n)) { return mk_result(get_subsingleton_info(ctx, to_expr(fn)), s); } else { @@ -84,14 +84,14 @@ vm_obj tactic_get_subsingleton_info(vm_obj const & fn, vm_obj const & n, vm_obj vm_obj tactic_get_spec_subsingleton_info(vm_obj const & app, vm_obj const & m, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); return mk_result(get_specialized_subsingleton_info(ctx, to_expr(app)), s); CATCH; } vm_obj tactic_get_spec_prefix_size(vm_obj const & fn, vm_obj const & n, vm_obj const & m, vm_obj const & s) { TRY; - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); return tactic::mk_success(mk_vm_nat(get_specialization_prefix_size(ctx, to_expr(fn), force_to_unsigned(n, 0))), tactic::to_state(s)); CATCH; diff --git a/src/library/tactic/generalize_tactic.cpp b/src/library/tactic/generalize_tactic.cpp index 9d6f0a58cc..5d8b369a0e 100644 --- a/src/library/tactic/generalize_tactic.cpp +++ b/src/library/tactic/generalize_tactic.cpp @@ -16,7 +16,7 @@ static vm_obj generalize(transparency_mode m, expr const & e, name const & id, t optional g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(m); + type_context_old ctx = cache.mk_type_context(m); expr target = ctx.instantiate_mvars(g->get_type()); expr target_abst = kabstract(ctx, target, e); if (closed(target_abst)) diff --git a/src/library/tactic/gexpr.cpp b/src/library/tactic/gexpr.cpp index c883ba3f3e..322b5dcea6 100644 --- a/src/library/tactic/gexpr.cpp +++ b/src/library/tactic/gexpr.cpp @@ -7,7 +7,7 @@ Author: Leonardo de Moura #include "library/tactic/gexpr.h" namespace lean { -expr gexpr::to_expr(type_context & ctx) const { +expr gexpr::to_expr(type_context_old & ctx) const { if (m_univ_poly) { declaration const & fdecl = ctx.env().get(const_name(m_expr)); buffer ls_buffer; diff --git a/src/library/tactic/gexpr.h b/src/library/tactic/gexpr.h index 0fbf4d8ea6..565efa3ea7 100644 --- a/src/library/tactic/gexpr.h +++ b/src/library/tactic/gexpr.h @@ -33,7 +33,7 @@ public: /** \brief Convert generalized expression into a regular expression. If it is universe polymorphic, we accomplish that by creating meta-variables using \c mctx. */ - expr to_expr(type_context & ctx) const; + expr to_expr(type_context_old & ctx) const; /** \brief Return "bare" expression (without adding fresh metavariables if universe polymorphic) */ expr to_bare_expr() const { return m_expr; } diff --git a/src/library/tactic/induction_tactic.cpp b/src/library/tactic/induction_tactic.cpp index 2640f92359..0f21a0c56c 100644 --- a/src/library/tactic/induction_tactic.cpp +++ b/src/library/tactic/induction_tactic.cpp @@ -33,7 +33,7 @@ static name * g_induction_concat = nullptr; throw exception(sstream() << "induction tactic failed, recursor '" << rec_info.get_name() << "' is ill-formed"); } -static void set_intron(expr & R, type_context & ctx, options const & opts, expr const & M, unsigned n, optional const & prefix, list & ns, buffer & new_names, bool use_unused_names) { +static void set_intron(expr & R, type_context_old & ctx, options const & opts, expr const & M, unsigned n, optional const & prefix, list & ns, buffer & new_names, bool use_unused_names) { if (n == 0) { R = M; } else { @@ -71,12 +71,12 @@ static void set_intron(expr & R, type_context & ctx, options const & opts, expr } } -static void set_intron(expr & R, type_context & ctx, options const & opts, expr const & M, unsigned n, buffer & new_names, bool use_unused_names) { +static void set_intron(expr & R, type_context_old & ctx, options const & opts, expr const & M, unsigned n, buffer & new_names, bool use_unused_names) { list tmp; set_intron(R, ctx, opts, M, n, optional(), tmp, new_names, use_unused_names); } -static void set_clear(expr & R, type_context & ctx, expr const & M, expr const & H) { +static void set_clear(expr & R, type_context_old & ctx, expr const & M, expr const & H) { try { metavar_context mctx = ctx.mctx(); R = clear(mctx, M, H); @@ -111,8 +111,8 @@ static void throw_invalid_major_premise_type(unsigned arg_idx, expr const & H_ty throw_invalid_major_premise_type(arg_idx, H_type, strm.str().c_str()); } -static expr whnf_until(type_context & ctx, name const & n, expr const & e) { - type_context::transparency_scope scope(ctx, transparency_mode::All); +static expr whnf_until(type_context_old & ctx, name const & n, expr const & e) { + type_context_old::transparency_scope scope(ctx, transparency_mode::All); return ctx.whnf_head_pred(e, [&](expr const & t) { expr fn = get_app_fn(t); if (is_constant(fn) && const_name(fn) == n) @@ -139,7 +139,7 @@ list induction(environment const & env, options const & opts, transparency } recursor_info rec_info = get_recursor_info(env, rec_name); - type_context ctx1 = mk_type_context_for(env, opts, mctx, g->get_context(), m); + type_context_old ctx1 = mk_type_context_for(env, opts, mctx, g->get_context(), m); expr H_type = whnf_until(ctx1, rec_info.get_type_name(), ctx1.infer(H)); buffer H_type_args; @@ -203,7 +203,7 @@ list induction(environment const & env, options const & opts, transparency } optional g2 = mctx.find_metavar_decl(*mvar2); lean_assert(g2); - type_context ctx2 = mk_type_context_for(env, opts, mctx, g2->get_context(), m); + type_context_old ctx2 = mk_type_context_for(env, opts, mctx, g2->get_context(), m); local_context lctx2 = g2->get_context(); indices.clear(); /* update indices buffer */ for (unsigned i = 0; i < indices_H.size() - 1; i++) @@ -420,7 +420,7 @@ vm_obj induction_tactic_core(transparency_mode const & m, expr const & H, name c vm_obj tactic_induction(vm_obj const & H, vm_obj const & ns, vm_obj const & rec, vm_obj const & m, vm_obj const & s) { if (is_none(rec)) { try { - type_context ctx = mk_type_context_for(s, m); + type_context_old ctx = mk_type_context_for(s, m); expr type = whnf_ginductive(ctx, ctx.infer(to_expr(H))); expr C = get_app_fn(type); if (is_constant(C)) { diff --git a/src/library/tactic/intro_tactic.cpp b/src/library/tactic/intro_tactic.cpp index 3032632e75..1933793c08 100644 --- a/src/library/tactic/intro_tactic.cpp +++ b/src/library/tactic/intro_tactic.cpp @@ -20,9 +20,9 @@ optional intron_core(environment const & env, options const & opts, metava lean_assert(is_metavar(mvar)); optional g = mctx.find_metavar_decl(mvar); if (!g) return none_expr(); - type_context ctx = mk_type_context_for(env, opts, mctx, g->get_context()); + type_context_old ctx = mk_type_context_for(env, opts, mctx, g->get_context()); expr type = g->get_type(); - type_context::tmp_locals new_locals(ctx); + type_context_old::tmp_locals new_locals(ctx); buffer new_Hs; for (unsigned i = 0; i < n; i++) { if (!is_pi(type) && !is_let(type)) { @@ -140,7 +140,7 @@ vm_obj tactic_intron(vm_obj const & num, vm_obj const & s) { vm_obj intro(name const & n, tactic_state const & s) { optional g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); expr type = g->get_type(); if (!is_pi(type) && !is_let(type)) { type = ctx.whnf(type); diff --git a/src/library/tactic/kabstract.cpp b/src/library/tactic/kabstract.cpp index 16142a7fef..04064fb5c2 100644 --- a/src/library/tactic/kabstract.cpp +++ b/src/library/tactic/kabstract.cpp @@ -154,7 +154,7 @@ void for_each_key_equivalence(environment const & env, std::function level2meta; typedef rb_expr_map expr2meta; - type_context m_ctx; + type_context_old m_ctx; level2meta m_level2meta; expr2meta m_expr2meta; level_set m_found_levels; @@ -151,8 +151,8 @@ vm_obj tactic_match_pattern(vm_obj const & p, vm_obj const & e, vm_obj const & m TRY; expr t; list uos; list os; unsigned nuvars, nmvars; get_pattern_fields(p, t, uos, os, nuvars, nmvars); - type_context ctx = mk_type_context_for(s, m); - type_context::tmp_mode_scope scope(ctx, nuvars, nmvars); + type_context_old ctx = mk_type_context_for(s, m); + type_context_old::tmp_mode_scope scope(ctx, nuvars, nmvars); if (ctx.is_def_eq(t, to_expr(e))) { for (unsigned i = 0; i < nuvars; i++) { if (!ctx.get_tmp_uvar_assignment(i)) diff --git a/src/library/tactic/norm_num_tactic.cpp b/src/library/tactic/norm_num_tactic.cpp index 93a0c2ecfb..2aeb8de7ad 100644 --- a/src/library/tactic/norm_num_tactic.cpp +++ b/src/library/tactic/norm_num_tactic.cpp @@ -11,7 +11,7 @@ Authors: Robert Y. Lewis, Leonardo de Moura namespace lean { vm_obj tactic_norm_num(vm_obj const & e, vm_obj const & _s) { tactic_state const & s = tactic::to_state(_s); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); try { pair p = mk_norm_num(ctx, to_expr(e)); return tactic::mk_success(mk_vm_pair(to_obj(p.first), to_obj(p.second)), s); diff --git a/src/library/tactic/revert_tactic.cpp b/src/library/tactic/revert_tactic.cpp index 95abeedacf..13af37afbf 100644 --- a/src/library/tactic/revert_tactic.cpp +++ b/src/library/tactic/revert_tactic.cpp @@ -13,7 +13,7 @@ expr revert(environment const & env, options const & opts, metavar_context & mct bool preserve_locals_order) { optional g = mctx.find_metavar_decl(mvar); lean_assert(g); - type_context ctx = mk_type_context_for(env, opts, mctx, g->get_context(), transparency_mode::All); + type_context_old ctx = mk_type_context_for(env, opts, mctx, g->get_context(), transparency_mode::All); expr val = ctx.revert(locals, mvar, preserve_locals_order); expr new_g = get_app_fn(val); mctx = ctx.mctx(); diff --git a/src/library/tactic/rewrite_tactic.cpp b/src/library/tactic/rewrite_tactic.cpp index 222d640cec..4b1a9b4bba 100644 --- a/src/library/tactic/rewrite_tactic.cpp +++ b/src/library/tactic/rewrite_tactic.cpp @@ -33,8 +33,8 @@ static vm_obj rewrite_core(expr h, expr e, rewrite_cfg const & cfg, tactic_state optional g = s.get_main_goal_decl(); if (!g) return mk_no_goals_exception(s); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(cfg.m_mode); - type_context::approximate_scope _(ctx, cfg.m_approx); + type_context_old ctx = cache.mk_type_context(cfg.m_mode); + type_context_old::approximate_scope _(ctx, cfg.m_approx); expr h_type = ctx.infer(h); /* Generate meta-variables for arguments */ buffer metas; @@ -90,7 +90,7 @@ static vm_obj rewrite_core(expr h, expr e, rewrite_cfg const & cfg, tactic_state expr e_eq_e_abst = mk_app(app_fn(e_eq_e), e_abst); expr motive = mk_lambda("_a", A, e_eq_e_abst); try { - type_context::transparency_scope scope(ctx, ensure_semireducible_mode(ctx.mode())); + type_context_old::transparency_scope scope(ctx, ensure_semireducible_mode(ctx.mode())); check(ctx, motive); } catch (exception & ex) { throw nested_exception("rewrite tactic failed, motive is not type correct", ex); diff --git a/src/library/tactic/simp_lemmas.cpp b/src/library/tactic/simp_lemmas.cpp index 790deb9c39..b09244b1c8 100644 --- a/src/library/tactic/simp_lemmas.cpp +++ b/src/library/tactic/simp_lemmas.cpp @@ -422,7 +422,7 @@ bool is_simp_relation(environment const & env, expr const & e, expr & lhs, expr return is_simp_relation(env, e, rel, lhs, rhs); } -static bool is_ceqv(type_context & ctx, name const & id, expr e); +static bool is_ceqv(type_context_old & ctx, name const & id, expr e); /** \brief Auxiliary functional object for creating "conditional equations" @@ -431,7 +431,7 @@ static bool is_ceqv(type_context & ctx, name const & id, expr e); */ class to_ceqvs_fn { environment const & m_env; - type_context & m_ctx; + type_context_old & m_ctx; static list mk_singleton(expr const & e, expr const & H) { return list(mk_pair(e, H)); @@ -493,7 +493,7 @@ class to_ceqvs_fn { } else if (auto arg = is_auto_param(e)) { return apply(arg->first, H, restricted); } else if (is_pi(e)) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr local = locals.push_local_from_binding(e); expr new_e = instantiate(binding_body(e), local); expr new_H = mk_app(H, local); @@ -508,7 +508,7 @@ class to_ceqvs_fn { } } else if (is_ite(e, c, Hdec, A, arg1, arg2) && is_prop(e)) { expr not_c = mk_app(mk_constant(get_not_name()), c); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr Hc = locals.push_local(name(), c); expr Hnc = locals.push_local(name(), not_c); expr H1 = mk_app({mk_constant(get_implies_of_if_pos_name()), c, arg1, arg2, Hdec, e, Hc}); @@ -547,7 +547,7 @@ class to_ceqvs_fn { } public: - to_ceqvs_fn(type_context & ctx):m_env(ctx.env()), m_ctx(ctx) {} + to_ceqvs_fn(type_context_old & ctx):m_env(ctx.env()), m_ctx(ctx) {} list operator()(name const & id, expr const & e, expr const & H) { bool restricted = false; @@ -557,11 +557,11 @@ public: } }; -static list to_ceqvs(type_context & ctx, name const & id, expr const & e, expr const & H) { +static list to_ceqvs(type_context_old & ctx, name const & id, expr const & e, expr const & H) { return to_ceqvs_fn(ctx)(id, e, H); } -static bool is_ceqv(type_context & ctx, name const & id, expr e) { +static bool is_ceqv(type_context_old & ctx, name const & id, expr e) { name_set to_find; // Define a procedure for removing arguments from to_find. auto visitor_fn = [&](expr const & e, unsigned) { @@ -576,7 +576,7 @@ static bool is_ceqv(type_context & ctx, name const & id, expr e) { }; environment const & env = ctx.env(); buffer hypotheses; // arguments that are propositions - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); while (is_pi(e)) { if (!to_find.empty()) { // Support for dependent types. @@ -699,7 +699,7 @@ static bool is_refl_app(expr const & pr) { return is_constant(fn) && const_name(fn) == get_eq_refl_name(); } -static simp_lemmas add_core(type_context & ctx, simp_lemmas const & s, name const & id, +static simp_lemmas add_core(type_context_old & ctx, simp_lemmas const & s, name const & id, levels const & univ_metas, buffer const & _emetas, expr const & e, expr const & h, unsigned priority) { lean_assert(ctx.in_tmp_mode()); @@ -744,13 +744,13 @@ static simp_lemmas add_core(type_context & ctx, simp_lemmas const & s, name cons return new_s; } -static simp_lemmas add_core(type_context & ctx, simp_lemmas const & s, name const & id, +static simp_lemmas add_core(type_context_old & ctx, simp_lemmas const & s, name const & id, buffer const & univ_metas, buffer const & emetas, expr const & e, expr const & h, unsigned priority) { return add_core(ctx, s, id, to_list(univ_metas), emetas, e, h, priority); } -static simp_lemmas add_core(type_context & ctx, simp_lemmas const & s, name const & id, levels const & univ_metas, +static simp_lemmas add_core(type_context_old & ctx, simp_lemmas const & s, name const & id, levels const & univ_metas, expr const & e, expr const & h, unsigned priority) { buffer emetas; return add_core(ctx, s, id, univ_metas, emetas, e, h, priority); @@ -772,7 +772,7 @@ bool is_rfl_lemma(environment const & env, name const & cname) { return get_refl_lemma_attribute().is_instance(env, cname); } -static levels mk_tmp_levels_for(type_context & ctx, declaration const & d) { +static levels mk_tmp_levels_for(type_context_old & ctx, declaration const & d) { buffer us; unsigned num_univs = d.get_num_univ_params(); for (unsigned i = 0; i < num_univs; i++) { @@ -781,9 +781,9 @@ static levels mk_tmp_levels_for(type_context & ctx, declaration const & d) { return to_list(us); } -static simp_lemmas add_core(type_context & ctx, simp_lemmas const & s, name const & cname, unsigned priority) { +static simp_lemmas add_core(type_context_old & ctx, simp_lemmas const & s, name const & cname, unsigned priority) { environment const & env = ctx.env(); - type_context::tmp_mode_scope scope(ctx); + type_context_old::tmp_mode_scope scope(ctx); declaration const & d = env.get(cname); levels ls = mk_tmp_levels_for(ctx, d); expr type = instantiate_type_univ_params(d, ls); @@ -811,7 +811,7 @@ static simp_lemmas add_core(type_context & ctx, simp_lemmas const & s, name cons /* Extended version. If cname is a definition with equational lemmas associated to it, then add the equational lemmas. */ -static simp_lemmas ext_add_core(type_context & ctx, simp_lemmas const & s, name const & cname, unsigned priority) { +static simp_lemmas ext_add_core(type_context_old & ctx, simp_lemmas const & s, name const & cname, unsigned priority) { simp_lemmas r = s; // Note: for relations that are not in Prop, the definition will be both @@ -886,8 +886,8 @@ static bool is_valid_congr_hyp_rhs(expr const & rhs, name_set & found_mvars) { return true; } -static simp_lemmas add_congr_core(type_context & ctx, simp_lemmas const & s, name const & n, unsigned prio) { - type_context::tmp_mode_scope scope(ctx); +static simp_lemmas add_congr_core(type_context_old & ctx, simp_lemmas const & s, name const & n, unsigned prio) { + type_context_old::tmp_mode_scope scope(ctx); declaration const & d = ctx.env().get(n); buffer us; unsigned num_univs = d.get_num_univ_params(); @@ -968,7 +968,7 @@ static simp_lemmas add_congr_core(type_context & ctx, simp_lemmas const & s, nam expr const & mvar = emetas[i]; if (explicits[i] && !found_mvars.contains(mlocal_name(mvar))) { expr type = mlocal_type(mvar); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); while (is_pi(type)) { expr local = locals.push_local_from_binding(type); type = instantiate(binding_body(type), local); @@ -1006,12 +1006,12 @@ static simp_lemmas add_congr_core(type_context & ctx, simp_lemmas const & s, nam return new_s; } -simp_lemmas add(type_context & ctx, simp_lemmas const & s, name const & id, unsigned priority) { +simp_lemmas add(type_context_old & ctx, simp_lemmas const & s, name const & id, unsigned priority) { return ext_add_core(ctx, s, id, priority); } -simp_lemmas add(type_context & ctx, simp_lemmas const & s, name const & id, expr const & e, expr const & h, unsigned priority) { - type_context::tmp_mode_scope scope(ctx); +simp_lemmas add(type_context_old & ctx, simp_lemmas const & s, name const & id, expr const & e, expr const & h, unsigned priority) { + type_context_old::tmp_mode_scope scope(ctx); auto r = add_core(ctx, s, id, list(), e, h, priority); if (is_eqp(r, s)) { report_failure(sstream() << "invalid simplification lemma '" << id << "': " << e); @@ -1019,7 +1019,7 @@ simp_lemmas add(type_context & ctx, simp_lemmas const & s, name const & id, expr return r; } -simp_lemmas add_congr(type_context & ctx, simp_lemmas const & s, name const & id, unsigned priority) { +simp_lemmas add_congr(type_context_old & ctx, simp_lemmas const & s, name const & id, unsigned priority) { return add_congr_core(ctx, s, id, priority); } @@ -1046,20 +1046,20 @@ simp_lemmas join(simp_lemmas const & s1, simp_lemmas const & s2) { } static void on_add_simp_lemma(environment const & env, name const & c, bool) { - type_context ctx(env); + type_context_old ctx(env); simp_lemmas s; flet set_ex(g_throw_ex, true); ext_add_core(ctx, s, c, LEAN_DEFAULT_PRIORITY); } static void on_add_congr_lemma(environment const & env, name const & c, bool) { - type_context ctx(env); + type_context_old ctx(env); simp_lemmas s; flet set_ex(g_throw_ex, true); add_congr_core(ctx, s, c, LEAN_DEFAULT_PRIORITY); } -static simp_lemmas get_simp_lemmas_from_attribute(type_context & ctx, name const & attr_name, simp_lemmas result) { +static simp_lemmas get_simp_lemmas_from_attribute(type_context_old & ctx, name const & attr_name, simp_lemmas result) { auto const & attr = get_attribute(ctx.env(), attr_name); buffer simp_lemmas; attr.get_instances(ctx.env(), simp_lemmas); @@ -1072,7 +1072,7 @@ static simp_lemmas get_simp_lemmas_from_attribute(type_context & ctx, name const return result; } -static simp_lemmas get_congr_lemmas_from_attribute(type_context & ctx, name const & attr_name, simp_lemmas result) { +static simp_lemmas get_congr_lemmas_from_attribute(type_context_old & ctx, name const & attr_name, simp_lemmas result) { auto const & attr = get_attribute(ctx.env(), attr_name); buffer congr_lemmas; attr.get_instances(ctx.env(), congr_lemmas); @@ -1142,7 +1142,7 @@ public: simp_lemmas mk_lemmas(environment const & env, entry & C, simp_lemmas_token tk) { lean_trace("simp_lemmas_cache", tout() << "make simp lemmas [" << tk << "]\n";); - type_context ctx(env); + type_context_old ctx(env); C.m_env = env; auto & cfg = get_simp_lemmas_config(tk); simp_lemmas lemmas; @@ -1218,7 +1218,7 @@ simp_lemmas get_simp_lemmas(environment const & env, name const & tk_name) { throw exception(sstream() << "unknown simp_lemmas collection '" << tk_name << "'"); } -static bool instantiate_emetas(type_context & ctx, list const & _emetas, list const & _instances) { +static bool instantiate_emetas(type_context_old & ctx, list const & _emetas, list const & _instances) { buffer emetas; buffer instances; to_buffer(_emetas, emetas); @@ -1256,9 +1256,9 @@ static bool instantiate_emetas(type_context & ctx, list const & _emetas, l return true; } -static expr refl_lemma_rewrite_core(type_context & ctx, expr const & e, simp_lemma const & sl) { +static expr refl_lemma_rewrite_core(type_context_old & ctx, expr const & e, simp_lemma const & sl) { lean_assert(sl.is_refl()); - type_context::tmp_mode_scope scope(ctx, sl.get_num_umeta(), sl.get_num_emeta()); + type_context_old::tmp_mode_scope scope(ctx, sl.get_num_umeta(), sl.get_num_emeta()); if (!ctx.is_def_eq(sl.get_lhs(), e)) return e; @@ -1277,7 +1277,7 @@ static expr refl_lemma_rewrite_core(type_context & ctx, expr const & e, simp_lem return ctx.instantiate_mvars(sl.get_rhs()); } -expr refl_lemma_rewrite(type_context & ctx, expr const & e, simp_lemma const & sl) { +expr refl_lemma_rewrite(type_context_old & ctx, expr const & e, simp_lemma const & sl) { if (!is_app(e)) return refl_lemma_rewrite_core(ctx, e, sl); unsigned e_nargs = get_app_num_args(e); @@ -1336,7 +1336,7 @@ vm_obj simp_lemmas_add(vm_obj const & lemmas, vm_obj const & lemma, vm_obj const tactic_state s = tactic::to_state(s0); LEAN_TACTIC_TRY; tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); expr e = to_expr(lemma); name id; if (is_constant(e)) @@ -1350,7 +1350,7 @@ vm_obj simp_lemmas_add(vm_obj const & lemmas, vm_obj const & lemma, vm_obj const buffer umetas; buffer emetas; e = to_idx_metavars(ctx.mctx(), e, umetas, emetas); - type_context::tmp_mode_scope scope(ctx, umetas.size(), emetas.size()); + type_context_old::tmp_mode_scope scope(ctx, umetas.size(), emetas.size()); expr e_type = ctx.infer(e); simp_lemmas new_lemmas = add_core(ctx, to_simp_lemmas(lemmas), id, umetas, emetas, e_type, e, LEAN_DEFAULT_PRIORITY); @@ -1362,7 +1362,7 @@ vm_obj simp_lemmas_add_simp(vm_obj const & lemmas, vm_obj const & lemma_name, vm tactic_state s = tactic::to_state(s0); LEAN_TACTIC_TRY; tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); simp_lemmas new_lemmas = add(ctx, to_simp_lemmas(lemmas), to_name(lemma_name), LEAN_DEFAULT_PRIORITY); return tactic::mk_success(to_obj(new_lemmas), s); LEAN_TACTIC_CATCH(s); @@ -1372,7 +1372,7 @@ vm_obj simp_lemmas_add_congr(vm_obj const & lemmas, vm_obj const & lemma_name, v tactic_state s = tactic::to_state(s0); LEAN_TACTIC_TRY; tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); simp_lemmas new_lemmas = add_congr(ctx, to_simp_lemmas(lemmas), to_name(lemma_name), LEAN_DEFAULT_PRIORITY); return tactic::mk_success(to_obj(new_lemmas), s); LEAN_TACTIC_CATCH(s); @@ -1423,7 +1423,7 @@ static bool instantiate_emetas(tmp_type_context & tmp_ctx, vm_obj const & prove_ } -static simp_result simp_lemma_rewrite_core(type_context & ctx, simp_lemma const & sl, vm_obj const & prove_fn, +static simp_result simp_lemma_rewrite_core(type_context_old & ctx, simp_lemma const & sl, vm_obj const & prove_fn, expr const & e, tactic_state const & s) { tmp_type_context tmp_ctx(ctx, sl.get_num_umeta(), sl.get_num_emeta()); if (!tmp_ctx.is_def_eq(sl.get_lhs(), e)) { @@ -1464,7 +1464,7 @@ static vm_obj simp_lemmas_rewrite_core(transparency_mode const & m, simp_lemmas if (!srs) return tactic::mk_exception("failed to apply simp_lemmas, no simp lemma", s); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(m); + type_context_old ctx = cache.mk_type_context(m); for (simp_lemma const & lemma : *srs) { simp_result r = simp_lemma_rewrite_core(ctx, lemma, prove_fn, e, s); @@ -1495,7 +1495,7 @@ static vm_obj simp_lemmas_drewrite_core(transparency_mode const & m, simp_lemmas if (!srs) return tactic::mk_exception("failed to apply simp_lemmas, no simp lemma", s); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(m); + type_context_old ctx = cache.mk_type_context(m); for (simp_lemma const & lemma : *srs) { if (lemma.is_refl()) { @@ -1515,8 +1515,8 @@ vm_obj simp_lemmas_drewrite(vm_obj const & sls, vm_obj const & e, vm_obj const & static bool is_valid_simp_lemma_cnst(name const & cname, tactic_state s) { try { tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); - type_context::tmp_mode_scope scope(ctx); + type_context_old ctx = cache.mk_type_context(); + type_context_old::tmp_mode_scope scope(ctx); declaration const & d = ctx.env().get(cname); levels ls = mk_tmp_levels_for(ctx, d); expr type = instantiate_type_univ_params(d, ls); @@ -1535,7 +1535,7 @@ vm_obj is_valid_simp_lemma_cnst(vm_obj const & n, vm_obj const & s) { static bool is_valid_simp_lemma(expr const & e, tactic_state s) { try { tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); expr type = ctx.infer(e); return !is_nil(to_ceqvs(ctx, name(), type, e)); } catch (exception &) { @@ -1562,7 +1562,7 @@ vm_obj simp_lemmas_pp(vm_obj const & S, vm_obj const & _s) { formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); tactic_state s = tactic::to_state(_s); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); formatter fmt = fmtf(s.env(), s.get_options(), ctx); format r = to_simp_lemmas(S).pp(fmt); return tactic::mk_success(to_obj(r), s); diff --git a/src/library/tactic/simp_lemmas.h b/src/library/tactic/simp_lemmas.h index 0d2b102f24..438deb03aa 100644 --- a/src/library/tactic/simp_lemmas.h +++ b/src/library/tactic/simp_lemmas.h @@ -137,9 +137,9 @@ simp_lemmas get_simp_lemmas(environment const & env, simp_lemmas_token tk); simp_lemmas get_default_simp_lemmas(environment const & env); simp_lemmas get_simp_lemmas(environment const & env, name const & tk_name); -simp_lemmas add(type_context & ctx, simp_lemmas const & s, name const & id, unsigned priority); -simp_lemmas add(type_context & ctx, simp_lemmas const & s, name const & id, expr const & e, expr const & h, unsigned priority); -simp_lemmas add_congr(type_context & ctx, simp_lemmas const & s, name const & id, unsigned priority); +simp_lemmas add(type_context_old & ctx, simp_lemmas const & s, name const & id, unsigned priority); +simp_lemmas add(type_context_old & ctx, simp_lemmas const & s, name const & id, expr const & e, expr const & h, unsigned priority); +simp_lemmas add_congr(type_context_old & ctx, simp_lemmas const & s, name const & id, unsigned priority); simp_lemmas join(simp_lemmas const & s1, simp_lemmas const & s2); /** \brief Return true iff 'e' is of the form 'lhs rel rhs' where rel is a transitive and reflexive @@ -148,7 +148,7 @@ bool is_simp_relation(environment const & env, expr const & e, expr & rel, expr /** \brief Rewrite 'e' using the given refl lemma. \pre sl.is_refl() */ -expr refl_lemma_rewrite(type_context & ctx, expr const & e, simp_lemma const & sl); +expr refl_lemma_rewrite(type_context_old & ctx, expr const & e, simp_lemma const & sl); bool is_simp_lemmas(vm_obj const & o); simp_lemmas const & to_simp_lemmas(vm_obj const & o); diff --git a/src/library/tactic/simp_result.cpp b/src/library/tactic/simp_result.cpp index 44716befac..7823e0091d 100644 --- a/src/library/tactic/simp_result.cpp +++ b/src/library/tactic/simp_result.cpp @@ -9,13 +9,13 @@ Author: Daniel Selsam namespace lean { -simp_result finalize(type_context & tctx, name const & rel, simp_result const & r) { +simp_result finalize(type_context_old & tctx, name const & rel, simp_result const & r) { if (r.has_proof()) return r; expr pf = mk_refl(tctx, rel, r.get_new()); return simp_result(r.get_new(), pf); } -simp_result join(type_context & tctx, name const & rel, simp_result const & r1, simp_result const & r2) { +simp_result join(type_context_old & tctx, name const & rel, simp_result const & r1, simp_result const & r2) { /* Assumes that both simp_results are with respect to the same relation */ if (!r1.has_proof()) { return r2; diff --git a/src/library/tactic/simp_result.h b/src/library/tactic/simp_result.h index e5f5e88386..574ab58849 100644 --- a/src/library/tactic/simp_result.h +++ b/src/library/tactic/simp_result.h @@ -36,8 +36,8 @@ public: bool is_done() const { return m_done; } }; -simp_result finalize(type_context & tctx, name const & rel, simp_result const & r); -simp_result join(type_context & tctx, name const & rel, simp_result const & r1, simp_result const & r2); +simp_result finalize(type_context_old & tctx, name const & rel, simp_result const & r); +simp_result join(type_context_old & tctx, name const & rel, simp_result const & r1, simp_result const & r2); simp_result finalize_eq(abstract_type_context & tctx, simp_result const & r); simp_result join_eq(abstract_type_context & tctx, simp_result const & r1, simp_result const & r2); diff --git a/src/library/tactic/simplify.cpp b/src/library/tactic/simplify.cpp index 6dd58648fd..aa37365100 100644 --- a/src/library/tactic/simplify.cpp +++ b/src/library/tactic/simplify.cpp @@ -252,11 +252,11 @@ simp_result simplify_core_fn::try_user_congr(expr const & e, simp_lemma const & buffer congr_hyps; to_buffer(cl.get_congr_hyps(), congr_hyps); - buffer factories; + buffer factories; buffer relations; for (expr const & m : congr_hyps) { factories.emplace_back(m_ctx); - type_context::tmp_locals & local_factory = factories.back(); + type_context_old::tmp_locals & local_factory = factories.back(); expr m_type = tmp_ctx.instantiate_mvars(tmp_ctx.infer(m)); while (is_pi(m_type)) { @@ -811,7 +811,7 @@ bool simplify_core_fn::simplify_constructor_eq_constructor(simp_result & r) { if (!inj_decl) return false; unsigned inj_arity = get_arity(inj_decl->get_type()); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr H = locals.push_local("_h", r.get_new()); expr inj = mk_app(m_ctx, inj_name, inj_arity, H); buffer inj_args; @@ -860,7 +860,7 @@ optional> simplify_core_fn::post(expr const &, optional< return optional>(); } -simplify_core_fn::simplify_core_fn(type_context & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, +simplify_core_fn::simplify_core_fn(type_context_old & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, simp_config const & cfg): m_ctx(ctx), m_defeq_canonizer(m_ctx, dcs), m_slss(slss), m_cfg(cfg) { } @@ -887,7 +887,7 @@ simp_result simplify_core_fn::operator()(name const & rel, expr const & e) { } } -static expr mk_mpr(type_context & ctx, name const & rel, expr const & h1, expr const & h2) { +static expr mk_mpr(type_context_old & ctx, name const & rel, expr const & h1, expr const & h2) { lean_assert(rel == get_eq_name() || rel == get_iff_name()); if (rel == get_eq_name()) return mk_eq_mpr(ctx, h1, h2); @@ -923,14 +923,14 @@ optional simplify_core_fn::prove_by_simp(name const & rel, expr const & e) simplify_ext_core_fn ------------------------------------ */ -simplify_ext_core_fn::simplify_ext_core_fn(type_context & ctx, defeq_can_state & dcs, simp_lemmas const & slss, +simplify_ext_core_fn::simplify_ext_core_fn(type_context_old & ctx, defeq_can_state & dcs, simp_lemmas const & slss, simp_config const & cfg): simplify_core_fn(ctx, dcs, slss, cfg) { } simp_result simplify_ext_core_fn::visit_lambda(expr const & e) { if (m_rel != get_eq_name() || !m_cfg.m_use_axioms) return simp_result(e); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr it = e; while (is_lambda(it)) { expr d = instantiate_rev(binding_domain(it), locals.size(), locals.as_buffer().data()); @@ -965,7 +965,7 @@ simp_result simplify_ext_core_fn::visit_lambda(expr const & e) { simp_result simplify_ext_core_fn::forall_congr(expr const & e) { lean_assert(m_rel == get_eq_name() || m_rel == get_iff_name()); buffer pis; - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr it = e; while (is_pi(it)) { expr d = instantiate_rev(binding_domain(it), locals.as_buffer().size(), locals.as_buffer().data()); @@ -1020,7 +1020,7 @@ simp_result simplify_ext_core_fn::imp_congr(expr const & e) { expr const & b = binding_body(e); simp_result r_a = visit(a, some_expr(e)); if (m_cfg.m_contextual) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr h = locals.push_local("_h", r_a.get_new()); flet set_slss(m_slss, add_to_slss(m_slss, locals.as_buffer())); freset reset_cache(m_cache); @@ -1091,12 +1091,12 @@ optional> simplify_fn::pre(expr const &, optional } // TODO(Leo): move to a different file -static optional unfold_using_nontrivial_eqns(type_context & ctx, expr const & e) { +static optional unfold_using_nontrivial_eqns(type_context_old & ctx, expr const & e) { if (!is_app(e)) return none_expr(); expr const & f = get_app_fn(e); if (!is_constant(f)) return none_expr(); if (has_simple_eqn_lemma(ctx.env(), const_name(f))) return none_expr(); - type_context::transparency_scope scope(ctx, transparency_mode::Semireducible); + type_context_old::transparency_scope scope(ctx, transparency_mode::Semireducible); return ctx.unfold_definition(e); } @@ -1179,7 +1179,7 @@ class vm_simplify_fn : public simplify_ext_core_fn { } public: - vm_simplify_fn(type_context & ctx, defeq_can_state & dcs, simp_lemmas const & slss, simp_config const & cfg, + vm_simplify_fn(type_context_old & ctx, defeq_can_state & dcs, simp_lemmas const & slss, simp_config const & cfg, vm_obj const & prove, vm_obj const & pre, vm_obj const & post, tactic_state const & s): simplify_ext_core_fn(ctx, dcs, slss, cfg), m_prove(prove), m_pre(pre), m_post(post), @@ -1216,7 +1216,7 @@ class tactic_simplify_fn : public simplify_fn { } public: - tactic_simplify_fn(type_context & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, list const & to_unfold, + tactic_simplify_fn(type_context_old & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, list const & to_unfold, simp_config const & cfg, tactic_state const & s, vm_obj const & prove): simplify_fn(ctx, dcs, slss, to_unfold, cfg), m_s(s), @@ -1240,7 +1240,7 @@ vm_obj tactic_simplify(vm_obj const & slss, vm_obj const & u, vm_obj const & e, try { simp_config cfg(c); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(transparency_mode::Reducible); + type_context_old ctx = cache.mk_type_context(transparency_mode::Reducible); defeq_can_state dcs = s.dcs(); tactic_simplify_fn simp(ctx, dcs, to_simp_lemmas(slss), to_list_name(u), cfg, s, prove); simp_result result = simp(to_name(rel), to_expr(e)); @@ -1262,7 +1262,7 @@ static vm_obj ext_simplify_core(vm_obj const & a, vm_obj const & c, simp_lemmas try { simp_config cfg(c); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(transparency_mode::Reducible); + type_context_old ctx = cache.mk_type_context(transparency_mode::Reducible); defeq_can_state dcs = s.dcs(); vm_simplify_fn simp(ctx, dcs, slss, cfg, prove, pre, post, s); pair p = simp(a, r, e); diff --git a/src/library/tactic/simplify.h b/src/library/tactic/simplify.h index 5ef466d516..7bc19e3d49 100644 --- a/src/library/tactic/simplify.h +++ b/src/library/tactic/simplify.h @@ -76,7 +76,7 @@ class simplify_core_fn { protected: typedef expr_struct_map simplify_cache; - type_context & m_ctx; + type_context_old & m_ctx; defeq_canonizer m_defeq_canonizer; name m_rel; simp_lemmas m_slss; @@ -153,7 +153,7 @@ protected: bool match(tmp_type_context & ctx, simp_lemma const & sl, expr const & t); public: - simplify_core_fn(type_context & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, + simplify_core_fn(type_context_old & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, simp_config const & cfg); environment const & env() const; @@ -173,7 +173,7 @@ protected: virtual simp_result visit_let(expr const & e) override; virtual simp_result visit_macro(expr const & e) override; public: - simplify_ext_core_fn(type_context & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, + simplify_ext_core_fn(type_context_old & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, simp_config const & cfg); }; @@ -186,7 +186,7 @@ protected: virtual optional> post(expr const & e, optional const & parent) override; virtual optional prove(expr const & e) override; public: - simplify_fn(type_context & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, list const & to_unfold, + simplify_fn(type_context_old & ctx, defeq_canonizer::state & dcs, simp_lemmas const & slss, list const & to_unfold, simp_config const & cfg): simplify_ext_core_fn(ctx, dcs, slss, cfg), m_to_unfold(to_name_set(to_unfold)) {} diff --git a/src/library/tactic/smt/congruence_closure.cpp b/src/library/tactic/smt/congruence_closure.cpp index 9070121afa..e1171e3a37 100644 --- a/src/library/tactic/smt/congruence_closure.cpp +++ b/src/library/tactic/smt/congruence_closure.cpp @@ -59,7 +59,7 @@ struct ext_congr_lemma_cache { typedef std::shared_ptr ext_congr_lemma_cache_ptr; -congruence_closure::congruence_closure(type_context & ctx, state & s, defeq_canonizer::state & dcs, +congruence_closure::congruence_closure(type_context_old & ctx, state & s, defeq_canonizer::state & dcs, cc_propagation_handler * phandler, cc_normalizer * normalizer): m_ctx(ctx), m_defeq_canonizer(ctx, dcs), m_state(s), m_cache_ptr(std::make_shared(ctx.env())), m_mode(ctx.mode()), @@ -83,7 +83,7 @@ inline ext_congr_lemma_cache_data & get_cache(congruence_closure const & cc) { } /* Automatically generated congruence lemma based on heterogeneous equality. */ -static optional mk_hcongr_lemma_core(type_context & ctx, expr const & fn, unsigned nargs) { +static optional mk_hcongr_lemma_core(type_context_old & ctx, expr const & fn, unsigned nargs) { optional eq_congr = mk_hcongr(ctx, fn, nargs); if (!eq_congr) return optional(); ext_congr_lemma res1(*eq_congr); @@ -1024,7 +1024,7 @@ expr congruence_closure::mk_congr_proof_core(expr const & lhs, expr const & rhs, /* Convert r into a proof of lhs = rhs using eq.rec and the proof that lhs_fn = rhs_fn */ expr lhs_fn_eq_rhs_fn = *get_eq_proof(lhs_fn, rhs_fn); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr x = locals.push_local("_x", m_ctx.infer(lhs_fn)); expr motive_rhs = mk_app(x, rhs_args); expr motive = heq_proofs ? mk_heq(m_ctx, lhs, motive_rhs) : mk_eq(m_ctx, lhs, motive_rhs); @@ -1056,7 +1056,7 @@ optional congruence_closure::mk_symm_congr_proof(expr const & e1, expr con (lhs1 ~R1~ rhs1) = (rhs1 ~R1~ lhs1) */ expr new_e1 = mk_rel(m_ctx, *R1, rhs1, lhs1); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr h1 = locals.push_local("_h1", e1); expr h2 = locals.push_local("_h2", new_e1); expr e1_iff_new_e1 = mk_app(m_ctx, get_iff_intro_name(), @@ -1633,7 +1633,7 @@ expr_pair congruence_closure::to_forall_not(expr const & ex, expr const & h_not_ lean_assert(is_exists(ex)); expr A, p; lean_verify(is_exists(ex, A, p)); - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); level lvl = get_level(m_ctx, A); expr x = locals.push_local("_x", A); expr px = head_beta_reduce(mk_app(p, x)); diff --git a/src/library/tactic/smt/congruence_closure.h b/src/library/tactic/smt/congruence_closure.h index 3a4a7eef59..b05605dc64 100644 --- a/src/library/tactic/smt/congruence_closure.h +++ b/src/library/tactic/smt/congruence_closure.h @@ -156,7 +156,7 @@ public: }; private: - type_context & m_ctx; + type_context_old & m_ctx; defeq_canonizer m_defeq_canonizer; state & m_state; buffer m_todo; @@ -253,13 +253,13 @@ private: friend ext_congr_lemma_cache_ptr const & get_cache_ptr(congruence_closure const & cc); public: - congruence_closure(type_context & ctx, state & s, defeq_canonizer::state & dcs, + congruence_closure(type_context_old & ctx, state & s, defeq_canonizer::state & dcs, cc_propagation_handler * phandler = nullptr, cc_normalizer * normalizer = nullptr); ~congruence_closure(); environment const & env() const { return m_ctx.env(); } - type_context & ctx() { return m_ctx; } + type_context_old & ctx() { return m_ctx; } transparency_mode mode() const { return m_mode; } defeq_canonizer & get_defeq_canonizer() { return m_defeq_canonizer; } diff --git a/src/library/tactic/smt/congruence_tactics.cpp b/src/library/tactic/smt/congruence_tactics.cpp index b7e79ccd32..f6c77de3e0 100644 --- a/src/library/tactic/smt/congruence_tactics.cpp +++ b/src/library/tactic/smt/congruence_tactics.cpp @@ -84,7 +84,7 @@ vm_obj cc_state_mk_using_hs_core(vm_obj const & cfg, vm_obj const & _s) { if (!g) return mk_no_goals_exception(s); try { local_context lctx = g->get_context(); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); defeq_can_state dcs = s.dcs(); congruence_closure::state r = mk_core(cfg); congruence_closure cc(ctx, r, dcs); @@ -102,7 +102,7 @@ vm_obj cc_state_mk_using_hs_core(vm_obj const & cfg, vm_obj const & _s) { vm_obj cc_state_pp_core(vm_obj const & ccs, vm_obj const & nonsingleton, vm_obj const & _s) { tactic_state const & s = tactic::to_state(_s); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); formatter fmt = fmtf(s.env(), s.get_options(), ctx); format r = to_cc_state(ccs).pp_eqcs(fmt, to_bool(nonsingleton)); @@ -111,7 +111,7 @@ vm_obj cc_state_pp_core(vm_obj const & ccs, vm_obj const & nonsingleton, vm_obj vm_obj cc_state_pp_eqc(vm_obj const & ccs, vm_obj const & e, vm_obj const & _s) { tactic_state const & s = tactic::to_state(_s); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); formatter fmt = fmtf(s.env(), s.get_options(), ctx); format r = to_cc_state(ccs).pp_eqc(fmt, to_expr(e)); @@ -157,7 +157,7 @@ vm_obj cc_state_inc_gmt(vm_obj const & ccs) { #define cc_state_proc(CODE) \ tactic_state const & s = tactic::to_state(_s); \ try { \ - type_context ctx = mk_type_context_for(s); \ + type_context_old ctx = mk_type_context_for(s); \ congruence_closure::state S = to_cc_state(ccs); \ defeq_can_state dcs = s.dcs(); \ congruence_closure cc(ctx, S, dcs); \ diff --git a/src/library/tactic/smt/ematch.cpp b/src/library/tactic/smt/ematch.cpp index f74c5757ee..7d5176bcc7 100644 --- a/src/library/tactic/smt/ematch.cpp +++ b/src/library/tactic/smt/ematch.cpp @@ -23,7 +23,7 @@ Author: Leonardo de Moura #include "library/tactic/smt/hinst_lemmas.h" namespace lean { -void ematch_state::internalize(type_context & ctx, expr const & e) { +void ematch_state::internalize(type_context_old & ctx, expr const & e) { switch (e.kind()) { case expr_kind::Var: case expr_kind::Sort: case expr_kind::Constant: case expr_kind::Meta: @@ -272,7 +272,7 @@ static list const & ac_t(ematch_cnstr const & c) { return to_ac_cnstr(c)-> */ class ematch_fn { typedef list state; - type_context & m_ctx; + type_context_old & m_ctx; ematch_state & m_em_state; congruence_closure & m_cc; buffer & m_new_instances; @@ -952,7 +952,7 @@ class ematch_fn { The given lemma is instantiated for each solution found. The new instances are stored at m_new_instances. */ void main(hinst_lemma const & lemma, state const & init, expr const & p, expr const & t) { - type_context::tmp_mode_scope scope(m_ctx, lemma.m_num_uvars, lemma.m_num_mvars); + type_context_old::tmp_mode_scope scope(m_ctx, lemma.m_num_uvars, lemma.m_num_mvars); lean_assert(!has_idx_metavar(t)); clear_choice_stack(); m_state = init; @@ -1017,12 +1017,12 @@ class ematch_fn { } public: - ematch_fn(type_context & ctx, ematch_state & ems, congruence_closure & cc, buffer & new_insts): + ematch_fn(type_context_old & ctx, ematch_state & ems, congruence_closure & cc, buffer & new_insts): m_ctx(ctx), m_em_state(ems), m_cc(cc), m_new_instances(new_insts) {} void ematch_term(hinst_lemma const & lemma, expr const & t) { /* The following scope is a temporary workaround, we need to refactor this module - and adapt all improvements added to type_context::is_def_eq. */ + and adapt all improvements added to type_context_old::is_def_eq. */ for (multi_pattern const & mp : lemma.m_multi_patterns) { ematch_term(lemma, mp, t); } @@ -1031,7 +1031,7 @@ public: /* Match internalized terms in m_em_state with the given lemma. */ void ematch_terms(hinst_lemma const & lemma, bool filter) { /* The following scope is a temporary workaround, we need to refactor this module - and adapt all improvements added to type_context::is_def_eq. */ + and adapt all improvements added to type_context_old::is_def_eq. */ for (multi_pattern const & mp : lemma.m_multi_patterns) { ematch_terms(lemma, mp, filter); } @@ -1041,7 +1041,7 @@ public: if (m_em_state.max_instances_exceeded()) return; /* The following scope is a temporary workaround, we need to refactor this module - and adapt all improvements added to type_context::is_def_eq. */ + and adapt all improvements added to type_context_old::is_def_eq. */ ematch_using_lemmas(m_em_state.get_new_lemmas(), false); ematch_using_lemmas(m_em_state.get_lemmas(), true); m_em_state.m_lemmas.merge(m_em_state.m_new_lemmas); @@ -1050,17 +1050,17 @@ public: } }; -void ematch(type_context & ctx, ematch_state & s, congruence_closure & cc, hinst_lemma const & lemma, expr const & t, buffer & result) { +void ematch(type_context_old & ctx, ematch_state & s, congruence_closure & cc, hinst_lemma const & lemma, expr const & t, buffer & result) { congruence_closure::state_scope scope(cc); ematch_fn(ctx, s, cc, result).ematch_term(lemma, t); } -void ematch(type_context & ctx, ematch_state & s, congruence_closure & cc, hinst_lemma const & lemma, bool filter, buffer & result) { +void ematch(type_context_old & ctx, ematch_state & s, congruence_closure & cc, hinst_lemma const & lemma, bool filter, buffer & result) { congruence_closure::state_scope scope(cc); ematch_fn(ctx, s, cc, result).ematch_terms(lemma, filter); } -void ematch(type_context & ctx, ematch_state & s, congruence_closure & cc, buffer & result) { +void ematch(type_context_old & ctx, ematch_state & s, congruence_closure & cc, buffer & result) { congruence_closure::state_scope scope(cc); ematch_fn(ctx, s, cc, result)(); } @@ -1102,7 +1102,7 @@ vm_obj ematch_state_mk(vm_obj const & cfg) { vm_obj ematch_state_internalize(vm_obj const & ems, vm_obj const & e, vm_obj const & s) { LEAN_TACTIC_TRY; ematch_state S = to_ematch_state(ems); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); S.internalize(ctx, to_expr(e)); return tactic::mk_success(to_obj(S), tactic::to_state(s)); LEAN_TACTIC_CATCH(tactic::to_state(s)); @@ -1122,7 +1122,7 @@ vm_obj mk_ematch_result(buffer const & new_inst_buffer, congruence vm_obj ematch_core(vm_obj const & md, vm_obj const & _ccs, vm_obj const & _ems, vm_obj const & hlemma, vm_obj const & t, vm_obj const & _s) { tactic_state const & s = tactic::to_state(_s); LEAN_TACTIC_TRY; - type_context ctx = mk_type_context_for(_s, md); + type_context_old ctx = mk_type_context_for(_s, md); ematch_state ems = to_ematch_state(_ems); defeq_can_state dcs = s.dcs(); congruence_closure::state ccs = to_cc_state(_ccs); @@ -1138,7 +1138,7 @@ vm_obj ematch_core(vm_obj const & md, vm_obj const & _ccs, vm_obj const & _ems, vm_obj ematch_all_core(vm_obj const & md, vm_obj const & _ccs, vm_obj const & _ems, vm_obj const & hlemma, vm_obj const & filter, vm_obj const & _s) { tactic_state const & s = tactic::to_state(_s); LEAN_TACTIC_TRY; - type_context ctx = mk_type_context_for(_s, md); + type_context_old ctx = mk_type_context_for(_s, md); ematch_state ems = to_ematch_state(_ems); defeq_can_state dcs = s.dcs(); congruence_closure::state ccs = to_cc_state(_ccs); diff --git a/src/library/tactic/smt/ematch.h b/src/library/tactic/smt/ematch.h index 858d3a3d9e..68382a0347 100644 --- a/src/library/tactic/smt/ematch.h +++ b/src/library/tactic/smt/ematch.h @@ -34,7 +34,7 @@ public: ematch_state(ematch_config const & cfg, hinst_lemmas const & lemmas = hinst_lemmas()): m_config(cfg), m_new_lemmas(lemmas) {} - void internalize(type_context & ctx, expr const & e); + void internalize(type_context_old & ctx, expr const & e); bool max_instances_exceeded() const { return m_max_instances_exceeded; } bool save_instance(expr const & e); /* Record the fact that the given lemma was instantiated with the given arguments. */ @@ -55,18 +55,18 @@ struct new_instance { }; /* Ematch patterns in lemma with t, and add instances of lemma at result */ -void ematch(type_context & ctx, ematch_state & s, congruence_closure & cc, hinst_lemma const & lemma, expr const & t, +void ematch(type_context_old & ctx, ematch_state & s, congruence_closure & cc, hinst_lemma const & lemma, expr const & t, buffer & result); /* Ematch patterns in lemma with terms internalized in the ematch_state, and add instances of lemma at result */ -void ematch(type_context & ctx, ematch_state & s, congruence_closure & cc, hinst_lemma const & lemma, bool filter, +void ematch(type_context_old & ctx, ematch_state & s, congruence_closure & cc, hinst_lemma const & lemma, bool filter, buffer & result); /* Ematch patterns of lemmas in s.m_lemmas and s.m_new_lemmas with terms internalized in the ematch_state. Add instances to result. Move s.m_new_lemmas to s.m_lemmas, and increment gmt from cc. For s.m_lemmas, only terms with mt >= gmt are considered. */ -void ematch(type_context & ctx, ematch_state & s, congruence_closure & cc, buffer & result); +void ematch(type_context_old & ctx, ematch_state & s, congruence_closure & cc, buffer & result); /* structure cc_config := diff --git a/src/library/tactic/smt/hinst_lemmas.cpp b/src/library/tactic/smt/hinst_lemmas.cpp index e3aaac3586..7cd7cc89a7 100644 --- a/src/library/tactic/smt/hinst_lemmas.cpp +++ b/src/library/tactic/smt/hinst_lemmas.cpp @@ -150,7 +150,7 @@ expr mk_pattern_hint(expr const & e) { typedef rb_tree idx_metavar_set; -static bool is_higher_order(type_context & ctx, expr const & e) { +static bool is_higher_order(type_context_old & ctx, expr const & e) { /* Remark: is it too expensive to use ctx.relaxed_whnf here? */ return is_pi(ctx.whnf(ctx.infer(e))); } @@ -159,7 +159,7 @@ static bool is_higher_order(type_context & ctx, expr const & e) { create n idx_metavars (one for each a_i), store the meta-variables in mvars, and store in trackable and residue the subsets of these meta-variables as described in the beginning of this file. Then returns B (instantiated with the new meta-variables) */ -expr extract_trackable(type_context & ctx, expr const & type, +expr extract_trackable(type_context_old & ctx, expr const & type, buffer & mvars, buffer & inst_implicit_flags, idx_metavar_set & trackable, idx_metavar_set & residue) { @@ -244,7 +244,7 @@ expr extract_trackable(type_context & ctx, expr const & type, return B; } -static expr dsimp(type_context & ctx, transparency_mode md, expr const & e) { +static expr dsimp(type_context_old & ctx, transparency_mode md, expr const & e) { /* We used to use ::lean::normalize here, but it was bad since it would unfold type class instances. First, this may be a performance problem. Second, it would expose a problem with the way we define some algebraic structures. @@ -260,7 +260,7 @@ static expr dsimp(type_context & ctx, transparency_mode md, expr const & e) { } struct mk_hinst_lemma_fn { - type_context & m_ctx; + type_context_old & m_ctx; transparency_mode m_md_norm; name_set m_no_inst_patterns; expr m_H; @@ -276,7 +276,7 @@ struct mk_hinst_lemma_fn { unsigned m_num_steps; name m_id; - mk_hinst_lemma_fn(type_context & ctx, transparency_mode md_norm, expr const & H, + mk_hinst_lemma_fn(type_context_old & ctx, transparency_mode md_norm, expr const & H, unsigned num_uvars, unsigned max_steps, bool simp, name const & id): m_ctx(ctx), m_md_norm(md_norm), @@ -504,7 +504,7 @@ struct mk_hinst_lemma_fn { Remaining metavariables are "renamed" (i.e., renumbered to avoid gaps due to residue hypotheses moved to the end). Trackable set is updated. subst will contain the mvars renaming */ - expr mk_proof(type_context::tmp_locals & locals, buffer & new_residue, buffer & subst) { + expr mk_proof(type_context_old::tmp_locals & locals, buffer & new_residue, buffer & subst) { unsigned j = 0; bool found_residue = false; bool only_tail_residue = true; @@ -565,7 +565,7 @@ struct mk_hinst_lemma_fn { lean_assert(m_mvars.size() == inst_implicit_flags.size()); buffer subst; buffer residue_locals; - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr proof = mk_proof(locals, residue_locals, subst); B = replace_mvars(B, subst); candidate_set hints = collect_pattern_hints(m_mvars, residue_locals, B); @@ -612,7 +612,7 @@ struct mk_hinst_lemma_fn { } }; -hinst_lemma mk_hinst_lemma_core(type_context & ctx, transparency_mode md_norm, expr const & H, unsigned num_uvars, +hinst_lemma mk_hinst_lemma_core(type_context_old & ctx, transparency_mode md_norm, expr const & H, unsigned num_uvars, unsigned max_steps, bool simp, name const & id) { if (num_uvars == 0 && !is_pi(ctx.relaxed_whnf(ctx.infer(H)))) { hinst_lemma h; @@ -623,11 +623,11 @@ hinst_lemma mk_hinst_lemma_core(type_context & ctx, transparency_mode md_norm, e return h; } else { try { - type_context::tmp_mode_scope tscope(ctx, num_uvars, 0); + type_context_old::tmp_mode_scope tscope(ctx, num_uvars, 0); bool erase_hints = false; return mk_hinst_lemma_fn(ctx, md_norm, H, num_uvars, max_steps, simp, id)(erase_hints); } catch (mk_hinst_lemma_fn::try_again_without_hints &) { - type_context::tmp_mode_scope tscope(ctx, num_uvars, 0); + type_context_old::tmp_mode_scope tscope(ctx, num_uvars, 0); try { bool erase_hints = true; return mk_hinst_lemma_fn(ctx, md_norm, H, num_uvars, max_steps, simp, id)(erase_hints); @@ -644,7 +644,7 @@ unsigned get_hinst_lemma_max_steps(options const & o) { return o.get_unsigned(*g_hinst_lemma_max_steps, LEAN_DEFAULT_HINST_LEMMA_PATTERN_MAX_STEPS); } -hinst_lemma mk_hinst_lemma(type_context & ctx, transparency_mode md_norm, expr const & H, bool simp) { +hinst_lemma mk_hinst_lemma(type_context_old & ctx, transparency_mode md_norm, expr const & H, bool simp) { unsigned max_steps = get_hinst_lemma_max_steps(ctx.get_options()); name id; if (is_local(H)) @@ -652,7 +652,7 @@ hinst_lemma mk_hinst_lemma(type_context & ctx, transparency_mode md_norm, expr c return mk_hinst_lemma_core(ctx, md_norm, H, 0, max_steps, simp, id); } -hinst_lemma mk_hinst_lemma(type_context & ctx, transparency_mode md_norm, name const & c, bool simp) { +hinst_lemma mk_hinst_lemma(type_context_old & ctx, transparency_mode md_norm, name const & c, bool simp) { unsigned max_steps = get_hinst_lemma_max_steps(ctx.get_options()); declaration const & d = ctx.env().get(c); buffer us; @@ -704,7 +704,7 @@ vm_obj to_obj(hinst_lemma const & s) { vm_obj hinst_lemma_mk_core(vm_obj const & m, vm_obj const & lemma, vm_obj const & simp, vm_obj const & s) { LEAN_TACTIC_TRY; - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); hinst_lemma h = mk_hinst_lemma(ctx, to_transparency_mode(m), to_expr(lemma), to_bool(simp)); return tactic::mk_success(to_obj(h), tactic::to_state(s)); LEAN_TACTIC_CATCH(tactic::to_state(s)); @@ -712,7 +712,7 @@ vm_obj hinst_lemma_mk_core(vm_obj const & m, vm_obj const & lemma, vm_obj const vm_obj hinst_lemma_mk_from_decl_core(vm_obj const & m, vm_obj const & lemma_name, vm_obj const & simp, vm_obj const & s) { LEAN_TACTIC_TRY; - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); hinst_lemma h = mk_hinst_lemma(ctx, to_transparency_mode(m), to_name(lemma_name), to_bool(simp)); return tactic::mk_success(to_obj(h), tactic::to_state(s)); LEAN_TACTIC_CATCH(tactic::to_state(s)); @@ -722,7 +722,7 @@ vm_obj hinst_lemma_pp(vm_obj const & h, vm_obj const & _s) { tactic_state const & s = tactic::to_state(_s); LEAN_TACTIC_TRY; formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); - type_context ctx = mk_type_context_for(s); + type_context_old ctx = mk_type_context_for(s); formatter fmt = fmtf(s.env(), s.get_options(), ctx); format r = pp_hinst_lemma(fmt, to_hinst_lemma(h)); return tactic::mk_success(to_obj(r), s); diff --git a/src/library/tactic/smt/hinst_lemmas.h b/src/library/tactic/smt/hinst_lemmas.h index d24e0fd965..066f097fc7 100644 --- a/src/library/tactic/smt/hinst_lemmas.h +++ b/src/library/tactic/smt/hinst_lemmas.h @@ -68,8 +68,8 @@ list mk_multipatterns(environment const & env, io_state const & i \c md_norm is the transparency_mode used for normalizing the type of the lemma. The idea is to unfold the lemmas using the given transparency mode. */ -hinst_lemma mk_hinst_lemma(type_context & ctx, transparency_mode md_norm, expr const & H, bool simp = false); -hinst_lemma mk_hinst_lemma(type_context & ctx, transparency_mode md_norm, name const & n, bool simp = false); +hinst_lemma mk_hinst_lemma(type_context_old & ctx, transparency_mode md_norm, expr const & H, bool simp = false); +hinst_lemma mk_hinst_lemma(type_context_old & ctx, transparency_mode md_norm, name const & n, bool simp = false); format pp_hinst_lemma(formatter const & fmt, hinst_lemma const & h); diff --git a/src/library/tactic/smt/smt_state.cpp b/src/library/tactic/smt/smt_state.cpp index a95c2e82a9..d442eb2e48 100644 --- a/src/library/tactic/smt/smt_state.cpp +++ b/src/library/tactic/smt/smt_state.cpp @@ -41,7 +41,7 @@ smt_goal::smt_goal(smt_config const & cfg): smt_goal(std::make_shared(cfg)) { } -smt::smt(type_context & ctx, defeq_can_state & dcs, smt_goal & g): +smt::smt(type_context_old & ctx, defeq_can_state & dcs, smt_goal & g): m_ctx(ctx), m_dcs(dcs), m_goal(g), @@ -109,10 +109,10 @@ void smt::ematch_using(hinst_lemma const & lemma, buffer & result) ::lean::ematch(m_ctx, m_goal.m_em_state, m_cc, lemma, false, result); } -static dsimplify_fn mk_dsimp(type_context & ctx, defeq_can_state & dcs, smt_pre_config const & cfg); +static dsimplify_fn mk_dsimp(type_context_old & ctx, defeq_can_state & dcs, smt_pre_config const & cfg); expr smt::normalize(expr const & e) { - type_context::zeta_scope _1(m_ctx, m_goal.get_pre_config().m_zeta); + type_context_old::zeta_scope _1(m_ctx, m_goal.get_pre_config().m_zeta); dsimplify_fn dsimp = mk_dsimp(m_ctx, m_dcs, m_goal.get_pre_config()); return dsimp(e); } @@ -197,7 +197,7 @@ static pair revert_all(tactic_state const & s) { return mk_pair(new_s, hs.size()); } -static dsimplify_fn mk_dsimp(type_context & ctx, defeq_can_state & dcs, smt_pre_config const & cfg) { +static dsimplify_fn mk_dsimp(type_context_old & ctx, defeq_can_state & dcs, smt_pre_config const & cfg) { dsimp_config dcfg; dcfg.m_max_steps = cfg.m_max_steps; dcfg.m_canonize_instances = false; @@ -224,7 +224,7 @@ static dsimplify_fn mk_dsimp(type_context & ctx, defeq_can_state & dcs, smt_pre_ return dsimplify_fn(ctx, dcs, eq_lemmas, list(), dcfg); } -static simplify_fn mk_simp(type_context & ctx, defeq_can_state & dcs, smt_pre_config const & cfg) { +static simplify_fn mk_simp(type_context_old & ctx, defeq_can_state & dcs, smt_pre_config const & cfg) { simp_config scfg; scfg.m_max_steps = cfg.m_max_steps; scfg.m_contextual = false; @@ -236,9 +236,9 @@ static simplify_fn mk_simp(type_context & ctx, defeq_can_state & dcs, smt_pre_co return simplify_fn(ctx, dcs, cfg.m_simp_lemmas, list(), scfg); } -static simp_result preprocess(type_context & ctx, defeq_can_state & dcs, smt_pre_config const & cfg, expr const & e) { - type_context::zeta_scope scope1(ctx, cfg.m_zeta); - type_context::transparency_scope scope2(ctx, transparency_mode::Reducible); +static simp_result preprocess(type_context_old & ctx, defeq_can_state & dcs, smt_pre_config const & cfg, expr const & e) { + type_context_old::zeta_scope scope1(ctx, cfg.m_zeta); + type_context_old::transparency_scope scope2(ctx, transparency_mode::Reducible); dsimplify_fn dsimp = mk_dsimp(ctx, dcs, cfg); expr new_e = dsimp(e); simplify_fn simp = mk_simp(ctx, dcs, cfg); @@ -249,7 +249,7 @@ static simp_result preprocess(type_context & ctx, defeq_can_state & dcs, smt_pre static vm_obj preprocess(tactic_state s, smt_pre_config const & cfg) { lean_assert(s.goals()); optional g = s.get_main_goal_decl(); - type_context ctx = mk_type_context_for(s, transparency_mode::Reducible); + type_context_old ctx = mk_type_context_for(s, transparency_mode::Reducible); expr target = g->get_type(); defeq_can_state dcs = s.dcs(); simp_result r = preprocess(ctx, dcs, cfg, target); @@ -266,7 +266,7 @@ static vm_obj preprocess(tactic_state s, smt_pre_config const & cfg) { } } -static expr_pair preprocess_forward(type_context & ctx, defeq_can_state & dcs, smt_pre_config const & cfg, expr const & type, expr const & h) { +static expr_pair preprocess_forward(type_context_old & ctx, defeq_can_state & dcs, smt_pre_config const & cfg, expr const & type, expr const & h) { simp_result r = preprocess(ctx, dcs, cfg, type); if (r.has_proof()) { expr new_h = mk_eq_mp(ctx, r.get_proof(), h); @@ -278,11 +278,11 @@ static expr_pair preprocess_forward(type_context & ctx, defeq_can_state & dcs, s } } -static expr_pair preprocess_forward(type_context & ctx, defeq_can_state & dcs, smt_goal const & g, expr const & type, expr const & h) { +static expr_pair preprocess_forward(type_context_old & ctx, defeq_can_state & dcs, smt_goal const & g, expr const & type, expr const & h) { return preprocess_forward(ctx, dcs, g.get_pre_config(), type, h); } -static name mk_intro_name(type_context & ctx, name const & bname, bool use_unused_names, list & user_ids) { +static name mk_intro_name(type_context_old & ctx, name const & bname, bool use_unused_names, list & user_ids) { if (user_ids) { name r = head(user_ids); user_ids = tail(user_ids); @@ -295,7 +295,7 @@ static name mk_intro_name(type_context & ctx, name const & bname, bool use_unuse } /* This try_to_pi version only unfolds the head symbol if it is a not-application or a reducible constant. */ -static expr convervative_try_to_pi(type_context & ctx, expr const & e) { +static expr convervative_try_to_pi(type_context_old & ctx, expr const & e) { expr new_e = ctx.whnf_head_pred(e, [&](expr const & t) { if (is_not(t)) return true; expr const & fn = get_app_fn(e); @@ -309,7 +309,7 @@ static expr intros(environment const & env, options const & opts, metavar_contex optional const & num, list ids) { optional decl = mctx.find_metavar_decl(mvar); lean_assert(decl); - type_context ctx(env, opts, mctx, decl->get_context(), transparency_mode::Semireducible); + type_context_old ctx(env, opts, mctx, decl->get_context(), transparency_mode::Semireducible); smt S(ctx, dcs, s_goal); /* We need to use dsimp to canonize instances as we introduce hypotheses. Example: suppose we are introducing @@ -318,9 +318,9 @@ static expr intros(environment const & env, options const & opts, metavar_contex The nested instances of has_add and has_zero must be canonized and registered at dcs. */ dsimplify_fn dsimp = mk_dsimp(ctx, dcs, s_goal.get_pre_config()); - type_context::zeta_scope _1(ctx, s_goal.get_pre_config().m_zeta); + type_context_old::zeta_scope _1(ctx, s_goal.get_pre_config().m_zeta); expr target = decl->get_type(); - type_context::tmp_locals locals(ctx); + type_context_old::tmp_locals locals(ctx); buffer new_Hs; buffer to_inst; for (unsigned i = 0; !num || i < *num; i++) { @@ -386,7 +386,7 @@ static expr intros(environment const & env, options const & opts, metavar_contex /* Assert lemma in the current state if does not have universal metavariables, and return true. Return false otherwise. */ -static bool add_em_fact(smt & S, type_context & ctx, hinst_lemma const & lemma) { +static bool add_em_fact(smt & S, type_context_old & ctx, hinst_lemma const & lemma) { if (lemma.m_num_mvars == 0 && lemma.m_num_uvars == 0) { expr type = lemma.m_prop; expr h = lemma.m_proof; @@ -401,7 +401,7 @@ static bool add_em_fact(smt & S, type_context & ctx, hinst_lemma const & lemma) } tactic_state add_em_facts(tactic_state const & ts, smt_goal & g) { - type_context ctx = mk_type_context_for(ts); + type_context_old ctx = mk_type_context_for(ts); defeq_can_state dcs = ts.dcs(); smt S(ctx, dcs, g); hinst_lemmas lemmas = g.get_em_state().get_new_lemmas(); @@ -629,7 +629,7 @@ static format pp_negative_facts(cc_state const & ccs, formatter const & fmt) { return format(); } -static format pp_equivalences(type_context & ctx, cc_state const & ccs, formatter const & fmt) { +static format pp_equivalences(type_context_old & ctx, cc_state const & ccs, formatter const & fmt) { format r; bool first = true; buffer roots; @@ -660,7 +660,7 @@ format smt_goal_to_format(smt_goal sg, tactic_state const & ts) { if (inst_mvars) target = mctx_tmp.instantiate_mvars(target); format turnstile(unicode ? "⊢" : "|-"); - type_context ctx(ts.env(), opts, mctx_tmp, lctx, transparency_mode::All); + type_context_old ctx(ts.env(), opts, mctx_tmp, lctx, transparency_mode::All); formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); formatter fmt = fmtf(ts.env(), opts, ctx); defeq_can_state dcs = ts.dcs(); @@ -698,7 +698,7 @@ format smt_state_to_format_core(vm_obj const & ss, tactic_state const & ts) { format turnstile(unicode ? "⊢" : "|-"); for (expr const & g : tail(ts.goals())) { metavar_decl d = mctx.get_metavar_decl(g); - type_context ctx(ts.env(), ts.get_options(), mctx, d.get_context(), transparency_mode::Semireducible); + type_context_old ctx(ts.env(), ts.get_options(), mctx, d.get_context(), transparency_mode::Semireducible); formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); formatter fmt = fmtf(ts.env(), ts.get_options(), ctx); r += line() + line() + turnstile + space() + nest(3, fmt(d.get_type())); @@ -742,7 +742,7 @@ vm_obj smt_tactic_close(vm_obj const & ss, vm_obj const & _ts) { return mk_smt_state_empty_exception(ts); lean_assert(ts.goals()); expr target = ts.get_main_goal_decl()->get_type(); - type_context ctx = mk_type_context_for(ts); + type_context_old ctx = mk_type_context_for(ts); smt_goal g = to_smt_goal(head(ss)); defeq_can_state dcs = ts.dcs(); smt S(ctx, dcs, g); @@ -844,7 +844,7 @@ vm_obj smt_tactic_ematch_core(vm_obj const & pred, vm_obj const & ss, vm_obj con lean_assert(ts.goals()); LEAN_TACTIC_TRY; expr target = ts.get_main_goal_decl()->get_type(); - type_context ctx = mk_type_context_for(ts); + type_context_old ctx = mk_type_context_for(ts); defeq_can_state dcs = ts.dcs(); smt_goal g = to_smt_goal(head(ss)); smt S(ctx, dcs, g); @@ -876,7 +876,7 @@ vm_obj smt_tactic_mk_ematch_eqn_lemmas_for_core(vm_obj const & md, vm_obj const if (is_nil(ss)) return mk_smt_state_empty_exception(ts); lean_assert(ts.goals()); LEAN_TACTIC_TRY; - type_context ctx = mk_type_context_for(ts); + type_context_old ctx = mk_type_context_for(ts); buffer eqns; get_ext_eqn_lemmas_for(ts.env(), to_name(decl_name), eqns); if (eqns.empty()) @@ -907,7 +907,7 @@ vm_obj smt_tactic_preprocess(vm_obj const & e, vm_obj const & ss, vm_obj const & if (is_nil(ss)) return mk_smt_state_empty_exception(ts); lean_assert(ts.goals()); LEAN_TACTIC_TRY; - type_context ctx = mk_type_context_for(ts); + type_context_old ctx = mk_type_context_for(ts); smt_goal g = to_smt_goal(head(ss)); defeq_can_state dcs = ts.dcs(); simp_result r = preprocess(ctx, dcs, g.get_pre_config(), to_expr(e)); @@ -939,7 +939,7 @@ vm_obj smt_tactic_set_lemmas(vm_obj const & lemmas, vm_obj const & ss, vm_obj co vm_obj smt_tactic_add_lemmas(vm_obj const & lemmas, vm_obj const & ss, vm_obj const & _ts) { tactic_state ts = tactic::to_state(_ts); if (is_nil(ss)) return mk_smt_state_empty_exception(ts); - type_context ctx = mk_type_context_for(ts); + type_context_old ctx = mk_type_context_for(ts); defeq_can_state dcs = ts.dcs(); smt_goal g = to_smt_goal(head(ss)); smt S(ctx, dcs, g); @@ -962,7 +962,7 @@ vm_obj smt_tactic_ematch_using(vm_obj const & hs, vm_obj const & ss, vm_obj cons lean_assert(ts.goals()); LEAN_TACTIC_TRY; expr target = ts.get_main_goal_decl()->get_type(); - type_context ctx = mk_type_context_for(ts); + type_context_old ctx = mk_type_context_for(ts); defeq_can_state dcs = ts.dcs(); smt_goal g = to_smt_goal(head(ss)); smt S(ctx, dcs, g); diff --git a/src/library/tactic/smt/smt_state.h b/src/library/tactic/smt/smt_state.h index c183df9d2c..42f3d8573f 100644 --- a/src/library/tactic/smt/smt_state.h +++ b/src/library/tactic/smt/smt_state.h @@ -50,7 +50,7 @@ public: class smt : public cc_propagation_handler, public cc_normalizer { private: - type_context & m_ctx; + type_context_old & m_ctx; defeq_can_state & m_dcs; smt_goal & m_goal; congruence_closure m_cc; @@ -61,7 +61,7 @@ private: virtual void new_aux_cc_term(expr const & e) override; virtual expr normalize(expr const & e) override; public: - smt(type_context & ctx, defeq_can_state & dcs, smt_goal & g); + smt(type_context_old & ctx, defeq_can_state & dcs, smt_goal & g); virtual ~smt(); void internalize(expr const & e); diff --git a/src/library/tactic/smt/theory_ac.cpp b/src/library/tactic/smt/theory_ac.cpp index 037d337319..08682d14f9 100644 --- a/src/library/tactic/smt/theory_ac.cpp +++ b/src/library/tactic/smt/theory_ac.cpp @@ -15,7 +15,7 @@ Author: Leonardo de Moura namespace lean { /* Given e and ac_term that is provably equal to e using AC, return a proof for e = ac_term */ -static expr mk_ac_refl_proof(type_context & ctx, expr const & e, expr const & ac_term, expr const & assoc, expr const & comm) { +static expr mk_ac_refl_proof(type_context_old & ctx, expr const & e, expr const & ac_term, expr const & assoc, expr const & comm) { return mk_perm_ac_macro(ctx, assoc, comm, e, ac_term); } @@ -23,7 +23,7 @@ static expr mk_ac_refl_proof(type_context & ctx, expr const & e, expr const & ac tr = sr We use a*b to denote an AC application. That is, (a*b)*(c*a) is the term (a*a*b*c). */ -static expr mk_ac_simp_proof(type_context & ctx, expr const & tr, expr const & t, expr const & s, expr const & r, expr const & sr, +static expr mk_ac_simp_proof(type_context_old & ctx, expr const & tr, expr const & t, expr const & s, expr const & r, expr const & sr, expr const & t_eq_s, expr const & assoc, expr const & comm) { if (tr == t) { return t_eq_s; @@ -48,7 +48,7 @@ static expr mk_ac_simp_proof(type_context & ctx, expr const & tr, expr const & t We use a*b to denote an AC application. That is, (a*b)*(c*a) is the term (a*a*b*c). The proof is constructed using congruence and the perm_ac macro. */ -static expr mk_ac_superpose_proof(type_context & ctx, +static expr mk_ac_superpose_proof(type_context_old & ctx, expr const & ra, expr const & sb, expr const & a, expr const & b, expr const & r, expr const & s, diff --git a/src/library/tactic/smt/theory_ac.h b/src/library/tactic/smt/theory_ac.h index 0e784cc45d..15b1732e33 100644 --- a/src/library/tactic/smt/theory_ac.h +++ b/src/library/tactic/smt/theory_ac.h @@ -89,7 +89,7 @@ public: }; private: - type_context & m_ctx; + type_context_old & m_ctx; congruence_closure & m_cc; state & m_state; ac_manager_old m_ac_manager; diff --git a/src/library/tactic/subst_tactic.cpp b/src/library/tactic/subst_tactic.cpp index 3e7d687a27..6b3f1cabc6 100644 --- a/src/library/tactic/subst_tactic.cpp +++ b/src/library/tactic/subst_tactic.cpp @@ -34,13 +34,13 @@ bool check_hypothesis_in_context(metavar_context const & mctx, expr const & mvar expr subst(environment const & env, options const & opts, transparency_mode const & m, metavar_context & mctx, expr const & mvar, expr const & H, bool symm, hsubstitution * subst) { #define lean_subst_trace(CODE) lean_trace(name({"tactic", "subst"}), CODE) -#define lean_subst_trace_state(MVAR, MSG) lean_trace(name({"tactic", "subst"}), tactic_state S = mk_tactic_state_for_metavar(env, opts, "subst", mctx, MVAR); type_context TMP_CTX = mk_cacheless_type_context_for(S, m); scope_trace_env _scope1(env, TMP_CTX); tout() << MSG << S.pp_core() << "\n";) +#define lean_subst_trace_state(MVAR, MSG) lean_trace(name({"tactic", "subst"}), tactic_state S = mk_tactic_state_for_metavar(env, opts, "subst", mctx, MVAR); type_context_old TMP_CTX = mk_cacheless_type_context_for(S, m); scope_trace_env _scope1(env, TMP_CTX); tout() << MSG << S.pp_core() << "\n";) lean_subst_trace_state(mvar, "initial:\n"); lean_assert(mctx.find_metavar_decl(mvar)); lean_assert(is_local(H)); metavar_decl g = mctx.get_metavar_decl(mvar); - type_context ctx = mk_type_context_for(env, opts, mctx, g.get_context(), m); + type_context_old ctx = mk_type_context_for(env, opts, mctx, g.get_context(), m); expr H_type = ctx.instantiate_mvars(ctx.infer(H)); expr lhs, rhs; lean_verify(is_eq(H_type, lhs, rhs)); @@ -66,7 +66,7 @@ expr subst(environment const & env, options const & opts, transparency_mode cons expr H2 = lctx.get_local(lhsH2[1]); bool depH2 = depends_on(type, H2); expr new_type = instantiate(abstract_local(type, lhs), rhs); - type_context ctx2 = mk_type_context_for(env, opts, mctx, g2.get_context(), m); + type_context_old ctx2 = mk_type_context_for(env, opts, mctx, g2.get_context(), m); expr motive; if (depH2) { new_type = instantiate(abstract_local(new_type, H2), mk_eq_refl(ctx2, rhs)); @@ -81,7 +81,7 @@ expr subst(environment const & env, options const & opts, transparency_mode cons `new_type` is type correct because `H2` and `H2_prime.symm` are definitionally equal by proof irrelevance. 3- Create motive by abstracting `lhs` and `H2_prime` in `new_type`. */ - type_context::tmp_locals locals(ctx2); + type_context_old::tmp_locals locals(ctx2); expr H2_prime = locals.push_local("_h", mk_eq(ctx2, rhs, lhs)); expr H2_prime_symm = mk_eq_symm(ctx2, H2_prime); /* replace H2 in type with H2'.symm, where H2' is a new local that is def-eq to H2.symm */ diff --git a/src/library/tactic/tactic_evaluator.h b/src/library/tactic/tactic_evaluator.h index a3f57da370..1b3bb592d9 100644 --- a/src/library/tactic/tactic_evaluator.h +++ b/src/library/tactic/tactic_evaluator.h @@ -23,7 +23,7 @@ private: protected: virtual void process_failure(vm_state & S, vm_obj const & r) override; public: - tactic_evaluator(type_context & ctx, options const & opts, expr const & ref, bool allow_profiler = false): + tactic_evaluator(type_context_old & ctx, options const & opts, expr const & ref, bool allow_profiler = false): tactic::evaluator(ctx, opts, allow_profiler), m_ref(ref) {} virtual vm_obj operator()(expr const & tactic, buffer const & args, tactic_state const & s) override; vm_obj operator()(expr const & tactic, tactic_state const & s) { diff --git a/src/library/tactic/tactic_state.cpp b/src/library/tactic/tactic_state.cpp index 26fb63ed79..53e67a3c24 100644 --- a/src/library/tactic/tactic_state.cpp +++ b/src/library/tactic/tactic_state.cpp @@ -171,7 +171,7 @@ tactic_state set_context_cache_id(tactic_state const & s, context_cache_id const } format tactic_state::pp_expr(formatter_factory const & fmtf, expr const & e) const { - type_context ctx = mk_cacheless_type_context_for(*this, transparency_mode::All); + type_context_old ctx = mk_cacheless_type_context_for(*this, transparency_mode::All); formatter fmt = fmtf(env(), get_options(), ctx); return fmt(e); } @@ -200,7 +200,7 @@ format tactic_state::pp_goal(formatter_factory const & fmtf, expr const & g, boo metavar_decl decl = mctx().get_metavar_decl(g); local_context lctx = decl.get_context(); metavar_context mctx_tmp = mctx(); - type_context ctx(env(), get_options(), mctx_tmp, lctx, transparency_mode::All); + type_context_old ctx(env(), get_options(), mctx_tmp, lctx, transparency_mode::All); formatter fmt = fmtf(env(), opts, ctx); if (inst_mvars) lctx = lctx.instantiate_mvars(mctx_tmp); @@ -312,7 +312,7 @@ vm_obj tactic_format_result(vm_obj const & o) { metavar_context mctx = s.mctx(); expr r = mctx.instantiate_mvars(s.main()); metavar_decl main_decl = mctx.get_metavar_decl(s.main()); - type_context ctx(s.env(), s.get_options(), mctx, main_decl.get_context(), transparency_mode::All); + type_context_old ctx(s.env(), s.get_options(), mctx, main_decl.get_context(), transparency_mode::All); formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); formatter fmt = fmtf(s.env(), s.get_options(), ctx); return tactic::mk_success(to_obj(fmt(r)), s); @@ -331,45 +331,45 @@ tactic_state_context_cache::tactic_state_context_cache(tactic_state & s): s = m_state; } -type_context tactic_state_context_cache::mk_type_context(tactic_state const & s, local_context const & lctx, transparency_mode m) { +type_context_old tactic_state_context_cache::mk_type_context(tactic_state const & s, local_context const & lctx, transparency_mode m) { lean_assert(s.get_cache_id() == m_state.get_cache_id()); - return type_context(s.env(), s.mctx(), lctx, *this, m); + return type_context_old(s.env(), s.mctx(), lctx, *this, m); } -type_context tactic_state_context_cache::mk_type_context(tactic_state const & s, transparency_mode m) { +type_context_old tactic_state_context_cache::mk_type_context(tactic_state const & s, transparency_mode m) { local_context lctx; if (auto d = s.get_main_goal_decl()) lctx = d->get_context(); return mk_type_context(s, lctx, m); } -type_context tactic_state_context_cache::mk_type_context(transparency_mode m) { +type_context_old tactic_state_context_cache::mk_type_context(transparency_mode m) { return mk_type_context(m_state, m); } -type_context mk_type_context_for(environment const & env, options const & o, metavar_context const & mctx, +type_context_old mk_type_context_for(environment const & env, options const & o, metavar_context const & mctx, local_context const & lctx, transparency_mode m) { - return type_context(env, o, mctx, lctx, m); + return type_context_old(env, o, mctx, lctx, m); } -type_context mk_type_context_for(tactic_state const & s, local_context const & lctx, transparency_mode m) { +type_context_old mk_type_context_for(tactic_state const & s, local_context const & lctx, transparency_mode m) { return mk_type_context_for(s.env(), s.get_options(), s.mctx(), lctx, m); } -type_context mk_type_context_for(tactic_state const & s, transparency_mode m) { +type_context_old mk_type_context_for(tactic_state const & s, transparency_mode m) { local_context lctx; if (auto d = s.get_main_goal_decl()) lctx = d->get_context(); return mk_type_context_for(s, lctx, m); } -type_context mk_type_context_for(vm_obj const & s) { +type_context_old mk_type_context_for(vm_obj const & s) { return mk_type_context_for(tactic::to_state(s)); } -type_context mk_type_context_for(vm_obj const & s, vm_obj const & m) { +type_context_old mk_type_context_for(vm_obj const & s, vm_obj const & m) { return mk_type_context_for(tactic::to_state(s), to_transparency_mode(m)); } -type_context mk_cacheless_type_context_for(tactic_state const & s, transparency_mode m) { +type_context_old mk_cacheless_type_context_for(tactic_state const & s, transparency_mode m) { return mk_type_context_for(s, m); } @@ -383,7 +383,7 @@ static void check_closed(char const * tac_name, expr const & e) { vm_obj tactic_infer_type(vm_obj const & e, vm_obj const & s0) { tactic_state s = tactic::to_state(s0); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); try { check_closed("infer_type", to_expr(e)); return tactic::mk_success(to_obj(ctx.infer(to_expr(e))), s); @@ -395,7 +395,7 @@ vm_obj tactic_infer_type(vm_obj const & e, vm_obj const & s0) { vm_obj tactic_whnf(vm_obj const & e, vm_obj const & t, vm_obj const & unfold_ginductive, vm_obj const & s0) { tactic_state s = tactic::to_state(s0); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(to_transparency_mode(t)); + type_context_old ctx = cache.mk_type_context(to_transparency_mode(t)); try { check_closed("whnf", to_expr(e)); if (to_bool(unfold_ginductive)) { @@ -411,7 +411,7 @@ vm_obj tactic_whnf(vm_obj const & e, vm_obj const & t, vm_obj const & unfold_gin vm_obj tactic_head_eta_expand(vm_obj const & e, vm_obj const & s0) { tactic_state s = tactic::to_state(s0); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); try { check_closed("head_eta_expand", to_expr(e)); return tactic::mk_success(to_obj(ctx.eta_expand(to_expr(e))), s); @@ -472,7 +472,7 @@ vm_obj tactic_zeta(vm_obj const & e0, vm_obj const & s0) { vm_obj tactic_is_class(vm_obj const & e, vm_obj const & s0) { tactic_state s = tactic::to_state(s0); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); try { check_closed("is_class", to_expr(e)); return tactic::mk_success(mk_vm_bool(static_cast(ctx.is_class(to_expr(e)))), s); @@ -484,7 +484,7 @@ vm_obj tactic_is_class(vm_obj const & e, vm_obj const & s0) { vm_obj tactic_mk_instance(vm_obj const & e, vm_obj const & s0) { tactic_state s = tactic::to_state(s0); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); try { check_closed("mk_instance", to_expr(e)); if (auto r = ctx.mk_class_instance(to_expr(e))) { @@ -508,7 +508,7 @@ static vm_obj mk_unify_exception(char const * header, expr const & e1, expr cons format r(header); unsigned indent = get_pp_indent(s.get_options()); formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); - type_context ctx = mk_cacheless_type_context_for(s, transparency_mode::All); + type_context_old ctx = mk_cacheless_type_context_for(s, transparency_mode::All); formatter fmt = fmtf(s.env(), s.get_options(), ctx); expr e1_type = ctx.infer(e1); expr e2_type = ctx.infer(e2); @@ -527,11 +527,11 @@ static vm_obj mk_unify_exception(char const * header, expr const & e1, expr cons vm_obj tactic_unify(vm_obj const & e1, vm_obj const & e2, vm_obj const & t, vm_obj const & approx, vm_obj const & s0) { tactic_state s = tactic::to_state(s0); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(to_transparency_mode(t)); + type_context_old ctx = cache.mk_type_context(to_transparency_mode(t)); try { check_closed("unify", to_expr(e1)); check_closed("unify", to_expr(e2)); - type_context::approximate_scope scope(ctx, to_bool(approx)); + type_context_old::approximate_scope scope(ctx, to_bool(approx)); bool r = ctx.is_def_eq(to_expr(e1), to_expr(e2)); if (r) { return tactic::mk_success(set_mctx(s, ctx.mctx())); @@ -547,11 +547,11 @@ vm_obj tactic_unify(vm_obj const & e1, vm_obj const & e2, vm_obj const & t, vm_o vm_obj tactic_is_def_eq(vm_obj const & e1, vm_obj const & e2, vm_obj const & t, vm_obj const & approx, vm_obj const & s0) { tactic_state s = tactic::to_state(s0); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(to_transparency_mode(t)); + type_context_old ctx = cache.mk_type_context(to_transparency_mode(t)); try { check_closed("is_def_eq", to_expr(e1)); check_closed("is_def_eq", to_expr(e2)); - type_context::approximate_scope scope(ctx, to_bool(approx)); + type_context_old::approximate_scope scope(ctx, to_bool(approx)); bool r = ctx.pure_is_def_eq(to_expr(e1), to_expr(e2)); if (r) { return tactic::mk_success(s); @@ -785,7 +785,7 @@ vm_obj tactic_decl_name(vm_obj const & _s) { } format tactic_state::pp() const { - type_context ctx = mk_cacheless_type_context_for(*this, transparency_mode::Semireducible); + type_context_old ctx = mk_cacheless_type_context_for(*this, transparency_mode::Semireducible); expr ts_expr = mk_constant("tactic_state"); optional to_fmt_inst = ctx.mk_class_instance(mk_app(mk_constant("has_to_format", {mk_level_zero()}), ts_expr)); if (!to_fmt_inst) { @@ -943,7 +943,7 @@ vm_obj tactic_type_check(vm_obj const & e, vm_obj const & m, vm_obj const & s0) tactic_state s = tactic::to_state(s0); try { tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(to_transparency_mode(m)); + type_context_old ctx = cache.mk_type_context(to_transparency_mode(m)); check(ctx, to_expr(e)); return tactic::mk_success(s); } catch (exception & ex) { @@ -992,7 +992,7 @@ vm_obj tactic_unfreeze_local_instances(vm_obj const & s0) { if (!g) return mk_no_goals_exception(s); local_context lctx = g->get_context(); tactic_state_context_cache cache(s); - type_context ctx = cache.mk_type_context(); + type_context_old ctx = cache.mk_type_context(); lctx.unfreeze_local_instances(); expr new_mvar = ctx.mk_metavar_decl(lctx, g->get_type()); ctx.assign(*s.get_main_goal(), new_mvar); diff --git a/src/library/tactic/tactic_state.h b/src/library/tactic/tactic_state.h index 4fd1fdd480..5a789ce864 100644 --- a/src/library/tactic/tactic_state.h +++ b/src/library/tactic/tactic_state.h @@ -177,12 +177,12 @@ format pp_indented_expr(tactic_state const & s, expr const & e); cache, a new empty cache will be created. */ class tactic_state_context_cache : public persistent_context_cache { /* - TODO(Leo): add name_generator to type_context, tactic_state, and this class. + TODO(Leo): add name_generator to type_context_old, tactic_state, and this class. When we create a `tactic_state_context_cache`: 1- Let `N` be the `name_generator` at `s`, then use it to create a child `name_generator` for this object. 2- Update `tactic_state & s` with new `N`. 3- Use the `name_generator` stored here to provide a child `name_generator` - to each `type_context` created using `mk_type_context`. + to each `type_context_old` created using `mk_type_context`. In this way, we don't have to propagate the name_generators back only forth. However, we will have to make sure we have replaced every occurrence of mk_type_context_for @@ -190,26 +190,26 @@ class tactic_state_context_cache : public persistent_context_cache { tactic_state m_state; public: tactic_state_context_cache(tactic_state & s); - /* Create a type_context object using this cache and the initial tactic_state object. */ - type_context mk_type_context(transparency_mode m = transparency_mode::Semireducible); - /* Create a type_context object using this cache and the given tactic_state object. + /* Create a type_context_old object using this cache and the initial tactic_state object. */ + type_context_old mk_type_context(transparency_mode m = transparency_mode::Semireducible); + /* Create a type_context_old object using this cache and the given tactic_state object. \pre s.get_cache_id() == m_state.get_cache_id(). */ - type_context mk_type_context(tactic_state const & s, transparency_mode m = transparency_mode::Semireducible); - type_context mk_type_context(tactic_state const & s, local_context const & lctx, transparency_mode m = transparency_mode::Semireducible); + type_context_old mk_type_context(tactic_state const & s, transparency_mode m = transparency_mode::Semireducible); + type_context_old mk_type_context(tactic_state const & s, local_context const & lctx, transparency_mode m = transparency_mode::Semireducible); }; -type_context mk_type_context_for(tactic_state const & s, transparency_mode m = transparency_mode::Semireducible); -type_context mk_type_context_for(tactic_state const & s, local_context const & lctx, transparency_mode m = transparency_mode::Semireducible); -type_context mk_type_context_for(environment const & env, options const & o, +type_context_old mk_type_context_for(tactic_state const & s, transparency_mode m = transparency_mode::Semireducible); +type_context_old mk_type_context_for(tactic_state const & s, local_context const & lctx, transparency_mode m = transparency_mode::Semireducible); +type_context_old mk_type_context_for(environment const & env, options const & o, metavar_context const & mctx, local_context const & lctx, transparency_mode m = transparency_mode::Semireducible); -type_context mk_type_context_for(vm_obj const & s); -type_context mk_type_context_for(vm_obj const & s, vm_obj const & m); +type_context_old mk_type_context_for(vm_obj const & s); +type_context_old mk_type_context_for(vm_obj const & s, vm_obj const & m); -type_context mk_cacheless_type_context_for(tactic_state const & s, transparency_mode m = transparency_mode::Semireducible); +type_context_old mk_cacheless_type_context_for(tactic_state const & s, transparency_mode m = transparency_mode::Semireducible); #define lean_tactic_trace(N, S, Code) lean_trace(N, { \ - type_context _ctx = mk_type_context_for(S); \ + type_context_old _ctx = mk_type_context_for(S); \ scope_trace_env _scope((S).env(), _ctx); \ Code \ }) diff --git a/src/library/tactic/unfold_tactic.cpp b/src/library/tactic/unfold_tactic.cpp index 9582ad00e5..eb2425327e 100644 --- a/src/library/tactic/unfold_tactic.cpp +++ b/src/library/tactic/unfold_tactic.cpp @@ -23,7 +23,7 @@ vm_obj tactic_unfold_projection(vm_obj const & _e, vm_obj const & m, vm_obj cons tactic_state const & s = tactic::to_state(_s); try { expr const & fn = get_app_fn(e); - type_context ctx = mk_type_context_for(s, to_transparency_mode(m)); + type_context_old ctx = mk_type_context_for(s, to_transparency_mode(m)); if (!is_constant(fn) || !is_projection(s.env(), const_name(fn))) return tactic::mk_exception("unfold projection failed, expression is not a projection application", s); if (auto new_e = ctx.reduce_projection(e)) @@ -34,7 +34,7 @@ vm_obj tactic_unfold_projection(vm_obj const & _e, vm_obj const & m, vm_obj cons } } -optional dunfold(type_context & ctx, expr const & e) { +optional dunfold(type_context_old & ctx, expr const & e) { environment const & env = ctx.env(); expr const & fn = get_app_fn(e); if (!is_constant(fn)) @@ -76,7 +76,7 @@ protected: expr const & fn = get_app_fn(e); if (!is_constant(fn) || !m_cs.contains(const_name(fn))) return none(); - type_context::transparency_scope scope(m_ctx, transparency_mode::Instances); + type_context_old::transparency_scope scope(m_ctx, transparency_mode::Instances); optional new_e; if (is_projection(m_ctx.env(), const_name(fn))) { new_e = m_ctx.reduce_projection(e); @@ -93,7 +93,7 @@ protected: } public: - unfold_core_fn(type_context & ctx, defeq_canonizer::state & dcs, list const & cs, dsimp_config const & cfg): + unfold_core_fn(type_context_old & ctx, defeq_canonizer::state & dcs, list const & cs, dsimp_config const & cfg): dsimplify_core_fn(ctx, dcs, cfg), m_cs(to_name_set(cs)) { m_cfg.m_zeta = false; @@ -105,7 +105,7 @@ class unfold_fn : public unfold_core_fn { return unfold_step(e); } public: - unfold_fn(type_context & ctx, defeq_canonizer::state & dcs, list const & cs, dsimp_config const & cfg): + unfold_fn(type_context_old & ctx, defeq_canonizer::state & dcs, list const & cs, dsimp_config const & cfg): unfold_core_fn(ctx, dcs, cs, cfg) { } }; @@ -119,7 +119,7 @@ vm_obj tactic_dunfold(vm_obj const & cs, vm_obj const & _e, vm_obj const & _cfg, (md := transparency.instances) -- this is not a new field. */ dsimp_config cfg(_cfg); - type_context ctx = mk_type_context_for(s, cfg.m_md); + type_context_old ctx = mk_type_context_for(s, cfg.m_md); unfold_fn F(ctx, dcs, to_list_name(cs), cfg); try { expr new_e = F(e); @@ -143,12 +143,12 @@ vm_obj tactic_dunfold_head(vm_obj const & _e, vm_obj const & m, vm_obj const & _ if (!is_constant(fn)) return tactic::mk_exception("dunfold_expr failed, expression is not a constant nor a constant application", s); if (is_projection(s.env(), const_name(fn))) { - type_context ctx = mk_type_context_for(s, to_transparency_mode(m)); + type_context_old ctx = mk_type_context_for(s, to_transparency_mode(m)); if (auto new_e = ctx.reduce_projection(e)) return tactic::mk_success(to_obj(*new_e), s); return tactic::mk_exception("dunfold_expr failed, failed to unfold projection", s); } else if (has_eqn_lemmas(env, const_name(fn))) { - type_context ctx = mk_type_context_for(s, to_transparency_mode(m)); + type_context_old ctx = mk_type_context_for(s, to_transparency_mode(m)); if (auto new_e = dunfold(ctx, e)) { return tactic::mk_success(to_obj(*new_e), s); } else { diff --git a/src/library/tactic/unfold_tactic.h b/src/library/tactic/unfold_tactic.h index 4d8c0f053d..c63028c8ac 100644 --- a/src/library/tactic/unfold_tactic.h +++ b/src/library/tactic/unfold_tactic.h @@ -9,7 +9,7 @@ Author: Leonardo de Moura namespace lean { /* Given (f ...), try to unfold it using (refl) equational lemmas for f. */ -optional dunfold(type_context & ctx, expr const & e); +optional dunfold(type_context_old & ctx, expr const & e); void initialize_unfold_tactic(); void finalize_unfold_tactic(); } diff --git a/src/library/tactic/user_attribute.cpp b/src/library/tactic/user_attribute.cpp index 3b65655b6e..54ab6dd777 100644 --- a/src/library/tactic/user_attribute.cpp +++ b/src/library/tactic/user_attribute.cpp @@ -69,7 +69,7 @@ public: attr_data_ptr parse_data(abstract_parser & p) const override final { lean_assert(dynamic_cast(&p)); auto & p2 = *static_cast(&p); - type_context ctx(p2.env(), p2.get_options()); + type_context_old ctx(p2.env(), p2.get_options()); expr parser = mk_app(ctx, get_user_attribute_parse_reflect_name(), 3, mk_constant(m_decl)); expr param = to_expr(run_parser(p2, parser)); return attr_data_ptr(new user_attribute_data(param)); @@ -95,7 +95,7 @@ vm_obj user_attribute_get_param_untyped(vm_obj const &, vm_obj const &, vm_obj c vm_obj user_attribute_set_untyped(expr const & beta, name const & attr_n, name const & n, expr const & val, bool persistent, unsigned prio, tactic_state const & s) { - type_context ctx(s.env(), s.get_options()); + type_context_old ctx(s.env(), s.get_options()); if (!ctx.is_def_eq(beta, ctx.infer(val))) { return tactic::mk_exception(sstream() << "set_untyped failed, '" << val << "' is not of type '" << beta << "'", s); } diff --git a/src/library/tactic/vm_monitor.cpp b/src/library/tactic/vm_monitor.cpp index 3761248e8f..c41e913aef 100644 --- a/src/library/tactic/vm_monitor.cpp +++ b/src/library/tactic/vm_monitor.cpp @@ -268,7 +268,7 @@ static format default_format(vm_state const & vm, unsigned idx) { if (auto type = info.second) { try { vm_state & curr_vm = get_vm_state(); - type_context ctx(curr_vm.env()); + type_context_old ctx(curr_vm.env()); level u = get_level(ctx, *type); expr has_to_format = mk_app(mk_constant(get_has_to_format_name(), {u}), *type); if (optional instance = ctx.mk_class_instance(has_to_format)) { @@ -304,7 +304,7 @@ vm_obj vm_pp_stack_obj(vm_obj const & i, vm_obj const & /*s*/) { format r; if (is_expr(o)) { formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); - type_context ctx(vm.env()); + type_context_old ctx(vm.env()); formatter fmt = fmtf(vm.env(), vm.get_options(), ctx); try { r = fmt(to_expr(o)); @@ -420,7 +420,7 @@ vm_obj vm_get_attribute(vm_obj const & vm_n, vm_obj const &) { vm_obj vm_pp_expr(vm_obj const & e, vm_obj const &) { auto const & vm = get_vm_state_being_debugged(); formatter_factory const & fmtf = get_global_ios().get_formatter_factory(); - type_context ctx(vm.env()); + type_context_old ctx(vm.env()); formatter fmt = fmtf(vm.env(), vm.get_options(), ctx); try { return mk_vm_success(to_obj(fmt(to_expr(e)))); diff --git a/src/library/type_context.cpp b/src/library/type_context.cpp index c9eb30eaa9..7b53954110 100644 --- a/src/library/type_context.cpp +++ b/src/library/type_context.cpp @@ -52,14 +52,14 @@ transparency_mode ensure_instances_mode(transparency_mode m) { } /* ===================== - type_context::tmp_locals + type_context_old::tmp_locals ===================== */ -type_context::tmp_locals::~tmp_locals() { +type_context_old::tmp_locals::~tmp_locals() { for (unsigned i = 0; i < m_locals.size(); i++) m_ctx.pop_local(); } -bool type_context::tmp_locals::all_let_decls() const { +bool type_context_old::tmp_locals::all_let_decls() const { for (expr const & l : m_locals) { if (optional d = m_ctx.m_lctx.find_local_decl(l)) { if (!d->get_value()) @@ -72,14 +72,14 @@ bool type_context::tmp_locals::all_let_decls() const { } /* ===================== - type_context + type_context_old ===================== */ -void type_context::cache_failure(expr const & t, expr const & s) { +void type_context_old::cache_failure(expr const & t, expr const & s) { m_cache->set_is_def_eq_failure(m_transparency_mode, t, s); } -bool type_context::is_cached_failure(expr const & t, expr const & s) { +bool type_context_old::is_cached_failure(expr const & t, expr const & s) { if (has_expr_metavar(t) || has_expr_metavar(s)) { return false; } else { @@ -87,11 +87,11 @@ bool type_context::is_cached_failure(expr const & t, expr const & s) { } } -void type_context::freeze_local_instances() { +void type_context_old::freeze_local_instances() { m_lctx.freeze_local_instances(m_local_instances); } -void type_context::init_local_instances() { +void type_context_old::init_local_instances() { m_local_instances = local_instances(); m_lctx.for_each([&](local_decl const & decl) { /* Do not use auxiliary declarations introduced by equation compiler. @@ -112,13 +112,13 @@ void type_context::init_local_instances() { }); } -void type_context::flush_instance_cache() { +void type_context_old::flush_instance_cache() { lean_trace("type_context_cache", tout() << "flushing instance cache\n";); m_cache->reset_frozen_local_instances(); m_cache->flush_instances(); } -void type_context::init_core(transparency_mode m) { +void type_context_old::init_core(transparency_mode m) { m_transparency_mode = m; m_smart_unfolding = m_cache->get_smart_unfolding(); if (auto lis = m_lctx.get_frozen_local_instances()) { @@ -136,7 +136,7 @@ void type_context::init_core(transparency_mode m) { } } -type_context::type_context(environment const & env, options const & o, metavar_context const & mctx, +type_context_old::type_context_old(environment const & env, options const & o, metavar_context const & mctx, local_context const & lctx, transparency_mode m): m_env(env), m_mctx(mctx), m_lctx(lctx), @@ -145,7 +145,7 @@ type_context::type_context(environment const & env, options const & o, metavar_c init_core(m); } -type_context::type_context(environment const & env, metavar_context const & mctx, +type_context_old::type_context_old(environment const & env, metavar_context const & mctx, local_context const & lctx, abstract_context_cache & cache, transparency_mode m): m_env(env), m_mctx(mctx), m_lctx(lctx), @@ -153,7 +153,7 @@ type_context::type_context(environment const & env, metavar_context const & mctx init_core(m); } -type_context::type_context(type_context && src): +type_context_old::type_context_old(type_context_old && src): m_env(std::move(src.m_env)), m_mctx(std::move(src.m_mctx)), m_lctx(std::move(src.m_lctx)), @@ -177,14 +177,14 @@ type_context::type_context(type_context && src): lean_assert(!src.m_transparency_pred); } -type_context::~type_context() { +type_context_old::~type_context_old() { } -void type_context::set_env(environment const & env) { +void type_context_old::set_env(environment const & env) { m_env = env; } -void type_context::update_local_instances(expr const & new_local, expr const & new_type) { +void type_context_old::update_local_instances(expr const & new_local, expr const & new_type) { if (!m_cache->get_frozen_local_instances()) { if (auto c_name = is_class(new_type)) { m_local_instances = local_instances(local_instance(*c_name, new_local), m_local_instances); @@ -193,19 +193,19 @@ void type_context::update_local_instances(expr const & new_local, expr const & n } } -expr type_context::push_local(name const & pp_name, expr const & type, binder_info const & bi) { +expr type_context_old::push_local(name const & pp_name, expr const & type, binder_info const & bi) { expr local = m_lctx.mk_local_decl(pp_name, type, bi); update_local_instances(local, type); return local; } -expr type_context::push_let(name const & ppn, expr const & type, expr const & value) { +expr type_context_old::push_let(name const & ppn, expr const & type, expr const & value) { expr local = m_lctx.mk_local_decl(ppn, type, value); update_local_instances(local, type); return local; } -void type_context::pop_local() { +void type_context_old::pop_local() { if (!m_cache->get_frozen_local_instances() && m_local_instances) { optional decl = m_lctx.find_last_local_decl(); if (decl && decl->get_name() == mlocal_name(head(m_local_instances).get_local())) { @@ -289,7 +289,7 @@ static bool process_to_revert(metavar_context const & mctx, buffer & to_re return false; } -pair type_context::revert_core(buffer & to_revert, local_context const & ctx, +pair type_context_old::revert_core(buffer & to_revert, local_context const & ctx, expr const & type, bool preserve_to_revert_order) { unsigned num = to_revert.size(); if (num == 0) @@ -347,7 +347,7 @@ pair type_context::revert_core(buffer & to_revert, lo return mk_pair(new_ctx, mk_pi(ctx, to_revert, type)); } -expr type_context::revert_core(buffer & to_revert, expr const & mvar, bool preserve_to_revert_order) { +expr type_context_old::revert_core(buffer & to_revert, expr const & mvar, bool preserve_to_revert_order) { lean_assert(is_metavar_decl_ref(mvar)); metavar_decl const & d = m_mctx.get_metavar_decl(mvar); pair p = revert_core(to_revert, d.get_context(), d.get_type(), preserve_to_revert_order); @@ -356,7 +356,7 @@ expr type_context::revert_core(buffer & to_revert, expr const & mvar, bool return copy_tag(mvar, mk_metavar_decl(p.first, p.second)); } -expr type_context::revert(buffer & to_revert, expr const & mvar, bool preserve_to_revert_order) { +expr type_context_old::revert(buffer & to_revert, expr const & mvar, bool preserve_to_revert_order) { lean_assert(is_metavar_decl_ref(mvar)); lean_assert(std::all_of(to_revert.begin(), to_revert.end(), [&](expr const & l) { return static_cast(m_mctx.find_metavar_decl(mvar)->get_context().find_local_decl(l)); })); @@ -375,7 +375,7 @@ expr type_context::revert(buffer & to_revert, expr const & mvar, bool pres /* We use delayed_abstract_locals to make sure the variables being abstracted will be abstracted correctly when any unassigned metavar ?M occurring in \c e gets instantiated. */ -expr type_context::abstract_locals(expr const & e, unsigned num_locals, expr const * locals) { +expr type_context_old::abstract_locals(expr const & e, unsigned num_locals, expr const * locals) { lean_assert(std::all_of(locals, locals+num_locals, is_local_decl_ref)); if (num_locals == 0) return e; @@ -388,7 +388,7 @@ expr type_context::abstract_locals(expr const & e, unsigned num_locals, expr con return delayed_abstract_locals(m_mctx, new_e, num_locals, locals); } -expr type_context::mk_binding(bool is_pi, local_context const & lctx, unsigned num_locals, expr const * locals, expr const & e) { +expr type_context_old::mk_binding(bool is_pi, local_context const & lctx, unsigned num_locals, expr const * locals, expr const & e) { buffer decls; buffer types; buffer> values; @@ -417,51 +417,51 @@ expr type_context::mk_binding(bool is_pi, local_context const & lctx, unsigned n return new_e; } -expr type_context::mk_lambda(local_context const & lctx, buffer const & locals, expr const & e) { +expr type_context_old::mk_lambda(local_context const & lctx, buffer const & locals, expr const & e) { return mk_binding(false, lctx, locals.size(), locals.data(), e); } -expr type_context::mk_pi(local_context const & lctx, buffer const & locals, expr const & e) { +expr type_context_old::mk_pi(local_context const & lctx, buffer const & locals, expr const & e) { return mk_binding(true, lctx, locals.size(), locals.data(), e); } -expr type_context::mk_lambda(local_context const & lctx, expr const & local, expr const & e) { +expr type_context_old::mk_lambda(local_context const & lctx, expr const & local, expr const & e) { return mk_binding(false, lctx, 1, &local, e); } -expr type_context::mk_pi(local_context const & lctx, expr const & local, expr const & e) { +expr type_context_old::mk_pi(local_context const & lctx, expr const & local, expr const & e) { return mk_binding(true, lctx, 1, &local, e); } -expr type_context::mk_lambda(local_context const & lctx, std::initializer_list const & locals, expr const & e) { +expr type_context_old::mk_lambda(local_context const & lctx, std::initializer_list const & locals, expr const & e) { return mk_binding(false, lctx, locals.size(), locals.begin(), e); } -expr type_context::mk_pi(local_context const & lctx, std::initializer_list const & locals, expr const & e) { +expr type_context_old::mk_pi(local_context const & lctx, std::initializer_list const & locals, expr const & e) { return mk_binding(true, lctx, locals.size(), locals.begin(), e); } -expr type_context::mk_lambda(buffer const & locals, expr const & e) { +expr type_context_old::mk_lambda(buffer const & locals, expr const & e) { return mk_lambda(m_lctx, locals, e); } -expr type_context::mk_pi(buffer const & locals, expr const & e) { +expr type_context_old::mk_pi(buffer const & locals, expr const & e) { return mk_pi(m_lctx, locals, e); } -expr type_context::mk_lambda(expr const & local, expr const & e) { +expr type_context_old::mk_lambda(expr const & local, expr const & e) { return mk_lambda(m_lctx, local, e); } -expr type_context::mk_pi(expr const & local, expr const & e) { +expr type_context_old::mk_pi(expr const & local, expr const & e) { return mk_pi(m_lctx, local, e); } -expr type_context::mk_lambda(std::initializer_list const & locals, expr const & e) { +expr type_context_old::mk_lambda(std::initializer_list const & locals, expr const & e) { return mk_lambda(m_lctx, locals, e); } -expr type_context::mk_pi(std::initializer_list const & locals, expr const & e) { +expr type_context_old::mk_pi(std::initializer_list const & locals, expr const & e) { return mk_pi(m_lctx, locals, e); } @@ -469,7 +469,7 @@ expr type_context::mk_pi(std::initializer_list const & locals, expr const Normalization -------------------- */ -optional type_context::get_decl(transparency_mode m, name const & n) { +optional type_context_old::get_decl(transparency_mode m, name const & n) { if (m_transparency_pred) { if ((*m_transparency_pred)(n)) { return env().find(n); @@ -481,7 +481,7 @@ optional type_context::get_decl(transparency_mode m, name const & n } } -optional type_context::get_decl(name const & n) { +optional type_context_old::get_decl(name const & n) { return get_decl(m_transparency_mode, n); } @@ -508,7 +508,7 @@ static expr ext_unfold_fn(environment const & env, expr const & fn) { } /* Unfold \c e if it is a constant */ -optional type_context::unfold_definition_core(expr const & e) { +optional type_context_old::unfold_definition_core(expr const & e) { if (is_constant(e)) { if (auto d = get_decl(const_name(e))) { if (length(const_levels(e)) == d->get_num_univ_params()) @@ -533,7 +533,7 @@ static optional extract_id_rhs(expr const & e) { } /* Unfold head(e) if it is a constant */ -optional type_context::unfold_definition(expr const & e) { +optional type_context_old::unfold_definition(expr const & e) { flet inc_depth(m_unfold_depth, m_unfold_depth+1); if (is_app(e)) { expr f0 = get_app_fn(e); @@ -607,7 +607,7 @@ optional type_context::unfold_definition(expr const & e) { } } -projection_info const * type_context::is_projection(expr const & e) { +projection_info const * type_context_old::is_projection(expr const & e) { expr const & f = get_app_fn(e); if (!is_constant(f)) return nullptr; @@ -619,7 +619,7 @@ projection_info const * type_context::is_projection(expr const & e) { return info; } -optional type_context::reduce_projection_core(projection_info const * info, expr const & e) { +optional type_context_old::reduce_projection_core(projection_info const * info, expr const & e) { buffer args; get_app_args(e, args); lean_assert(args.size() > info->m_nparams); @@ -639,14 +639,14 @@ optional type_context::reduce_projection_core(projection_info const * info return some_expr(r); } -optional type_context::reduce_projection(expr const & e) { +optional type_context_old::reduce_projection(expr const & e) { projection_info const * info = is_projection(e); if (!info) return none_expr(); return reduce_projection_core(info, e); } -optional type_context::reduce_aux_recursor(expr const & e) { +optional type_context_old::reduce_aux_recursor(expr const & e) { expr const & f = get_app_fn(e); if (!is_constant(f)) return none_expr(); @@ -658,7 +658,7 @@ optional type_context::reduce_aux_recursor(expr const & e) { } } -optional type_context::reduce_large_elim_recursor(expr const & e) { +optional type_context_old::reduce_large_elim_recursor(expr const & e) { expr const & f = get_app_fn(e); if (!is_constant(f)) return none_expr(); @@ -670,7 +670,7 @@ optional type_context::reduce_large_elim_recursor(expr const & e) { return none_expr(); } -bool type_context::should_unfold_macro(expr const &) { +bool type_context_old::should_unfold_macro(expr const &) { /* If m_transparency_mode is set to ALL, then we unfold all macros. In this way, we make sure type inference does not fail. We also unfold macros when reducing inside of is_def_eq. */ @@ -681,7 +681,7 @@ bool type_context::should_unfold_macro(expr const &) { } } -optional type_context::expand_macro(expr const & e) { +optional type_context_old::expand_macro(expr const & e) { lean_assert(is_macro(e)); if (should_unfold_macro(e)) { return macro_def(e).expand(e, *this); @@ -690,11 +690,11 @@ optional type_context::expand_macro(expr const & e) { } } -bool type_context::use_zeta() const { +bool type_context_old::use_zeta() const { return m_zeta; } -optional type_context::reduce_recursor(expr const & e) { +optional type_context_old::reduce_recursor(expr const & e) { if (auto r = norm_ext(e)) return r; if (auto r = reduce_aux_recursor(e)) @@ -715,7 +715,7 @@ optional type_context::reduce_recursor(expr const & e) { Remark: if proj_reduce is false, then projection reduction is not performed. */ -expr type_context::whnf_core(expr const & e0, bool proj_reduce) { +expr type_context_old::whnf_core(expr const & e0, bool proj_reduce) { expr e = e0; while (true) { switch (e.kind()) { case expr_kind::Var: case expr_kind::Sort: @@ -818,7 +818,7 @@ expr type_context::whnf_core(expr const & e0, bool proj_reduce) { }}} } -expr type_context::whnf(expr const & e) { +expr type_context_old::whnf(expr const & e) { switch (e.kind()) { case expr_kind::Var: case expr_kind::Sort: case expr_kind::Pi: case expr_kind::Lambda: @@ -846,7 +846,7 @@ expr type_context::whnf(expr const & e) { } } -expr type_context::whnf_head_pred(expr const & e, std::function const & pred) { // NOLINT +expr type_context_old::whnf_head_pred(expr const & e, std::function const & pred) { // NOLINT expr t = e; while (true) { expr t1 = whnf_core(t, true); @@ -860,17 +860,17 @@ expr type_context::whnf_head_pred(expr const & e, std::function const & pred) { // NOLINT +expr type_context_old::whnf_transparency_pred(expr const & e, std::function const & pred) { // NOLINT flet const *>set_trans_pred(m_transparency_pred, &pred); // NOLINT return whnf(e); } -expr type_context::relaxed_whnf(expr const & e) { +expr type_context_old::relaxed_whnf(expr const & e) { relaxed_scope scope(*this); return whnf(e); } -optional type_context::is_stuck_projection(expr const & e) { +optional type_context_old::is_stuck_projection(expr const & e) { expr const & f = get_app_fn(e); if (!is_constant(f)) return none_expr(); // it is not projection app projection_info const * info = m_cache->get_proj_info(*this, const_name(f)); @@ -883,7 +883,7 @@ optional type_context::is_stuck_projection(expr const & e) { return is_stuck(mk); } -optional type_context::is_stuck(expr const & e) { +optional type_context_old::is_stuck(expr const & e) { if (is_meta(e)) { return some_expr(e); } else if (auto r = is_stuck_projection(e)) { @@ -895,7 +895,7 @@ optional type_context::is_stuck(expr const & e) { } } -expr type_context::try_to_pi(expr const & e) { +expr type_context_old::try_to_pi(expr const & e) { expr new_e = whnf(e); if (is_pi(new_e)) return new_e; @@ -903,7 +903,7 @@ expr type_context::try_to_pi(expr const & e) { return e; } -expr type_context::relaxed_try_to_pi(expr const & e) { +expr type_context_old::relaxed_try_to_pi(expr const & e) { relaxed_scope scope(*this); return try_to_pi(e); } @@ -912,12 +912,12 @@ expr type_context::relaxed_try_to_pi(expr const & e) { Type inference --------------- */ -expr type_context::infer(expr const & e) { +expr type_context_old::infer(expr const & e) { relaxed_scope scope(*this); return infer_core(e); } -expr type_context::infer_core(expr const & e) { +expr type_context_old::infer_core(expr const & e) { if (auto r = m_cache->get_infer(e)) return *r; unsigned postponed_sz = m_postponed.size(); @@ -963,7 +963,7 @@ expr type_context::infer_core(expr const & e) { return r; } -expr type_context::infer_local(expr const & e) { +expr type_context_old::infer_local(expr const & e) { lean_assert(is_local(e)); if (is_local_decl_ref(e)) { optional d = m_lctx.find_local_decl(e); @@ -987,7 +987,7 @@ static void throw_unknown_metavar(expr const & e) { }); } -expr type_context::infer_metavar(expr const & e) { +expr type_context_old::infer_metavar(expr const & e) { if (is_metavar_decl_ref(e)) { auto d = m_mctx.find_metavar_decl(e); if (!d) throw_unknown_metavar(e); @@ -1000,7 +1000,7 @@ expr type_context::infer_metavar(expr const & e) { } } -expr type_context::infer_constant(expr const & e) { +expr type_context_old::infer_constant(expr const & e) { declaration d = env().get(const_name(e)); auto const & ps = d.get_univ_params(); auto const & ls = const_levels(e); @@ -1013,7 +1013,7 @@ expr type_context::infer_constant(expr const & e) { return instantiate_type_univ_params(d, ls); } -expr type_context::infer_macro(expr const & e) { +expr type_context_old::infer_macro(expr const & e) { if (is_delayed_abstraction(e)) { expr const & mvar = get_delayed_abstraction_expr(e); if (!is_metavar_decl_ref(mvar)) { @@ -1035,7 +1035,7 @@ expr type_context::infer_macro(expr const & e) { return def.check_type(e, *this, infer_only); } -expr type_context::infer_lambda(expr e) { +expr type_context_old::infer_lambda(expr e) { buffer es, ds; tmp_locals ls(*this); while (is_lambda(e)) { @@ -1056,7 +1056,7 @@ expr type_context::infer_lambda(expr e) { return r; } -optional type_context::get_level_core(expr const & A) { +optional type_context_old::get_level_core(expr const & A) { lean_assert(m_transparency_mode == transparency_mode::All); expr A_type = whnf(infer_core(A)); while (true) { @@ -1076,7 +1076,7 @@ optional type_context::get_level_core(expr const & A) { return some_level(r); } else if (is_tmp_mvar(A_type) && in_tmp_mode()) { /* The condition `in_tmp_mode()` may seem unnecessary, but we - include it since `type_context` often has to process + include it since `type_context_old` often has to process ill-formed expressions produced by error recovery. */ level r = mk_tmp_univ_mvar(); assign(A_type, mk_sort(r)); @@ -1090,7 +1090,7 @@ optional type_context::get_level_core(expr const & A) { } } -level type_context::get_level(expr const & A) { +level type_context_old::get_level(expr const & A) { if (auto r = get_level_core(A)) { return *r; } else { @@ -1100,7 +1100,7 @@ level type_context::get_level(expr const & A) { } } -expr type_context::infer_pi(expr e) { +expr type_context_old::infer_pi(expr e) { tmp_locals ls(*this); buffer us; while (is_pi(e)) { @@ -1119,7 +1119,7 @@ expr type_context::infer_pi(expr e) { return mk_sort(r); } -expr type_context::infer_app(expr const & e) { +expr type_context_old::infer_app(expr const & e) { check_system("infer_type"); buffer args; expr const & f = get_app_args(e, args); @@ -1144,7 +1144,7 @@ expr type_context::infer_app(expr const & e) { return instantiate_rev(f_type, nargs-j, args.data()+j); } -expr type_context::infer_let(expr e) { +expr type_context_old::infer_let(expr e) { /* We may also infer the type of a let-expression by using tmp_locals, push_let, and they closing the resulting type with @@ -1163,24 +1163,24 @@ expr type_context::infer_let(expr e) { return infer_core(instantiate_rev(e, vs.size(), vs.data())); } -expr type_context::check(expr const & e) { +expr type_context_old::check(expr const & e) { // TODO(Leo): infer doesn't really check anything return infer(e); } -bool type_context::is_prop(expr const & e) { +bool type_context_old::is_prop(expr const & e) { expr t = whnf(infer(e)); return t == mk_Prop(); } -bool type_context::is_proof(expr const & e) { +bool type_context_old::is_proof(expr const & e) { return is_prop(infer(e)); } /* ------------------------------- Temporary assignment mode support ------------------------------- */ -void type_context::ensure_num_tmp_mvars(unsigned num_uvars, unsigned num_mvars) { +void type_context_old::ensure_num_tmp_mvars(unsigned num_uvars, unsigned num_mvars) { lean_assert(in_tmp_mode()); if (m_tmp_data->m_uassignment.size() < num_uvars) m_tmp_data->m_uassignment.resize(num_uvars, none_level()); @@ -1188,29 +1188,29 @@ void type_context::ensure_num_tmp_mvars(unsigned num_uvars, unsigned num_mvars) m_tmp_data->m_eassignment.resize(num_mvars, none_expr()); } -optional type_context::get_tmp_uvar_assignment(unsigned idx) const { +optional type_context_old::get_tmp_uvar_assignment(unsigned idx) const { lean_assert(in_tmp_mode()); lean_assert(idx < m_tmp_data->m_uassignment.size()); return m_tmp_data->m_uassignment[idx]; } -optional type_context::get_tmp_mvar_assignment(unsigned idx) const { +optional type_context_old::get_tmp_mvar_assignment(unsigned idx) const { lean_assert(in_tmp_mode()); lean_assert(idx < m_tmp_data->m_eassignment.size()); return m_tmp_data->m_eassignment[idx]; } -optional type_context::get_tmp_assignment(level const & l) const { +optional type_context_old::get_tmp_assignment(level const & l) const { lean_assert(is_idx_metauniv(l)); return get_tmp_uvar_assignment(to_meta_idx(l)); } -optional type_context::get_tmp_assignment(expr const & e) const { +optional type_context_old::get_tmp_assignment(expr const & e) const { lean_assert(is_idx_metavar(e)); return get_tmp_mvar_assignment(to_meta_idx(e)); } -void type_context::assign_tmp(level const & u, level const & l) { +void type_context_old::assign_tmp(level const & u, level const & l) { lean_assert(in_tmp_mode()); lean_assert(is_idx_metauniv(u)); lean_assert(to_meta_idx(u) < m_tmp_data->m_uassignment.size()); @@ -1221,7 +1221,7 @@ void type_context::assign_tmp(level const & u, level const & l) { m_tmp_data->m_uassignment[idx] = l; } -void type_context::assign_tmp(expr const & m, expr const & v) { +void type_context_old::assign_tmp(expr const & m, expr const & v) { lean_assert(in_tmp_mode()); lean_assert(is_idx_metavar(m)); lean_assert(to_meta_idx(m) < m_tmp_data->m_eassignment.size()); @@ -1234,21 +1234,21 @@ void type_context::assign_tmp(expr const & m, expr const & v) { m_tmp_data->m_eassignment[to_meta_idx(m)] = v; } -level type_context::mk_tmp_univ_mvar() { +level type_context_old::mk_tmp_univ_mvar() { lean_assert(in_tmp_mode()); unsigned idx = m_tmp_data->m_uassignment.size(); m_tmp_data->m_uassignment.push_back(none_level()); return mk_idx_metauniv(idx); } -expr type_context::mk_tmp_mvar(expr const & type) { +expr type_context_old::mk_tmp_mvar(expr const & type) { lean_assert(in_tmp_mode()); unsigned idx = m_tmp_data->m_eassignment.size(); m_tmp_data->m_eassignment.push_back(none_expr()); return mk_idx_metavar(idx, type); } -void type_context::resize_tmp_mvars(unsigned sz) { +void type_context_old::resize_tmp_mvars(unsigned sz) { lean_assert(in_tmp_mode()); m_tmp_data->m_eassignment.resize(sz, optional()); } @@ -1256,61 +1256,61 @@ void type_context::resize_tmp_mvars(unsigned sz) { /* ----------------------------------- Uniform interface to temporary & regular metavariables ----------------------------------- */ -bool type_context::is_mvar(level const & l) const { +bool type_context_old::is_mvar(level const & l) const { return (in_tmp_mode() && is_idx_metauniv(l)) || is_metavar_decl_ref(l); } -bool type_context::is_mvar(expr const & e) const { +bool type_context_old::is_mvar(expr const & e) const { return (in_tmp_mode() && is_idx_metavar(e)) || is_metavar_decl_ref(e); } -bool type_context::is_mode_mvar(level const & l) const { +bool type_context_old::is_mode_mvar(level const & l) const { if (in_tmp_mode()) return is_idx_metauniv(l); else return is_metavar_decl_ref(l); } -bool type_context::is_mode_mvar(expr const & e) const { +bool type_context_old::is_mode_mvar(expr const & e) const { if (in_tmp_mode()) return is_idx_metavar(e); else return is_metavar_decl_ref(e); } -bool type_context::is_assigned(level const & l) const { - const_cast(this)->m_used_assignment = true; +bool type_context_old::is_assigned(level const & l) const { + const_cast(this)->m_used_assignment = true; if (in_tmp_mode() && is_idx_metauniv(l)) return static_cast(get_tmp_assignment(l)); else return m_mctx.is_assigned(l); } -bool type_context::is_assigned(expr const & e) const { - const_cast(this)->m_used_assignment = true; +bool type_context_old::is_assigned(expr const & e) const { + const_cast(this)->m_used_assignment = true; if (in_tmp_mode() && is_idx_metavar(e)) return static_cast(get_tmp_assignment(e)); else return m_mctx.is_assigned(e); } -optional type_context::get_assignment(level const & l) const { - const_cast(this)->m_used_assignment = true; +optional type_context_old::get_assignment(level const & l) const { + const_cast(this)->m_used_assignment = true; if (in_tmp_mode() && is_idx_metauniv(l)) return get_tmp_assignment(l); else return m_mctx.get_assignment(l); } -optional type_context::get_assignment(expr const & e) const { - const_cast(this)->m_used_assignment = true; +optional type_context_old::get_assignment(expr const & e) const { + const_cast(this)->m_used_assignment = true; if (in_tmp_mode() && is_idx_metavar(e)) return get_tmp_assignment(e); else return m_mctx.get_assignment(e); } -void type_context::assign(level const & u, level const & l) { +void type_context_old::assign(level const & u, level const & l) { m_used_assignment = true; if (in_tmp_mode() && is_idx_metauniv(u)) assign_tmp(u, l); @@ -1318,7 +1318,7 @@ void type_context::assign(level const & u, level const & l) { m_mctx.assign(u, l); } -void type_context::assign(expr const & m, expr const & v) { +void type_context_old::assign(expr const & m, expr const & v) { m_used_assignment = true; if (in_tmp_mode() && is_idx_metavar(m)) assign_tmp(m, v); @@ -1326,18 +1326,18 @@ void type_context::assign(expr const & m, expr const & v) { m_mctx.assign(m, v); } -level type_context::mk_fresh_univ_metavar() { +level type_context_old::mk_fresh_univ_metavar() { if (in_tmp_mode()) return mk_tmp_univ_mvar(); else return mk_univ_metavar_decl(); } -level type_context::instantiate_mvars(level const & l) { +level type_context_old::instantiate_mvars(level const & l) { return ::lean::instantiate_mvars(*this, l); } -expr type_context::instantiate_mvars(expr const & e, bool postpone_push_delayed) { +expr type_context_old::instantiate_mvars(expr const & e, bool postpone_push_delayed) { return ::lean::instantiate_mvars(*this, e, postpone_push_delayed); } @@ -1345,7 +1345,7 @@ expr type_context::instantiate_mvars(expr const & e, bool postpone_push_delayed) Backtracking ----------------------------------- */ -void type_context::push_scope() { +void type_context_old::push_scope() { if (in_tmp_mode()) { m_scopes.emplace_back(m_mctx, m_tmp_data->m_uassignment.size(), m_tmp_data->m_eassignment.size(), m_tmp_data->m_trail.size()); } else { @@ -1353,7 +1353,7 @@ void type_context::push_scope() { } } -void type_context::pop_scope() { +void type_context_old::pop_scope() { lean_assert(!m_scopes.empty()); scope_data const & s = m_scopes.back(); m_mctx = s.m_mctx; @@ -1377,7 +1377,7 @@ void type_context::pop_scope() { m_scopes.pop_back(); } -void type_context::commit_scope() { +void type_context_old::commit_scope() { lean_assert(!m_scopes.empty()); m_scopes.pop_back(); } @@ -1416,7 +1416,7 @@ static bool generalized_check_meta(level const & m, level const & rhs, bool & fo creating a fresh metavariable ?w and assigning ?u := max v ?w */ -bool type_context::solve_u_eq_max_u_v(level const & lhs, level const & rhs) { +bool type_context_old::solve_u_eq_max_u_v(level const & lhs, level const & rhs) { lean_assert(is_meta(lhs)); lean_assert(occurs(lhs, rhs)); buffer rest; @@ -1440,7 +1440,7 @@ bool type_context::solve_u_eq_max_u_v(level const & lhs, level const & rhs) { } } -lbool type_context::is_def_eq_core(level const & l1, level const & l2, bool partial) { +lbool type_context_old::is_def_eq_core(level const & l1, level const & l2, bool partial) { if (is_equivalent(l1, l2)) return l_true; @@ -1510,17 +1510,17 @@ lbool type_context::is_def_eq_core(level const & l1, level const & l2, bool part lean_unreachable(); } -lbool type_context::partial_is_def_eq(level const & l1, level const & l2) { +lbool type_context_old::partial_is_def_eq(level const & l1, level const & l2) { return is_def_eq_core(l1, l2, true); } -bool type_context::full_is_def_eq(level const & l1, level const & l2) { +bool type_context_old::full_is_def_eq(level const & l1, level const & l2) { lbool r = is_def_eq_core(l1, l2, false); lean_assert(r != l_undef); return r == l_true; } -bool type_context::is_def_eq(level const & l1, level const & l2) { +bool type_context_old::is_def_eq(level const & l1, level const & l2) { lbool success = partial_is_def_eq(l1, l2); if (success == l_undef) { m_postponed.emplace_back(l1, l2); @@ -1534,7 +1534,7 @@ bool type_context::is_def_eq(level const & l1, level const & l2) { } } -bool type_context::is_def_eq(levels const & ls1, levels const & ls2) { +bool type_context_old::is_def_eq(levels const & ls1, levels const & ls2) { if (is_nil(ls1) && is_nil(ls2)) { return true; } else if (!is_nil(ls1) && !is_nil(ls2)) { @@ -1546,7 +1546,7 @@ bool type_context::is_def_eq(levels const & ls1, levels const & ls2) { } } -bool type_context::process_postponed(scope const & s) { +bool type_context_old::process_postponed(scope const & s) { unsigned sz = s.m_postponed_sz; lean_assert(m_postponed.size() >= sz); if (m_postponed.size() == sz) @@ -1603,7 +1603,7 @@ bool type_context::process_postponed(scope const & s) { /** \brief Return some definition \c d iff \c e is a target for delta-reduction, and the given definition is the one to be expanded. */ -optional type_context::is_delta(expr const & e) { +optional type_context_old::is_delta(expr const & e) { expr const & f = get_app_fn(e); if (is_constant(f)) { return get_decl(const_name(f)); @@ -1612,12 +1612,12 @@ optional type_context::is_delta(expr const & e) { } } -bool type_context::approximate() { +bool type_context_old::approximate() { return in_tmp_mode() || m_approximate; } /* If \c e is a let local-decl, then unfold it, otherwise return e. */ -expr type_context::try_zeta(expr const & e) { +expr type_context_old::try_zeta(expr const & e) { if (!is_local_decl_ref(e)) return e; if (auto d = m_lctx.find_local_decl(e)) { @@ -1627,7 +1627,7 @@ expr type_context::try_zeta(expr const & e) { return e; } -expr type_context::expand_let_decls(expr const & e) { +expr type_context_old::expand_let_decls(expr const & e) { return replace(e, [&](expr const & e, unsigned) { if (is_local_decl_ref(e)) { if (auto d = m_lctx.find_local_decl(e)) { @@ -1793,7 +1793,7 @@ Now, we consider some workarounds/approximations. then we use first-order unification (if approximate() is true) */ -bool type_context::process_assignment(expr const & m, expr const & v) { +bool type_context_old::process_assignment(expr const & m, expr const & v) { lean_trace(name({"type_context", "is_def_eq_detail"}), scope_trace_env scope(env(), *this); tout() << "process_assignment " << m << " := " << v << "\n";); @@ -1971,7 +1971,7 @@ bool type_context::process_assignment(expr const & m, expr const & v) { mvar args[0] ... args[args.size()-1] =?= v */ -bool type_context::process_assignment_fo_approx_core(expr const & mvar, buffer const & args, expr const & v) { +bool type_context_old::process_assignment_fo_approx_core(expr const & mvar, buffer const & args, expr const & v) { lean_assert(is_mvar(mvar)); buffer v_args; expr v_fn = get_app_args(v, v_args); @@ -2056,7 +2056,7 @@ bool type_context::process_assignment_fo_approx_core(expr const & mvar, buffer const & args, expr const & v) { +bool type_context_old::process_assignment_fo_approx(expr const & mvar, buffer const & args, expr const & v) { expr curr_v = v; while (true) { { @@ -2077,14 +2077,14 @@ bool type_context::process_assignment_fo_approx(expr const & mvar, buffer struct check_assignment_failed {}; struct check_assignment_fn : public replace_visitor { - type_context & m_ctx; + type_context_old & m_ctx; buffer const & m_locals; buffer const & m_in_ctx_locals; expr const & m_mvar; optional m_mvar_decl; expr m_value; - check_assignment_fn(type_context & ctx, buffer const & locals, buffer const & in_ctx_locals, expr const & mvar): + check_assignment_fn(type_context_old & ctx, buffer const & locals, buffer const & in_ctx_locals, expr const & mvar): m_ctx(ctx), m_locals(locals), m_in_ctx_locals(in_ctx_locals), m_mvar(mvar) { if (!m_ctx.in_tmp_mode()) { m_mvar_decl = m_ctx.m_mctx.get_metavar_decl(mvar); @@ -2278,7 +2278,7 @@ struct check_assignment_fn : public replace_visitor { }; /* Auxiliary method for process_assignment */ -optional type_context::check_assignment(buffer const & locals, buffer const & in_ctx_locals, expr const & mvar, expr v) { +optional type_context_old::check_assignment(buffer const & locals, buffer const & in_ctx_locals, expr const & mvar, expr v) { try { return some_expr(check_assignment_fn(*this, locals, in_ctx_locals, mvar)(v)); } catch (check_assignment_failed &) { @@ -2286,7 +2286,7 @@ optional type_context::check_assignment(buffer const & locals, buffe } } -bool type_context::is_def_eq_binding(expr e1, expr e2) { +bool type_context_old::is_def_eq_binding(expr e1, expr e2) { lean_assert(e1.kind() == e2.kind()); lean_assert(is_binding(e1)); expr_kind k = e1.kind(); @@ -2315,13 +2315,13 @@ bool type_context::is_def_eq_binding(expr e1, expr e2) { instantiate_rev(e2, subst.size(), subst.data())); } -optional type_context::mk_class_instance_at(local_context const & lctx, expr const & type) { +optional type_context_old::mk_class_instance_at(local_context const & lctx, expr const & type) { if (m_cache->get_frozen_local_instances() && m_cache->get_frozen_local_instances() == lctx.get_frozen_local_instances()) { return mk_class_instance(type); } else { context_cacheless tmp_cache(*m_cache, true); - type_context tmp_ctx(env(), m_mctx, lctx, tmp_cache, m_transparency_mode); + type_context_old tmp_ctx(env(), m_mctx, lctx, tmp_cache, m_transparency_mode); auto r = tmp_ctx.mk_class_instance(type); if (r) m_mctx = tmp_ctx.mctx(); @@ -2332,7 +2332,7 @@ optional type_context::mk_class_instance_at(local_context const & lctx, ex /** \brief Create a nested type class instance of the given type, and assign it to metavariable \c m. Return true iff the instance was successfully created. \remark This method is used to resolve nested type class resolution problems. */ -bool type_context::mk_nested_instance(expr const & m, expr const & m_type) { +bool type_context_old::mk_nested_instance(expr const & m, expr const & m_type) { lean_assert(is_mvar(m)); /* IMPORTANT: when mk_nested_instance is invoked we must make sure that we use the local context where 'm' was declared. */ @@ -2354,7 +2354,7 @@ bool type_context::mk_nested_instance(expr const & m, expr const & m_type) { } } -expr type_context::complete_instance(expr const & e) { +expr type_context_old::complete_instance(expr const & e) { if (!has_expr_metavar(e)) return e; if (is_app(e)) { @@ -2396,7 +2396,7 @@ expr type_context::complete_instance(expr const & e) { return e; } -bool type_context::is_def_eq_args(expr const & e1, expr const & e2) { +bool type_context_old::is_def_eq_args(expr const & e1, expr const & e2) { lean_assert(is_app(e1) && is_app(e2)); buffer args1, args2; expr const & fn = get_app_args(e1, args1); @@ -2466,7 +2466,7 @@ bool type_context::is_def_eq_args(expr const & e1, expr const & e2) { Example: (lambda x : A, f ?M) =?= f The lhs cannot be eta-reduced because ?M is a meta-variable. */ -bool type_context::is_def_eq_eta(expr const & e1, expr const & e2) { +bool type_context_old::is_def_eq_eta(expr const & e1, expr const & e2) { if (is_lambda(e1) && !is_lambda(e2)) { expr e2_type = relaxed_whnf(infer(e2)); if (is_pi(e2_type)) { @@ -2484,7 +2484,7 @@ bool type_context::is_def_eq_eta(expr const & e1, expr const & e2) { return false; } -bool type_context::is_def_eq_proof_irrel(expr const & e1, expr const & e2) { +bool type_context_old::is_def_eq_proof_irrel(expr const & e1, expr const & e2) { expr e1_type = infer(e1); expr e2_type = infer(e2); if (is_prop(e1_type) || is_prop(e2_type)) { @@ -2521,7 +2521,7 @@ bool type_context::is_def_eq_proof_irrel(expr const & e1, expr const & e2) { ?m1 z_1' .... z_s' a_1 ... a_k */ -optional type_context::elim_delayed_abstraction(expr const & e) { +optional type_context_old::elim_delayed_abstraction(expr const & e) { buffer args; expr f = get_app_args(e, args); lean_assert(is_delayed_abstraction(f)); @@ -2590,7 +2590,7 @@ static bool mvar_has_user_facing_name(expr const & m) { return mlocal_name(m) != mlocal_pp_name(m); } -lbool type_context::quick_is_def_eq(expr const & e1, expr const & e2) { +lbool type_context_old::quick_is_def_eq(expr const & e1, expr const & e2) { if (e1 == e2) return l_true; if (is_cached_equiv(e1, e2)) @@ -2714,7 +2714,7 @@ static bool same_head_symbol(expr const & t, expr const & s) { return is_constant(f_t) && is_constant(f_s) && const_name(f_t) == const_name(f_s); } -expr type_context::try_to_unstuck_using_complete_instance(expr const & e) { +expr type_context_old::try_to_unstuck_using_complete_instance(expr const & e) { lean_assert(is_stuck(e)); /* This method tries to unstuck terms such as: @@ -2770,7 +2770,7 @@ expr type_context::try_to_unstuck_using_complete_instance(expr const & e) { return complete_instance(e); } -bool type_context::on_is_def_eq_failure(expr const & e1, expr const & e2) { +bool type_context_old::on_is_def_eq_failure(expr const & e1, expr const & e2) { lean_trace(name({"type_context", "is_def_eq_detail"}), scope_trace_env scope(env(), *this); tout() << "on failure: " << e1 << " =?= " << e2 << "\n";); @@ -2836,7 +2836,7 @@ static optional eval_num(expr const & e) { } /* If e is a (small) numeral, then return it. Otherwise return none. */ -optional type_context::to_small_num(expr const & e) { +optional type_context_old::to_small_num(expr const & e) { if (optional r = eval_num(e)) { if (r->is_unsigned_int()) { unsigned r1 = r->get_unsigned_int(); @@ -2848,7 +2848,7 @@ optional type_context::to_small_num(expr const & e) { } /* If \c t is of the form (s + k) where k is a numeral, then return k. Otherwise, return none. */ -optional type_context::is_offset_term (expr const & t) { +optional type_context_old::is_offset_term (expr const & t) { if (is_app_of(t, get_has_add_add_name(), 4) && /* We do not consider (s + k) to be an offset term when has_add.add is marked as irreducible */ get_reducible_status(env(), get_has_add_add_name()) != reducible_status::Irreducible) { @@ -2884,7 +2884,7 @@ static expr get_offset_term(expr const & t) { /* Return true iff t is of the form (@add _ nat_has_add a b) \pre is_offset_term(t) */ -static bool uses_nat_has_add_instance_or_succ(type_context & ctx, expr const & t) { +static bool uses_nat_has_add_instance_or_succ(type_context_old & ctx, expr const & t) { if (is_app_of(t, get_nat_succ_name(), 1)) { return true; } else if (is_app_of(t, get_has_add_add_name(), 4)) { @@ -2924,7 +2924,7 @@ static expr update_offset(expr const & t, unsigned k) { t' + k_1 =?= s' + k_2 where k_1 and k_2 are numerals, and type is nat */ -lbool type_context::try_offset_eq_offset(expr const & t, expr const & s) { +lbool type_context_old::try_offset_eq_offset(expr const & t, expr const & s) { optional k1 = is_offset_term(t); if (!k1) return l_undef; optional k2 = is_offset_term(s); @@ -2948,7 +2948,7 @@ lbool type_context::try_offset_eq_offset(expr const & t, expr const & s) { t' + k_1 =?= k_2 where k_1 and k_2 are numerals, and type is nat */ -lbool type_context::try_offset_eq_numeral(expr const & t, expr const & s) { +lbool type_context_old::try_offset_eq_numeral(expr const & t, expr const & s) { optional k1 = is_offset_term(t); if (!k1) return l_undef; optional k2 = to_small_num(s); @@ -2975,7 +2975,7 @@ lbool type_context::try_offset_eq_numeral(expr const & t, expr const & s) { If t and s are encoding the same samll numeral, we return l_true. Otherwise, we return l_undef. */ -lbool type_context::try_numeral_eq_numeral(expr const & t, expr const & s) { +lbool type_context_old::try_numeral_eq_numeral(expr const & t, expr const & s) { optional n1 = eval_num(t); if (!n1) return l_undef; optional n2 = eval_num(s); @@ -2991,7 +2991,7 @@ lbool type_context::try_numeral_eq_numeral(expr const & t, expr const & s) { } /* Solve offset constraints. See discussion at issue #1226 */ -lbool type_context::try_nat_offset_cnstrs(expr const & t, expr const & s) { +lbool type_context_old::try_nat_offset_cnstrs(expr const & t, expr const & s) { /* We should not use this feature when transparency_mode is none. See issue #1295 */ if (m_transparency_mode == transparency_mode::None) return l_undef; @@ -3008,7 +3008,7 @@ lbool type_context::try_nat_offset_cnstrs(expr const & t, expr const & s) { return try_numeral_eq_numeral(t, s); } -lbool type_context::is_def_eq_delta(expr const & t, expr const & s) { +lbool type_context_old::is_def_eq_delta(expr const & t, expr const & s) { optional d_t = is_delta(t); optional d_s = is_delta(s); @@ -3118,7 +3118,7 @@ lbool type_context::is_def_eq_delta(expr const & t, expr const & s) { return l_undef; } -lbool type_context::is_def_eq_proj(expr t, expr s) { +lbool type_context_old::is_def_eq_proj(expr t, expr s) { projection_info const * t_proj = is_projection(t); projection_info const * s_proj = is_projection(s); if (t_proj && !s_proj) { @@ -3168,7 +3168,7 @@ lbool type_context::is_def_eq_proj(expr t, expr s) { return l_undef; } -bool type_context::is_def_eq_core_core(expr t, expr s) { +bool type_context_old::is_def_eq_core_core(expr t, expr s) { lbool r = quick_is_def_eq(t, s); if (r != l_undef) return r == l_true; @@ -3246,7 +3246,7 @@ bool type_context::is_def_eq_core_core(expr t, expr s) { return on_is_def_eq_failure(t, s); } -bool type_context::is_def_eq_core(expr const & t, expr const & s) { +bool type_context_old::is_def_eq_core(expr const & t, expr const & s) { unsigned postponed_sz = m_postponed.size(); bool r = is_def_eq_core_core(t, s); if (r && postponed_sz == m_postponed.size()) { @@ -3255,7 +3255,7 @@ bool type_context::is_def_eq_core(expr const & t, expr const & s) { return r; } -bool type_context::is_def_eq(expr const & t, expr const & s) { +bool type_context_old::is_def_eq(expr const & t, expr const & s) { scope S(*this); flet in_is_def_eq(m_in_is_def_eq, true); bool success = is_def_eq_core(t, s); @@ -3271,12 +3271,12 @@ bool type_context::is_def_eq(expr const & t, expr const & s) { } } -bool type_context::relaxed_is_def_eq(expr const & e1, expr const & e2) { +bool type_context_old::relaxed_is_def_eq(expr const & e1, expr const & e2) { relaxed_scope scope(*this); return is_def_eq(e1, e2); } -bool type_context::try_unification_hint(unification_hint const & hint, expr const & e1, expr const & e2) { +bool type_context_old::try_unification_hint(unification_hint const & hint, expr const & e1, expr const & e2) { scope S(*this); flet disable_smart_unfolding(m_smart_unfolding, false); if (::lean::try_unification_hint(*this, hint, e1, e2) && process_postponed(S)) { @@ -3287,7 +3287,7 @@ bool type_context::try_unification_hint(unification_hint const & hint, expr cons } } -bool type_context::try_unification_hints(expr const & e1, expr const & e2) { +bool type_context_old::try_unification_hints(expr const & e1, expr const & e2) { expr e1_fn = get_app_fn(e1); expr e2_fn = get_app_fn(e2); if (is_constant(e1_fn) && is_constant(e2_fn)) { @@ -3312,7 +3312,7 @@ bool type_context::try_unification_hints(expr const & e1, expr const & e2) { ------------- */ /** \brief If the constant \c e is a class, return its name */ -optional type_context::constant_is_class(expr const & e) { +optional type_context_old::constant_is_class(expr const & e) { name const & cls_name = const_name(e); if (lean::is_class(env(), cls_name)) { return optional(cls_name); @@ -3321,7 +3321,7 @@ optional type_context::constant_is_class(expr const & e) { } } -optional type_context::is_full_class(expr type) { +optional type_context_old::is_full_class(expr type) { expr new_type = whnf(type); if (is_pi(new_type)) { type = new_type; @@ -3345,7 +3345,7 @@ optional type_context::is_full_class(expr type) { l_true: \c type is a class, and the name of the class is stored in \c result. l_false: \c type is not a class. l_undef: procedure did not establish whether \c type is a class or not. */ -lbool type_context::is_quick_class(expr const & type, name & result) { +lbool type_context_old::is_quick_class(expr const & type, name & result) { expr const * it = &type; while (true) { switch (it->kind()) { @@ -3388,7 +3388,7 @@ lbool type_context::is_quick_class(expr const & type, name & result) { } /** \brief Return true iff \c type is a class or Pi that produces a class. */ -optional type_context::is_class(expr const & type) { +optional type_context_old::is_class(expr const & type) { name result; switch (is_quick_class(type, result)) { case l_true: return optional(result); @@ -3418,7 +3418,7 @@ struct instance_synthesizer { state m_state; }; - type_context & m_ctx; + type_context_old & m_ctx; expr m_main_mvar; state m_state; // active state buffer m_choices; @@ -3426,7 +3426,7 @@ struct instance_synthesizer { transparency_mode m_old_transparency_mode; bool m_old_zeta; - instance_synthesizer(type_context & ctx): + instance_synthesizer(type_context_old & ctx): m_ctx(ctx), m_displayed_trace_header(false), m_old_transparency_mode(m_ctx.m_transparency_mode), @@ -3474,7 +3474,7 @@ struct instance_synthesizer { /* Try to synthesize e.m_mvar using instance inst : inst_type. */ bool try_instance(stack_entry const & e, expr const & inst, expr const & inst_type) { try { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr const & mvar = e.m_mvar; expr mvar_type = m_ctx.infer(mvar); while (true) { @@ -3619,7 +3619,7 @@ struct instance_synthesizer { } bool process_special(stack_entry const & e) { - type_context::tmp_locals locals(m_ctx); + type_context_old::tmp_locals locals(m_ctx); expr const & mvar = e.m_mvar; expr mvar_type = m_ctx.infer(mvar); while (true) { @@ -3890,7 +3890,7 @@ terms searching for unassigned metavariables for implementing this translation. For all these reasons, we have discarded this alternative design. */ -expr type_context::preprocess_class(expr const & type, +expr type_context_old::preprocess_class(expr const & type, buffer & u_replacements, buffer & e_replacements) { if (!has_metavar(type)) { @@ -3898,7 +3898,7 @@ expr type_context::preprocess_class(expr const & type, if (is_constant(C) && !has_class_out_params(env(), const_name(C))) return type; } - type_context::tmp_locals locals(*this); + type_context_old::tmp_locals locals(*this); expr it = type; while (true) { expr new_it = relaxed_whnf(it); @@ -3946,7 +3946,7 @@ expr type_context::preprocess_class(expr const & type, return locals.mk_pi(new_class); } -static void instantiate_replacements(type_context & ctx, +static void instantiate_replacements(type_context_old & ctx, buffer & u_replacements, buffer & e_replacements) { for (level_pair & p : u_replacements) { @@ -3957,7 +3957,7 @@ static void instantiate_replacements(type_context & ctx, } } -optional type_context::mk_class_instance(expr const & type_0) { +optional type_context_old::mk_class_instance(expr const & type_0) { expr type = instantiate_mvars(type_0); scope S(*this); optional result; @@ -4001,7 +4001,7 @@ optional type_context::mk_class_instance(expr const & type_0) { return result; } -optional type_context::mk_subsingleton_instance(expr const & type) { +optional type_context_old::mk_subsingleton_instance(expr const & type) { if (optional> r = m_cache->get_subsingleton(type)) return *r; expr Type = whnf(infer(type)); @@ -4020,7 +4020,7 @@ optional type_context::mk_subsingleton_instance(expr const & type) { Auxiliary ------------- */ -expr type_context::eta_expand(expr const & e) { +expr type_context_old::eta_expand(expr const & e) { tmp_locals locals(*this); expr it = e; while (is_lambda(it)) { @@ -4041,39 +4041,39 @@ expr type_context::eta_expand(expr const & e) { return locals.mk_lambda(r); } -tmp_type_context::tmp_type_context(type_context & ctx, unsigned num_umeta, unsigned num_emeta): +tmp_type_context::tmp_type_context(type_context_old & ctx, unsigned num_umeta, unsigned num_emeta): m_ctx(ctx), m_tmp_data(m_tmp_uassignment, m_tmp_eassignment, ctx.lctx()) { m_tmp_uassignment.resize(num_umeta, none_level()); m_tmp_eassignment.resize(num_emeta, none_expr()); } bool tmp_type_context::is_def_eq(expr const & e1, expr const & e2) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.is_def_eq(e1, e2); } bool tmp_type_context::match(expr const & e1, expr const & e2) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.match(e1, e2); } expr tmp_type_context::infer(expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.infer(e); } expr tmp_type_context::whnf(expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.whnf(e); } level tmp_type_context::mk_tmp_univ_mvar() { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.mk_tmp_univ_mvar(); } expr tmp_type_context::mk_tmp_mvar(expr const & type) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.mk_tmp_mvar(type); } @@ -4092,53 +4092,53 @@ void tmp_type_context::clear_eassignment() { } expr tmp_type_context::instantiate_mvars(expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.instantiate_mvars(e); } void tmp_type_context::assign(expr const & m, expr const & v) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); m_ctx.assign(m, v); } expr tmp_type_context::mk_lambda(buffer const & locals, expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.mk_lambda(locals, e); } expr tmp_type_context::mk_pi(buffer const & locals, expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.mk_pi(locals, e); } expr tmp_type_context::mk_lambda(expr const & local, expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.mk_lambda(local, e); } expr tmp_type_context::mk_pi(expr const & local, expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.mk_pi(local, e); } expr tmp_type_context::mk_lambda(std::initializer_list const & locals, expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.mk_lambda(locals, e); } expr tmp_type_context::mk_pi(std::initializer_list const & locals, expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.mk_pi(locals, e); } bool tmp_type_context::is_prop(expr const & e) { - type_context::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); + type_context_old::tmp_mode_scope_with_data tmp_scope(m_ctx, m_tmp_data); return m_ctx.is_prop(e); } /** \brief Helper class for pretty printing terms that contain local_decl_ref's and metavar_decl_ref's */ class pp_ctx { - type_context m_ctx; + type_context_old m_ctx; formatter m_fmt; public: pp_ctx(environment const & env, options const & opts, metavar_context const & mctx, local_context const & lctx): @@ -4159,7 +4159,7 @@ mk_pp_ctx(environment const & env, options const & opts, metavar_context const & } std::function -mk_pp_ctx(type_context const & ctx) { +mk_pp_ctx(type_context_old const & ctx) { return mk_pp_ctx(ctx.env(), ctx.get_options(), ctx.mctx(), ctx.lctx()); } diff --git a/src/library/type_context.h b/src/library/type_context.h index 479d4b22b7..1ca4613f78 100644 --- a/src/library/type_context.h +++ b/src/library/type_context.h @@ -34,7 +34,7 @@ bool is_at_least_instances(transparency_mode m); transparency_mode ensure_semireducible_mode(transparency_mode m); transparency_mode ensure_instances_mode(transparency_mode m); -class type_context : public abstract_type_context { +class type_context_old : public abstract_type_context { typedef buffer> tmp_uassignment; typedef buffer> tmp_eassignment; typedef buffer mctx_stack; @@ -160,7 +160,7 @@ public: would not be the same for all subterms. For example, if we have a term `C.rec_on ?x_i h` and offset `k`. If we replace `x_i` with its assignment `v`, the offset for `v` is 0. We would need to have a macro to mark the offset of subterms, but then this macro would have to interact with reduction. - Another problem is that `type_context` invokes many auxiliary functions and modules. + Another problem is that `type_context_old` invokes many auxiliary functions and modules. Most of them would have to be offset aware. So, we decide to use a different and simpler approach, where we simply cache the @@ -247,7 +247,7 @@ public: *** TMP mode *** - To be able to use temporary metavariables, the type_context must + To be able to use temporary metavariables, the type_context_old must be put into TMP mode. We have an auxiliary object to set/unset TMP mode. @@ -297,7 +297,7 @@ public: However, this is not a general solution because the local instance may be used to resolve type class resolution problems in the type itself. - Thus, to avoid these problems, when the `type_context` is in TMP mode, we do not + Thus, to avoid these problems, when the `type_context_old` is in TMP mode, we do not assign regular metavariables. In TMP mode, regular metavariables are always treated as opaque constants. @@ -336,7 +336,7 @@ public: - `app_builder`: a helper procedure for creating applications where missing arguments and universes levels are inferred using type inference. - It takes a `type_context` `ctx` as argument. + It takes a `type_context_old` `ctx` as argument. We use `(tmp-match) lctx | t =?= s` where `lctx` is `ctx.lctx()` - Simplifier and Ematcher. They solve nested matching problems. @@ -361,7 +361,7 @@ public: This case is very similar to the previous one. Remark: only the two last applications require offsets. Moreover, `k` is `0` if - the `type_context` is not already in TMP mode. + the `type_context_old` is not already in TMP mode. */ /* This class supports temporary meta-variables "mode". In this "tmp" mode, @@ -373,7 +373,7 @@ public: These assignments are only used during type class resolution and matching operations. They are references to stack allocated buffers provided by customers. - They are nullptr if type_context is not in tmp_mode. */ + They are nullptr if type_context_old is not in tmp_mode. */ struct tmp_data { tmp_uassignment & m_uassignment; tmp_eassignment & m_eassignment; @@ -432,7 +432,7 @@ private: may confuse users (see issue #1794). This was a recurrent problem before smart unfolding was implemented. The idea is quite simple, given an application `f a_1 ... a_n`, - type_context checks whether there is a `f._sunfold` helper + type_context_old checks whether there is a `f._sunfold` helper definition in the environment, if there is one, it uses it to unfold the term, and then reduces the resulting term until an `id_rhs _ t` application is the head. If this application is found, @@ -457,11 +457,11 @@ private: is produced instead of `nat.succ (... incomprehensible mess that uses nat.brec_on ...)`. Note that `nat.add._sunfold` and `nat.add` are not definitionally equal. - Given an application `f a_1 ... a_n`, the type_context only assumes that + Given an application `f a_1 ... a_n`, the type_context_old only assumes that if `f._sunfold a_1 ... a_n` can be reduced to `id_rhs _ t`, then `f a_1 ... a_n` and `t` are definitionally equal. - Remark: type_context also uses smart unfolding for definitions `f._match_` + Remark: type_context_old also uses smart unfolding for definitions `f._match_` */ bool m_smart_unfolding{true}; @@ -470,8 +470,8 @@ private: /* Auxiliary object used to temporarily swap `m_update_left` and `m_update_right`. We use it before invoking methods where we swap left/right. */ struct swap_update_flags_scope { - type_context & m_ctx; - swap_update_flags_scope(type_context & ctx):m_ctx(ctx) { + type_context_old & m_ctx; + swap_update_flags_scope(type_context_old & ctx):m_ctx(ctx) { std::swap(m_ctx.m_update_left, m_ctx.m_update_right); } ~swap_update_flags_scope() { @@ -547,28 +547,28 @@ private: projection_info const * is_projection(expr const & e); optional reduce_projection_core(projection_info const * info, expr const & e); - type_context(abstract_context_cache * cache, metavar_context const & mctx, local_context const & lctx, + type_context_old(abstract_context_cache * cache, metavar_context const & mctx, local_context const & lctx, transparency_mode m); public: - type_context(environment const & env, metavar_context const & mctx, local_context const & lctx, + type_context_old(environment const & env, metavar_context const & mctx, local_context const & lctx, abstract_context_cache & cache, transparency_mode m = transparency_mode::Reducible); - type_context(environment const & env, options const & o, metavar_context const & mctx, local_context const & lctx, + type_context_old(environment const & env, options const & o, metavar_context const & mctx, local_context const & lctx, transparency_mode m = transparency_mode::Reducible); - type_context(environment const & env, options const & o, local_context const & lctx, + type_context_old(environment const & env, options const & o, local_context const & lctx, transparency_mode m = transparency_mode::Reducible): - type_context(env, o, metavar_context(), lctx, m) {} - explicit type_context(environment const & env, transparency_mode m = transparency_mode::Reducible): - type_context(env, options(), metavar_context(), local_context(), m) {} - type_context(environment const & env, options const & o, transparency_mode m = transparency_mode::Reducible): - type_context(env, o, metavar_context(), local_context(), m) {} - type_context(environment const & env, abstract_context_cache & cache, transparency_mode m = transparency_mode::Reducible): - type_context(env, metavar_context(), local_context(), cache, m) {} - type_context(type_context const &) = delete; - type_context(type_context &&); - virtual ~type_context(); + type_context_old(env, o, metavar_context(), lctx, m) {} + explicit type_context_old(environment const & env, transparency_mode m = transparency_mode::Reducible): + type_context_old(env, options(), metavar_context(), local_context(), m) {} + type_context_old(environment const & env, options const & o, transparency_mode m = transparency_mode::Reducible): + type_context_old(env, o, metavar_context(), local_context(), m) {} + type_context_old(environment const & env, abstract_context_cache & cache, transparency_mode m = transparency_mode::Reducible): + type_context_old(env, metavar_context(), local_context(), cache, m) {} + type_context_old(type_context_old const &) = delete; + type_context_old(type_context_old &&); + virtual ~type_context_old(); - type_context & operator=(type_context const &) = delete; - type_context & operator=(type_context &&) = delete; + type_context_old & operator=(type_context_old const &) = delete; + type_context_old & operator=(type_context_old &&) = delete; virtual environment const & env() const override { return m_env; } options const & get_options() const { return m_cache->get_options(); } @@ -600,15 +600,15 @@ public: when using `push_local` or `push_let`. We also do not need to flush the instance/subsingleton cache when we using `push_local`, `push_let` and `pop_local`. - 2- (Faster type_context initialization) + 2- (Faster type_context_old initialization) We don't need to recompute the set of local instances when we initialize - another type_context using a local_context object with frozen local instances. + another type_context_old using a local_context object with frozen local instances. This is particularly useful if the local_context is huge. Recall that to compute the set of local instance, we need to traverse the whole local context. - Recall that we create many short lived type_context objects in the tactic framework. - For example, the tactic `infer_type t` creates a type_context object just to infer the type of `t`. + Recall that we create many short lived type_context_old objects in the tactic framework. + For example, the tactic `infer_type t` creates a type_context_old object just to infer the type of `t`. - 3- The instance and subsingleton caches can be reused in other type_context objects + 3- The instance and subsingleton caches can be reused in other type_context_old objects IF the local_context is set with the same frozen local instances. 4- (Drawback) Local instances cannot be reverted anymore. @@ -747,39 +747,39 @@ public: expr complete_instance(expr const & e); struct transparency_scope : public flet { - transparency_scope(type_context & ctx, transparency_mode m): + transparency_scope(type_context_old & ctx, transparency_mode m): flet(ctx.m_transparency_mode, m) { } }; struct approximate_scope : public flet { - approximate_scope(type_context & ctx, bool approx = true): + approximate_scope(type_context_old & ctx, bool approx = true): flet(ctx.m_approximate, approx) {} }; struct zeta_scope : public flet { - zeta_scope(type_context & ctx, bool val): + zeta_scope(type_context_old & ctx, bool val): flet(ctx.m_zeta, val) {} }; struct nozeta_scope : public zeta_scope { - nozeta_scope(type_context & ctx):zeta_scope(ctx, false) {} + nozeta_scope(type_context_old & ctx):zeta_scope(ctx, false) {} }; struct full_postponed_scope : public flet { - full_postponed_scope(type_context & ctx, bool full = true): + full_postponed_scope(type_context_old & ctx, bool full = true): flet(ctx.m_full_postponed, full) {} }; struct smart_unfolding_scope : public flet { - smart_unfolding_scope(type_context & ctx, bool enable = true): + smart_unfolding_scope(type_context_old & ctx, bool enable = true): flet(ctx.m_smart_unfolding, enable) {} }; struct relaxed_scope { transparency_scope m_transparency_scope; zeta_scope m_zeta_scope; - relaxed_scope(type_context & ctx): + relaxed_scope(type_context_old & ctx): m_transparency_scope(ctx, transparency_mode::All), m_zeta_scope(ctx, true) {} }; @@ -790,12 +790,12 @@ public: -------------------------- */ public: struct tmp_mode_scope { - type_context & m_ctx; + type_context_old & m_ctx; buffer> m_tmp_uassignment; buffer> m_tmp_eassignment; tmp_data * m_old_data; tmp_data m_data; - tmp_mode_scope(type_context & ctx, unsigned next_uidx = 0, unsigned next_midx = 0): + tmp_mode_scope(type_context_old & ctx, unsigned next_uidx = 0, unsigned next_midx = 0): m_ctx(ctx), m_old_data(ctx.m_tmp_data), m_data(m_tmp_uassignment, m_tmp_eassignment, ctx.lctx()) { m_tmp_uassignment.resize(next_uidx, none_level()); m_tmp_eassignment.resize(next_midx, none_expr()); @@ -806,9 +806,9 @@ public: } }; struct tmp_mode_scope_with_data { - type_context & m_ctx; + type_context_old & m_ctx; tmp_data * m_old_data; - tmp_mode_scope_with_data(type_context & ctx, tmp_data & data): + tmp_mode_scope_with_data(type_context_old & ctx, tmp_data & data): m_ctx(ctx), m_old_data(ctx.m_tmp_data) { m_ctx.m_tmp_data = &data; } @@ -827,10 +827,10 @@ public: /* Helper class to reset m_used_assignment flag */ class reset_used_assignment { - type_context & m_ctx; + type_context_old & m_ctx; bool m_old_used_assignment; public: - reset_used_assignment(type_context & ctx): + reset_used_assignment(type_context_old & ctx): m_ctx(ctx), m_old_used_assignment(m_ctx.m_used_assignment) { m_ctx.m_used_assignment = false; @@ -879,12 +879,12 @@ public: bool is_tmp_mvar(level const & l) const { return is_idx_metauniv(l); } bool is_tmp_mvar(expr const & e) const { return is_idx_metavar(e); } /* Return true iff - 1- `l` is a temporary universe metavariable and type_context is in tmp mode, OR - 2- `l` is a regular universe metavariable an type_context is not in tmp_mode. */ + 1- `l` is a temporary universe metavariable and type_context_old is in tmp mode, OR + 2- `l` is a regular universe metavariable an type_context_old is not in tmp_mode. */ bool is_mode_mvar(level const & l) const; /* Return true iff - 1- `e` is a temporary metavariable and type_context is in tmp mode, OR - 2- `e` is a regular metavariable an type_context is not in tmp_mode. */ + 1- `e` is a temporary metavariable and type_context_old is in tmp mode, OR + 2- `e` is a regular metavariable an type_context_old is not in tmp_mode. */ bool is_mode_mvar(expr const & e) const; bool is_assigned(level const & l) const; @@ -929,12 +929,12 @@ public: private: void commit_scope(); class scope { - friend class type_context; - type_context & m_owner; + friend class type_context_old; + type_context_old & m_owner; bool m_keep; unsigned m_postponed_sz; public: - scope(type_context & o):m_owner(o), m_keep(false), m_postponed_sz(o.m_postponed.size()) { m_owner.push_scope(); } + scope(type_context_old & o):m_owner(o), m_keep(false), m_postponed_sz(o.m_postponed.size()) { m_owner.push_scope(); } ~scope() { m_owner.m_postponed.resize(m_postponed_sz); if (!m_keep) m_owner.pop_scope(); } void commit() { m_postponed_sz = m_owner.m_postponed.size(); m_owner.commit_scope(); m_keep = true; } }; @@ -996,16 +996,16 @@ private: public: /* Helper class for creating pushing local declarations into the local context m_lctx */ class tmp_locals { - type_context & m_ctx; + type_context_old & m_ctx; buffer m_locals; /* \brief Return true iff all locals in m_locals are let-decls */ bool all_let_decls() const; public: - tmp_locals(type_context & ctx):m_ctx(ctx) {} + tmp_locals(type_context_old & ctx):m_ctx(ctx) {} ~tmp_locals(); - type_context & ctx() { return m_ctx; } + type_context_old & ctx() { return m_ctx; } expr push_local(name const & pp_name, expr const & type, binder_info const & bi = binder_info()) { expr r = m_ctx.push_local(pp_name, type, bi); @@ -1042,13 +1042,13 @@ public: }; class tmp_type_context : public abstract_type_context { - type_context & m_ctx; + type_context_old & m_ctx; buffer> m_tmp_uassignment; buffer> m_tmp_eassignment; - type_context::tmp_data m_tmp_data; + type_context_old::tmp_data m_tmp_data; public: - tmp_type_context(type_context & ctx, unsigned num_umeta = 0, unsigned num_emeta = 0); - type_context & ctx() const { return m_ctx; } + tmp_type_context(type_context_old & ctx, unsigned num_umeta = 0, unsigned num_emeta = 0); + type_context_old & ctx() const { return m_ctx; } virtual environment const & env() const override { return m_ctx.env(); } virtual expr infer(expr const & e) override; @@ -1084,7 +1084,7 @@ mk_pp_ctx(environment const & env, options const & opts, metavar_context const & /** Create a formatting function that can 'decode' metavar_decl_refs and local_decl_refs with declarations stored in ctx */ std::function -mk_pp_ctx(type_context const & ctx); +mk_pp_ctx(type_context_old const & ctx); void initialize_type_context(); void finalize_type_context(); diff --git a/src/library/unfold_macros.cpp b/src/library/unfold_macros.cpp index b21af2ef09..1da88e9bb9 100644 --- a/src/library/unfold_macros.cpp +++ b/src/library/unfold_macros.cpp @@ -39,7 +39,7 @@ class unfold_untrusted_macros_fn : public replace_visitor_with_tc { } public: - unfold_untrusted_macros_fn(type_context & ctx, optional const & lvl): + unfold_untrusted_macros_fn(type_context_old & ctx, optional const & lvl): replace_visitor_with_tc(ctx), m_trust_lvl(lvl) {} }; @@ -54,7 +54,7 @@ static bool contains_untrusted_macro(unsigned trust_lvl, expr const & e) { expr unfold_untrusted_macros(environment const & env, expr const & e, optional const & trust_lvl) { if (!trust_lvl || contains_untrusted_macro(*trust_lvl, e)) { - type_context ctx(env, transparency_mode::All); + type_context_old ctx(env, transparency_mode::All); return unfold_untrusted_macros_fn(ctx, trust_lvl)(e); } else { return e; diff --git a/src/library/unification_hint.cpp b/src/library/unification_hint.cpp index 176fbddbfe..32c3d26592 100644 --- a/src/library/unification_hint.cpp +++ b/src/library/unification_hint.cpp @@ -55,7 +55,7 @@ struct unification_hint_state { void register_hint(environment const & env, name const & decl_name, expr const & value, unsigned priority) { m_decl_names_to_prio.insert(decl_name, priority); - type_context _ctx(env, options(), transparency_mode::All); + type_context_old _ctx(env, options(), transparency_mode::All); tmp_type_context ctx(_ctx); expr e_hint = value; unsigned num_vars = 0; @@ -221,7 +221,7 @@ format pp_unification_hints(unification_hints const & hints, formatter const & f } class unification_hint_fn { - type_context & m_owner; + type_context_old & m_owner; unification_hint const & m_hint; buffer> m_assignment; @@ -324,7 +324,7 @@ class unification_hint_fn { } public: - unification_hint_fn(type_context & o, unification_hint const & hint): + unification_hint_fn(type_context_old & o, unification_hint const & hint): m_owner(o), m_hint(hint) { m_assignment.resize(m_hint.get_num_vars()); } @@ -364,7 +364,7 @@ public: } }; -bool try_unification_hint(type_context & o, unification_hint const & hint, expr const & lhs, expr const & rhs) { +bool try_unification_hint(type_context_old & o, unification_hint const & hint, expr const & lhs, expr const & rhs) { return unification_hint_fn(o, hint)(lhs, rhs); } diff --git a/src/library/unification_hint.h b/src/library/unification_hint.h index 2509e368db..59a94150d3 100644 --- a/src/library/unification_hint.h +++ b/src/library/unification_hint.h @@ -64,8 +64,8 @@ void get_unification_hints(environment const & env, name const & n1, name const format pp_unification_hints(unification_hints const & hints, formatter const & fmt); -class type_context; -bool try_unification_hint(type_context & o, unification_hint const & hint, expr const & lhs, expr const & rhs); +class type_context_old; +bool try_unification_hint(type_context_old & o, unification_hint const & hint, expr const & lhs, expr const & rhs); void initialize_unification_hint(); void finalize_unification_hint(); diff --git a/src/library/util.cpp b/src/library/util.cpp index 2a5244f6db..7c75677d4b 100644 --- a/src/library/util.cpp +++ b/src/library/util.cpp @@ -351,8 +351,8 @@ unsigned get_num_inductive_hypotheses_for(environment const & env, name const & lean_assert(rec_mask.empty()); name I_name = *inductive::is_intro_rule(env, n); inductive::inductive_decl decl = *inductive::is_inductive_decl(env, I_name); - type_context tc(env); - type_context::tmp_locals locals(tc); + type_context_old tc(env); + type_context_old::tmp_locals locals(tc); expr type = tc.whnf(env.get(n).get_type()); unsigned r = 0; while (is_pi(type)) { diff --git a/src/library/vm/interaction_state.h b/src/library/vm/interaction_state.h index dd0a4a38ed..33a2dcb6f3 100644 --- a/src/library/vm/interaction_state.h +++ b/src/library/vm/interaction_state.h @@ -61,12 +61,12 @@ struct interaction_monad { static optional is_exception(vm_state & S, vm_obj const & ex); class evaluator { - type_context & m_ctx; + type_context_old & m_ctx; options m_opts; protected: virtual void process_failure(vm_state & S, vm_obj const & r); public: - evaluator(type_context & ctx, options const & opts, bool allow_profiler = false); + evaluator(type_context_old & ctx, options const & opts, bool allow_profiler = false); environment compile(name const & interaction_name, expr const & interaction); vm_obj invoke(vm_state & S, name const & interaction_name, std::initializer_list const & args); diff --git a/src/library/vm/interaction_state_imp.h b/src/library/vm/interaction_state_imp.h index 567e893f0e..89088395e5 100644 --- a/src/library/vm/interaction_state_imp.h +++ b/src/library/vm/interaction_state_imp.h @@ -274,7 +274,7 @@ vm_obj interaction_monad::evaluator::invoke(vm_state & S, name const & in } template -interaction_monad::evaluator::evaluator(type_context & ctx, options const & opts, bool allow_profiler): +interaction_monad::evaluator::evaluator(type_context_old & ctx, options const & opts, bool allow_profiler): m_ctx(ctx), m_opts(opts) { if (!allow_profiler) // do not bother to invoke the profiler for most trivial calls into Lean diff --git a/src/library/vm/vm_parser.cpp b/src/library/vm/vm_parser.cpp index 5ce1676d6f..696cd63e58 100644 --- a/src/library/vm/vm_parser.cpp +++ b/src/library/vm/vm_parser.cpp @@ -44,7 +44,7 @@ typedef interaction_monad lean_parser; catch (exception const & ex) { return lean_parser::mk_exception(ex, s); } vm_obj run_parser(parser & p, expr const & spec, buffer const & args) { - type_context ctx(p.env(), p.get_options()); + type_context_old ctx(p.env(), p.get_options()); auto r = lean_parser::evaluator(ctx, p.get_options())(spec, args, lean_parser_state {&p}); return lean_parser::get_success_value(r); } @@ -60,7 +60,7 @@ expr parse_interactive_param(parser & p, expr const & param_ty) { } try { vm_obj vm_parsed = run_parser(p, param_args[2]); - type_context ctx(p.env()); + type_context_old ctx(p.env()); name n("_reflect"); lean_parser::evaluator eval(ctx, p.get_options()); auto env = eval.compile(n, param_args[1]); diff --git a/src/library/vm/vm_task.cpp b/src/library/vm/vm_task.cpp index e4f46743d7..00e5f7737e 100644 --- a/src/library/vm/vm_task.cpp +++ b/src/library/vm/vm_task.cpp @@ -71,7 +71,7 @@ vm_obj vm_task_map(vm_obj const &, vm_obj const &, vm_obj const & fn, vm_obj con auto file_name = logtree().get_location().m_file_name; // Tracing - type_context tc(env); + type_context_old tc(env); scope_trace_env scope_trace(env, opts, tc); scope_traces_as_messages scope_traces_as_msg(file_name, logtree().get_location().m_range.m_begin); diff --git a/src/shell/lean.cpp b/src/shell/lean.cpp index f6b88e7d88..eb15dcfae4 100644 --- a/src/shell/lean.cpp +++ b/src/shell/lean.cpp @@ -645,7 +645,7 @@ int main(int argc, char ** argv) { set_io_cmdline_args({argv + optind, argv + argc}); eval_helper fn(main_env, main_opts, "main"); - type_context tc(main_env, main_opts); + type_context_old tc(main_env, main_opts); scope_trace_env scope2(main_env, main_opts, tc); try { diff --git a/src/shell/leandoc.cpp b/src/shell/leandoc.cpp index fead589ca4..50a0822624 100644 --- a/src/shell/leandoc.cpp +++ b/src/shell/leandoc.cpp @@ -225,7 +225,7 @@ static void gen_decl_doc(std::ostream & out, environment const & env, formatter } void gen_doc(environment const & env, options const & _opts, std::ostream & out) { - type_context ctx(env); + type_context_old ctx(env); options opts = _opts.update_if_undef(name{"pp", "width"}, 100); auto fmt_factory = lean::mk_pretty_formatter_factory(); auto fmt = fmt_factory(env, opts, ctx); diff --git a/src/tests/library/delayed_abstraction.cpp b/src/tests/library/delayed_abstraction.cpp index 1bd7bf0796..17ad3d3557 100644 --- a/src/tests/library/delayed_abstraction.cpp +++ b/src/tests/library/delayed_abstraction.cpp @@ -49,7 +49,7 @@ void tst1() { expr e2 = mk_delayed_abstraction(e1, {mkp(A1, A2), mkp(a1, a2), mkp(b1, b2)}); lean_assert(mctx.instantiate_mvars(e1) == a1); lean_assert(mctx.instantiate_mvars(e2) == a2); - type_context ctx(env, options(), mctx, lctx2); + type_context_old ctx(env, options(), mctx, lctx2); lean_assert(ctx.infer(e2) == A2); }