lean4-htt/src/library/cache_helper.h
Leonardo de Moura cabb4350d9 feat(library): instances are not reducible by default anymore
Motivation: see "Other goodies" section at
https://github.com/leanprover/lean/wiki/Refactoring-structures

We had to add a new transparency mode: Instances at type_context.
In this mode, instances and reducible definitions are considered
transparent.

The new mode is used in the defeq_canonizer, code generator,
and sizeof lemma generation at inductive_compiler.

We also use the new mode in the unfold tactics.
2017-04-26 14:10:11 -07:00

56 lines
1.6 KiB
C++

/*
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include <memory>
#include "library/type_context.h"
namespace lean {
/** \brief Helper class for making sure we have a cache that is compatible
with a given environment and transparency mode. */
template<typename Cache>
class cache_compatibility_helper {
std::unique_ptr<Cache> m_cache_ptr[LEAN_NUM_TRANSPARENCY_MODES];
public:
Cache & get_cache_for(environment const & env, transparency_mode m) {
unsigned midx = static_cast<unsigned>(m);
if (!m_cache_ptr[midx] || !is_eqp(env, m_cache_ptr[midx]->env())) {
m_cache_ptr[midx].reset(new Cache(env));
}
return *m_cache_ptr[midx].get();
}
Cache & get_cache_for(type_context const & ctx) {
return get_cache_for(ctx.env(), ctx.mode());
}
void clear() {
for (unsigned i = 0; i < 4; i++) m_cache_ptr[i].reset();
}
};
/** \brief Helper class for making sure we have a cache that is compatible
with a given environment. */
template<typename Cache>
class transparencyless_cache_compatibility_helper {
std::unique_ptr<Cache> m_cache_ptr;
public:
Cache & get_cache_for(environment const & env) {
if (!m_cache_ptr || !is_eqp(env, m_cache_ptr->env())) {
m_cache_ptr.reset(new Cache(env));
}
return *m_cache_ptr.get();
}
Cache & get_cache_for(type_context const & ctx) {
return get_cache_for(ctx.env());
}
void clear() {
m_cache_ptr.reset();
}
};
}