2014-07-26 21:26:34 +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
|
|
|
|
*/
|
|
|
|
#include <vector>
|
2015-01-20 20:36:56 +00:00
|
|
|
#include "library/unfold_macros.h"
|
2015-02-11 01:31:40 +00:00
|
|
|
#include "library/abbreviation.h"
|
2014-07-26 21:26:34 +00:00
|
|
|
#include "kernel/type_checker.h"
|
|
|
|
#include "frontends/lean/theorem_queue.h"
|
|
|
|
#include "frontends/lean/parser.h"
|
2015-06-10 22:02:43 +00:00
|
|
|
#include "frontends/lean/util.h"
|
2014-07-26 21:26:34 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2015-05-09 01:41:33 +00:00
|
|
|
void theorem_queue::init_queue() {
|
|
|
|
m_queue.reset(new worker_queue<certified_declaration>(m_num_threads, []() { enable_expr_caching(false); }));
|
|
|
|
}
|
|
|
|
void theorem_queue::consume() {
|
|
|
|
for (auto const & c : m_queue->join())
|
|
|
|
m_ready.push_back(c);
|
|
|
|
init_queue();
|
|
|
|
}
|
|
|
|
theorem_queue::theorem_queue(parser & p, unsigned num_threads):m_parser(p), m_num_threads(num_threads) {
|
|
|
|
init_queue();
|
|
|
|
}
|
2014-07-26 21:26:34 +00:00
|
|
|
void theorem_queue::add(environment const & env, name const & n, level_param_names const & ls, local_level_decls const & lls,
|
|
|
|
expr const & t, expr const & v) {
|
2015-05-09 01:41:33 +00:00
|
|
|
m_queue->add([=]() {
|
2014-07-26 21:26:34 +00:00
|
|
|
level_param_names new_ls;
|
|
|
|
expr type, value;
|
2015-05-08 21:36:38 +00:00
|
|
|
std::tie(type, value, new_ls) = m_parser.elaborate_definition_at(env, lls, n, t, v);
|
2014-08-10 18:04:16 +00:00
|
|
|
new_ls = append(ls, new_ls);
|
2015-06-10 22:02:43 +00:00
|
|
|
value = postprocess(env, value);
|
2015-05-09 18:42:29 +00:00
|
|
|
auto r = check(env, mk_theorem(env, n, new_ls, type, value));
|
2014-08-10 18:04:16 +00:00
|
|
|
m_parser.cache_definition(n, t, v, new_ls, type, value);
|
|
|
|
return r;
|
2014-07-26 21:26:34 +00:00
|
|
|
});
|
|
|
|
}
|
2015-05-09 01:41:33 +00:00
|
|
|
void theorem_queue::add(certified_declaration const & c) {
|
|
|
|
m_ready.push_back(c);
|
|
|
|
}
|
|
|
|
void theorem_queue::for_each(std::function<void(certified_declaration const & c)> const & fn) {
|
|
|
|
consume();
|
|
|
|
for (auto const & c : m_ready)
|
|
|
|
fn(c);
|
|
|
|
}
|
|
|
|
void theorem_queue::join() { m_queue->join(); }
|
|
|
|
void theorem_queue::interrupt() { m_queue->interrupt(); }
|
|
|
|
bool theorem_queue::done() const { return m_queue->done(); }
|
2014-07-26 21:26:34 +00:00
|
|
|
}
|