Lazy Discrimination Tree #
This file defines a new type of discrimination tree optimized for rapid population of imported modules for use in tactics. It uses a lazy initialization strategy.
The discrimination tree can be created through
createImportedDiscrTree
. This creates a discrimination tree from all
public imported modules in an environment using a callback that provides the
entries as InitEntry
values.
The function getMatch
can be used to get the values that match the
expression as well as an updated lazy discrimination tree that has
elaborated additional parts of the tree.
Equations
Equations
Equations
Hash function
Equations
- (Lean.Meta.LazyDiscrTree.Key.const a a_1).hash = mixHash 5237 (mixHash a.hash (hash a_1))
- (Lean.Meta.LazyDiscrTree.Key.fvar a a_1).hash = mixHash 3541 (mixHash (hash a) (hash a_1))
- (Lean.Meta.LazyDiscrTree.Key.lit a).hash = mixHash 1879 (hash a)
- Lean.Meta.LazyDiscrTree.Key.star.hash = 7883
- Lean.Meta.LazyDiscrTree.Key.other.hash = 2411
- Lean.Meta.LazyDiscrTree.Key.arrow.hash = 17
- (Lean.Meta.LazyDiscrTree.Key.proj a a_1 a_2).hash = mixHash (hash a_2) (mixHash (hash a) (hash a_1))
Instances For
Equations
Equations
- Lean.Meta.LazyDiscrTree.MatchClone.tmpMVarId = { name := `_discr_tree_tmp }
Instances For
Returns true iff the argument should be treated as a "wildcard" by the discrimination tree.
This includes proofs, instance implicit arguments, implicit arguments,
and terms of the form noIndexing t
This is a clone of Lean.Meta.DiscrTree.ignoreArg
and mainly added to
avoid coupling between DiscrTree
and LazyDiscrTree
while both are
potentially subject to independent changes.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns true
if e
is one of the following
- A nat literal (numeral)
Nat.zero
Nat.succ x
whereisNumeral x
OfNat.ofNat _ x _
whereisNumeral x
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.LazyDiscrTree.MatchClone.isNatType e = do let __do_lift ← Lean.Meta.whnf e pure (__do_lift.isConstOf `Nat)
Instances For
Equations
Instances For
Eliminate loose bound variables via beta-reduction.
This is primarily used to reduce pi-terms ∀(x : P), T
into
non-dependent functions P → T
. The latter has a more specific
discrimination tree key .arrow..
and this improves the accuracy of the
discrimination tree.
Clone of Lean.Meta.DiscrTree.elimLooseBVarsByBeta
. See it for more
discussion.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
An unprocessed entry in the lazy discrimination tree.
Equations
Instances For
Index identifying trie in a discrimination tree.
Equations
Instances For
Discrimination tree trie. See LazyDiscrTree
.
- node :: (
- values : Array α
Values for matches ending at this trie.
- star : TrieIndex
Index of trie matching star.
- children : Std.HashMap Key TrieIndex
Following matches based on key of trie.
Lazy entries at this trie that are not processed.
- )
Instances For
LazyDiscrTree
is a variant of the discriminator tree datatype
DiscrTree
in Lean core that is designed to be efficiently
initializable with a large number of patterns. This is useful
in contexts such as searching an entire Lean environment for
expressions that match a pattern.
Lazy discriminator trees achieve good performance by minimizing the amount of work that is done up front to build the discriminator tree. When first adding patterns to the tree, only the root discriminator key is computed and processing the remaining terms is deferred until demanded by a match.
Backing array of trie entries. Should be owned by this trie.
- roots : Std.HashMap Key TrieIndex
Map from discriminator trie roots to the index.
Instances For
Initial capacity for key and todo vector.
Equations
Instances For
Get the root key and rest of terms of an expression using the specified config.
Equations
Instances For
Create a key path from an expression using the function used for patterns.
This differs from Lean.Meta.DiscrTree.mkPath and targetPath in that the expression should uses free variables rather than meta-variables for holes.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
Instances For
Equations
- Lean.Meta.LazyDiscrTree.setTrie i v = modify fun (x : Array (Lean.Meta.LazyDiscrTree.Trie α)) => x.set! i v
Instances For
Add a lazy entry to an existing trie.
Equations
- Lean.Meta.LazyDiscrTree.addLazyEntryToTrie i e = modify fun (x : Array (Lean.Meta.LazyDiscrTree.Trie α)) => x.modify i fun (x : Lean.Meta.LazyDiscrTree.Trie α) => x.pushPending e
Instances For
This evaluates all lazy entries in a trie and updates values
, starIdx
, and children
accordingly.
Equations
- Lean.Meta.LazyDiscrTree.evalLazyEntries values starIdx children entries = Array.foldlM Lean.Meta.LazyDiscrTree.evalLazyEntry (values, starIdx, children) entries
Instances For
This drops a specific key from the lazy discrimination tree so that all the entries matching that key exactly are removed.
Equations
Instances For
A match result contains the terms formed from matching a term against patterns in the discrimination tree.
The elements in the match result.
The top-level array represents an array from
score
values to the results with that score. Ascore
is the number of non-star matches in a pattern against the term, and thus bounded by the size of the term being matched against. The elements of this array are themselves arrays of non-empty arrays so that we can defer concatenating results until needed.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Number of elements in result
Equations
Instances For
Append results to array
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- mr.appendResults a = mr.appendResultsAux a fun (x : Nat) (a : α) => a
Instances For
Evaluate all partial matches and add resulting matches to MatchResult
.
The partial matches are stored in an array that is used as a stack. When adding multiple partial matches to explore next, to ensure the order of results matches user expectations, this code must add paths we want to prioritize and return results earlier are added last.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Find values that match e
in root
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Find values that match e
in d
.
The results are ordered so that the longest matches in terms of number of non-star keys are first with ties going to earlier operators first.
Equations
Instances For
Structure for quickly initializing a lazy discrimination tree with a large number of elements using concurrent functions for generating entries.
- roots : Std.HashMap Key Nat
Maps keys to index in tries array.
Lazy entries for root of trie.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add an entry to the pre-discrimination tree.
Equations
Instances For
Convert a pre-discrimination tree to a lazy discrimination tree.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Merge two discrimination trees.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates an entry for a subterm of an initial entry.
This is slightly more efficient than using fromExpr
on subterms since it avoids a redundant call
to whnf
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
- ngen : NameGenerator
- core : Core.Cache
- meta : Meta.Cache
Instances For
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Lean.Meta.LazyDiscrTree.blacklistInsertion env declName = (!Lean.Meta.allowCompletion env declName || declName == `sorryAx || declName.isInternalDetail || false || false)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Contains the pre discrimination tree and any errors occurring during initialization of the library search tree.
- tree : PreDiscrTree α
- errors : Array ImportFailure
Instances For
Combine two initial results.
Equations
Instances For
Equations
Equations
- Lean.Meta.LazyDiscrTree.toFlat d tree = do let de ← ST.Ref.swap d.errors #[] pure { tree := tree, errors := de }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Get the results of each task and merge using combining function
Equations
- Lean.Meta.LazyDiscrTree.combineGet z tasks = Array.foldl (fun (x : α) (t : Task α) => x ++ t.get) z tasks
Instances For
Equations
- Lean.Meta.LazyDiscrTree.getChildNgen = do let ngen ← Lean.getNGen match ngen.mkChild with | (cngen, ngen) => do Lean.setNGen ngen pure cngen
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- t.dropKeys keys = List.foldlM (fun (x1 : Lean.Meta.LazyDiscrTree α) (x2 : List Lean.Meta.LazyDiscrTree.Key) => x1.dropKey x2) t keys
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create a discriminator tree for imported environment.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates the core context used for initializing a tree using the current context.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
A discriminator tree for the current module's declarations only.
Note. We use different discriminator trees for imported and current module declarations since imported declarations are typically much more numerous but not changed after the environment is created.
- ref : IO.Ref (LazyDiscrTree α)
Instances For
Create a discriminator tree for current module declarations.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates reference for lazy discriminator tree that only contains this module's definitions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns candidates from this module in this module that match the expression.
moduleRef
is a references to a lazy discriminator tree only containing this module's definitions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
findMatchesExt
searches for entries in a lazily initialized discriminator tree.
It provides some additional capabilities beyond findMatches
to adjust results
based on priority and cache module declarations
modulesTreeRef
points to the discriminator tree for local environment. Used for caching and created bycreateLocalTree
.ext
should be an environment extension with an IO.Ref for caching the import lazy discriminator tree.addEntry
is the function for creating discriminator tree entries from constants.droppedKeys
contains keys we do not want to consider when searching for matches. It is used for dropping very general keys.constantsPerTask
stores number of constants in imported modules used to decide when to create new task.adjustResult
takes the priority and value to produce a final result.ty
is the expression type.
Equations
- One or more equations did not get rendered due to their size.
Instances For
findMatches
searches for entries in a lazily initialized discriminator tree.
ext
should be an environment extension with an IO.Ref for caching the import lazy discriminator tree.addEntry
is the function for creating discriminator tree entries from constants.droppedKeys
contains keys we do not want to consider when searching for matches. It is used for dropping very general keys.
Equations
- One or more equations did not get rendered due to their size.