feat(frontends/lean/builtin_cmds): add 'print [reducible]', 'print [irreducible]' and 'print [quasireducible]' commands

This commit is contained in:
Leonardo de Moura 2015-05-29 16:47:29 -07:00
parent 7a0e198147
commit 6d2f37857d
5 changed files with 65 additions and 17 deletions

View file

@ -354,6 +354,18 @@ bool print_polymorphic(parser & p) {
return false; return false;
} }
static void print_reducible_info(parser & p, reducible_status s1) {
buffer<name> r;
for_each_reducible(p.env(), [&](name const & n, reducible_status s2) {
if (s1 == s2)
r.push_back(n);
});
io_state_stream out = p.regular_stream();
std::sort(r.begin(), r.end());
for (name const & n : r)
out << n << "\n";
}
environment print_cmd(parser & p) { environment print_cmd(parser & p) {
flycheck_information info(p.regular_stream()); flycheck_information info(p.regular_stream());
if (info.enabled()) { if (info.enabled()) {
@ -370,6 +382,15 @@ environment print_cmd(parser & p) {
options opts = out.get_options(); options opts = out.get_options();
opts = opts.update(get_pp_notation_option_name(), false); opts = opts.update(get_pp_notation_option_name(), false);
out.update_options(opts) << e << endl; out.update_options(opts) << e << endl;
} else if (p.curr_is_token_or_id(get_reducible_tk())) {
p.next();
print_reducible_info(p, reducible_status::Reducible);
} else if (p.curr_is_token_or_id(get_quasireducible_tk())) {
p.next();
print_reducible_info(p, reducible_status::Quasireducible);
} else if (p.curr_is_token_or_id(get_irreducible_tk())) {
p.next();
print_reducible_info(p, reducible_status::Irreducible);
} else if (p.curr_is_token_or_id(get_options_tk())) { } else if (p.curr_is_token_or_id(get_options_tk())) {
p.next(); p.next();
p.regular_stream() << p.ios().get_options() << endl; p.regular_stream() << p.ios().get_options() << endl;

View file

@ -21,19 +21,10 @@ struct reducible_entry {
reducible_entry(reducible_status s, name const & n):m_status(s), m_name(n) {} reducible_entry(reducible_status s, name const & n):m_status(s), m_name(n) {}
}; };
class reducible_state { typedef name_map<reducible_status> reducible_state;
name_map<reducible_status> m_status;
public:
void add(reducible_entry const & e);
reducible_status get_status(name const & n) const;
};
void reducible_state::add(reducible_entry const & e) { static reducible_status get_status(reducible_state const & s, name const & n) {
m_status.insert(e.m_name, e.m_status); if (auto it = s.find(n))
}
reducible_status reducible_state::get_status(name const & n) const {
if (auto it = m_status.find(n))
return *it; return *it;
else else
return reducible_status::Semireducible; return reducible_status::Semireducible;
@ -46,7 +37,7 @@ struct reducible_config {
typedef reducible_state state; typedef reducible_state state;
typedef reducible_entry entry; typedef reducible_entry entry;
static void add_entry(environment const &, io_state const &, state & s, entry const & e) { static void add_entry(environment const &, io_state const &, state & s, entry const & e) {
s.add(e); s.insert(e.m_name, e.m_status);
} }
static name const & get_class_name() { static name const & get_class_name() {
return *g_class_name; return *g_class_name;
@ -87,6 +78,11 @@ void finalize_reducible() {
delete g_class_name; delete g_class_name;
} }
void for_each_reducible(environment const & env, std::function<void(name const &, reducible_status)> const & fn) {
reducible_state m_state = reducible_ext::get_state(env);
m_state.for_each(fn);
}
static void check_declaration(environment const & env, name const & n) { static void check_declaration(environment const & env, name const & n) {
declaration const & d = env.get(n); declaration const & d = env.get(n);
if (!d.is_definition()) if (!d.is_definition())
@ -100,7 +96,7 @@ environment set_reducible(environment const & env, name const & n, reducible_sta
reducible_status get_reducible_status(environment const & env, name const & n) { reducible_status get_reducible_status(environment const & env, name const & n) {
reducible_state const & s = reducible_ext::get_state(env); reducible_state const & s = reducible_ext::get_state(env);
return s.get_status(n); return get_status(s, n);
} }
bool is_at_least_quasireducible(environment const & env, name const & n) { bool is_at_least_quasireducible(environment const & env, name const & n) {
@ -111,14 +107,14 @@ bool is_at_least_quasireducible(environment const & env, name const & n) {
name_predicate mk_not_reducible_pred(environment const & env) { name_predicate mk_not_reducible_pred(environment const & env) {
reducible_state m_state = reducible_ext::get_state(env); reducible_state m_state = reducible_ext::get_state(env);
return [=](name const & n) { // NOLINT return [=](name const & n) { // NOLINT
return m_state.get_status(n) != reducible_status::Reducible; return get_status(m_state, n) != reducible_status::Reducible;
}; };
} }
name_predicate mk_not_quasireducible_pred(environment const & env) { name_predicate mk_not_quasireducible_pred(environment const & env) {
reducible_state m_state = reducible_ext::get_state(env); reducible_state m_state = reducible_ext::get_state(env);
return [=](name const & n) { // NOLINT return [=](name const & n) { // NOLINT
auto r = m_state.get_status(n); auto r = get_status(m_state, n);
return r != reducible_status::Reducible && r != reducible_status::Quasireducible; return r != reducible_status::Reducible && r != reducible_status::Quasireducible;
}; };
} }
@ -126,7 +122,7 @@ name_predicate mk_not_quasireducible_pred(environment const & env) {
name_predicate mk_irreducible_pred(environment const & env) { name_predicate mk_irreducible_pred(environment const & env) {
reducible_state m_state = reducible_ext::get_state(env); reducible_state m_state = reducible_ext::get_state(env);
return [=](name const & n) { // NOLINT return [=](name const & n) { // NOLINT
return m_state.get_status(n) == reducible_status::Irreducible; return get_status(m_state, n) == reducible_status::Irreducible;
}; };
} }

View file

@ -28,6 +28,9 @@ reducible_status get_reducible_status(environment const & env, name const & n);
bool is_at_least_quasireducible(environment const & env, name const & n); bool is_at_least_quasireducible(environment const & env, name const & n);
/* \brief Execute the given function for each declaration explicitly marked with a reducibility annotation */
void for_each_reducible(environment const & env, std::function<void(name const &, reducible_status)> const & fn);
/** \brief Create a predicate that returns true for all non reducible constants in \c env */ /** \brief Create a predicate that returns true for all non reducible constants in \c env */
name_predicate mk_not_reducible_pred(environment const & env); name_predicate mk_not_reducible_pred(environment const & env);
/** \brief Create a predicate that returns true for all non reducible and non quasireducible constants in \c env */ /** \brief Create a predicate that returns true for all non reducible and non quasireducible constants in \c env */

View file

@ -0,0 +1,19 @@
prelude
definition id₁ [reducible] {A : Type} (a : A) := a
definition id₂ [reducible] {A : Type} (a : A) := a
definition id₄ [quasireducible] {A : Type} (a : A) := a
definition id₃ [quasireducible] {A : Type} (a : A) := a
definition id₅ [irreducible] {A : Type} (a : A) := a
definition id₆ [irreducible] {A : Type} (a : A) := a
definition pr [reducible] {A B : Type} (a : A) (b : B) := a
definition pr2 {A B : Type} (a : A) (b : B) := a
print [reducible]
print "-----------"
print [quasireducible]
print "-----------"
print [irreducible]

View file

@ -0,0 +1,9 @@
id₁
id₂
pr
-----------
id₃
id₄
-----------
id₅
id₆