diff --git a/src/frontends/lean/builtin_cmds.cpp b/src/frontends/lean/builtin_cmds.cpp index 2d08a1fb2..3637db6b1 100644 --- a/src/frontends/lean/builtin_cmds.cpp +++ b/src/frontends/lean/builtin_cmds.cpp @@ -23,7 +23,6 @@ Author: Leonardo de Moura #include "library/locals.h" #include "library/coercion.h" #include "library/constants.h" -#include "library/reducible.h" #include "library/light_lt_manager.h" #include "library/normalize.h" #include "library/print.h" @@ -36,8 +35,8 @@ Author: Leonardo de Moura #include "library/pp_options.h" #include "library/composition_manager.h" #include "library/aux_recursors.h" -#include "library/relation_manager.h" #include "library/projection.h" +#include "library/attribute_manager.h" #include "library/private.h" #include "library/decl_stats.h" #include "library/app_builder.h" @@ -46,7 +45,6 @@ Author: Leonardo de Moura #include "library/congr_lemma_manager.h" #include "library/abstract_expr_manager.h" #include "library/definitional/projection.h" -#include "library/blast/simplifier/simp_rule_set.h" #include "library/blast/blast.h" #include "library/blast/simplifier/simplifier.h" #include "library/blast/backward/backward_rule_set.h" @@ -294,33 +292,35 @@ static void print_definition(parser const & p, name const & n, pos_info const & static void print_attributes(parser const & p, name const & n) { environment const & env = p.env(); io_state_stream out = p.regular_stream(); - if (is_coercion(env, n)) - out << " [coercion]"; - if (is_class(env, n)) - out << " [class]"; - if (is_instance(env, n)) - out << " [instance]"; - if (is_simp_rule(env, n)) - out << " [simp]"; - if (is_congr_rule(env, n)) - out << " [congr]"; - if (auto light_arg = is_light_rule(env, n)) - out << " [light " << *light_arg << "]"; - if (is_backward_rule(env, n)) - out << " [backward]"; - if (is_no_pattern(env, n)) - out << " [no_pattern]"; - if (is_forward_lemma(env, n)) - out << " [forward]"; - if (is_elim_lemma(env, n)) - out << " [elim]"; - if (is_intro_lemma(env, n)) - out << " [intro]"; - switch (get_reducible_status(env, n)) { - case reducible_status::Reducible: out << " [reducible]"; break; - case reducible_status::Irreducible: out << " [irreducible]"; break; - case reducible_status::Quasireducible: out << " [quasireducible]"; break; - case reducible_status::Semireducible: break; + buffer attrs; + get_attributes(attrs); + for (char const * attr : attrs) { + if (strcmp(attr, "semireducible") == 0) + continue; + if (has_attribute(env, attr, n)) { + out << " " << get_attribute_token(attr); + switch (get_attribute_kind(attr)) { + case attribute_kind::Default: + break; + case attribute_kind::Prioritized: { + unsigned prio = get_attribute_prio(env, attr, n); + if (prio != LEAN_DEFAULT_PRIORITY) + out << " [priority " << prio << "]"; + break; + } + case attribute_kind::Parametric: + case attribute_kind::OptParametric: + out << " " << get_attribute_param(env, attr, n) << "]"; + break; + case attribute_kind::MultiParametric: { + list ps = get_attribute_params(env, attr, n); + for (auto p : ps) { + out << " " << p; + } + out << "]"; + break; + }} + } } } diff --git a/src/library/attribute_manager.cpp b/src/library/attribute_manager.cpp index 4c716c090..d46b908ca 100644 --- a/src/library/attribute_manager.cpp +++ b/src/library/attribute_manager.cpp @@ -180,6 +180,24 @@ char const * get_attribute_from_token(char const * tk) { return nullptr; } +template +char const * get_attribute_token(Decls const & decls, char const * attr) { + for (auto const & d : decls) { + if (d.m_id == attr) + return d.m_token.c_str(); + } + return nullptr; +} + +char const * get_attribute_token(char const * attr) { + if (auto r = get_attribute_token(*g_default_attrs, attr)) return r; + if (auto r = get_attribute_token(*g_prio_attrs, attr)) return r; + if (auto r = get_attribute_token(*g_param_attrs, attr)) return r; + if (auto r = get_attribute_token(*g_opt_param_attrs, attr)) return r; + if (auto r = get_attribute_token(*g_params_attrs, attr)) return r; + return nullptr; +} + attribute_kind get_attribute_kind (char const * attr) { lean_assert(is_attribute(attr)); if (is_attribute(*g_default_attrs, attr)) return attribute_kind::Default; diff --git a/src/library/attribute_manager.h b/src/library/attribute_manager.h index a4bbbf2eb..78affbb09 100644 --- a/src/library/attribute_manager.h +++ b/src/library/attribute_manager.h @@ -47,6 +47,7 @@ bool is_attribute(char const * attr); void get_attributes(buffer &); void get_attribute_tokens(buffer &); char const * get_attribute_from_token(char const * attr_token); +char const * get_attribute_token(char const * attr); attribute_kind get_attribute_kind (char const * attr); environment set_attribute(environment const & env, io_state const & ios, char const * attr, diff --git a/tests/lean/608.hlean.expected.out b/tests/lean/608.hlean.expected.out index d28192a5d..31f30db69 100644 --- a/tests/lean/608.hlean.expected.out +++ b/tests/lean/608.hlean.expected.out @@ -1,11 +1,11 @@ -definition id [reducible] : Π {A : Type}, A → A := +definition id [reducible] [unfold_full] : Π {A : Type}, A → A := λ (A : Type) (a : A), a -definition category.id [reducible] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a := +definition category.id [reducible] [unfold 1] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a := ID ----------- -definition id [reducible] : Π {A : Type}, A → A +definition id [reducible] [unfold_full] : Π {A : Type}, A → A λ (A : Type) (a : A), a -definition category.id [reducible] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a +definition category.id [reducible] [unfold 1] : Π {ob : Type} [C : precategory ob] {a : ob}, hom a a ID diff --git a/tests/lean/backward_rule1.lean.expected.out b/tests/lean/backward_rule1.lean.expected.out index c573d6387..39e245a36 100644 --- a/tests/lean/backward_rule1.lean.expected.out +++ b/tests/lean/backward_rule1.lean.expected.out @@ -1,6 +1,6 @@ -constant H [backward] : A → B -constant G [backward] : A → B → C -constant f [backward] : T → A +constant H [intro] : A → B +constant G [intro] : A → B → C +constant f [intro] : T → A backward rules exists_unique ==> exists_unique.intro B ==> H