2014-05-21 01:34:15 +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 <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include "util/serializer.h"
|
2014-08-03 02:47:55 +00:00
|
|
|
#include "util/optional.h"
|
2014-05-26 22:29:42 +00:00
|
|
|
#include "kernel/inductive/inductive.h"
|
2014-05-21 01:34:15 +00:00
|
|
|
#include "library/shared_environment.h"
|
2014-05-24 21:07:05 +00:00
|
|
|
#include "library/io_state.h"
|
2014-05-21 01:34:15 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-08-14 17:59:09 +00:00
|
|
|
class corrupted_file_exception : public exception {
|
|
|
|
public:
|
|
|
|
corrupted_file_exception(std::string const & fname);
|
|
|
|
};
|
|
|
|
|
2014-08-03 02:47:55 +00:00
|
|
|
class module_name {
|
|
|
|
optional<unsigned> m_relative;
|
|
|
|
name m_name;
|
|
|
|
public:
|
|
|
|
module_name(name const & n):m_name(n) {}
|
|
|
|
module_name(unsigned k, name const & n):m_relative(k), m_name(n) {}
|
|
|
|
module_name(optional<unsigned> const & k, name const & n):m_relative(k), m_name(n) {}
|
|
|
|
name const & get_name() const { return m_name; }
|
|
|
|
bool is_relative() const { return static_cast<bool>(m_relative); }
|
|
|
|
optional<unsigned> const & get_k() const { return m_relative; }
|
|
|
|
};
|
|
|
|
|
2015-05-05 01:05:00 +00:00
|
|
|
/** \brief Return the list of declarations performed in the current module */
|
|
|
|
list<name> const & get_curr_module_decl_names(environment const & env);
|
|
|
|
/** \brief Return the list of universes declared in the current module */
|
|
|
|
list<name> const & get_curr_module_univ_names(environment const & env);
|
|
|
|
/** \brief Return the list of modules directly imported by the current module */
|
|
|
|
list<module_name> const & get_curr_module_imports(environment const & env);
|
|
|
|
|
2014-09-17 23:28:22 +00:00
|
|
|
/** \brief Return an environment based on \c env, where all modules in \c modules are imported.
|
|
|
|
Modules included directly or indirectly by them are also imported.
|
|
|
|
The environment \c env is usually an empty environment.
|
2014-05-29 17:56:28 +00:00
|
|
|
|
2014-09-17 23:28:22 +00:00
|
|
|
If \c keep_proofs is false, then the proof of the imported theorems is discarded after being
|
|
|
|
checked. The idea is to save memory.
|
2014-05-21 01:34:15 +00:00
|
|
|
*/
|
2014-08-03 02:47:55 +00:00
|
|
|
environment import_modules(environment const & env, std::string const & base, unsigned num_modules, module_name const * modules,
|
2014-05-29 17:56:28 +00:00
|
|
|
unsigned num_threads, bool keep_proofs, io_state const & ios);
|
2014-08-03 02:47:55 +00:00
|
|
|
environment import_module(environment const & env, std::string const & base, module_name const & module,
|
2014-05-29 17:56:28 +00:00
|
|
|
unsigned num_threads, bool keep_proofs, io_state const & ios);
|
2014-05-21 01:34:15 +00:00
|
|
|
|
2014-09-29 22:17:27 +00:00
|
|
|
/** \brief Return the direct imports of the main module in the given environment. */
|
|
|
|
list<module_name> get_direct_imports(environment const & env);
|
|
|
|
|
|
|
|
/** \brief Return true iff the direct imports of the main module in the given environment have
|
|
|
|
been modified in the file system. */
|
|
|
|
bool direct_imports_have_changed(environment const & env);
|
|
|
|
|
2014-09-17 23:28:22 +00:00
|
|
|
/** \brief Store/Export module using \c env to the output stream \c out. */
|
2014-05-21 01:34:15 +00:00
|
|
|
void export_module(std::ostream & out, environment const & env);
|
|
|
|
|
2014-05-21 18:54:29 +00:00
|
|
|
/** \brief An asynchronous update. It goes into a task queue, and can be executed by a different execution thread. */
|
|
|
|
typedef std::function<void(shared_environment & env)> asynch_update_fn;
|
|
|
|
|
|
|
|
/** \brief Delayed update. It is performed after all imported modules have been loaded.
|
|
|
|
The delayes updates are executed based on the import order.
|
|
|
|
Example: if module A was imported before B, then delayed updates from A
|
|
|
|
are executed before the ones from B.
|
|
|
|
*/
|
2014-05-24 21:07:05 +00:00
|
|
|
typedef std::function<environment(environment const & env, io_state const & ios)> delayed_update_fn;
|
2014-05-21 01:34:15 +00:00
|
|
|
|
2014-09-17 23:28:22 +00:00
|
|
|
/** \brief A reader for importing data from a stream using deserializer \c d.
|
|
|
|
There are three ways to update the environment being constructed.
|
2014-05-21 18:54:29 +00:00
|
|
|
1- Direct update it using \c senv.
|
|
|
|
2- Asynchronous update using add_asynch_update.
|
|
|
|
3- Delayed update using add_delayed_update.
|
2014-05-21 01:34:15 +00:00
|
|
|
*/
|
2015-05-08 21:36:38 +00:00
|
|
|
typedef void (*module_object_reader)(deserializer & d, shared_environment & senv,
|
2014-05-21 18:54:29 +00:00
|
|
|
std::function<void(asynch_update_fn const &)> & add_asynch_update,
|
|
|
|
std::function<void(delayed_update_fn const &)> & add_delayed_update);
|
2014-05-21 01:34:15 +00:00
|
|
|
|
2014-09-17 23:28:22 +00:00
|
|
|
/** \brief Register a module object reader. The key \c k is used to identify the class of objects
|
|
|
|
that can be read by the given reader.
|
2014-05-21 01:34:15 +00:00
|
|
|
*/
|
|
|
|
void register_module_object_reader(std::string const & k, module_object_reader r);
|
|
|
|
|
2014-05-29 20:58:47 +00:00
|
|
|
namespace module {
|
2014-09-17 23:28:22 +00:00
|
|
|
/** \brief Add a function that should be invoked when the environment is exported.
|
2014-05-21 01:34:15 +00:00
|
|
|
The key \c k identifies which module_object_reader should be used to deserialize the object
|
|
|
|
when the module is imported.
|
|
|
|
|
|
|
|
\see module_object_reader
|
|
|
|
*/
|
2015-05-09 01:41:33 +00:00
|
|
|
environment add(environment const & env, std::string const & k, std::function<void(environment const &, serializer &)> const & writer);
|
2014-05-21 01:34:15 +00:00
|
|
|
|
2014-06-13 15:26:05 +00:00
|
|
|
/** \brief Add the global universe declaration to the environment, and mark it to be exported. */
|
|
|
|
environment add_universe(environment const & env, name const & l);
|
2014-05-31 19:12:41 +00:00
|
|
|
|
2014-05-21 01:34:15 +00:00
|
|
|
/** \brief Add the given declaration to the environment, and mark it to be exported. */
|
|
|
|
environment add(environment const & env, certified_declaration const & d);
|
2014-09-17 23:28:22 +00:00
|
|
|
/** \brief Add the given declaration to the environment, and mark it to be exported.
|
2014-05-23 17:50:34 +00:00
|
|
|
This method throws an exception if the trust_level <= LEAN_BELIEVER_TRUST_LEVEL
|
|
|
|
*/
|
|
|
|
environment add(environment const & env, declaration const & d);
|
2014-05-26 22:29:42 +00:00
|
|
|
|
2014-09-17 23:28:22 +00:00
|
|
|
/** \brief Return true iff \c n is a definition added to the current module using #module::add */
|
|
|
|
bool is_definition(environment const & env, name const & n);
|
|
|
|
|
2014-05-26 22:29:42 +00:00
|
|
|
/** \brief Add the given inductive declaration to the environment, and mark it to be exported. */
|
|
|
|
environment add_inductive(environment env,
|
|
|
|
level_param_names const & level_params,
|
|
|
|
unsigned num_params,
|
|
|
|
list<inductive::inductive_decl> const & decls);
|
2014-06-13 02:33:02 +00:00
|
|
|
|
2015-04-01 04:45:11 +00:00
|
|
|
/** \brief The following function must be invoked to register the quotient type computation rules in the kernel. */
|
|
|
|
environment declare_quotient(environment const & env);
|
|
|
|
|
2015-04-23 22:27:56 +00:00
|
|
|
/** \brief The following function must be invoked to register the builtin HITs in the kernel. */
|
|
|
|
environment declare_hits(environment const & env);
|
|
|
|
|
2014-06-13 02:33:02 +00:00
|
|
|
/**
|
|
|
|
\brief Declare a single inductive datatype. This is just a helper function implemented on top of
|
|
|
|
the previous (more general) add_inductive.
|
|
|
|
*/
|
|
|
|
environment add_inductive(environment const & env,
|
|
|
|
name const & ind_name, // name of new inductive datatype
|
|
|
|
level_param_names const & level_params, // level parameters
|
|
|
|
unsigned num_params, // number of params
|
|
|
|
expr const & type, // type of the form: params -> indices -> Type
|
|
|
|
list<inductive::intro_rule> const & intro_rules); // introduction rules
|
|
|
|
|
2014-05-21 01:34:15 +00:00
|
|
|
}
|
2014-09-23 00:30:29 +00:00
|
|
|
|
|
|
|
void initialize_module();
|
|
|
|
void finalize_module();
|
2014-05-29 20:58:47 +00:00
|
|
|
}
|