feat(frontends/lean): send tactic hint table to elaborator
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
5a7e198583
commit
ec18bd93f9
9 changed files with 42 additions and 23 deletions
|
@ -8,9 +8,9 @@ Author: Leonardo de Moura
|
|||
#include <string>
|
||||
#include <functional>
|
||||
#include "kernel/environment.h"
|
||||
#include "library/tactic/tactic.h"
|
||||
|
||||
namespace lean {
|
||||
class tactic {}; // TODO(Leo): remove after tactic framework is ported to Lean 0.2
|
||||
class parser;
|
||||
|
||||
typedef std::function<environment(parser&)> command_fn;
|
||||
|
|
|
@ -22,6 +22,7 @@ Author: Leonardo de Moura
|
|||
#include "library/explicit.h"
|
||||
#include "library/unifier.h"
|
||||
#include "frontends/lean/parameter.h"
|
||||
#include "frontends/lean/hint_table.h"
|
||||
|
||||
namespace lean {
|
||||
class elaborator {
|
||||
|
@ -32,6 +33,7 @@ class elaborator {
|
|||
io_state m_ios;
|
||||
unifier_plugin m_plugin;
|
||||
name_generator m_ngen;
|
||||
hint_table m_hints;
|
||||
type_checker m_tc;
|
||||
substitution m_subst;
|
||||
context m_ctx;
|
||||
|
@ -110,10 +112,10 @@ class elaborator {
|
|||
|
||||
public:
|
||||
elaborator(environment const & env, io_state const & ios, name_generator const & ngen,
|
||||
substitution const & s = substitution(), context const & ctx = context()):
|
||||
hint_table const & htable, substitution const & s = substitution(), context const & ctx = context()):
|
||||
m_env(env), m_ios(ios),
|
||||
m_plugin([](constraint const &, name_generator const &) { return lazy_list<list<constraint>>(); }),
|
||||
m_ngen(ngen), m_tc(env, m_ngen.mk_child(), mk_default_converter(m_env, optional<module_idx>(0))),
|
||||
m_ngen(ngen), m_hints(htable), m_tc(env, m_ngen.mk_child(), mk_default_converter(m_env, optional<module_idx>(0))),
|
||||
m_subst(s), m_ctx(ctx) {
|
||||
}
|
||||
|
||||
|
@ -612,15 +614,16 @@ public:
|
|||
static name g_tmp_prefix = name::mk_internal_unique_name();
|
||||
|
||||
expr elaborate(environment const & env, io_state const & ios, expr const & e, name_generator const & ngen,
|
||||
substitution const & s, list<parameter> const & ctx) {
|
||||
return elaborator(env, ios, ngen, s, ctx)(e);
|
||||
hint_table const & htable, substitution const & s, list<parameter> const & ctx) {
|
||||
return elaborator(env, ios, ngen, htable, s, ctx)(e);
|
||||
}
|
||||
|
||||
expr elaborate(environment const & env, io_state const & ios, expr const & e) {
|
||||
return elaborate(env, ios, e, name_generator(g_tmp_prefix), substitution(), list<parameter>());
|
||||
expr elaborate(environment const & env, io_state const & ios, expr const & e, hint_table const & htable) {
|
||||
return elaborate(env, ios, e, name_generator(g_tmp_prefix), htable, substitution(), list<parameter>());
|
||||
}
|
||||
|
||||
std::pair<expr, expr> elaborate(environment const & env, io_state const & ios, name const & n, expr const & t, expr const & v) {
|
||||
return elaborator(env, ios, name_generator(g_tmp_prefix))(t, v, n);
|
||||
std::pair<expr, expr> elaborate(environment const & env, io_state const & ios, name const & n, expr const & t, expr const & v,
|
||||
hint_table const & htable) {
|
||||
return elaborator(env, ios, name_generator(g_tmp_prefix), htable)(t, v, n);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,12 @@ Author: Leonardo de Moura
|
|||
#include "kernel/environment.h"
|
||||
#include "kernel/metavar.h"
|
||||
#include "library/io_state.h"
|
||||
#include "frontends/lean/hint_table.h"
|
||||
|
||||
namespace lean {
|
||||
expr elaborate(environment const & env, io_state const & ios, expr const & e, name_generator const & ngen,
|
||||
substitution const & s = substitution(), list<parameter> const & ctx = list<parameter>());
|
||||
expr elaborate(environment const & env, io_state const & ios, expr const & e);
|
||||
std::pair<expr, expr> elaborate(environment const & env, io_state const & ios, name const & n, expr const & t, expr const & v);
|
||||
hint_table const & htable = hint_table(), substitution const & s = substitution(), list<parameter> const & ctx = list<parameter>());
|
||||
expr elaborate(environment const & env, io_state const & ios, expr const & e, hint_table const & htable = hint_table());
|
||||
std::pair<expr, expr> elaborate(environment const & env, io_state const & ios, name const & n, expr const & t, expr const & v,
|
||||
hint_table const & htable = hint_table());
|
||||
}
|
||||
|
|
13
src/frontends/lean/hint_table.h
Normal file
13
src/frontends/lean/hint_table.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#pragma once
|
||||
#include "util/rb_map.h"
|
||||
#include "library/tactic/tactic.h"
|
||||
|
||||
namespace lean {
|
||||
typedef rb_map<unsigned, tactic, unsigned_cmp> hint_table;
|
||||
}
|
|
@ -546,15 +546,15 @@ expr parser::mk_Type() {
|
|||
}
|
||||
|
||||
expr parser::elaborate(expr const & e) {
|
||||
return ::lean::elaborate(m_env, m_ios, e);
|
||||
return ::lean::elaborate(m_env, m_ios, e, m_hints);
|
||||
}
|
||||
|
||||
expr parser::elaborate(environment const & env, expr const & e) {
|
||||
return ::lean::elaborate(env, m_ios, e);
|
||||
return ::lean::elaborate(env, m_ios, e, m_hints);
|
||||
}
|
||||
|
||||
std::pair<expr, expr> parser::elaborate(name const & n, expr const & t, expr const & v) {
|
||||
return ::lean::elaborate(m_env, m_ios, n, t, v);
|
||||
return ::lean::elaborate(m_env, m_ios, n, t, v, m_hints);
|
||||
}
|
||||
|
||||
/** \brief Parse <tt>ID ':' expr</tt>, where the expression represents the type of the identifier. */
|
||||
|
@ -973,7 +973,7 @@ tactic parser::parse_tactic(unsigned /* rbp */) {
|
|||
}
|
||||
|
||||
void parser::save_hint(expr const & e, tactic const & t) {
|
||||
m_hints.insert(mk_pair(get_tag(e), t));
|
||||
m_hints.insert(get_tag(e), t);
|
||||
}
|
||||
|
||||
void parser::parse_command() {
|
||||
|
|
|
@ -20,6 +20,7 @@ Author: Leonardo de Moura
|
|||
#include "library/io_state_stream.h"
|
||||
#include "library/kernel_bindings.h"
|
||||
#include "frontends/lean/parameter.h"
|
||||
#include "frontends/lean/hint_table.h"
|
||||
#include "frontends/lean/scanner.h"
|
||||
#include "frontends/lean/local_decls.h"
|
||||
#include "frontends/lean/parser_config.h"
|
||||
|
@ -39,7 +40,6 @@ struct interrupt_parser {};
|
|||
typedef local_decls<parameter> local_expr_decls;
|
||||
typedef local_decls<level> local_level_decls;
|
||||
typedef environment local_environment;
|
||||
typedef std::unordered_map<unsigned, tactic> hint_table;
|
||||
|
||||
class parser {
|
||||
environment m_env;
|
||||
|
|
|
@ -200,9 +200,6 @@ struct unifier_fn {
|
|||
struct cnstr_cmp {
|
||||
int operator()(cnstr const & c1, cnstr const & c2) const { return c1.second < c2.second ? -1 : (c1.second == c2.second ? 0 : 1); }
|
||||
};
|
||||
struct unsigned_cmp {
|
||||
int operator()(unsigned i1, unsigned i2) const { return i1 < i2 ? -1 : (i1 == i2 ? 0 : 1); }
|
||||
};
|
||||
typedef rb_tree<cnstr, cnstr_cmp> cnstr_set;
|
||||
typedef rb_tree<unsigned, unsigned_cmp> cnstr_idx_set;
|
||||
typedef rb_map<name, cnstr_idx_set, name_quick_cmp> name_to_cnstrs;
|
||||
|
|
|
@ -10,9 +10,6 @@ Author: Leonardo de Moura
|
|||
#include "util/rb_map.h"
|
||||
#include "util/name.h"
|
||||
using namespace lean;
|
||||
|
||||
struct int_cmp { int operator()(int i1, int i2) const { return i1 < i2 ? -1 : (i1 > i2 ? 1 : 0); } };
|
||||
|
||||
typedef rb_map<int, name, int_cmp> int2name;
|
||||
|
||||
static void tst0() {
|
||||
|
|
|
@ -367,4 +367,11 @@ template<typename T, typename CMP>
|
|||
rb_tree<T, CMP> insert(rb_tree<T, CMP> const & t, T const & v) { rb_tree<T, CMP> r(t); r.insert(v); return r; }
|
||||
template<typename T, typename CMP>
|
||||
rb_tree<T, CMP> erase(rb_tree<T, CMP> const & t, T const & v) { rb_tree<T, CMP> r(t); r.erase(v); return r; }
|
||||
|
||||
struct unsigned_cmp {
|
||||
int operator()(unsigned i1, unsigned i2) const { return i1 < i2 ? -1 : (i1 == i2 ? 0 : 1); }
|
||||
};
|
||||
struct int_cmp {
|
||||
int operator()(int i1, int i2) const { return i1 < i2 ? -1 : (i1 == i2 ? 0 : 1); }
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue