refactor(kernel): move formatting stuff out of the kernel

This commit is contained in:
Leonardo de Moura 2018-06-07 16:16:11 -07:00
parent 8ae1e51b6d
commit 2a79da1ab6
54 changed files with 69 additions and 88 deletions

View file

@ -13,6 +13,7 @@ Author: Gabriel Ebner
#include "kernel/inductive/inductive.h"
#include "kernel/standard_kernel.h"
#include "kernel/for_each_fn.h"
#include "library/formatter.h"
#include "checker/text_import.h"
#include "checker/simple_pp.h"
@ -107,14 +108,6 @@ int main(int argc, char ** argv) {
}
} initer;
set_print_fn([] (std::ostream & out, expr const & e) {
try {
out << simple_pp(environment(), e, lowlevel_notations());
} catch (throwable & e) {
out << "!!!" << e.what() << "!!!";
}
});
try {
std::ifstream in(argv[1]);
if (!in) throw exception(sstream() << "file not found: " << argv[1]);

View file

@ -27,7 +27,7 @@ Author: Leonardo de Moura
#include "library/module.h"
#include "library/aux_definition.h"
#include "library/documentation.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/scope_pos_info_provider.h"
#include "library/replace_visitor.h"
#include "library/equations_compiler/util.h"
#include "library/equations_compiler/equations.h"

View file

@ -10,13 +10,13 @@ Author: Leonardo de Moura
#include "runtime/flet.h"
#include "util/sexpr/option_declarations.h"
#include "kernel/find_fn.h"
#include "kernel/error_msgs.h"
#include "kernel/for_each_fn.h"
#include "kernel/abstract.h"
#include "kernel/replace_fn.h"
#include "kernel/instantiate.h"
#include "kernel/scope_pos_info_provider.h"
#include "kernel/inductive/inductive.h"
#include "library/scope_pos_info_provider.h"
#include "library/error_msgs.h"
#include "library/trace.h"
#include "library/user_recursors.h"
#include "library/aux_recursors.h"

View file

@ -6,15 +6,15 @@ Author: Leonardo de Moura
*/
#pragma once
#include <vector>
#include "kernel/pos_info_provider.h"
#include "library/pos_info_provider.h"
#include "library/local_context.h"
#include "library/type_context.h"
#include "library/context_cache.h"
#include "library/tactic/tactic_state.h"
#include "library/tactic/elaborate.h"
#include "library/tactic/elaborator_exception.h"
#include "frontends/lean/info_manager.h"
#include "library/sorry.h"
#include "frontends/lean/info_manager.h"
namespace lean {
enum class elaborator_strategy {

View file

@ -18,7 +18,7 @@ Author: Leonardo de Moura
#include "kernel/find_fn.h"
#include "kernel/abstract.h"
#include "kernel/instantiate.h"
#include "kernel/error_msgs.h"
#include "library/error_msgs.h"
#include "library/st_task_queue.h"
#include "library/profiling.h"
#include "library/library_task_builder.h"
@ -48,7 +48,7 @@ Author: Leonardo de Moura
#include "library/pp_options.h"
#include "library/noncomputable.h"
#include "library/replace_visitor.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/scope_pos_info_provider.h"
#include "library/type_context.h"
#include "library/pattern_attribute.h"
#include "library/equations_compiler/equations.h"

View file

@ -9,7 +9,7 @@ Author: Leonardo de Moura
#include <utility>
#include <memory>
#include "util/rb_map.h"
#include "kernel/pos_info_provider.h"
#include "library/pos_info_provider.h"
namespace lean {
typedef rb_map<unsigned, pos_info, unsigned_cmp> pos_info_table;

View file

@ -12,7 +12,7 @@ Author: Leonardo de Moura
#include "runtime/utf8.h"
#include "util/name.h"
#include "kernel/environment.h"
#include "kernel/pos_info_provider.h"
#include "library/pos_info_provider.h"
#include "library/io_state.h"
#include "frontends/lean/token_table.h"

View file

@ -15,9 +15,9 @@ Author: Leonardo de Moura
#include "kernel/instantiate.h"
#include "kernel/abstract.h"
#include "kernel/replace_fn.h"
#include "kernel/error_msgs.h"
#include "kernel/old_type_checker.h"
#include "kernel/inductive/inductive.h"
#include "library/error_msgs.h"
#include "library/replace_visitor.h"
#include "library/trace.h"
#include "library/attribute_manager.h"

View file

@ -13,7 +13,7 @@ Author: Leonardo de Moura
#include "library/trace.h"
#include "library/placeholder.h"
#include "library/explicit.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/scope_pos_info_provider.h"
#include "library/vm/vm_nat.h"
#include "library/vm/vm_format.h"
#include "library/vm/vm_expr.h"

View file

@ -11,9 +11,9 @@ Author: Leonardo de Moura
#include "kernel/abstract.h"
#include "kernel/instantiate.h"
#include "kernel/replace_fn.h"
#include "kernel/error_msgs.h"
#include "kernel/for_each_fn.h"
#include "kernel/old_type_checker.h"
#include "library/error_msgs.h"
#include "library/kernel_serializer.h"
#include "library/scoped_ext.h"
#include "library/annotation.h"

View file

@ -1,6 +1,6 @@
add_library(kernel OBJECT level.cpp expr.cpp expr_eq_fn.cpp for_each_fn.cpp
replace_fn.cpp free_vars.cpp abstract.cpp instantiate.cpp local_ctx.cpp
formatter.cpp declaration.cpp environment.cpp pos_info_provider.cpp
old_type_checker.cpp error_msgs.cpp kernel_exception.cpp
normalizer_extension.cpp init_module.cpp expr_cache.cpp scope_pos_info_provider.cpp
equiv_manager.cpp quot.cpp abstract_type_context.cpp inductive.cpp standard_kernel.cpp)
add_library(kernel OBJECT level.cpp expr.cpp expr_eq_fn.cpp
for_each_fn.cpp replace_fn.cpp free_vars.cpp abstract.cpp
instantiate.cpp local_ctx.cpp declaration.cpp environment.cpp
old_type_checker.cpp normalizer_extension.cpp
init_module.cpp expr_cache.cpp equiv_manager.cpp quot.cpp
abstract_type_context.cpp inductive.cpp standard_kernel.cpp)

View file

@ -21,7 +21,6 @@ Author: Leonardo de Moura
#include "util/list_fn.h"
#include "util/sexpr/format.h"
#include "kernel/level.h"
#include "kernel/formatter.h"
#include "kernel/expr_eq_fn.h"
namespace lean {

View file

@ -9,6 +9,7 @@ Author: Leonardo de Moura
namespace lean {
environment environment::add_inductive_decls(inductive_decls const & decls) const {
#if 0
std::cout << "add_inductive_decls\n";
for (expr const & p : decls.m_params) {
std::cout << "param>> " << p << " : " << mlocal_type(p) << "\n";
@ -19,6 +20,7 @@ environment environment::add_inductive_decls(inductive_decls const & decls) cons
std::cout << ">> " << c << " : " << mlocal_type(c) << "\n";
}
}
#endif
// TODO(Leo)
return *this;
}

View file

@ -7,22 +7,18 @@ Author: Leonardo de Moura
#include "kernel/environment.h"
#include "kernel/old_type_checker.h"
#include "kernel/expr.h"
#include "kernel/formatter.h"
#include "kernel/level.h"
#include "kernel/declaration.h"
#include "kernel/error_msgs.h"
#include "kernel/local_ctx.h"
#include "kernel/quot.h"
namespace lean {
void initialize_kernel_module() {
initialize_error_msgs();
initialize_level();
initialize_expr();
initialize_declaration();
initialize_old_type_checker();
initialize_environment();
initialize_formatter();
initialize_quot();
initialize_local_ctx();
}
@ -30,12 +26,10 @@ void initialize_kernel_module() {
void finalize_kernel_module() {
finalize_local_ctx();
finalize_quot();
finalize_formatter();
finalize_environment();
finalize_old_type_checker();
finalize_declaration();
finalize_expr();
finalize_level();
finalize_error_msgs();
}
}

View file

@ -1,15 +0,0 @@
/*
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <vector>
#include <string>
#include "runtime/sstream.h"
#include "kernel/scope_pos_info_provider.h"
#include "kernel/kernel_exception.h"
#include "kernel/error_msgs.h"
namespace lean {
}

View file

@ -17,7 +17,6 @@ Author: Leonardo de Moura
#include "kernel/expr_maps.h"
#include "kernel/instantiate.h"
#include "kernel/free_vars.h"
#include "kernel/error_msgs.h"
#include "kernel/kernel_exception.h"
#include "kernel/abstract.h"
#include "kernel/replace_fn.h"

View file

@ -17,4 +17,5 @@ add_library(library OBJECT deep_copy.cpp expr_lt.cpp io_state.cpp
eval_helper.cpp messages.cpp message_builder.cpp module_mgr.cpp comp_val.cpp
documentation.cpp check.cpp parray.cpp process.cpp
pipe.cpp handle.cpp profiling.cpp time_task.cpp abstract_context_cache.cpp
context_cache.cpp unique_id.cpp persistent_context_cache.cpp elab_context.cpp)
context_cache.cpp unique_id.cpp persistent_context_cache.cpp elab_context.cpp
scope_pos_info_provider.cpp error_msgs.cpp formatter.cpp pos_info_provider.cpp)

View file

@ -8,7 +8,7 @@ Author: Sebastian Ullrich
#include <string>
#include "util/name_map.h"
#include "util/exception_with_pos.h"
#include "kernel/pos_info_provider.h"
#include "library/pos_info_provider.h"
namespace lean {
/** \brief Exception used to track parsing erros, it does not leak outside of this class. */

View file

@ -11,7 +11,7 @@ Author: Leonardo de Moura
#include "library/normalize.h"
#include "library/util.h"
#include "library/trace.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/scope_pos_info_provider.h"
#include "library/module.h"
#include "library/vm/vm.h"
#include "library/sorry.h"

View file

@ -9,7 +9,7 @@ Author: Leonardo de Moura
#include "kernel/replace_fn.h"
#include "kernel/instantiate.h"
#include "kernel/for_each_fn.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/scope_pos_info_provider.h"
#include "library/trace.h"
#include "library/projection.h"
#include "library/constants.h"

View file

@ -5,7 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "kernel/pos_info_provider.h"
#include "library/pos_info_provider.h"
namespace lean {
struct procedure {
name m_name;

View file

@ -12,10 +12,10 @@ Author: Leonardo de Moura
#include "kernel/expr.h"
#include "kernel/abstract.h"
#include "kernel/instantiate.h"
#include "kernel/error_msgs.h"
#include "kernel/for_each_fn.h"
#include "kernel/find_fn.h"
#include "kernel/replace_fn.h"
#include "library/error_msgs.h"
#include "library/exception.h"
#include "library/kernel_serializer.h"
#include "library/io_state_stream.h"

View file

@ -8,10 +8,10 @@ Author: Leonardo de Moura
#include "kernel/instantiate.h"
#include "kernel/abstract.h"
#include "kernel/find_fn.h"
#include "kernel/free_vars.h"
#include "kernel/old_type_checker.h"
#include "kernel/inductive/inductive.h"
#include "kernel/scope_pos_info_provider.h"
#include "kernel/free_vars.h"
#include "library/scope_pos_info_provider.h"
#include "library/util.h"
#include "library/module.h"
#include "library/aliases.h"

View file

@ -5,14 +5,13 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "kernel/instantiate.h"
#include "kernel/error_msgs.h"
#include "library/error_msgs.h"
#include "library/type_context.h"
#include "library/trace.h"
#include "library/constants.h"
#include "library/pp_options.h"
#include "library/app_builder.h"
#include "library/aux_definition.h"
#include "frontends/lean/elaborator.h"
#include "library/replace_visitor_with_tc.h"
#include "library/vm/vm.h"
#include "library/vm/vm_list.h"
@ -23,6 +22,7 @@ Author: Leonardo de Moura
#include "library/equations_compiler/pack_mutual.h"
#include "library/equations_compiler/elim_match.h"
#include "library/equations_compiler/util.h"
#include "frontends/lean/elaborator.h"
namespace lean {
#define trace_wf(Code) lean_trace(name({"eqn_compiler", "wf_rec"}), type_context_old ctx = mk_type_context(); scope_trace_env _scope1(m_env, ctx); Code)

View file

@ -9,7 +9,7 @@ Author: Leonardo de Moura
#include "util/name_set.h"
#include "kernel/replace_fn.h"
#include "kernel/for_each_fn.h"
#include "kernel/error_msgs.h"
#include "library/error_msgs.h"
namespace lean {
format pp_indent_expr(formatter const & fmt, expr const & e) {

View file

@ -6,7 +6,7 @@ Author: Leonardo de Moura
*/
#pragma once
#include "kernel/expr.h"
#include "kernel/formatter.h"
#include "library/formatter.h"
namespace lean {
format pp_indent_expr(formatter const & fmt, expr const & e);
format pp_type_expected(formatter const & fmt, expr const & e, expr const * fn_type = nullptr);

View file

@ -7,8 +7,8 @@ Author: Leonardo de Moura
#pragma once
#include <string>
#include "runtime/sstream.h"
#include "kernel/ext_exception.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/ext_exception.h"
#include "library/scope_pos_info_provider.h"
namespace lean {
class generic_exception : public ext_exception {

View file

@ -8,8 +8,8 @@ Author: Leonardo de Moura
#include "runtime/exception.h"
#include "util/exception_with_pos.h"
#include "util/sexpr/options.h"
#include "kernel/formatter.h"
#include "kernel/expr.h"
#include "library/formatter.h"
namespace lean {
/** \brief Base class for exceptions with support for pretty printing on demand. */

View file

@ -6,7 +6,7 @@ Author: Leonardo de Moura
*/
#include <utility>
#include "util/sexpr/option_declarations.h"
#include "kernel/formatter.h"
#include "library/formatter.h"
#ifndef LEAN_DEFAULT_FORMATTER_HIDE_FULL_TERMS
#define LEAN_DEFAULT_FORMATTER_HIDE_FULL_TERMS false

View file

@ -51,9 +51,13 @@ Author: Leonardo de Moura
#include "library/profiling.h"
#include "library/time_task.h"
#include "library/unique_id.h"
#include "library/error_msgs.h"
#include "library/formatter.h"
namespace lean {
void initialize_library_core_module() {
initialize_error_msgs();
initialize_formatter();
initialize_constants();
initialize_profiling();
initialize_trace();
@ -69,6 +73,8 @@ void finalize_library_core_module() {
finalize_trace();
finalize_profiling();
finalize_constants();
finalize_formatter();
finalize_error_msgs();
}
void initialize_library_module() {

View file

@ -10,7 +10,8 @@ Author: Leonardo de Moura
#include "util/sexpr/options.h"
#include "util/exception_with_pos.h"
#include "kernel/expr.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/formatter.h"
#include "library/scope_pos_info_provider.h"
namespace lean {
/**

View file

@ -7,10 +7,10 @@ Author: Leonardo de Moura
#pragma once
#include <string>
#include "kernel/environment.h"
#include "kernel/ext_exception.h"
#include "kernel/abstract_type_context.h"
#include "library/exception.h"
#include "library/io_state.h"
#include "library/ext_exception.h"
namespace lean {
/** \brief Base class for \c regular and \c diagnostic wrapper classes. */

View file

@ -9,6 +9,7 @@ Author: Leonardo de Moura
#include "util/name_set.h"
#include "kernel/local_ctx.h"
#include "kernel/expr.h"
#include "library/formatter.h"
#include "library/local_instances.h"
#include "library/subscripted_name_set.h"

View file

@ -12,9 +12,9 @@ Author: Leonardo de Moura
#include "runtime/serializer.h"
#include "runtime/optional.h"
#include "util/task.h"
#include "kernel/pos_info_provider.h"
#include "kernel/inductive/inductive.h"
#include "library/io_state.h"
#include "library/pos_info_provider.h"
namespace lean {
class corrupted_file_exception : public exception {

View file

@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "kernel/pos_info_provider.h"
#include "library/pos_info_provider.h"
namespace lean {
char const * pos_info_provider::get_file_name() const {

View file

@ -5,7 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "util/sexpr/option_declarations.h"
#include "kernel/error_msgs.h"
#include "library/error_msgs.h"
#include "library/pp_options.h"
#ifndef LEAN_DEFAULT_PP_MAX_DEPTH

View file

@ -5,11 +5,11 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <utility>
#include "kernel/formatter.h"
#include "kernel/environment.h"
#include "kernel/find_fn.h"
#include "kernel/instantiate.h"
#include "kernel/free_vars.h"
#include "library/formatter.h"
#include "library/annotation.h"
#include "library/util.h"
#include "library/print.h"

View file

@ -5,7 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "kernel/formatter.h"
#include "library/formatter.h"
namespace lean {
/** \brief Return true iff \c t contains a constant named \c n or a local constant with named (pp or not) \c n */

View file

@ -6,7 +6,7 @@ Author: Leonardo de Moura
*/
#include <string>
#include "runtime/sstream.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/scope_pos_info_provider.h"
namespace lean {
LEAN_THREAD_PTR(pos_info_provider, g_p);

View file

@ -6,7 +6,7 @@ Author: Leonardo de Moura
*/
#pragma once
#include <string>
#include "kernel/pos_info_provider.h"
#include "library/pos_info_provider.h"
namespace lean {
class scope_pos_info_provider {

View file

@ -5,7 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include <library/sorry.h>
#include "kernel/scope_pos_info_provider.h"
#include "library/scope_pos_info_provider.h"
#include "library/tactic/elaborator_exception.h"
namespace lean {

View file

@ -7,7 +7,7 @@ Author: Leonardo de Moura
#include "util/fresh_name.h"
#include "kernel/kernel_exception.h"
#include "kernel/old_type_checker.h"
#include "kernel/error_msgs.h"
#include "library/error_msgs.h"
#include "library/trace.h"
#include "library/util.h"
#include "library/vm/vm.h"

View file

@ -8,7 +8,7 @@ Author: Leonardo de Moura
#include "util/fresh_name.h"
#include "util/sexpr/option_declarations.h"
#include "kernel/instantiate.h"
#include "kernel/error_msgs.h"
#include "library/error_msgs.h"
#include "library/trace.h"
#include "library/util.h"
#include "library/user_recursors.h"

View file

@ -6,10 +6,10 @@ Author: Leonardo de Moura
*/
#include <vector>
#include <algorithm>
#include "kernel/error_msgs.h"
#include "kernel/instantiate.h"
#include "kernel/for_each_fn.h"
#include "kernel/find_fn.h"
#include "library/error_msgs.h"
#include "library/constants.h"
#include "library/trace.h"
#include "library/util.h"

View file

@ -10,11 +10,11 @@ Author: Leonardo de Moura
#include "util/sexpr/option_declarations.h"
#include "kernel/instantiate.h"
#include "kernel/abstract.h"
#include "kernel/error_msgs.h"
#include "kernel/replace_fn.h"
#include "kernel/for_each_fn.h"
#include "kernel/quot.h"
#include "kernel/inductive/inductive.h"
#include "library/error_msgs.h"
#include "library/trace.h"
#include "library/class.h"
#include "library/pp_options.h"

View file

@ -10,11 +10,11 @@ Author: Leonardo de Moura
#include "kernel/find_fn.h"
#include "kernel/free_vars.h"
#include "kernel/instantiate.h"
#include "kernel/error_msgs.h"
#include "kernel/old_type_checker.h"
#include "kernel/abstract.h"
#include "kernel/abstract_type_context.h"
#include "kernel/inductive/inductive.h"
#include "library/error_msgs.h"
#include "library/locals.h"
#include "library/util.h"
#include "library/annotation.h"

View file

@ -7,7 +7,7 @@ Authors: Leonardo de Moura, Sebastian Ullrich
#pragma once
#include <algorithm>
#include "kernel/environment.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/scope_pos_info_provider.h"
#include "library/type_context.h"
#include "library/vm/vm.h"

View file

@ -17,7 +17,7 @@ Author: Leonardo de Moura
#include "runtime/compiler_hints.h"
#include "util/rc.h"
#include "kernel/environment.h"
#include "kernel/pos_info_provider.h"
#include "library/pos_info_provider.h"
namespace lean {
class vm_obj;

View file

@ -8,7 +8,7 @@ Author: Leonardo de Moura
#include "util/sexpr/format.h"
#include "library/trace.h"
#include "library/parray.h"
#include "kernel/scope_pos_info_provider.h"
#include "library/scope_pos_info_provider.h"
#include "library/vm/vm.h"
#include "library/vm/vm_array.h"
#include "library/vm/vm_io.h"

View file

@ -27,8 +27,8 @@ Author: Leonardo de Moura
#include "util/sexpr/option_declarations.h"
#include "kernel/environment.h"
#include "kernel/kernel_exception.h"
#include "kernel/formatter.h"
#include "kernel/standard_kernel.h"
#include "library/formatter.h"
#include "library/st_task_queue.h"
#include "library/eval_helper.h"
#include "library/mt_task_queue.h"

View file

@ -7,13 +7,13 @@ Authors: Gabriel Ebner, Sebastian Ullrich
#pragma once
#include <string>
#include <vector>
#include "kernel/pos_info_provider.h"
#include "util/cancellable.h"
#include "kernel/environment.h"
#include "library/pos_info_provider.h"
#include "library/io_state.h"
#include "library/module_mgr.h"
#include "frontends/lean/json.h"
#include "library/mt_task_queue.h"
#include "util/cancellable.h"
#include "frontends/lean/json.h"
namespace lean {

View file

@ -5,7 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include "kernel/pos_info_provider.h"
#include "library/pos_info_provider.h"
namespace lean {
class simple_pos_info_provider : public pos_info_provider {
char const * m_fname;