feat(library/module): use io_state to report warning messages
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
5df2331159
commit
1cff37a084
3 changed files with 30 additions and 13 deletions
|
@ -43,6 +43,7 @@ Author: Leonardo de Moura
|
|||
namespace lean {
|
||||
static environment get_global_environment(lua_State * L);
|
||||
io_state * get_io_state(lua_State * L);
|
||||
io_state get_tmp_io_state(lua_State * L);
|
||||
|
||||
// Level
|
||||
DECL_UDATA(level)
|
||||
|
@ -1161,9 +1162,16 @@ static int import_modules(environment const & env, lua_State * L, int s) {
|
|||
buffer<std::string> mnames;
|
||||
to_string_buffer(L, s, mnames);
|
||||
unsigned num_threads = 1;
|
||||
if (lua_gettop(L) > s)
|
||||
int nargs = lua_gettop(L);
|
||||
if (nargs > s)
|
||||
num_threads = lua_tonumber(L, s+1);
|
||||
return push_environment(L, import_modules(env, mnames.size(), mnames.data(), num_threads));
|
||||
|
||||
if (nargs > s + 1 && is_io_state(L, s+2))
|
||||
return push_environment(L, import_modules(env, mnames.size(), mnames.data(), num_threads, to_io_state(L, s+2)));
|
||||
else if (io_state * ios = get_io_state(L))
|
||||
return push_environment(L, import_modules(env, mnames.size(), mnames.data(), num_threads, *ios));
|
||||
else
|
||||
return push_environment(L, import_modules(env, mnames.size(), mnames.data(), num_threads, get_tmp_io_state(L)));
|
||||
}
|
||||
|
||||
static int import_modules(lua_State * L) {
|
||||
|
@ -1397,6 +1405,10 @@ io_state * get_io_state(lua_State * L) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
io_state get_tmp_io_state(lua_State * L) {
|
||||
return io_state(get_global_options(L), get_global_formatter(L));
|
||||
}
|
||||
|
||||
// Justification
|
||||
DECL_UDATA(justification)
|
||||
|
||||
|
|
|
@ -142,6 +142,7 @@ struct import_modules_fn {
|
|||
typedef std::tuple<module_idx, unsigned, delayed_update_fn> delayed_update;
|
||||
shared_environment m_senv;
|
||||
unsigned m_num_threads;
|
||||
io_state m_ios;
|
||||
mutex m_asynch_mutex;
|
||||
condition_variable m_asynch_cv;
|
||||
std::vector<asynch_update_fn> m_asynch_tasks;
|
||||
|
@ -162,8 +163,8 @@ struct import_modules_fn {
|
|||
typedef std::shared_ptr<module_info> module_info_ptr;
|
||||
std::unordered_map<std::string, module_info_ptr> m_module_info;
|
||||
|
||||
import_modules_fn(environment const & env, unsigned num_threads):
|
||||
m_senv(env), m_num_threads(num_threads),
|
||||
import_modules_fn(environment const & env, unsigned num_threads, io_state const & ios):
|
||||
m_senv(env), m_num_threads(num_threads), m_ios(ios),
|
||||
m_import_counter(0), m_all_modules_imported(false) {
|
||||
if (m_num_threads == 0)
|
||||
m_num_threads = 1;
|
||||
|
@ -343,7 +344,7 @@ struct import_modules_fn {
|
|||
return std::get<1>(u1) < std::get<1>(u2);
|
||||
});
|
||||
for (auto const & d : m_delayed_tasks) {
|
||||
env = std::get<2>(d)(env);
|
||||
env = std::get<2>(d)(env, m_ios);
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
@ -366,11 +367,13 @@ struct import_modules_fn {
|
|||
}
|
||||
};
|
||||
|
||||
environment import_modules(environment const & env, unsigned num_modules, std::string const * modules, unsigned num_threads) {
|
||||
return import_modules_fn(env, num_threads)(num_modules, modules);
|
||||
environment import_modules(environment const & env, unsigned num_modules, std::string const * modules,
|
||||
unsigned num_threads, io_state const & ios) {
|
||||
return import_modules_fn(env, num_threads, ios)(num_modules, modules);
|
||||
}
|
||||
|
||||
environment import_module(environment const & env, std::string const & module, unsigned num_threads) {
|
||||
return import_modules(env, 1, &module, num_threads);
|
||||
environment import_module(environment const & env, std::string const & module,
|
||||
unsigned num_threads, io_state const & ios) {
|
||||
return import_modules(env, 1, &module, num_threads, ios);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ Author: Leonardo de Moura
|
|||
#include <iostream>
|
||||
#include "util/serializer.h"
|
||||
#include "library/shared_environment.h"
|
||||
#include "library/io_state.h"
|
||||
|
||||
namespace lean {
|
||||
/**
|
||||
|
@ -16,8 +17,10 @@ namespace lean {
|
|||
Modules included directly or indirectly by them are also imported.
|
||||
The environment \c env is usually an empty environment.
|
||||
*/
|
||||
environment import_modules(environment const & env, unsigned num_modules, std::string const * modules, unsigned num_threads = 1);
|
||||
environment import_module(environment const & env, std::string const & module, unsigned num_threads = 1);
|
||||
environment import_modules(environment const & env, unsigned num_modules, std::string const * modules,
|
||||
unsigned num_threads, io_state const & ios);
|
||||
environment import_module(environment const & env, std::string const & module,
|
||||
unsigned num_threads, io_state const & ios);
|
||||
|
||||
/**
|
||||
\brief Store/Export module using \c env to the output stream \c out.
|
||||
|
@ -32,8 +35,7 @@ typedef std::function<void(shared_environment & env)> asynch_update_fn;
|
|||
Example: if module A was imported before B, then delayed updates from A
|
||||
are executed before the ones from B.
|
||||
*/
|
||||
typedef std::function<environment(environment const & env)> delayed_update_fn;
|
||||
|
||||
typedef std::function<environment(environment const & env, io_state const & ios)> delayed_update_fn;
|
||||
|
||||
/**
|
||||
\brief A reader for importing data from a stream using deserializer \c d.
|
||||
|
|
Loading…
Reference in a new issue