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
createImportedEnvironment
. This creates a discrimination tree from all
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.
Discrimination tree key.
- const: Lake.Name → Nat → Lean.Meta.LazyDiscrTree.Key
- fvar: Lean.FVarId → Nat → Lean.Meta.LazyDiscrTree.Key
- lit: Lean.Literal → Lean.Meta.LazyDiscrTree.Key
- star: Lean.Meta.LazyDiscrTree.Key
- other: Lean.Meta.LazyDiscrTree.Key
- arrow: Lean.Meta.LazyDiscrTree.Key
- proj: Lake.Name → Nat → Nat → Lean.Meta.LazyDiscrTree.Key
Instances For
Equations
- Lean.Meta.LazyDiscrTree.instInhabitedKey = { default := Lean.Meta.LazyDiscrTree.Key.const default default }
Equations
Equations
- Lean.Meta.LazyDiscrTree.instReprKey = { reprPrec := Lean.Meta.LazyDiscrTree.reprKey✝ }
Hash function
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.LazyDiscrTree.instInhabitedTrie = { default := { values := default, star := default, children := default, pending := default } }
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.
- config : Lean.Meta.WhnfCoreConfig
Configuration for normalization.
- tries : Array (Lean.Meta.LazyDiscrTree.Trie α)
Backing array of trie entries. Should be owned by this trie.
Map from discriminator trie roots to the index.
Instances For
Equations
- One or more equations did not get rendered due to their size.
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
Create a key path from an expression we are matching against.
This should have mvars instantiated where feasible.
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
This drops a specific key from the lazy discrimination tree so that all the entries matching that key exactly are removed.
Equations
- One or more equations did not get rendered due to their size.
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
Number of elements in result
Equations
- mr.size = Array.foldl (fun (i : Nat) (a : Array (Array α)) => Array.foldl (fun (n : Nat) (a : Array α) => n + a.size) i a) 0 mr.elts
Instances For
Append results to array
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
- score : Nat
Instances For
Equations
- Lean.Meta.LazyDiscrTree.instInhabitedPartialMatch = { default := { todo := default, score := default, c := default } }
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
- d.getMatch e = Lean.Meta.withReducible (Lean.Meta.LazyDiscrTree.runMatch d (Lean.Meta.LazyDiscrTree.getMatchCore d.roots e))
Instances For
Equations
- Lean.Meta.LazyDiscrTree.instInhabitedPreDiscrTree = { default := { roots := default, tries := default } }
Merge two discrimination trees.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.LazyDiscrTree.PreDiscrTree.instAppendPreDiscrTree = { append := Lean.Meta.LazyDiscrTree.PreDiscrTree.append }
Initial entry in lazy discrimination tree
Return root key for an entry.
- entry : Lean.Meta.LazyDiscrTree.LazyEntry α
Returns rest of entry for later insertion.
Instances For
Constructs an initial entry from an expression and value.
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
- ngen : Lean.NameGenerator
- core : Lean.Core.Cache
- meta : Lean.Meta.Cache
Instances For
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
Combine two initial results.
Equations
- Lean.Meta.LazyDiscrTree.InitResults.append x y = match x with | { tree := xv, errors := xe } => match y with | { tree := yv, errors := ye } => { tree := xv ++ yv, errors := xe ++ ye }
Instances For
Equations
- Lean.Meta.LazyDiscrTree.InitResults.instAppendInitResults = { append := Lean.Meta.LazyDiscrTree.InitResults.append }
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 (x : Lean.Meta.LazyDiscrTree α) (x_1 : List Lean.Meta.LazyDiscrTree.Key) => x.dropKey x_1) 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
Allocate constants to tasks according to constantsPerTask
.
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 (Lean.Meta.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.