refactor(library/type_context): move unification_hints to cache object

This commit is contained in:
Leonardo de Moura 2018-03-05 12:17:09 -08:00
parent d6d44a1994
commit f873def910
8 changed files with 24 additions and 6 deletions

View file

@ -109,6 +109,10 @@ bool context_cacheless::get_aux_recursor(type_context & 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<unification_hint> & hints) {
return ::lean::get_unification_hints(ctx.env(), f1, f2, hints);
}
void initialize_abstract_context_cache() {
g_class_instance_max_depth = new name{"class", "instance_max_depth"};
register_unsigned_option(*g_class_instance_max_depth, LEAN_DEFAULT_CLASS_INSTANCE_MAX_DEPTH,

View file

@ -12,6 +12,7 @@ Author: Leonardo de Moura
#include "library/projection.h"
#include "library/fun_info.h"
#include "library/local_instances.h"
#include "library/unification_hint.h"
namespace lean {
#define LEAN_NUM_TRANSPARENCY_MODES 5
@ -181,6 +182,7 @@ public:
virtual optional<declaration> 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<unification_hint> & hints) = 0;
/* Cache support for type_context module */
@ -296,6 +298,7 @@ public:
virtual optional<declaration> 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<unification_hint> & hints) override;
/* Cache support for type_context module */

View file

@ -5,6 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "library/context_cache.h"
#include "library/type_context.h"
namespace lean {
context_cache::context_cache():
@ -43,6 +44,12 @@ 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<unification_hint> & hints) {
if (!m_uhints)
m_uhints = ::lean::get_unification_hints(ctx.env());
::lean::get_unification_hints(*m_uhints, f1, f2, hints);
}
template<typename R, typename C>
optional<R> find_at(C const & c, expr const & e) {
auto it = c.find(e);

View file

@ -87,6 +87,8 @@ class context_cache : public context_cacheless {
cache manager. */
instance_cache m_instance_cache;
subsingleton_cache m_subsingleton_cache;
optional<unification_hints> m_uhints;
public:
context_cache();
context_cache(options const & o);
@ -100,6 +102,7 @@ public:
virtual optional<declaration> 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<unification_hint> & hints) override;
/* Cache support for type_context module */

View file

@ -63,6 +63,10 @@ bool persistent_context_cache::get_aux_recursor(type_context & ctx, name const &
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<unification_hint> & hints) {
return m_cache_ptr->get_unification_hints(ctx, f1, f2, hints);
}
optional<expr> persistent_context_cache::get_infer(expr const & e) {
return m_cache_ptr->get_infer(e);
}

View file

@ -46,6 +46,7 @@ public:
virtual optional<declaration> 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<unification_hint> & hints) override;
/* Cache support for type_context module */

View file

@ -134,7 +134,6 @@ void type_context::init_core(transparency_mode m) {
init_local_instances();
flush_instance_cache();
}
m_uhints = get_unification_hints(env());
}
type_context::type_context(environment const & env, options const & o, metavar_context const & mctx,
@ -164,8 +163,7 @@ type_context::type_context(type_context && src):
m_transparency_mode(src.m_transparency_mode),
m_approximate(src.m_approximate),
m_zeta(src.m_zeta),
m_smart_unfolding(src.m_smart_unfolding),
m_uhints(src.m_uhints) {
m_smart_unfolding(src.m_smart_unfolding) {
lean_assert(!src.m_tmp_data);
lean_assert(!src.m_used_assignment);
lean_assert(!src.m_in_is_def_eq);
@ -184,7 +182,6 @@ type_context::~type_context() {
void type_context::set_env(environment const & env) {
m_env = env;
m_uhints = get_unification_hints(env);
}
void type_context::update_local_instances(expr const & new_local, expr const & new_type) {
@ -3295,7 +3292,7 @@ bool type_context::try_unification_hints(expr const & e1, expr const & e2) {
expr e2_fn = get_app_fn(e2);
if (is_constant(e1_fn) && is_constant(e2_fn)) {
buffer<unification_hint> hints;
get_unification_hints(m_uhints, const_name(e1_fn), const_name(e2_fn), hints);
m_cache->get_unification_hints(*this, const_name(e1_fn), const_name(e2_fn), hints);
for (unification_hint const & hint : hints) {
lean_trace(name({"type_context", "unification_hint"}),
scope_trace_env scope(env(), *this);

View file

@ -524,7 +524,6 @@ private:
that cannot be solved precisely are ignored. This step is approximate, and it is
useful to skip it until we have additional information. */
bool m_full_postponed{true};
unification_hints m_uhints;
std::function<bool(name const & e)> const * m_transparency_pred{nullptr}; // NOLINT