refactor(kernel/record): remove kernel extension for records, we will

implement it outside of the kernel on top of the inductive datatypes
This commit is contained in:
Leonardo de Moura 2014-09-24 09:16:03 -07:00
parent da481c3274
commit 358074ae3d
6 changed files with 3 additions and 136 deletions

View file

@ -250,8 +250,6 @@ add_subdirectory(kernel)
set(LEAN_LIBS ${LEAN_LIBS} kernel)
add_subdirectory(kernel/inductive)
set(LEAN_LIBS ${LEAN_LIBS} inductive)
add_subdirectory(kernel/record)
set(LEAN_LIBS ${LEAN_LIBS} record)
add_subdirectory(library)
set(LEAN_LIBS ${LEAN_LIBS} library)
add_subdirectory(library/tactic)

View file

@ -11,7 +11,6 @@ Author: Leonardo de Moura
#include "kernel/type_checker.h"
#include "kernel/instantiate.h"
#include "kernel/replace_fn.h"
#include "kernel/record/record.h"
#include "library/scoped_ext.h"
#include "library/placeholder.h"
#include "library/locals.h"
@ -280,9 +279,7 @@ struct structure_cmd_fn {
level r_lvl = mk_result_level(m_env, r_lvls);
m_type = update_result_sort(m_type, r_lvl);
}
m_env = record::add_record(m_p.env(), to_list(m_level_names.begin(), m_level_names.end()), m_name, m_type,
m_mk, intro_type);
// TODO(Leo): create aliases, declare notation, create to_parent methods.
// TODO(Leo): create record, aliases, declare notation, create to_parent methods.
return m_env;
}
};

View file

@ -1,2 +0,0 @@
add_library(record record.cpp)
target_link_libraries(record ${LEAN_LIBS})

View file

@ -1,66 +0,0 @@
/*
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 <memory>
#include "kernel/type_checker.h"
#include "kernel/record/record.h"
namespace lean { namespace record {
static name g_tmp_prefix = name::mk_internal_unique_name();
/** \brief Environment extension used to store record information */
struct record_env_ext : public environment_extension {
struct record_info {
list<field> m_fields;
};
// mapping from introduction rule name to computation rule data
rb_map<name, record_info, name_quick_cmp> m_record_info;
record_env_ext() {}
};
/** \brief Helper functional object for processing record declarations. */
struct add_record_fn {
typedef std::unique_ptr<type_checker> type_checker_ptr;
environment m_env;
name_generator m_ngen;
type_checker_ptr m_tc;
level_param_names const & m_level_params;
name const & m_record_name;
expr const & m_record_type;
name const & m_intro_name;
expr const & m_intro_type;
add_record_fn(environment const & env, level_param_names const & level_params, name const & rec_name, expr const & rec_type,
name const & intro_name, expr const & intro_type):
m_env(env), m_ngen(g_tmp_prefix), m_tc(new type_checker(m_env)),
m_level_params(level_params), m_record_name(rec_name), m_record_type(rec_type),
m_intro_name(intro_name), m_intro_type(intro_type) {}
environment operator()() {
// TODO(Leo):
std::cout << m_record_name << " : " << m_record_type << "\n";
std::cout << " >> " << m_intro_name << " : " << m_intro_type << "\n";
return m_env;
}
};
environment add_record(environment const & env, level_param_names const & level_params, name const & rec_name, expr const & rec_type,
name const & intro_name, expr const & intro_type) {
return add_record_fn(env, level_params, rec_name, rec_type, intro_name, intro_type)();
}
optional<pair<expr, constraint_seq>> record_normalizer_extension::operator()(expr const &, extension_context &) const {
return none_ecs();
}
bool record_normalizer_extension::may_reduce_later(expr const &, extension_context &) const {
return false;
}
bool record_normalizer_extension::supports(name const &) const {
return false;
}
}}

View file

@ -1,57 +0,0 @@
/*
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 <memory>
#include <utility>
#include "util/list.h"
#include "util/optional.h"
#include "kernel/environment.h"
namespace lean { namespace record {
typedef pair<name, expr> field;
inline name const & field_name(field const & f) { return f.first; }
inline expr const & field_type(field const & f) { return f.second; }
/** \brief Declare a record type. */
environment add_record(environment const & env,
level_param_names const & level_params,
name const & rec_name,
expr const & rec_type,
name const & intro_name,
expr const & intro_type);
/** \brief Normalizer extension for applying record computational rules. */
class record_normalizer_extension : public normalizer_extension {
public:
virtual optional<pair<expr, constraint_seq>> operator()(expr const & e, extension_context & ctx) const;
virtual bool may_reduce_later(expr const & e, extension_context & ctx) const;
virtual bool supports(name const & feature) const;
};
/** \brief If \c n is the name of a record in the environment \c env, then return the
list of all fields. Return none otherwise
*/
optional<list<field>> is_record(environment const & env, name const & n);
/** \brief If \c n is the name of a record's field in \c env, then return the name of the record type
associated with it.
*/
optional<name> is_field(environment const & env, name const & n);
/** \brief If \c n is the name of an introduction rule for a record in \c env, then return the name of the record type
associated with it.
*/
optional<name> is_intro_rule(environment const & env, name const & n);
/** \brief If \c n is the name of an elimination rule for a record in \c env, then return the name of the record type
associated with it.
*/
optional<name> is_elim_rule(environment const & env, name const & n);
/** \brief Given the eliminator \c n, this function return the position of major premise */
optional<unsigned> get_elim_major_idx(environment const & env, name const & n);
}}

View file

@ -5,12 +5,10 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "kernel/inductive/inductive.h"
#include "kernel/record/record.h"
#include "library/inductive_unifier_plugin.h"
namespace lean {
using inductive::inductive_normalizer_extension;
using record::record_normalizer_extension;
/** \brief Create standard Lean environment */
environment mk_environment(unsigned trust_lvl) {
@ -18,9 +16,8 @@ environment mk_environment(unsigned trust_lvl) {
true /* Type.{0} is proof irrelevant */,
true /* Eta */,
true /* Type.{0} is impredicative */,
/* builtin support for inductive and record datatypes */
compose(std::unique_ptr<normalizer_extension>(new inductive_normalizer_extension()),
std::unique_ptr<normalizer_extension>(new record_normalizer_extension())));
/* builtin support for inductive */
std::unique_ptr<normalizer_extension>(new inductive_normalizer_extension()));
return set_unifier_plugin(env, mk_inductive_unifier_plugin());
}
}