Once-per-file cache for tactics #
This file defines cache data structures for tactics that are initialized the first time they are accessed. Since Lean 4 starts one process per file, these caches are once-per-file and can for example be used to cache information about the imported modules.
initialize numberOfImports : Cache Nat ← Cache.mk do (← getEnv).imports.size -- (does not work in the same module where the cache is defined) #eval show MetaM Nat from numberOfImports.get
DeclCache α data structure computes
a fold over the environment's constants:
DeclCache.mk empty f constructs such a cache
empty : α and
f : Name → ConstantInfo → α → MetaM α.
The result of the constants in the imports is cached
between tactic invocations,
while for constants defined in the same file
f is evaluated again every time.
This kind of cache can be used e.g.
to populate discrimination trees.
Access the cache. Calling this function for the first time will initialize the cache with the function provided in the constructor.
- mk' :: (
- cache : Mathlib.Tactic.Cache α
The cached data.
Function for adding a declaration from the current file to the cache.
Function for adding a declaration from the library to the cache. Defaults to the same behaviour as adding a declaration from the current file.
Cached fold over the environment's declarations,
where a given function is applied to
α for every constant.
The cached structure
α is initialized with
addLibraryDecl is called for every imported constant, and the result is cached.
After all imported constants have been added, we run
get is called,
addDecl is also called for every constant in the current file.
A type synonym for a
DeclCache containing a pair of discrimination trees.
The first will store declarations in the current file,
the second will store declarations from imports (and will hopefully be "read-only" after creation).
from a function that returns a collection of keys and values for each declaration.
Get matches from both the discrimination tree for declarations in the current file, and for the imports.
Note that if you are calling this multiple times with the same environment,
it will rebuild the discrimination tree for the current file multiple times,
and it would be more efficient to call
and then call
DiscrTree.getMatch multiple times.