feat(kernel/environment): add forget method
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
7b15e558a2
commit
9ed700a5a6
4 changed files with 22 additions and 0 deletions
|
@ -108,6 +108,10 @@ environment environment::replace(certified_definition const & t) const {
|
|||
return environment(m_header, m_id, insert(m_definitions, n, t.get_definition()), m_global_levels, m_extensions);
|
||||
}
|
||||
|
||||
environment environment::forget() const {
|
||||
return environment(m_header, environment_id(), m_definitions, m_global_levels, m_extensions);
|
||||
}
|
||||
|
||||
class extension_manager {
|
||||
std::vector<std::shared_ptr<environment_extension const>> m_exts;
|
||||
mutex m_mutex;
|
||||
|
|
|
@ -181,6 +181,13 @@ public:
|
|||
|
||||
/** \brief Update the environment extension with the given id. */
|
||||
environment update(unsigned extid, std::shared_ptr<environment_extension const> const & ext) const;
|
||||
|
||||
/**
|
||||
\brief Return a new environment, where its "history" has been truncated/forgotten.
|
||||
That is, <tt>is_descendant(e)</tt> will return false for any environment \c e that
|
||||
is not pointer equal to the result.
|
||||
*/
|
||||
environment forget() const;
|
||||
};
|
||||
|
||||
class name_generator;
|
||||
|
|
|
@ -884,6 +884,7 @@ static int mk_empty_environment(lua_State * L) {
|
|||
bool impredicative = get_bool_named_param(L, 1, "impredicative", true);
|
||||
return push_environment(L, environment(trust_lvl, proof_irrel, eta, impredicative));
|
||||
}
|
||||
static int environment_forget(lua_State * L) { return push_environment(L, to_environment(L, 1).forget()); }
|
||||
|
||||
static const struct luaL_Reg environment_m[] = {
|
||||
{"__gc", environment_gc}, // never throws
|
||||
|
@ -900,6 +901,7 @@ static const struct luaL_Reg environment_m[] = {
|
|||
{"get", safe_function<environment_get>},
|
||||
{"add", safe_function<environment_add>},
|
||||
{"replace", safe_function<environment_replace>},
|
||||
{"forget", safe_function<environment_forget>},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
|
|
9
tests/lua/env7.lua
Normal file
9
tests/lua/env7.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
local env1 = empty_environment()
|
||||
local env2 = add_decl(env1, mk_var_decl("A", Type))
|
||||
assert(env2:is_descendant(env1))
|
||||
assert(env2:is_descendant(env2))
|
||||
assert(not env1:is_descendant(env2))
|
||||
local env3 = env2:forget()
|
||||
assert(not env3:is_descendant(env1))
|
||||
assert(not env3:is_descendant(env2))
|
||||
assert(env3:is_descendant(env3))
|
Loading…
Reference in a new issue