diff --git a/library/init/lean/attributes.lean b/library/init/lean/attributes.lean index d6a4bfacb6..04a53a1ce5 100644 --- a/library/init/lean/attributes.lean +++ b/library/init/lean/attributes.lean @@ -167,6 +167,11 @@ do m ← attributeMapRef.get, | some attr := pure attr | none := throw (IO.userError ("unknown attribute '" ++ toString attrName ++ "'")) +@[export lean.attribute_application_time_core] +def attributeApplicationTime (n : Name) : IO AttributeApplicationTime := +do attr ← getAttributeImpl n, + pure attr.applicationTime + namespace Environment /- Add attribute `attr` to declaration `decl` with arguments `args`. If `persistent == true`, then attribute is saved on .olean file. diff --git a/src/frontends/lean/decl_attributes.cpp b/src/frontends/lean/decl_attributes.cpp index 5bd60c5eb2..8466b58d9a 100644 --- a/src/frontends/lean/decl_attributes.cpp +++ b/src/frontends/lean/decl_attributes.cpp @@ -23,6 +23,7 @@ namespace lean { // ========================================== // New attribute manager API object* is_attribute_core(object* n, object* w); +object* attribute_application_time_core(object* n, object* w); object* add_attribute_core(object* env, object* decl, object* attr, object* args, uint8 persistent, object *w); object* add_scoped_attribute_core(object* env, object* decl, object* attr, object* args, object *w); object* erase_attribute_core(object* env, object* decl, object* attr, uint8 persistent, object *w); @@ -39,6 +40,13 @@ environment add_scoped_attribute(environment const & env, name const & decl, nam environment erase_attribute(environment const & env, name const & decl, name const & attr, bool persistent) { return get_io_result(erase_attribute_core(env.to_obj_arg(), decl.to_obj_arg(), attr.to_obj_arg(), persistent, io_mk_world())); } +/* +inductive AttributeApplicationTime +| afterTypeChecking | afterCompilation +*/ +bool is_after_compilation_attribute(name const & n) { + return get_io_scalar_result(attribute_application_time_core(n.to_obj_arg(), io_mk_world())) == 1; +} // ========================================== @@ -160,7 +168,11 @@ void decl_attributes::parse_core(parser & p, bool compact) { expr e = parse_attr_arg(p, id); args = expr_to_syntax(e); } - m_new_entries = cons({id, deleted, scoped, args}, m_new_entries); + if (is_after_compilation_attribute(id)) { + m_after_comp_entries = cons({id, deleted, scoped, args}, m_after_comp_entries); + } else { + m_after_tc_entries = cons({id, deleted, scoped, args}, m_after_tc_entries); + } } else { throw parser_error(sstream() << "unknown attribute [" << id << "]", pos); } @@ -197,7 +209,11 @@ void decl_attributes::set_attribute(environment const & env, name const & attr_n } else if (is_new_attribute(attr_name)) { // Temporary Hack... ignore attr_data_ptr syntax args(box(0)); - m_new_entries = cons({attr_name, false, false, args}, m_new_entries); + if (is_after_compilation_attribute(attr_name)) { + m_after_comp_entries = cons({attr_name, false, false, args}, m_after_comp_entries); + } else { + m_after_tc_entries = cons({attr_name, false, false, args}, m_after_tc_entries); + } } else { throw exception(sstream() << "unknown attribute [" << attr_name << "]"); } @@ -214,7 +230,25 @@ attr_data_ptr decl_attributes::get_attribute(environment const & env, name const return nullptr; } -environment decl_attributes::apply(environment env, io_state const & ios, name const & d) const { +environment decl_attributes::apply_new_entries(environment env, list const & es, name const & d) const { + buffer new_entries; + to_buffer(es, new_entries); + unsigned i = new_entries.size(); + while (i > 0) { + --i; + auto const & entry = new_entries[i]; + if (entry.m_deleted) { + env = erase_attribute(env, d, entry.m_attr, m_persistent); + } else if (entry.m_scoped) { + env = add_scoped_attribute(env, d, entry.m_attr, entry.m_args); + } else { + env = add_attribute(env, d, entry.m_attr, entry.m_args, m_persistent); + } + } + return env; +} + +environment decl_attributes::apply_after_tc(environment env, io_state const & ios, name const & d) const { buffer entries; to_buffer(m_entries, entries); unsigned i = entries.size(); @@ -231,21 +265,16 @@ environment decl_attributes::apply(environment env, io_state const & ios, name c env = entry.m_attr->set_untyped(env, ios, d, prio, entry.m_params, m_persistent); } } - buffer new_entries; - to_buffer(m_new_entries, new_entries); - i = new_entries.size(); - while (i > 0) { - --i; - auto const & entry = new_entries[i]; - if (entry.m_deleted) { - env = erase_attribute(env, d, entry.m_attr, m_persistent); - } else if (entry.m_scoped) { - env = add_scoped_attribute(env, d, entry.m_attr, entry.m_args); - } else { - env = add_attribute(env, d, entry.m_attr, entry.m_args, m_persistent); - } - } - return env; + return apply_new_entries(env, m_after_tc_entries, d); +} + +environment decl_attributes::apply_after_comp(environment env, name const & d) const { + return apply_new_entries(env, m_after_comp_entries, d); +} + +environment decl_attributes::apply_all(environment env, io_state const & ios, name const & d) const { + environment new_env = apply_after_tc(env, ios, d); + return apply_after_comp(new_env, d); } bool decl_attributes::ok_for_inductive_type() const { diff --git a/src/frontends/lean/decl_attributes.h b/src/frontends/lean/decl_attributes.h index 2bf6e353e2..a2aee1d828 100644 --- a/src/frontends/lean/decl_attributes.h +++ b/src/frontends/lean/decl_attributes.h @@ -30,10 +30,12 @@ public: private: bool m_persistent; list m_entries; - list m_new_entries; + list m_after_tc_entries; + list m_after_comp_entries; void parse_core(parser & p, bool compact); expr parse_attr_arg(parser & p, name const & attr_id); syntax expr_to_syntax(expr const & e); + environment apply_new_entries(environment env, list const & es, name const & d) const; public: decl_attributes(bool persistent = true): m_persistent(persistent) {} void set_attribute(environment const & env, name const & attr_name, attr_data_ptr data = get_default_attr_data()); @@ -42,7 +44,9 @@ public: void parse(parser & p); /* Parse attributes after `@[` ... ] */ void parse_compact(parser & p); - environment apply(environment env, io_state const & ios, name const & d) const; + environment apply_after_tc(environment env, io_state const & ios, name const & d) const; + environment apply_after_comp(environment env, name const & d) const; + environment apply_all(environment env, io_state const & ios, name const & d) const; list const & get_entries() const { return m_entries; } void set_persistent(bool persistent) { m_persistent = persistent; } bool ok_for_inductive_type() const; diff --git a/src/frontends/lean/decl_cmds.cpp b/src/frontends/lean/decl_cmds.cpp index 0e7afdfe08..4bc0457ed8 100644 --- a/src/frontends/lean/decl_cmds.cpp +++ b/src/frontends/lean/decl_cmds.cpp @@ -112,7 +112,7 @@ static environment declare_var(parser & p, environment env, env = add_protected(env, full_n); env = ensure_decl_namespaces(env, full_n); /* Apply attributes last so that they may access any information on the new decl */ - env = meta.m_attrs.apply(env, p.ios(), full_n); + env = meta.m_attrs.apply_all(env, p.ios(), full_n); return env; } } @@ -489,7 +489,7 @@ static environment attribute_cmd_core(parser & p, bool persistent) { } while (p.curr_is_identifier()); environment env = p.env(); for (name const & d : ds) - env = attributes.apply(env, p.ios(), d); + env = attributes.apply_all(env, p.ios(), d); return env; } diff --git a/src/frontends/lean/definition_cmds.cpp b/src/frontends/lean/definition_cmds.cpp index 3e7dadb1df..b49cf09b98 100644 --- a/src/frontends/lean/definition_cmds.cpp +++ b/src/frontends/lean/definition_cmds.cpp @@ -263,7 +263,7 @@ static environment elab_defs_core(parser & p, decl_cmd_kind kind, cmd_meta const } /* Apply attributes last so that they may access any information on the new decl */ for (auto const & c_real_name : new_d_names) { - elab.set_env(meta.m_attrs.apply(elab.env(), p.ios(), c_real_name)); + elab.set_env(meta.m_attrs.apply_after_tc(elab.env(), p.ios(), c_real_name)); } /* Compile functions */ if (!meta.m_modifiers.m_is_noncomputable) { @@ -274,6 +274,10 @@ static environment elab_defs_core(parser & p, decl_cmd_kind kind, cmd_meta const elab.set_env(compile_decl(p, elab.env(), c_name, c_real_name, header_pos)); } } + /* Apply attributes last so that they may access any information on the new decl */ + for (auto const & c_real_name : new_d_names) { + elab.set_env(meta.m_attrs.apply_after_comp(elab.env(), c_real_name)); + } return elab.env(); } @@ -569,11 +573,12 @@ static environment elab_single_def(parser & p, decl_cmd_kind const & kind, cmd_m new_env = mk_smart_unfolding_definition(new_env, p.get_options(), c_real_name); } /* Apply attributes last so that they may access any information on the new decl */ - new_env = meta.m_attrs.apply(new_env, p.ios(), c_real_name); + new_env = meta.m_attrs.apply_after_tc(new_env, p.ios(), c_real_name); /* Compile function */ if (!meta.m_modifiers.m_is_noncomputable) { new_env = compile_decl(p, new_env, c_name, c_real_name, header_pos); } + new_env = meta.m_attrs.apply_after_comp(new_env, c_real_name); return new_env; }; diff --git a/src/frontends/lean/inductive_cmds.cpp b/src/frontends/lean/inductive_cmds.cpp index 21d4544f51..af7167bdf3 100644 --- a/src/frontends/lean/inductive_cmds.cpp +++ b/src/frontends/lean/inductive_cmds.cpp @@ -675,11 +675,11 @@ public: add_namespaces(new_inds); for (expr const & ind : new_inds) { /* Apply attributes last so that they may access any information on the new decl */ - m_env = m_meta_info.m_attrs.apply(m_env, m_p.ios(), local_name_p(ind)); + m_env = m_meta_info.m_attrs.apply_all(m_env, m_p.ios(), local_name_p(ind)); } lean_assert(new_inds.size() == m_mut_attrs.size()); for (unsigned i = 0; i < new_inds.size(); ++i) - m_env = m_mut_attrs[i].apply(m_env, m_p.ios(), local_name_p(new_inds[i])); + m_env = m_mut_attrs[i].apply_all(m_env, m_p.ios(), local_name_p(new_inds[i])); } struct parse_result { diff --git a/src/frontends/lean/lean_elaborator.cpp b/src/frontends/lean/lean_elaborator.cpp index 67b9f2fe1d..234754551e 100644 --- a/src/frontends/lean/lean_elaborator.cpp +++ b/src/frontends/lean/lean_elaborator.cpp @@ -172,7 +172,7 @@ environment elab_attribute_cmd(environment env, expr const & cmd) { auto attributes = to_decl_attributes(env, app_fn(e), local); buffer eids; get_app_args(app_arg(e), eids); for (auto const & e : eids) - env = attributes.apply(env, get_dummy_ios(), const_name(e)); + env = attributes.apply_all(env, get_dummy_ios(), const_name(e)); return env; } diff --git a/src/frontends/lean/structure_cmd.cpp b/src/frontends/lean/structure_cmd.cpp index 293a129e07..d4af645639 100644 --- a/src/frontends/lean/structure_cmd.cpp +++ b/src/frontends/lean/structure_cmd.cpp @@ -1283,7 +1283,7 @@ struct structure_cmd_fn { declare_no_confusion(); } /* Apply attributes last so that they may access any information on the new decl */ - m_env = m_meta_info.m_attrs.apply(m_env, m_p.ios(), m_name); + m_env = m_meta_info.m_attrs.apply_all(m_env, m_p.ios(), m_name); } environment operator()() { diff --git a/src/stage0/init/lean/attributes.cpp b/src/stage0/init/lean/attributes.cpp index 76d3fe7951..b8a042b222 100644 --- a/src/stage0/init/lean/attributes.cpp +++ b/src/stage0/init/lean/attributes.cpp @@ -14,8 +14,8 @@ typedef lean::uint32 uint32; typedef lean::uint64 uint64; #pragma GCC diagnostic ignored "-Wunused-label" #pragma GCC diagnostic ignored "-Wunused-but-set-variable" #endif +obj* l_Lean_getAttributeImpl___closed__1; obj* l_Lean_registerTagAttribute___lambda__6___closed__2; -obj* l_AssocList_mfoldl___main___at_Lean_Environment_getAttributeNames___spec__1(obj*, obj*); obj* l_Lean_attributeArrayRef; obj* l_Lean_ParametricAttribute_getParam(obj*); extern "C" uint8 lean_name_dec_eq(obj*, obj*); @@ -39,9 +39,13 @@ obj* l_List_foldl___main___at_Lean_Environment_toValidNamespace___spec__1___boxe obj* l_HashMapImp_expand___at_Lean_registerAttribute___spec__4(obj*, obj*); obj* l_Lean_registerParametricAttribute___rarg(obj*, obj*, obj*, obj*, obj*); obj* l_Lean_AttributeImpl_inhabited___lambda__3___boxed(obj*, obj*, obj*, obj*); +obj* l_Array_miterateAux___main___at_Lean_getAttributeNames___spec__2(obj*, obj*, obj*, obj*); namespace lean { obj* activate_scoped_attributes_core(obj*, obj*, obj*); } +namespace lean { +obj* attribute_application_time_core(obj*, obj*); +} obj* l_Lean_registerTagAttribute___lambda__5___closed__1; obj* l_Lean_Environment_popScopeCore___lambda__1(obj*); obj* l_Lean_scopeManagerExt___elambda__1(obj*); @@ -51,7 +55,6 @@ uint8 has_open_scopes_core(obj*); } uint8 l_HashMapImp_contains___at_Lean_registerAttribute___spec__1(obj*, obj*); obj* l_Lean_Environment_popScopeCore___closed__1; -obj* l_Lean_Environment_getAttributeNames(obj*); obj* l_Lean_registerAttribute(obj*, obj*); obj* l_Lean_Environment_pushScopeCore___lambda__1(obj*, obj*, uint8, obj*); obj* l_HashMapImp_contains___at_Lean_registerAttribute___spec__1___boxed(obj*, obj*); @@ -65,17 +68,14 @@ namespace lean { obj* get_namespaces_core(obj*); } uint8 l_List_isEmpty___main___rarg(obj*); -obj* l_HashMapImp_find___at_Lean_Environment_getAttributeImpl___spec__1(obj*, obj*); obj* l_RBNode_fold___main___at_Lean_registerParametricAttribute___spec__1___rarg___boxed(obj*, obj*); obj* l_HashMapImp_insert___at_Lean_registerAttribute___spec__3(obj*, obj*, obj*); -obj* l_Lean_Environment_getAttributeImpl___boxed(obj*); obj* l_RBNode_fold___main___at_Lean_registerParametricAttribute___spec__1(obj*); namespace lean { obj* get_scope_header_core(obj*); } obj* l_Lean_registerTagAttribute___lambda__1(obj*); obj* l_List_toArrayAux___main___rarg(obj*, obj*); -obj* l_AssocList_find___main___at_Lean_Environment_getAttributeImpl___spec__2(obj*, obj*); obj* l_Array_uget(obj*, obj*, usize, obj*); obj* l_Lean_Name_toStringWithSep___main(obj*, obj*); obj* l_Lean_SimplePersistentEnvExtension_getState___rarg(obj*, obj*); @@ -98,7 +98,6 @@ obj* l_RBNode_fold___main___at_RBMap_size___spec__1___rarg(obj*, obj*); obj* l___private_init_data_array_qsort_1__partitionAux___main___at_Lean_registerParametricAttribute___spec__6(obj*); extern "C" obj* lean_io_initializing(obj*); obj* l_Array_binSearchAux___main___at_Lean_ParametricAttribute_getParam___spec__2(obj*); -obj* l_Lean_Environment_getAttributeImpl(obj*); obj* l_Lean_registerTagAttribute___lambda__4(obj*); obj* l___private_init_data_array_qsort_1__partitionAux___main___at_Lean_registerParametricAttribute___spec__4___rarg(obj*, obj*, obj*, obj*, obj*, obj*); obj* l_Lean_registerTagAttribute___lambda__7___closed__1; @@ -142,6 +141,7 @@ obj* l_Lean_Environment_pushScope___boxed(obj*, obj*, obj*, obj*); obj* l_Lean_PersistentEnvExtension_getState___rarg(obj*, obj*); obj* l_Array_miterateAux___main___at_Lean_regScopeManagerExtension___spec__3(obj*, obj*, obj*, obj*); obj* l_Lean_Environment_getModuleIdxFor(obj*, obj*); +obj* l_AssocList_mfoldl___main___at_Lean_getAttributeNames___spec__1___boxed(obj*, obj*); obj* l_Lean_scopeManagerExt___elambda__3___boxed(obj*, obj*); obj* l_RBNode_find___main___at_Lean_ParametricAttribute_setParam___spec__1___rarg___boxed(obj*, obj*); obj* l_Lean_registerTagAttribute___lambda__4___closed__1; @@ -159,7 +159,6 @@ uint8 nat_dec_lt(obj*, obj*); obj* l___private_init_data_array_qsort_1__partitionAux___main___at_Lean_registerParametricAttribute___spec__6___rarg(obj*, obj*, obj*, obj*, obj*, obj*); obj* l_Array_binSearchAux___main___at_Lean_ParametricAttribute_getParam___spec__2___rarg(obj*, obj*, obj*, obj*, obj*); obj* l_mkHashMap___at_Lean_mkAttributeMapRef___spec__1(obj*); -obj* l_AssocList_find___main___at_Lean_Environment_getAttributeImpl___spec__2___boxed(obj*, obj*); obj* l_Lean_registerTagAttribute___closed__6; extern obj* l_Char_HasRepr___closed__1; obj* l_Lean_ParametricAttribute_Inhabited___closed__1; @@ -175,10 +174,10 @@ obj* l_Lean_registerSimplePersistentEnvExtension___rarg(obj*, obj*); obj* l_Lean_Environment_addAttribute___boxed(obj*, obj*, obj*, obj*, obj*, obj*); uint8 l_AssocList_contains___main___at_Lean_registerAttribute___spec__2(obj*, obj*); obj* l_RBNode_find___main___at_Lean_ParametricAttribute_setParam___spec__1(obj*); -obj* l_Lean_Environment_getAttributeNames___rarg(obj*); namespace lean { obj* nat_add(obj*, obj*); } +obj* l_HashMapImp_find___at_Lean_getAttributeImpl___spec__1___boxed(obj*, obj*); namespace lean { obj* add_attribute_core(obj*, obj*, obj*, obj*, uint8, obj*); } @@ -199,8 +198,8 @@ obj* l_Lean_registerTagAttribute___lambda__3(obj*); obj* l_ExceptT_Monad___rarg___lambda__8___boxed(obj*, obj*); obj* l_Array_push(obj*, obj*, obj*); obj* l_Lean_TagAttribute_Inhabited; +obj* l_AssocList_find___main___at_Lean_getAttributeImpl___spec__2___boxed(obj*, obj*); obj* l_Array_miterateAux___main___at_Lean_Environment_popScope___spec__1___boxed(obj*, obj*, obj*, obj*, obj*); -obj* l_AssocList_mfoldl___main___at_Lean_Environment_getAttributeNames___spec__1___boxed(obj*, obj*); obj* l_RBNode_find___main___at_Lean_ParametricAttribute_getParam___spec__1(obj*); obj* l_Lean_registerAttribute___closed__1; obj* l___private_init_data_array_qsort_1__partitionAux___main___at_Lean_registerParametricAttribute___spec__5___rarg___boxed(obj*, obj*, obj*, obj*, obj*, obj*); @@ -212,7 +211,6 @@ obj* register_namespace_core(obj*, obj*); } obj* l_Lean_regScopeManagerExtension___lambda__2(obj*); obj* l_IO_Prim_mkRef(obj*, obj*, obj*); -obj* l_Lean_Environment_getAttributeImpl___rarg___closed__1; uint8 l_Lean_TagAttribute_hasTag(obj*, obj*, obj*); obj* l_Lean_scopeManagerExt___elambda__2___boxed(obj*); uint8 l_Array_binSearchAux___main___at_Lean_TagAttribute_hasTag___spec__1(obj*, obj*, obj*, obj*); @@ -220,11 +218,12 @@ obj* l_Lean_registerTagAttribute___lambda__5___closed__2; obj* l_Lean_registerParametricAttribute___rarg___lambda__4___boxed(obj*, obj*, obj*, obj*, obj*, obj*, obj*, obj*); obj* l___private_init_data_array_qsort_1__partitionAux___main___at_Lean_registerParametricAttribute___spec__4___rarg___boxed(obj*, obj*, obj*, obj*, obj*, obj*); obj* l_Array_miterateAux___main___at_Lean_Environment_activateScopedAttributes___spec__1(obj*, obj*, obj*, obj*, obj*, obj*); -obj* l_Lean_Environment_getAttributeNames___boxed(obj*); +obj* l_AssocList_find___main___at_Lean_getAttributeImpl___spec__2(obj*, obj*); obj* l_Array_qsortAux___main___at_Lean_registerParametricAttribute___spec__2___rarg___boxed(obj*, obj*, obj*, obj*); obj* l_Lean_scopeManagerExt___elambda__4___boxed(obj*, obj*, obj*); obj* l_List_foldl___main___at_Lean_Environment_toValidNamespace___spec__1(obj*, obj*, obj*, obj*); obj* l_Lean_ScopeManagerState_saveNamespace(obj*, obj*); +obj* l_Lean_getAttributeNames(obj*); obj* l_Array_qsortAux___main___at_Lean_registerTagAttribute___spec__2(obj*, obj*, obj*); obj* l_Lean_regScopeManagerExtension___closed__1; obj* l_HashMapImp_moveEntries___main___at_Lean_registerAttribute___spec__5(obj*, obj*, obj*); @@ -237,7 +236,6 @@ obj* l_Lean_registerTagAttribute___lambda__7___boxed(obj*, obj*, obj*, obj*, obj obj* l_Lean_PersistentEnvExtension_addEntry___rarg(obj*, obj*, obj*); obj* l_IO_Prim_Ref_get(obj*, obj*, obj*); uint8 l_Lean_Name_quickLt(obj*, obj*); -obj* l_HashMapImp_find___at_Lean_Environment_getAttributeImpl___spec__1___boxed(obj*, obj*); namespace lean { usize usize_modn(usize, obj*); } @@ -246,6 +244,7 @@ obj* l___private_init_data_array_qsort_1__partitionAux___main___at_Lean_register obj* l_Lean_ParametricAttribute_setParam___rarg___closed__2; obj* l_Lean_registerParametricAttribute___rarg___lambda__2(obj*, obj*); obj* l_Lean_scopeManagerExt___elambda__3(obj*, obj*); +obj* l_AssocList_mfoldl___main___at_Lean_getAttributeNames___spec__1(obj*, obj*); obj* l_Lean_scopeManagerExt___elambda__1___boxed(obj*); obj* l_Array_miterateAux___main___at_Lean_Environment_pushScope___spec__1___boxed(obj*, obj*, obj*, obj*, obj*, obj*, obj*); obj* l_Lean_registerTagAttribute___lambda__6(obj*, obj*, obj*, obj*, obj*); @@ -263,7 +262,6 @@ obj* l_AssocList_contains___main___at_Lean_registerAttribute___spec__2___boxed(o obj* l_Lean_AttributeImpl_inhabited___lambda__2(obj*, obj*, obj*, obj*); obj* l_Lean_registerTagAttribute___lambda__5___closed__3; obj* l_List_tail___main___rarg(obj*); -obj* l_Lean_Environment_getAttributeImpl___rarg(obj*, obj*); obj* l_Lean_AttributeImpl_inhabited___lambda__1(obj*, obj*, obj*, uint8, obj*); obj* l_Lean_registerTagAttribute___closed__5; extern obj* l_Lean_Name_toString___closed__1; @@ -287,16 +285,17 @@ uint8 in_section_core(obj*); obj* l_Lean_AttributeImpl_inhabited___lambda__2___boxed(obj*, obj*, obj*, obj*); obj* l_Lean_ParametricAttribute_getParam___rarg(obj*, obj*, obj*, obj*); obj* l_RBNode_find___main___at_Lean_ParametricAttribute_setParam___spec__1___rarg(obj*, obj*); +obj* l_Array_miterateAux___main___at_Lean_getAttributeNames___spec__2___boxed(obj*, obj*, obj*, obj*); obj* l_Lean_Environment_pushScopeCore(obj*, obj*, uint8); obj* l_AssocList_replace___main___at_Lean_registerAttribute___spec__7(obj*, obj*, obj*); obj* l_Lean_Environment_isNamespace___boxed(obj*, obj*); -obj* l_Array_miterateAux___main___at_Lean_Environment_getAttributeNames___spec__2___boxed(obj*, obj*, obj*, obj*); obj* l_Lean_registerPersistentEnvExtensionUnsafe___rarg(obj*, obj*); obj* l_RBNode_fold___main___at_Lean_registerTagAttribute___spec__1(obj*, obj*); obj* l_Lean_attributeMapRef; obj* l___private_init_data_array_qsort_1__partitionAux___main___at_Lean_registerTagAttribute___spec__3(obj*, obj*, obj*, obj*, obj*); obj* l_Lean_Environment_hasOpenScopes___boxed(obj*); obj* l_Lean_AttributeImpl_inhabited___lambda__3(obj*, obj*, uint8, obj*); +obj* l_HashMapImp_find___at_Lean_getAttributeImpl___spec__1(obj*, obj*); namespace lean { obj* pop_scope_core(obj*, obj*); } @@ -311,12 +310,12 @@ namespace lean { obj* to_valid_namespace_core(obj*, obj*); } obj* l_IO_Prim_Ref_reset(obj*, obj*, obj*); +obj* l_Lean_getAttributeImpl(obj*, obj*); obj* l_Lean_scopeManagerExt___elambda__4(obj*, obj*, obj*); obj* l_Lean_TagAttribute_hasTag___boxed(obj*, obj*, obj*); obj* l_Lean_Environment_eraseAttribute___boxed(obj*, obj*, obj*, obj*, obj*); obj* l_Lean_AttributeImpl_inhabited; obj* l_Lean_regScopeManagerExtension___lambda__3(obj*); -obj* l_Array_miterateAux___main___at_Lean_Environment_getAttributeNames___spec__2(obj*, obj*, obj*, obj*); obj* l_Lean_registerTagAttribute___lambda__6___boxed(obj*, obj*, obj*, obj*, obj*); obj* _init_l_Lean_ScopeManagerState_Inhabited() { _start: @@ -3412,7 +3411,7 @@ return x_17; } } } -obj* l_AssocList_mfoldl___main___at_Lean_Environment_getAttributeNames___spec__1(obj* x_1, obj* x_2) { +obj* l_AssocList_mfoldl___main___at_Lean_getAttributeNames___spec__1(obj* x_1, obj* x_2) { _start: { if (lean::obj_tag(x_2) == 0) @@ -3434,7 +3433,7 @@ goto _start; } } } -obj* l_Array_miterateAux___main___at_Lean_Environment_getAttributeNames___spec__2(obj* x_1, obj* x_2, obj* x_3, obj* x_4) { +obj* l_Array_miterateAux___main___at_Lean_getAttributeNames___spec__2(obj* x_1, obj* x_2, obj* x_3, obj* x_4) { _start: { obj* x_5; uint8 x_6; @@ -3450,7 +3449,7 @@ else { obj* x_7; obj* x_8; obj* x_9; obj* x_10; x_7 = lean::array_fget(x_2, x_3); -x_8 = l_AssocList_mfoldl___main___at_Lean_Environment_getAttributeNames___spec__1(x_4, x_7); +x_8 = l_AssocList_mfoldl___main___at_Lean_getAttributeNames___spec__1(x_4, x_7); lean::dec(x_7); x_9 = lean::mk_nat_obj(1u); x_10 = lean::nat_add(x_3, x_9); @@ -3461,7 +3460,7 @@ goto _start; } } } -obj* l_Lean_Environment_getAttributeNames___rarg(obj* x_1) { +obj* l_Lean_getAttributeNames(obj* x_1) { _start: { obj* x_2; obj* x_3; @@ -3479,7 +3478,7 @@ x_6 = lean::box(0); x_7 = lean::cnstr_get(x_5, 1); lean::inc(x_7); x_8 = lean::mk_nat_obj(0u); -x_9 = l_Array_miterateAux___main___at_Lean_Environment_getAttributeNames___spec__2(x_5, x_7, x_8, x_6); +x_9 = l_Array_miterateAux___main___at_Lean_getAttributeNames___spec__2(x_5, x_7, x_8, x_6); lean::dec(x_7); lean::dec(x_5); lean::cnstr_set(x_3, 0, x_9); @@ -3497,7 +3496,7 @@ x_12 = lean::box(0); x_13 = lean::cnstr_get(x_10, 1); lean::inc(x_13); x_14 = lean::mk_nat_obj(0u); -x_15 = l_Array_miterateAux___main___at_Lean_Environment_getAttributeNames___spec__2(x_10, x_13, x_14, x_12); +x_15 = l_Array_miterateAux___main___at_Lean_getAttributeNames___spec__2(x_10, x_13, x_14, x_12); lean::dec(x_13); lean::dec(x_10); x_16 = lean::alloc_cnstr(0, 2, 0); @@ -3530,43 +3529,26 @@ return x_20; } } } -obj* l_Lean_Environment_getAttributeNames(obj* x_1) { -_start: -{ -obj* x_2; -x_2 = lean::alloc_closure(reinterpret_cast(l_Lean_Environment_getAttributeNames___rarg), 1, 0); -return x_2; -} -} -obj* l_AssocList_mfoldl___main___at_Lean_Environment_getAttributeNames___spec__1___boxed(obj* x_1, obj* x_2) { +obj* l_AssocList_mfoldl___main___at_Lean_getAttributeNames___spec__1___boxed(obj* x_1, obj* x_2) { _start: { obj* x_3; -x_3 = l_AssocList_mfoldl___main___at_Lean_Environment_getAttributeNames___spec__1(x_1, x_2); +x_3 = l_AssocList_mfoldl___main___at_Lean_getAttributeNames___spec__1(x_1, x_2); lean::dec(x_2); return x_3; } } -obj* l_Array_miterateAux___main___at_Lean_Environment_getAttributeNames___spec__2___boxed(obj* x_1, obj* x_2, obj* x_3, obj* x_4) { +obj* l_Array_miterateAux___main___at_Lean_getAttributeNames___spec__2___boxed(obj* x_1, obj* x_2, obj* x_3, obj* x_4) { _start: { obj* x_5; -x_5 = l_Array_miterateAux___main___at_Lean_Environment_getAttributeNames___spec__2(x_1, x_2, x_3, x_4); +x_5 = l_Array_miterateAux___main___at_Lean_getAttributeNames___spec__2(x_1, x_2, x_3, x_4); lean::dec(x_2); lean::dec(x_1); return x_5; } } -obj* l_Lean_Environment_getAttributeNames___boxed(obj* x_1) { -_start: -{ -obj* x_2; -x_2 = l_Lean_Environment_getAttributeNames(x_1); -lean::dec(x_1); -return x_2; -} -} -obj* l_AssocList_find___main___at_Lean_Environment_getAttributeImpl___spec__2(obj* x_1, obj* x_2) { +obj* l_AssocList_find___main___at_Lean_getAttributeImpl___spec__2(obj* x_1, obj* x_2) { _start: { if (lean::obj_tag(x_2) == 0) @@ -3598,7 +3580,7 @@ return x_9; } } } -obj* l_HashMapImp_find___at_Lean_Environment_getAttributeImpl___spec__1(obj* x_1, obj* x_2) { +obj* l_HashMapImp_find___at_Lean_getAttributeImpl___spec__1(obj* x_1, obj* x_2) { _start: { obj* x_3; obj* x_4; usize x_5; usize x_6; obj* x_7; usize x_8; obj* x_9; obj* x_10; @@ -3611,12 +3593,12 @@ x_7 = lean::box_size_t(x_6); x_8 = lean::unbox_size_t(x_7); lean::dec(x_7); x_9 = lean::array_uget(x_3, x_8); -x_10 = l_AssocList_find___main___at_Lean_Environment_getAttributeImpl___spec__2(x_2, x_9); +x_10 = l_AssocList_find___main___at_Lean_getAttributeImpl___spec__2(x_2, x_9); lean::dec(x_9); return x_10; } } -obj* _init_l_Lean_Environment_getAttributeImpl___rarg___closed__1() { +obj* _init_l_Lean_getAttributeImpl___closed__1() { _start: { obj* x_1; @@ -3624,7 +3606,7 @@ x_1 = lean::mk_string("unknown attribute '"); return x_1; } } -obj* l_Lean_Environment_getAttributeImpl___rarg(obj* x_1, obj* x_2) { +obj* l_Lean_getAttributeImpl(obj* x_1, obj* x_2) { _start: { obj* x_3; obj* x_4; @@ -3638,14 +3620,14 @@ if (x_5 == 0) { obj* x_6; obj* x_7; x_6 = lean::cnstr_get(x_4, 0); -x_7 = l_HashMapImp_find___at_Lean_Environment_getAttributeImpl___spec__1(x_6, x_1); +x_7 = l_HashMapImp_find___at_Lean_getAttributeImpl___spec__1(x_6, x_1); lean::dec(x_6); if (lean::obj_tag(x_7) == 0) { obj* x_8; obj* x_9; obj* x_10; obj* x_11; obj* x_12; obj* x_13; x_8 = l_Lean_Name_toString___closed__1; x_9 = l_Lean_Name_toStringWithSep___main(x_8, x_1); -x_10 = l_Lean_Environment_getAttributeImpl___rarg___closed__1; +x_10 = l_Lean_getAttributeImpl___closed__1; x_11 = lean::string_append(x_10, x_9); lean::dec(x_9); x_12 = l_Char_HasRepr___closed__1; @@ -3673,14 +3655,14 @@ x_16 = lean::cnstr_get(x_4, 1); lean::inc(x_16); lean::inc(x_15); lean::dec(x_4); -x_17 = l_HashMapImp_find___at_Lean_Environment_getAttributeImpl___spec__1(x_15, x_1); +x_17 = l_HashMapImp_find___at_Lean_getAttributeImpl___spec__1(x_15, x_1); lean::dec(x_15); if (lean::obj_tag(x_17) == 0) { obj* x_18; obj* x_19; obj* x_20; obj* x_21; obj* x_22; obj* x_23; obj* x_24; x_18 = l_Lean_Name_toString___closed__1; x_19 = l_Lean_Name_toStringWithSep___main(x_18, x_1); -x_20 = l_Lean_Environment_getAttributeImpl___rarg___closed__1; +x_20 = l_Lean_getAttributeImpl___closed__1; x_21 = lean::string_append(x_20, x_19); lean::dec(x_19); x_22 = l_Char_HasRepr___closed__1; @@ -3729,41 +3711,86 @@ return x_30; } } } -obj* l_Lean_Environment_getAttributeImpl(obj* x_1) { -_start: -{ -obj* x_2; -x_2 = lean::alloc_closure(reinterpret_cast(l_Lean_Environment_getAttributeImpl___rarg), 2, 0); -return x_2; -} -} -obj* l_AssocList_find___main___at_Lean_Environment_getAttributeImpl___spec__2___boxed(obj* x_1, obj* x_2) { +obj* l_AssocList_find___main___at_Lean_getAttributeImpl___spec__2___boxed(obj* x_1, obj* x_2) { _start: { obj* x_3; -x_3 = l_AssocList_find___main___at_Lean_Environment_getAttributeImpl___spec__2(x_1, x_2); +x_3 = l_AssocList_find___main___at_Lean_getAttributeImpl___spec__2(x_1, x_2); lean::dec(x_2); lean::dec(x_1); return x_3; } } -obj* l_HashMapImp_find___at_Lean_Environment_getAttributeImpl___spec__1___boxed(obj* x_1, obj* x_2) { +obj* l_HashMapImp_find___at_Lean_getAttributeImpl___spec__1___boxed(obj* x_1, obj* x_2) { _start: { obj* x_3; -x_3 = l_HashMapImp_find___at_Lean_Environment_getAttributeImpl___spec__1(x_1, x_2); +x_3 = l_HashMapImp_find___at_Lean_getAttributeImpl___spec__1(x_1, x_2); lean::dec(x_2); lean::dec(x_1); return x_3; } } -obj* l_Lean_Environment_getAttributeImpl___boxed(obj* x_1) { +namespace lean { +obj* attribute_application_time_core(obj* x_1, obj* x_2) { _start: { -obj* x_2; -x_2 = l_Lean_Environment_getAttributeImpl(x_1); -lean::dec(x_1); -return x_2; +obj* x_3; +x_3 = l_Lean_getAttributeImpl(x_1, x_2); +if (lean::obj_tag(x_3) == 0) +{ +uint8 x_4; +x_4 = !lean::is_exclusive(x_3); +if (x_4 == 0) +{ +obj* x_5; uint8 x_6; obj* x_7; +x_5 = lean::cnstr_get(x_3, 0); +x_6 = lean::cnstr_get_scalar(x_5, sizeof(void*)*8); +lean::dec(x_5); +x_7 = lean::box(x_6); +lean::cnstr_set(x_3, 0, x_7); +return x_3; +} +else +{ +obj* x_8; obj* x_9; uint8 x_10; obj* x_11; obj* x_12; +x_8 = lean::cnstr_get(x_3, 0); +x_9 = lean::cnstr_get(x_3, 1); +lean::inc(x_9); +lean::inc(x_8); +lean::dec(x_3); +x_10 = lean::cnstr_get_scalar(x_8, sizeof(void*)*8); +lean::dec(x_8); +x_11 = lean::box(x_10); +x_12 = lean::alloc_cnstr(0, 2, 0); +lean::cnstr_set(x_12, 0, x_11); +lean::cnstr_set(x_12, 1, x_9); +return x_12; +} +} +else +{ +uint8 x_13; +x_13 = !lean::is_exclusive(x_3); +if (x_13 == 0) +{ +return x_3; +} +else +{ +obj* x_14; obj* x_15; obj* x_16; +x_14 = lean::cnstr_get(x_3, 0); +x_15 = lean::cnstr_get(x_3, 1); +lean::inc(x_15); +lean::inc(x_14); +lean::dec(x_3); +x_16 = lean::alloc_cnstr(1, 2, 0); +lean::cnstr_set(x_16, 0, x_14); +lean::cnstr_set(x_16, 1, x_15); +return x_16; +} +} +} } } namespace lean { @@ -3771,7 +3798,7 @@ obj* add_attribute_core(obj* x_1, obj* x_2, obj* x_3, obj* x_4, uint8 x_5, obj* _start: { obj* x_7; -x_7 = l_Lean_Environment_getAttributeImpl___rarg(x_3, x_6); +x_7 = l_Lean_getAttributeImpl(x_3, x_6); if (lean::obj_tag(x_7) == 0) { uint8 x_8; @@ -3852,7 +3879,7 @@ obj* add_scoped_attribute_core(obj* x_1, obj* x_2, obj* x_3, obj* x_4, obj* x_5) _start: { obj* x_6; -x_6 = l_Lean_Environment_getAttributeImpl___rarg(x_3, x_5); +x_6 = l_Lean_getAttributeImpl(x_3, x_5); if (lean::obj_tag(x_6) == 0) { uint8 x_7; @@ -3921,7 +3948,7 @@ obj* erase_attribute_core(obj* x_1, obj* x_2, obj* x_3, uint8 x_4, obj* x_5) { _start: { obj* x_6; -x_6 = l_Lean_Environment_getAttributeImpl___rarg(x_3, x_5); +x_6 = l_Lean_getAttributeImpl(x_3, x_5); if (lean::obj_tag(x_6) == 0) { uint8 x_7; @@ -4001,7 +4028,7 @@ obj* activate_scoped_attribute_core(obj* x_1, obj* x_2, obj* x_3, obj* x_4) { _start: { obj* x_5; -x_5 = l_Lean_Environment_getAttributeImpl___rarg(x_2, x_4); +x_5 = l_Lean_getAttributeImpl(x_2, x_4); if (lean::obj_tag(x_5) == 0) { uint8 x_6; @@ -7642,10 +7669,11 @@ l_Lean_registerAttribute___closed__2 = _init_l_Lean_registerAttribute___closed__ lean::mark_persistent(l_Lean_registerAttribute___closed__2); REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name("Lean"), "registerAttribute"), 2, l_Lean_registerAttribute); REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name("Lean"), "isAttribute"), 2, lean::is_attribute_core); -REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name(lean::mk_const_name("Lean"), "Environment"), "getAttributeNames"), 1, l_Lean_Environment_getAttributeNames___boxed); -l_Lean_Environment_getAttributeImpl___rarg___closed__1 = _init_l_Lean_Environment_getAttributeImpl___rarg___closed__1(); -lean::mark_persistent(l_Lean_Environment_getAttributeImpl___rarg___closed__1); -REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name(lean::mk_const_name("Lean"), "Environment"), "getAttributeImpl"), 1, l_Lean_Environment_getAttributeImpl___boxed); +REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name("Lean"), "getAttributeNames"), 1, l_Lean_getAttributeNames); +l_Lean_getAttributeImpl___closed__1 = _init_l_Lean_getAttributeImpl___closed__1(); +lean::mark_persistent(l_Lean_getAttributeImpl___closed__1); +REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name("Lean"), "getAttributeImpl"), 2, l_Lean_getAttributeImpl); +REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name("Lean"), "attributeApplicationTime"), 2, lean::attribute_application_time_core); REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name(lean::mk_const_name("Lean"), "Environment"), "addAttribute"), 6, l_Lean_Environment_addAttribute___boxed); REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name(lean::mk_const_name("Lean"), "Environment"), "addScopedAttribute"), 5, lean::add_scoped_attribute_core); REGISTER_LEAN_FUNCTION(lean::mk_const_name(lean::mk_const_name(lean::mk_const_name("Lean"), "Environment"), "eraseAttribute"), 5, l_Lean_Environment_eraseAttribute___boxed);