Returns a hash of get_instances
. You can use this to tell if your attribute instances have changed.
Configuration for a user attribute cache. For example, the simp
attribute has a cache of type simp_lemmas.
mk_cache
is a function where you are given all of the declarations tagged with your attribute and you return the new value for the cache. That is,mk_cache
makes the object you want to be cached.dependencies
is a list of other attributes whose caches need to be computed first.
Close the current goal by filling it with the trivial user_attribute_cache_cfg unit
.
- name : name
- descr : string
- after_set : option (name → ℕ → bool → tactic unit)
- before_unset : option (name → bool → tactic unit)
- cache_cfg : user_attribute_cache_cfg cache_ty . "dflt_cache_cfg"
- reflect_param : has_reflect param_ty
- parser : lean.parser param_ty . "dflt_parser"
A user attribute is an attribute defined by the user (ie, not built in to Lean).
Type parameters #
cache_ty
is the type of a cached VM object that is computed from all of the declarations in the environment tagged with this attribute.param_ty
is an argument for the attribute when it is used. For instance withparam_ty
beingℕ
you could write@[my_attribute 4]
.
Data #
A user_attribute
consists of the following pieces of data:
name
is the name of the attribute, egsimp
descr
is a plaintext description of the attribute for humans.after_set
is an optional handler that will be called after the attribute has been applied to a declaration. Failing the tactic will fail the entireattribute/def/...
command, i.e. the attribute will not be applied after all. Declaring anafter_set
handler without abefore_unset
handler will make the attribute non-removable.before_unset
Optional handler that will be called before the attribute is removed from a declaration.cache_cfg
describes how to construct the user attribute's cache. See docstring foruser_attribute_cache_cfg
reflect_param
demands thatparam_ty
can be reflected. This means we have a function fromparam_ty
to an expr. See the docstring forhas_reflect
.parser
Parser that will be invoked after parsing the attribute's name. The parse result will be reflected and stored and can be retrieved withuser_attribute.get_param
.
Registers a new user-defined attribute. The argument must be the name of a definition of type
user_attribute α β
. Once registered, you may tag declarations with this attribute.
Returns the attribute cache for the given user attribute.
Get the value of the parameter for the attribute on a given declatation. Will fail if the attribute does not exist.