2015-09-25 19:45:16 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2015-10-31 00:45:27 +00:00
|
|
|
#include <vector>
|
|
|
|
#include "util/sstream.h"
|
2015-11-09 01:29:47 +00:00
|
|
|
#include "util/sexpr/option_declarations.h"
|
2015-09-28 23:40:19 +00:00
|
|
|
#include "kernel/for_each_fn.h"
|
2015-09-25 21:43:42 +00:00
|
|
|
#include "kernel/type_checker.h"
|
|
|
|
#include "library/replace_visitor.h"
|
2015-09-29 17:42:35 +00:00
|
|
|
#include "library/util.h"
|
|
|
|
#include "library/reducible.h"
|
|
|
|
#include "library/normalize.h"
|
2015-10-31 00:45:27 +00:00
|
|
|
#include "library/class.h"
|
2015-11-01 05:31:58 +00:00
|
|
|
#include "library/type_context.h"
|
2015-11-08 01:42:58 +00:00
|
|
|
#include "library/congr_lemma_manager.h"
|
2015-10-01 23:21:17 +00:00
|
|
|
#include "library/projection.h"
|
2015-10-31 00:45:27 +00:00
|
|
|
#include "library/tactic/goal.h"
|
2015-09-25 19:45:16 +00:00
|
|
|
#include "library/blast/expr.h"
|
|
|
|
#include "library/blast/state.h"
|
|
|
|
#include "library/blast/blast.h"
|
2015-11-09 02:09:31 +00:00
|
|
|
#include "library/blast/assumption.h"
|
2015-11-09 03:18:40 +00:00
|
|
|
#include "library/blast/intros.h"
|
2015-11-10 18:47:41 +00:00
|
|
|
#include "library/blast/proof_expr.h"
|
2015-09-29 16:02:58 +00:00
|
|
|
#include "library/blast/blast_exception.h"
|
2015-09-25 19:45:16 +00:00
|
|
|
|
2015-11-09 01:29:47 +00:00
|
|
|
#ifndef LEAN_DEFAULT_BLAST_MAX_DEPTH
|
|
|
|
#define LEAN_DEFAULT_BLAST_MAX_DEPTH 128
|
|
|
|
#endif
|
|
|
|
#ifndef LEAN_DEFAULT_BLAST_INIT_DEPTH
|
|
|
|
#define LEAN_DEFAULT_BLAST_INIT_DEPTH 1
|
|
|
|
#endif
|
|
|
|
#ifndef LEAN_DEFAULT_BLAST_INC_DEPTH
|
|
|
|
#define LEAN_DEFAULT_BLAST_INC_DEPTH 5
|
|
|
|
#endif
|
|
|
|
|
2015-09-25 19:45:16 +00:00
|
|
|
namespace lean {
|
|
|
|
namespace blast {
|
2015-11-04 19:24:22 +00:00
|
|
|
static name * g_prefix = nullptr;
|
|
|
|
static name * g_tmp_prefix = nullptr;
|
2015-09-29 17:42:35 +00:00
|
|
|
|
2015-11-09 01:29:47 +00:00
|
|
|
/* Options */
|
|
|
|
static name * g_blast_max_depth = nullptr;
|
|
|
|
static name * g_blast_init_depth = nullptr;
|
|
|
|
static name * g_blast_inc_depth = nullptr;
|
|
|
|
|
|
|
|
unsigned get_blast_max_depth(options const & o) {
|
|
|
|
return o.get_unsigned(*g_blast_max_depth, LEAN_DEFAULT_BLAST_MAX_DEPTH);
|
|
|
|
}
|
|
|
|
unsigned get_blast_init_depth(options const & o) {
|
|
|
|
return o.get_unsigned(*g_blast_init_depth, LEAN_DEFAULT_BLAST_INIT_DEPTH);
|
|
|
|
}
|
|
|
|
unsigned get_blast_inc_depth(options const & o) {
|
|
|
|
return o.get_unsigned(*g_blast_inc_depth, LEAN_DEFAULT_BLAST_INC_DEPTH);
|
|
|
|
}
|
|
|
|
|
2015-10-05 01:24:21 +00:00
|
|
|
class blastenv {
|
2015-10-31 01:14:34 +00:00
|
|
|
friend class scope_assignment;
|
2015-11-04 20:29:28 +00:00
|
|
|
typedef std::vector<tmp_type_context *> tmp_type_context_pool;
|
2015-11-08 01:42:58 +00:00
|
|
|
typedef std::unique_ptr<tmp_type_context> tmp_type_context_ptr;
|
2015-11-04 20:29:28 +00:00
|
|
|
|
2015-10-06 20:03:04 +00:00
|
|
|
environment m_env;
|
|
|
|
io_state m_ios;
|
2015-10-31 00:45:27 +00:00
|
|
|
name_generator m_ngen;
|
2015-11-05 23:59:40 +00:00
|
|
|
tmp_local_generator m_tmp_local_generator;
|
2015-11-08 23:20:05 +00:00
|
|
|
list<expr> m_initial_context; // for setting type_context local instances
|
2015-10-06 20:03:04 +00:00
|
|
|
name_set m_lemma_hints;
|
|
|
|
name_set m_unfold_hints;
|
|
|
|
name_map<level> m_uvar2uref; // map global universe metavariables to blast uref's
|
|
|
|
name_map<pair<expr, expr>> m_mvar2meta_mref; // map global metavariables to blast mref's
|
|
|
|
name_predicate m_not_reducible_pred;
|
2015-10-31 00:45:27 +00:00
|
|
|
name_predicate m_class_pred;
|
|
|
|
name_predicate m_instance_pred;
|
2015-10-06 20:03:04 +00:00
|
|
|
name_map<projection_info> m_projection_info;
|
|
|
|
state m_curr_state; // current state
|
2015-11-09 01:29:47 +00:00
|
|
|
std::vector<state> m_choice_points;
|
2015-11-04 20:29:28 +00:00
|
|
|
tmp_type_context_pool m_tmp_ctx_pool;
|
2015-11-08 01:42:58 +00:00
|
|
|
tmp_type_context_ptr m_tmp_ctx; // for app_builder and congr_lemma_manager
|
|
|
|
app_builder m_app_builder;
|
|
|
|
fun_info_manager m_fun_info_manager;
|
|
|
|
congr_lemma_manager m_congr_lemma_manager;
|
2015-09-25 21:43:42 +00:00
|
|
|
|
2015-11-09 01:29:47 +00:00
|
|
|
/* options */
|
|
|
|
unsigned m_max_depth;
|
|
|
|
unsigned m_init_depth;
|
|
|
|
unsigned m_inc_depth;
|
|
|
|
|
2015-11-01 05:31:58 +00:00
|
|
|
class tctx : public type_context {
|
2015-11-09 21:36:49 +00:00
|
|
|
blastenv & m_benv;
|
|
|
|
std::vector<state::assignment_snapshot> m_stack;
|
2015-10-31 00:45:27 +00:00
|
|
|
public:
|
2015-11-01 05:31:58 +00:00
|
|
|
tctx(blastenv & benv):
|
2015-11-05 23:59:40 +00:00
|
|
|
type_context(benv.m_env, benv.m_ios, benv.m_tmp_local_generator),
|
|
|
|
m_benv(benv) {}
|
2015-10-31 00:45:27 +00:00
|
|
|
|
|
|
|
virtual bool is_extra_opaque(name const & n) const {
|
|
|
|
// TODO(Leo): class and instances
|
|
|
|
return m_benv.m_not_reducible_pred(n) || m_benv.m_projection_info.contains(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool is_uvar(level const & l) const {
|
|
|
|
return blast::is_uref(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool is_mvar(expr const & e) const {
|
|
|
|
return blast::is_mref(e);
|
|
|
|
}
|
|
|
|
|
2015-11-01 06:01:19 +00:00
|
|
|
virtual optional<level> get_assignment(level const & u) const {
|
|
|
|
if (auto v = m_benv.m_curr_state.get_uref_assignment(u))
|
|
|
|
return some_level(*v);
|
|
|
|
else
|
|
|
|
return none_level();
|
2015-10-31 00:45:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-01 06:01:19 +00:00
|
|
|
virtual optional<expr> get_assignment(expr const & m) const {
|
|
|
|
if (auto v = m_benv.m_curr_state.get_mref_assignment(m))
|
|
|
|
return some_expr(*v);
|
|
|
|
else
|
|
|
|
return none_expr();
|
2015-10-31 00:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void update_assignment(level const & u, level const & v) {
|
|
|
|
m_benv.m_curr_state.assign_uref(u, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void update_assignment(expr const & m, expr const & v) {
|
|
|
|
m_benv.m_curr_state.assign_mref(m, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool validate_assignment(expr const & m, buffer<expr> const & locals, expr const & v) {
|
|
|
|
// We must check
|
|
|
|
// 1. All href in new_v are in the context of m.
|
|
|
|
// 2. The context of any (unassigned) mref in new_v must be a subset of the context of m.
|
|
|
|
// If it is not we force it to be.
|
2015-11-04 19:24:22 +00:00
|
|
|
// 3. Any (non tmp) local constant occurring in new_v occurs in locals
|
2015-10-31 00:45:27 +00:00
|
|
|
// 4. m does not occur in new_v
|
|
|
|
state & s = m_benv.m_curr_state;
|
|
|
|
metavar_decl const * d = s.get_metavar_decl(m);
|
|
|
|
lean_assert(d);
|
|
|
|
bool ok = true;
|
|
|
|
for_each(v, [&](expr const & e, unsigned) {
|
|
|
|
if (!ok)
|
|
|
|
return false; // stop search
|
|
|
|
if (is_href(e)) {
|
|
|
|
if (!d->contains_href(e)) {
|
|
|
|
ok = false; // failed 1
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-04 19:24:22 +00:00
|
|
|
} else if (is_local(e) && !is_tmp_local(e)) {
|
2015-10-31 00:45:27 +00:00
|
|
|
if (std::all_of(locals.begin(), locals.end(), [&](expr const & a) {
|
2015-11-06 00:18:49 +00:00
|
|
|
return mlocal_name(a) != mlocal_name(e); })) {
|
2015-10-31 00:45:27 +00:00
|
|
|
ok = false; // failed 3
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (is_mref(e)) {
|
|
|
|
if (m == e) {
|
|
|
|
ok = false; // failed 4
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
s.restrict_mref_context_using(e, m); // enforce 2
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Return the type of a local constant (local or not).
|
|
|
|
\remark This method allows the customer to store the type of local constants
|
|
|
|
in a different place. */
|
|
|
|
virtual expr infer_local(expr const & e) const {
|
|
|
|
if (is_href(e)) {
|
2015-11-09 21:19:59 +00:00
|
|
|
state const & s = m_benv.m_curr_state;
|
2015-11-09 22:52:21 +00:00
|
|
|
hypothesis const * h = s.get_hypothesis_decl(e);
|
2015-10-31 00:45:27 +00:00
|
|
|
lean_assert(h);
|
|
|
|
return h->get_type();
|
|
|
|
} else {
|
|
|
|
return mlocal_type(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr infer_metavar(expr const & m) const {
|
2015-11-02 21:37:48 +00:00
|
|
|
// Remark: we do not tolerate external meta-variables here.
|
|
|
|
lean_assert(is_mref(m));
|
2015-10-31 00:45:27 +00:00
|
|
|
state const & s = m_benv.m_curr_state;
|
|
|
|
metavar_decl const * d = s.get_metavar_decl(m);
|
|
|
|
lean_assert(d);
|
|
|
|
return d->get_type();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual level mk_uvar() {
|
2015-11-09 20:41:52 +00:00
|
|
|
return mk_fresh_uref();
|
2015-10-31 00:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr mk_mvar(expr const & type) {
|
|
|
|
return m_benv.m_curr_state.mk_metavar(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void push() {
|
2015-11-09 21:36:49 +00:00
|
|
|
m_stack.push_back(m_benv.m_curr_state.save_assignment());
|
2015-10-31 00:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void pop() {
|
2015-11-09 21:36:49 +00:00
|
|
|
m_benv.m_curr_state.restore_assignment(m_stack.back());
|
2015-10-31 00:45:27 +00:00
|
|
|
m_stack.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void commit() {
|
|
|
|
m_stack.pop_back();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-25 21:43:42 +00:00
|
|
|
class to_blast_expr_fn : public replace_visitor {
|
|
|
|
type_checker m_tc;
|
|
|
|
state & m_state;
|
2015-09-28 23:40:19 +00:00
|
|
|
// We map each metavariable to a metavariable application and the mref associated with it.
|
2015-10-02 22:48:01 +00:00
|
|
|
name_map<level> & m_uvar2uref;
|
2015-09-25 21:43:42 +00:00
|
|
|
name_map<pair<expr, expr>> & m_mvar2meta_mref;
|
2015-09-29 19:13:20 +00:00
|
|
|
name_map<expr> & m_local2href;
|
2015-09-25 21:43:42 +00:00
|
|
|
|
2015-10-02 22:48:01 +00:00
|
|
|
level to_blast_level(level const & l) {
|
|
|
|
level lhs;
|
|
|
|
switch (l.kind()) {
|
2015-11-06 00:18:49 +00:00
|
|
|
case level_kind::Succ: return mk_succ(to_blast_level(succ_of(l)));
|
|
|
|
case level_kind::Zero: return mk_level_zero();
|
|
|
|
case level_kind::Param: return mk_param_univ(param_id(l));
|
|
|
|
case level_kind::Global: return mk_global_univ(global_id(l));
|
2015-10-02 22:48:01 +00:00
|
|
|
case level_kind::Max:
|
|
|
|
lhs = to_blast_level(max_lhs(l));
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_max(lhs, to_blast_level(max_rhs(l)));
|
2015-10-02 22:48:01 +00:00
|
|
|
case level_kind::IMax:
|
|
|
|
lhs = to_blast_level(imax_lhs(l));
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_imax(lhs, to_blast_level(imax_rhs(l)));
|
2015-10-02 22:48:01 +00:00
|
|
|
case level_kind::Meta:
|
|
|
|
if (auto r = m_uvar2uref.find(meta_id(l))) {
|
|
|
|
return *r;
|
|
|
|
} else {
|
2015-11-09 20:41:52 +00:00
|
|
|
level uref = mk_fresh_uref();
|
2015-10-02 22:48:01 +00:00
|
|
|
m_uvar2uref.insert(meta_id(l), uref);
|
|
|
|
return uref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lean_unreachable();
|
|
|
|
}
|
|
|
|
|
2015-10-06 15:35:24 +00:00
|
|
|
virtual expr visit_sort(expr const & e) {
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_sort(to_blast_level(sort_level(e)));
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr visit_macro(expr const & e) {
|
|
|
|
buffer<expr> new_args;
|
|
|
|
for (unsigned i = 0; i < macro_num_args(e); i++) {
|
|
|
|
new_args.push_back(visit(macro_arg(e, i)));
|
|
|
|
}
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_macro(macro_def(e), new_args.size(), new_args.data());
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr visit_constant(expr const & e) {
|
|
|
|
levels new_ls = map(const_levels(e), [&](level const & l) { return to_blast_level(l); });
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_constant(const_name(e), new_ls);
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr visit_var(expr const & e) {
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_var(var_idx(e));
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 16:02:58 +00:00
|
|
|
void throw_unsupported_metavar_occ(expr const & e) {
|
2015-09-25 21:43:42 +00:00
|
|
|
// TODO(Leo): improve error message
|
2015-09-29 16:02:58 +00:00
|
|
|
throw blast_exception("'blast' tactic failed, goal contains a "
|
|
|
|
"meta-variable application that is not supported", e);
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expr mk_mref_app(expr const & mref, unsigned nargs, expr const * args) {
|
|
|
|
lean_assert(is_mref(mref));
|
|
|
|
buffer<expr> new_args;
|
|
|
|
for (unsigned i = 0; i < nargs; i++) {
|
|
|
|
new_args.push_back(visit(args[i]));
|
|
|
|
}
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_app(mref, new_args.size(), new_args.data());
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expr visit_meta_app(expr const & e) {
|
|
|
|
lean_assert(is_meta(e));
|
|
|
|
buffer<expr> args;
|
|
|
|
expr const & mvar = get_app_args(e, args);
|
|
|
|
if (pair<expr, expr> const * meta_mref = m_mvar2meta_mref.find(mlocal_name(mvar))) {
|
|
|
|
lean_assert(is_meta(meta_mref->first));
|
|
|
|
lean_assert(is_mref(meta_mref->second));
|
|
|
|
buffer<expr> decl_args;
|
|
|
|
get_app_args(meta_mref->first, decl_args);
|
|
|
|
if (decl_args.size() > args.size())
|
|
|
|
throw_unsupported_metavar_occ(e);
|
2015-09-28 23:40:19 +00:00
|
|
|
// Make sure the the current metavariable application prefix matches the one
|
|
|
|
// found before.
|
2015-09-25 21:43:42 +00:00
|
|
|
for (unsigned i = 0; i < decl_args.size(); i++) {
|
2015-09-28 23:40:19 +00:00
|
|
|
if (is_local(decl_args[i])) {
|
|
|
|
if (!is_local(args[i]) || mlocal_name(args[i]) != mlocal_name(decl_args[i]))
|
|
|
|
throw_unsupported_metavar_occ(e);
|
|
|
|
} else if (decl_args[i] != args[i]) {
|
2015-09-25 21:43:42 +00:00
|
|
|
throw_unsupported_metavar_occ(e);
|
2015-09-28 23:40:19 +00:00
|
|
|
}
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
return mk_mref_app(meta_mref->second, args.size() - decl_args.size(), args.data() + decl_args.size());
|
|
|
|
} else {
|
|
|
|
unsigned i = 0;
|
2015-09-28 23:40:19 +00:00
|
|
|
hypothesis_idx_buffer ctx;
|
|
|
|
// Find prefix that contains only closed terms.
|
2015-09-25 21:43:42 +00:00
|
|
|
for (; i < args.size(); i++) {
|
2015-09-28 23:40:19 +00:00
|
|
|
if (!closed(args[i]))
|
2015-09-25 21:43:42 +00:00
|
|
|
break;
|
2015-09-28 23:40:19 +00:00
|
|
|
if (!is_local(args[i])) {
|
|
|
|
// Ignore arguments that are not local constants.
|
|
|
|
// In the blast tactic we only support higher-order patterns.
|
|
|
|
continue;
|
|
|
|
}
|
2015-09-25 21:43:42 +00:00
|
|
|
expr const & l = args[i];
|
|
|
|
if (!std::all_of(args.begin(), args.begin() + i,
|
2015-09-28 23:40:19 +00:00
|
|
|
[&](expr const & prev) { return mlocal_name(prev) != mlocal_name(l); })) {
|
|
|
|
// Local has already been processed
|
|
|
|
continue;
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
2015-09-29 19:13:20 +00:00
|
|
|
auto href = m_local2href.find(mlocal_name(l));
|
|
|
|
if (!href) {
|
|
|
|
// One of the arguments is a local constant that is not in m_local2href
|
2015-09-28 23:40:19 +00:00
|
|
|
throw_unsupported_metavar_occ(e);
|
|
|
|
}
|
2015-09-29 19:13:20 +00:00
|
|
|
ctx.push_back(href_index(*href));
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
unsigned prefix_sz = i;
|
|
|
|
expr aux = e;
|
|
|
|
for (; i < args.size(); i++)
|
|
|
|
aux = app_fn(aux);
|
|
|
|
lean_assert(is_meta(aux));
|
2015-09-28 23:40:19 +00:00
|
|
|
expr type = visit(m_tc.infer(aux).first);
|
|
|
|
expr mref = m_state.mk_metavar(ctx, type);
|
2015-10-06 20:03:04 +00:00
|
|
|
m_mvar2meta_mref.insert(mlocal_name(mvar), mk_pair(e, mref));
|
2015-09-25 21:43:42 +00:00
|
|
|
return mk_mref_app(mref, args.size() - prefix_sz, args.data() + prefix_sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr visit_meta(expr const & e) {
|
|
|
|
return visit_meta_app(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr visit_local(expr const & e) {
|
2015-09-29 19:13:20 +00:00
|
|
|
if (auto r = m_local2href.find(mlocal_name(e)))
|
2015-09-25 21:43:42 +00:00
|
|
|
return * r;
|
|
|
|
else
|
2015-09-29 16:02:58 +00:00
|
|
|
throw blast_exception("blast tactic failed, ill-formed input goal", e);
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr visit_app(expr const & e) {
|
|
|
|
if (is_meta(e)) {
|
|
|
|
return visit_meta_app(e);
|
|
|
|
} else {
|
|
|
|
expr f = visit(app_fn(e));
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_app(f, visit(app_arg(e)));
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr visit_lambda(expr const & e) {
|
|
|
|
expr d = visit(binding_domain(e));
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_lambda(binding_name(e), d, visit(binding_body(e)), binding_info(e));
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr visit_pi(expr const & e) {
|
|
|
|
expr d = visit(binding_domain(e));
|
2015-11-06 00:18:49 +00:00
|
|
|
return mk_pi(binding_name(e), d, visit(binding_body(e)), binding_info(e));
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2015-09-28 23:40:19 +00:00
|
|
|
to_blast_expr_fn(environment const & env, state & s,
|
2015-10-02 22:48:01 +00:00
|
|
|
name_map<level> & uvar2uref, name_map<pair<expr, expr>> & mvar2meta_mref,
|
|
|
|
name_map<expr> & local2href):
|
|
|
|
m_tc(env), m_state(s), m_uvar2uref(uvar2uref), m_mvar2meta_mref(mvar2meta_mref), m_local2href(local2href) {}
|
2015-09-25 21:43:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
state to_state(goal const & g) {
|
|
|
|
state s;
|
2015-09-29 17:42:35 +00:00
|
|
|
type_checker_ptr norm_tc = mk_type_checker(m_env, name_generator(*g_prefix), UnfoldReducible);
|
2015-09-29 19:13:20 +00:00
|
|
|
name_map<expr> local2href;
|
2015-10-06 20:03:04 +00:00
|
|
|
to_blast_expr_fn to_blast_expr(m_env, s, m_uvar2uref, m_mvar2meta_mref, local2href);
|
2015-09-25 21:43:42 +00:00
|
|
|
buffer<expr> hs;
|
|
|
|
g.get_hyps(hs);
|
|
|
|
for (expr const & h : hs) {
|
2015-09-29 00:39:30 +00:00
|
|
|
lean_assert(is_local(h));
|
2015-09-29 17:42:35 +00:00
|
|
|
expr type = normalize(*norm_tc, mlocal_type(h));
|
|
|
|
expr new_type = to_blast_expr(type);
|
2015-11-10 17:20:26 +00:00
|
|
|
expr href = s.mk_hypothesis(local_pp_name(h), new_type, h);
|
2015-09-29 19:13:20 +00:00
|
|
|
local2href.insert(mlocal_name(h), href);
|
2015-09-25 21:43:42 +00:00
|
|
|
}
|
2015-09-29 17:42:35 +00:00
|
|
|
expr target = normalize(*norm_tc, g.get_type());
|
|
|
|
expr new_target = to_blast_expr(target);
|
2015-09-29 00:39:30 +00:00
|
|
|
s.set_target(new_target);
|
2015-09-29 01:55:24 +00:00
|
|
|
lean_assert(s.check_invariant());
|
2015-09-25 21:43:42 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-11-01 05:31:58 +00:00
|
|
|
tctx m_tctx;
|
2015-10-31 00:45:27 +00:00
|
|
|
|
2015-11-08 23:20:05 +00:00
|
|
|
void save_initial_context() {
|
|
|
|
hypothesis_idx_buffer hidxs;
|
2015-11-09 21:19:59 +00:00
|
|
|
m_curr_state.get_sorted_hypotheses(hidxs);
|
2015-11-08 23:20:05 +00:00
|
|
|
buffer<expr> ctx;
|
|
|
|
for (unsigned hidx : hidxs) {
|
|
|
|
ctx.push_back(mk_href(hidx));
|
|
|
|
}
|
|
|
|
m_initial_context = to_list(ctx);
|
|
|
|
}
|
|
|
|
|
2015-11-09 01:29:47 +00:00
|
|
|
void set_options(options const & o) {
|
|
|
|
m_max_depth = get_blast_max_depth(o);
|
|
|
|
m_init_depth = get_blast_init_depth(o);
|
|
|
|
m_inc_depth = get_blast_inc_depth(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool next_choice_point() {
|
|
|
|
if (m_choice_points.empty())
|
|
|
|
return false;
|
|
|
|
m_curr_state = m_choice_points.back();
|
|
|
|
m_choice_points.pop_back();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum status { NoAction, ClosedBranch, Continue };
|
|
|
|
|
|
|
|
optional<unsigned> activate_hypothesis() {
|
2015-11-09 21:19:59 +00:00
|
|
|
return m_curr_state.activate_hypothesis();
|
2015-11-09 01:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pair<status, expr> next_action() {
|
2015-11-09 03:18:40 +00:00
|
|
|
if (intros_action()) {
|
|
|
|
return mk_pair(Continue, expr());
|
|
|
|
} else if (activate_hypothesis()) {
|
2015-11-09 01:29:47 +00:00
|
|
|
// TODO(Leo): we should probably eagerly simplify the activated hypothesis.
|
|
|
|
return mk_pair(Continue, expr());
|
2015-11-09 02:09:31 +00:00
|
|
|
} else if (auto pr = assumption_action()) {
|
|
|
|
return mk_pair(ClosedBranch, *pr);
|
2015-11-09 01:29:47 +00:00
|
|
|
} else {
|
|
|
|
// TODO(Leo): add more actions...
|
|
|
|
return mk_pair(NoAction, expr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
optional<expr> resolve(expr pr) {
|
|
|
|
while (m_curr_state.has_proof_steps()) {
|
|
|
|
proof_step s = m_curr_state.top_proof_step();
|
|
|
|
if (auto new_pr = s.resolve(m_curr_state, pr)) {
|
|
|
|
pr = *new_pr;
|
|
|
|
m_curr_state.pop_proof_step();
|
|
|
|
} else {
|
|
|
|
return none_expr(); // continue the search
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return some_expr(pr); // closed all branches
|
|
|
|
}
|
|
|
|
|
|
|
|
optional<expr> search_upto(unsigned depth) {
|
|
|
|
while (true) {
|
2015-11-10 17:54:28 +00:00
|
|
|
if (m_curr_state.get_proof_depth() > depth) {
|
2015-11-09 01:29:47 +00:00
|
|
|
// maximum depth reached
|
|
|
|
if (!next_choice_point()) {
|
|
|
|
return none_expr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto s = next_action();
|
|
|
|
switch (s.first) {
|
|
|
|
case NoAction:
|
|
|
|
if (!next_choice_point())
|
|
|
|
return none_expr();
|
|
|
|
break;
|
|
|
|
case ClosedBranch:
|
|
|
|
if (auto pr = resolve(s.second))
|
|
|
|
return pr;
|
|
|
|
break;
|
|
|
|
case Continue:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
optional<expr> search() {
|
|
|
|
state s = m_curr_state;
|
|
|
|
unsigned d = m_init_depth;
|
|
|
|
while (d <= m_max_depth) {
|
|
|
|
if (auto r = search_upto(d))
|
|
|
|
return r;
|
|
|
|
d += m_inc_depth;
|
|
|
|
m_curr_state = s;
|
|
|
|
m_choice_points.clear();
|
|
|
|
}
|
|
|
|
return none_expr();
|
|
|
|
}
|
|
|
|
|
|
|
|
expr to_tactic_proof(expr const & pr) {
|
2015-11-10 18:47:41 +00:00
|
|
|
// When a proof is found we must
|
|
|
|
// 1- Remove all occurrences of href's from pr
|
|
|
|
expr pr1 = unfold_hypotheses_ge(m_curr_state, pr, 0);
|
|
|
|
// 2- Replace mrefs with their assignments,
|
2015-11-09 01:29:47 +00:00
|
|
|
// and convert unassigned meta-variables back into
|
|
|
|
// tactic meta-variables.
|
2015-11-10 18:47:41 +00:00
|
|
|
expr pr2 = m_curr_state.instantiate_urefs_mrefs(pr1);
|
|
|
|
// TODO(Leo):
|
2015-11-09 01:29:47 +00:00
|
|
|
// 3- The external tactic meta-variables that have been instantiated
|
|
|
|
// by blast must also be communicated back to the tactic framework.
|
2015-11-10 18:47:41 +00:00
|
|
|
return pr2;
|
2015-11-09 01:29:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 19:45:16 +00:00
|
|
|
public:
|
2015-10-05 01:24:21 +00:00
|
|
|
blastenv(environment const & env, io_state const & ios, list<name> const & ls, list<name> const & ds):
|
2015-10-31 00:45:27 +00:00
|
|
|
m_env(env), m_ios(ios), m_ngen(*g_prefix), m_lemma_hints(to_name_set(ls)), m_unfold_hints(to_name_set(ds)),
|
|
|
|
m_not_reducible_pred(mk_not_reducible_pred(env)),
|
|
|
|
m_class_pred(mk_class_pred(env)),
|
|
|
|
m_instance_pred(mk_instance_pred(env)),
|
2015-11-08 01:42:58 +00:00
|
|
|
m_tmp_ctx(mk_tmp_type_context()),
|
|
|
|
m_app_builder(*m_tmp_ctx),
|
|
|
|
m_fun_info_manager(*m_tmp_ctx),
|
|
|
|
m_congr_lemma_manager(m_app_builder, m_fun_info_manager),
|
2015-11-01 05:31:58 +00:00
|
|
|
m_tctx(*this) {
|
2015-11-09 20:41:52 +00:00
|
|
|
init_uref_mref_href_idxs();
|
2015-11-09 01:29:47 +00:00
|
|
|
set_options(m_ios.get_options());
|
2015-09-25 19:45:16 +00:00
|
|
|
}
|
2015-09-25 21:43:42 +00:00
|
|
|
|
2015-11-04 20:29:28 +00:00
|
|
|
~blastenv() {
|
|
|
|
for (auto ctx : m_tmp_ctx_pool)
|
|
|
|
delete ctx;
|
|
|
|
}
|
|
|
|
|
2015-10-31 01:14:34 +00:00
|
|
|
void init_state(goal const & g) {
|
2015-09-29 17:04:11 +00:00
|
|
|
m_curr_state = to_state(g);
|
2015-11-08 23:20:05 +00:00
|
|
|
save_initial_context();
|
|
|
|
m_tctx.set_local_instances(m_initial_context);
|
|
|
|
m_tmp_ctx->set_local_instances(m_initial_context);
|
2015-10-31 01:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
optional<expr> operator()(goal const & g) {
|
|
|
|
init_state(g);
|
2015-11-09 01:29:47 +00:00
|
|
|
if (auto r = search()) {
|
|
|
|
return some_expr(to_tactic_proof(*r));
|
|
|
|
} else {
|
|
|
|
return none_expr();
|
|
|
|
}
|
2015-09-25 19:45:16 +00:00
|
|
|
}
|
2015-09-29 17:04:11 +00:00
|
|
|
|
|
|
|
environment const & get_env() const { return m_env; }
|
|
|
|
|
|
|
|
io_state const & get_ios() const { return m_ios; }
|
|
|
|
|
2015-10-01 23:21:17 +00:00
|
|
|
state & get_curr_state() { return m_curr_state; }
|
|
|
|
|
|
|
|
bool is_reducible(name const & n) const {
|
|
|
|
if (m_not_reducible_pred(n))
|
|
|
|
return false;
|
|
|
|
return !m_projection_info.contains(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
projection_info const * get_projection_info(name const & n) const {
|
|
|
|
return m_projection_info.find(n);
|
|
|
|
}
|
2015-10-31 00:45:27 +00:00
|
|
|
|
|
|
|
expr mk_fresh_local(expr const & type, binder_info const & bi) {
|
2015-11-06 00:18:49 +00:00
|
|
|
return m_tmp_local_generator.mk_tmp_local(type, bi);
|
2015-10-31 00:45:27 +00:00
|
|
|
}
|
2015-11-01 05:31:58 +00:00
|
|
|
expr whnf(expr const & e) { return m_tctx.whnf(e); }
|
|
|
|
expr infer_type(expr const & e) { return m_tctx.infer(e); }
|
|
|
|
bool is_prop(expr const & e) { return m_tctx.is_prop(e); }
|
|
|
|
bool is_def_eq(expr const & e1, expr const & e2) { return m_tctx.is_def_eq(e1, e2); }
|
|
|
|
optional<expr> mk_class_instance(expr const & e) { return m_tctx.mk_class_instance(e); }
|
2015-11-04 20:29:28 +00:00
|
|
|
|
|
|
|
tmp_type_context * mk_tmp_type_context();
|
|
|
|
|
|
|
|
void recycle_tmp_type_context(tmp_type_context * ctx) {
|
2015-11-04 23:46:56 +00:00
|
|
|
lean_assert(ctx);
|
|
|
|
ctx->clear();
|
2015-11-04 20:29:28 +00:00
|
|
|
m_tmp_ctx_pool.push_back(ctx);
|
|
|
|
}
|
2015-11-04 23:52:38 +00:00
|
|
|
|
2015-11-08 01:42:58 +00:00
|
|
|
optional<congr_lemma> mk_congr_lemma_for_simp(expr const & fn, unsigned num_args) {
|
|
|
|
return m_congr_lemma_manager.mk_congr_simp(fn, num_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
optional<congr_lemma> mk_congr_lemma_for_simp(expr const & fn) {
|
|
|
|
return m_congr_lemma_manager.mk_congr_simp(fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
fun_info get_fun_info(expr const & fn) {
|
|
|
|
return m_fun_info_manager.get(fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
fun_info get_fun_info(expr const & fn, unsigned nargs) {
|
|
|
|
return m_fun_info_manager.get(fn, nargs);
|
|
|
|
}
|
|
|
|
|
2015-11-04 23:52:38 +00:00
|
|
|
/** \brief Convert an external expression into a blast expression
|
|
|
|
It converts meta-variables to blast meta-variables, and ensures the expressions
|
|
|
|
are maximally shared.
|
|
|
|
\remark This procedure should only be used for debugging purposes. */
|
|
|
|
expr internalize(expr const & e) {
|
|
|
|
name_map<expr> local2href;
|
|
|
|
return to_blast_expr_fn(m_env, m_curr_state, m_uvar2uref, m_mvar2meta_mref, local2href)(e);
|
|
|
|
}
|
2015-11-08 21:09:48 +00:00
|
|
|
|
|
|
|
app_builder & get_app_builder() {
|
|
|
|
return m_app_builder;
|
|
|
|
}
|
2015-09-25 19:45:16 +00:00
|
|
|
};
|
2015-09-29 17:04:11 +00:00
|
|
|
|
2015-10-05 01:24:21 +00:00
|
|
|
LEAN_THREAD_PTR(blastenv, g_blastenv);
|
|
|
|
struct scope_blastenv {
|
|
|
|
blastenv * m_prev_blastenv;
|
2015-09-29 17:04:11 +00:00
|
|
|
public:
|
2015-10-05 01:24:21 +00:00
|
|
|
scope_blastenv(blastenv & c):m_prev_blastenv(g_blastenv) { g_blastenv = &c; }
|
|
|
|
~scope_blastenv() { g_blastenv = m_prev_blastenv; }
|
2015-09-29 17:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
environment const & env() {
|
2015-10-05 01:24:21 +00:00
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->get_env();
|
2015-09-29 17:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
io_state const & ios() {
|
2015-10-05 01:24:21 +00:00
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->get_ios();
|
2015-09-29 17:04:11 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 21:09:48 +00:00
|
|
|
app_builder & get_app_builder() {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->get_app_builder();
|
|
|
|
}
|
|
|
|
|
2015-10-01 23:21:17 +00:00
|
|
|
state & curr_state() {
|
2015-10-05 01:24:21 +00:00
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->get_curr_state();
|
2015-09-29 17:04:11 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 23:21:17 +00:00
|
|
|
bool is_reducible(name const & n) {
|
2015-10-05 01:24:21 +00:00
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->is_reducible(n);
|
2015-10-01 23:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
projection_info const * get_projection_info(name const & n) {
|
2015-10-05 01:24:21 +00:00
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->get_projection_info(n);
|
2015-10-01 23:21:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-31 00:45:27 +00:00
|
|
|
expr whnf(expr const & e) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->whnf(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
expr infer_type(expr const & e) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->infer_type(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_prop(expr const & e) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->is_prop(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_def_eq(expr const & e1, expr const & e2) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->is_def_eq(e1, e2);
|
|
|
|
}
|
|
|
|
|
|
|
|
optional<expr> mk_class_instance(expr const & e) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->mk_class_instance(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
expr mk_fresh_local(expr const & type, binder_info const & bi) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->mk_fresh_local(type, bi);
|
|
|
|
}
|
|
|
|
|
2015-11-08 01:42:58 +00:00
|
|
|
optional<congr_lemma> mk_congr_lemma_for_simp(expr const & fn, unsigned num_args) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->mk_congr_lemma_for_simp(fn, num_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
optional<congr_lemma> mk_congr_lemma_for_simp(expr const & fn) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->mk_congr_lemma_for_simp(fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
fun_info get_fun_info(expr const & fn) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->get_fun_info(fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
fun_info get_fun_info(expr const & fn, unsigned nargs) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->get_fun_info(fn, nargs);
|
|
|
|
}
|
|
|
|
|
2015-09-29 17:04:11 +00:00
|
|
|
void display_curr_state() {
|
|
|
|
curr_state().display(env(), ios());
|
|
|
|
display("\n");
|
|
|
|
}
|
|
|
|
|
2015-10-31 01:14:34 +00:00
|
|
|
void display_expr(expr const & e) {
|
|
|
|
ios().get_diagnostic_channel() << e << "\n";
|
|
|
|
}
|
|
|
|
|
2015-09-29 17:04:11 +00:00
|
|
|
void display(char const * msg) {
|
|
|
|
ios().get_diagnostic_channel() << msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void display(sstream const & msg) {
|
|
|
|
ios().get_diagnostic_channel() << msg.str();
|
|
|
|
}
|
2015-10-01 23:21:17 +00:00
|
|
|
|
2015-10-31 01:14:34 +00:00
|
|
|
scope_assignment::scope_assignment():m_keep(false) {
|
2015-10-31 00:45:27 +00:00
|
|
|
lean_assert(g_blastenv);
|
2015-11-01 05:31:58 +00:00
|
|
|
g_blastenv->m_tctx.push();
|
2015-10-31 00:45:27 +00:00
|
|
|
}
|
2015-10-01 23:21:17 +00:00
|
|
|
|
2015-10-31 01:14:34 +00:00
|
|
|
scope_assignment::~scope_assignment() {
|
2015-10-31 00:45:27 +00:00
|
|
|
if (m_keep)
|
2015-11-01 05:31:58 +00:00
|
|
|
g_blastenv->m_tctx.commit();
|
2015-10-31 00:45:27 +00:00
|
|
|
else
|
2015-11-01 05:31:58 +00:00
|
|
|
g_blastenv->m_tctx.pop();
|
2015-10-01 23:21:17 +00:00
|
|
|
}
|
2015-10-02 20:11:17 +00:00
|
|
|
|
2015-10-31 01:14:34 +00:00
|
|
|
void scope_assignment::commit() {
|
2015-10-31 00:45:27 +00:00
|
|
|
m_keep = true;
|
2015-10-02 20:11:17 +00:00
|
|
|
}
|
2015-10-31 01:14:34 +00:00
|
|
|
|
|
|
|
struct scope_debug::imp {
|
2015-11-09 20:27:33 +00:00
|
|
|
scoped_expr_caching m_scope1;
|
|
|
|
blastenv m_benv;
|
|
|
|
scope_blastenv m_scope2;
|
2015-10-31 01:14:34 +00:00
|
|
|
imp(environment const & env, io_state const & ios):
|
2015-11-09 20:27:33 +00:00
|
|
|
m_scope1(true),
|
2015-10-31 01:14:34 +00:00
|
|
|
m_benv(env, ios, list<name>(), list<name>()),
|
|
|
|
m_scope2(m_benv) {
|
|
|
|
expr aux_mvar = mk_metavar("dummy_mvar", mk_true());
|
|
|
|
goal aux_g(aux_mvar, mlocal_type(aux_mvar));
|
|
|
|
m_benv.init_state(aux_g);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
scope_debug::scope_debug(environment const & env, io_state const & ios):
|
|
|
|
m_imp(new imp(env, ios)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
scope_debug::~scope_debug() {}
|
2015-11-01 06:57:34 +00:00
|
|
|
|
|
|
|
/** \brief We need to redefine infer_local and infer_metavar, because the types of hypotheses
|
|
|
|
and blast meta-variables are stored in the blast state */
|
|
|
|
class tmp_tctx : public tmp_type_context {
|
|
|
|
public:
|
2015-11-05 23:59:40 +00:00
|
|
|
tmp_tctx(environment const & env, io_state const & ios, tmp_local_generator & gen):
|
|
|
|
tmp_type_context(env, ios, gen) {}
|
2015-11-01 06:57:34 +00:00
|
|
|
|
|
|
|
/** \brief Return the type of a local constant (local or not).
|
|
|
|
\remark This method allows the customer to store the type of local constants
|
|
|
|
in a different place. */
|
|
|
|
virtual expr infer_local(expr const & e) const {
|
|
|
|
state const & s = curr_state();
|
|
|
|
if (is_href(e)) {
|
2015-11-09 22:52:21 +00:00
|
|
|
hypothesis const * h = s.get_hypothesis_decl(e);
|
2015-11-01 06:57:34 +00:00
|
|
|
lean_assert(h);
|
|
|
|
return h->get_type();
|
|
|
|
} else {
|
|
|
|
return mlocal_type(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual expr infer_metavar(expr const & m) const {
|
2015-11-02 21:37:48 +00:00
|
|
|
if (is_mref(m)) {
|
|
|
|
state const & s = curr_state();
|
|
|
|
metavar_decl const * d = s.get_metavar_decl(m);
|
|
|
|
lean_assert(d);
|
|
|
|
return d->get_type();
|
|
|
|
} else {
|
|
|
|
// The type of external meta-variables is encoded in the usual way.
|
|
|
|
// In temporary type_context objects, we may have temporary meta-variables
|
|
|
|
// created by external modules (e.g., simplifier and app_builder).
|
|
|
|
return mlocal_type(m);
|
|
|
|
}
|
2015-11-01 06:57:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-04 20:29:28 +00:00
|
|
|
tmp_type_context * blastenv::mk_tmp_type_context() {
|
|
|
|
tmp_type_context * r;
|
|
|
|
if (m_tmp_ctx_pool.empty()) {
|
2015-11-05 23:59:40 +00:00
|
|
|
r = new tmp_tctx(m_env, m_ios, m_tmp_local_generator);
|
2015-11-04 20:29:28 +00:00
|
|
|
} else {
|
|
|
|
r = m_tmp_ctx_pool.back();
|
|
|
|
m_tmp_ctx_pool.pop_back();
|
|
|
|
}
|
2015-11-08 23:20:05 +00:00
|
|
|
r->set_local_instances(m_initial_context);
|
2015-11-01 06:57:34 +00:00
|
|
|
return r;
|
|
|
|
}
|
2015-11-04 20:29:28 +00:00
|
|
|
|
2015-11-06 00:07:11 +00:00
|
|
|
blast_tmp_type_context::blast_tmp_type_context(unsigned num_umeta, unsigned num_emeta) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
m_ctx = g_blastenv->mk_tmp_type_context();
|
|
|
|
m_ctx->clear();
|
|
|
|
m_ctx->set_next_uvar_idx(num_umeta);
|
|
|
|
m_ctx->set_next_mvar_idx(num_emeta);
|
|
|
|
}
|
|
|
|
|
2015-11-04 20:29:28 +00:00
|
|
|
blast_tmp_type_context::blast_tmp_type_context() {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
m_ctx = g_blastenv->mk_tmp_type_context();
|
|
|
|
}
|
|
|
|
|
|
|
|
blast_tmp_type_context::~blast_tmp_type_context() {
|
|
|
|
g_blastenv->recycle_tmp_type_context(m_ctx);
|
|
|
|
}
|
2015-11-04 23:52:38 +00:00
|
|
|
|
|
|
|
expr internalize(expr const & e) {
|
|
|
|
lean_assert(g_blastenv);
|
|
|
|
return g_blastenv->internalize(e);
|
|
|
|
}
|
2015-09-25 19:45:16 +00:00
|
|
|
}
|
|
|
|
optional<expr> blast_goal(environment const & env, io_state const & ios, list<name> const & ls, list<name> const & ds,
|
|
|
|
goal const & g) {
|
2015-11-09 20:27:33 +00:00
|
|
|
scoped_expr_caching scope1(true);
|
2015-10-05 01:24:21 +00:00
|
|
|
blast::blastenv b(env, ios, ls, ds);
|
|
|
|
blast::scope_blastenv scope2(b);
|
|
|
|
return b(g);
|
2015-09-25 19:45:16 +00:00
|
|
|
}
|
2015-09-29 17:42:35 +00:00
|
|
|
void initialize_blast() {
|
2015-11-09 01:29:47 +00:00
|
|
|
blast::g_prefix = new name(name::mk_internal_unique_name());
|
|
|
|
blast::g_tmp_prefix = new name(name::mk_internal_unique_name());
|
|
|
|
blast::g_blast_max_depth = new name{"blast", "max_depth"};
|
|
|
|
blast::g_blast_init_depth = new name{"blast", "init_depth"};
|
|
|
|
blast::g_blast_inc_depth = new name{"blast", "inc_depth"};
|
|
|
|
|
|
|
|
register_unsigned_option(*blast::g_blast_max_depth, LEAN_DEFAULT_BLAST_MAX_DEPTH,
|
|
|
|
"(blast) max search depth for blast");
|
|
|
|
register_unsigned_option(*blast::g_blast_init_depth, LEAN_DEFAULT_BLAST_INIT_DEPTH,
|
|
|
|
"(blast) initial search depth for blast (remark: blast uses iteration deepening)");
|
|
|
|
register_unsigned_option(*blast::g_blast_inc_depth, LEAN_DEFAULT_BLAST_INC_DEPTH,
|
|
|
|
"(blast) search depth increment for blast (remark: blast uses iteration deepening)");
|
2015-09-29 17:42:35 +00:00
|
|
|
}
|
|
|
|
void finalize_blast() {
|
|
|
|
delete blast::g_prefix;
|
2015-11-04 19:24:22 +00:00
|
|
|
delete blast::g_tmp_prefix;
|
2015-09-29 17:42:35 +00:00
|
|
|
}
|
2015-09-25 19:45:16 +00:00
|
|
|
}
|