feat(library/module): use io_state to report warning messages

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-05-24 14:07:05 -07:00
parent 5df2331159
commit 1cff37a084
3 changed files with 30 additions and 13 deletions

View file

@ -43,6 +43,7 @@ Author: Leonardo de Moura
namespace lean { namespace lean {
static environment get_global_environment(lua_State * L); static environment get_global_environment(lua_State * L);
io_state * get_io_state(lua_State * L); io_state * get_io_state(lua_State * L);
io_state get_tmp_io_state(lua_State * L);
// Level // Level
DECL_UDATA(level) DECL_UDATA(level)
@ -1161,9 +1162,16 @@ static int import_modules(environment const & env, lua_State * L, int s) {
buffer<std::string> mnames; buffer<std::string> mnames;
to_string_buffer(L, s, mnames); to_string_buffer(L, s, mnames);
unsigned num_threads = 1; unsigned num_threads = 1;
if (lua_gettop(L) > s) int nargs = lua_gettop(L);
if (nargs > s)
num_threads = lua_tonumber(L, s+1); 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) { static int import_modules(lua_State * L) {
@ -1397,6 +1405,10 @@ io_state * get_io_state(lua_State * L) {
return nullptr; return nullptr;
} }
io_state get_tmp_io_state(lua_State * L) {
return io_state(get_global_options(L), get_global_formatter(L));
}
// Justification // Justification
DECL_UDATA(justification) DECL_UDATA(justification)

View file

@ -142,6 +142,7 @@ struct import_modules_fn {
typedef std::tuple<module_idx, unsigned, delayed_update_fn> delayed_update; typedef std::tuple<module_idx, unsigned, delayed_update_fn> delayed_update;
shared_environment m_senv; shared_environment m_senv;
unsigned m_num_threads; unsigned m_num_threads;
io_state m_ios;
mutex m_asynch_mutex; mutex m_asynch_mutex;
condition_variable m_asynch_cv; condition_variable m_asynch_cv;
std::vector<asynch_update_fn> m_asynch_tasks; 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; typedef std::shared_ptr<module_info> module_info_ptr;
std::unordered_map<std::string, module_info_ptr> m_module_info; std::unordered_map<std::string, module_info_ptr> m_module_info;
import_modules_fn(environment const & env, unsigned num_threads): import_modules_fn(environment const & env, unsigned num_threads, io_state const & ios):
m_senv(env), m_num_threads(num_threads), m_senv(env), m_num_threads(num_threads), m_ios(ios),
m_import_counter(0), m_all_modules_imported(false) { m_import_counter(0), m_all_modules_imported(false) {
if (m_num_threads == 0) if (m_num_threads == 0)
m_num_threads = 1; m_num_threads = 1;
@ -343,7 +344,7 @@ struct import_modules_fn {
return std::get<1>(u1) < std::get<1>(u2); return std::get<1>(u1) < std::get<1>(u2);
}); });
for (auto const & d : m_delayed_tasks) { for (auto const & d : m_delayed_tasks) {
env = std::get<2>(d)(env); env = std::get<2>(d)(env, m_ios);
} }
return env; 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) { environment import_modules(environment const & env, unsigned num_modules, std::string const * modules,
return import_modules_fn(env, num_threads)(num_modules, 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) { environment import_module(environment const & env, std::string const & module,
return import_modules(env, 1, &module, num_threads); unsigned num_threads, io_state const & ios) {
return import_modules(env, 1, &module, num_threads, ios);
} }
} }

View file

@ -9,6 +9,7 @@ Author: Leonardo de Moura
#include <iostream> #include <iostream>
#include "util/serializer.h" #include "util/serializer.h"
#include "library/shared_environment.h" #include "library/shared_environment.h"
#include "library/io_state.h"
namespace lean { namespace lean {
/** /**
@ -16,8 +17,10 @@ namespace lean {
Modules included directly or indirectly by them are also imported. Modules included directly or indirectly by them are also imported.
The environment \c env is usually an empty environment. 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_modules(environment const & env, unsigned num_modules, std::string const * modules,
environment import_module(environment const & env, std::string const & module, unsigned num_threads = 1); 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. \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 Example: if module A was imported before B, then delayed updates from A
are executed before the ones from B. 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. \brief A reader for importing data from a stream using deserializer \c d.