2014-05-20 22:42:52 +00:00
|
|
|
/*
|
|
|
|
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 <functional>
|
|
|
|
#include "util/shared_mutex.h"
|
|
|
|
#include "kernel/environment.h"
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
/** \brief Auxiliary object used when multiple threads are trying to populate the same environment. */
|
|
|
|
class shared_environment {
|
2015-08-15 01:37:17 +00:00
|
|
|
friend class import_modules_fn;
|
2014-05-20 22:42:52 +00:00
|
|
|
environment m_env;
|
2014-05-27 15:34:44 +00:00
|
|
|
mutable mutex m_mutex;
|
2015-08-15 01:37:17 +00:00
|
|
|
/**
|
|
|
|
\brief Add declaration that was not type checked.
|
|
|
|
The method throws an exception if trust_level() == 0
|
|
|
|
It blocks this object for a small amount of time.
|
|
|
|
|
|
|
|
Only module
|
|
|
|
*/
|
|
|
|
void add(declaration const & d);
|
2014-05-20 22:42:52 +00:00
|
|
|
public:
|
|
|
|
shared_environment();
|
|
|
|
shared_environment(environment const & env);
|
|
|
|
/** \brief Return a copy of the current environment. This is a constant time operation. */
|
|
|
|
environment get_environment() const;
|
2014-05-21 18:54:29 +00:00
|
|
|
environment env() const { return get_environment(); }
|
2014-05-20 22:42:52 +00:00
|
|
|
/**
|
|
|
|
\brief Add the given certified declaration to the environment.
|
|
|
|
This is a constant time operation.
|
|
|
|
It blocks this object for a small amount of time.
|
|
|
|
*/
|
|
|
|
void add(certified_declaration const & d);
|
|
|
|
/**
|
|
|
|
\brief Replace the axiom with name <tt>t.get_declaration().get_name()</tt> with the theorem t.get_declaration().
|
|
|
|
This is a constant time operation.
|
|
|
|
It blocks this object for a small amount of time.
|
|
|
|
*/
|
|
|
|
void replace(certified_declaration const & t);
|
|
|
|
/**
|
|
|
|
\brief Update the environment using the given function.
|
|
|
|
This procedure blocks access to this object.
|
|
|
|
*/
|
|
|
|
void update(std::function<environment(environment const &)> const & f);
|
|
|
|
};
|
|
|
|
}
|