Sym Extensions #
Extensible state mechanism for SymM, allowing modules to register persistent state
that lives across simp invocations within a sym => block. Follows the same pattern
as Grind.SolverExtension in Lean/Meta/Tactic/Grind/Types.lean.
Opaque extension state type used to store type-erased extension values.
A registered extension for SymM. Each extension gets a unique index into the
extensions array in Sym.State. Can only be created via registerSymExtension.
Instances For
Registers a new SymM state extension. Extensions can only be registered during initialization.
Returns a handle for typed access to the extension's state.
Instances For
Returns initial state for all registered extensions.
Instances For
Information about a single argument position in a function's type signature.
This is used during pattern matching and structural definitional equality tests to identify arguments that can be skipped or handled specially (e.g., instance arguments can be synthesized, proof arguments can be inferred).
- isProof : Bool
trueif this argument is a proof (its type is aProp). - isInstance : Bool
trueif this argument is a type class instance.
Instances For
Information about a function symbol. It stores which argument positions are proofs or instances, enabling optimizations during pattern matching and structural definitional equality tests such as skipping proof arguments or deferring instance synthesis.
- argsInfo : Array ProofInstArgInfo
Information about each argument position.
Instances For
Information on how to build congruence proofs for function applications. This enables efficient rewriting of subterms without repeatedly inferring types or instances.
- none : CongrInfo
None of the arguments of the function can be rewritten.
- fixedPrefix
(prefixSize suffixSize : Nat)
: CongrInfo
For functions with a fixed prefix of implicit/instance arguments followed by explicit non-dependent arguments that can be rewritten independently.
prefixSize: Number of leading arguments (types, instances) that are determined by the suffix arguments and should not be rewritten directly.suffixSize: Number of trailing arguments that can be rewritten using simple congruence.
Examples (showing
prefixSize,suffixSize): - interlaced
(rewritable : Array Bool)
: CongrInfo
For functions with interlaced rewritable and non-rewritable arguments. Each element indicates whether the corresponding argument position can be rewritten.
Example: For
HEq {α : Sort u} (a : α) {β : Sort u} (b : β), the mask would be#[false, true, false, true]— we can rewriteaandb, but notαorβ. - congrTheorem
(thm : CongrTheorem)
: CongrInfo
For functions that have proofs and
Decidablearguments. For this kind of function we generate a custom theorem. Example:Array.eraseIdx {α : Type u} (xs : Array α) (i : Nat) (h : i < xs.size) : Array α. The proof argumenthdepends onxsandi. To be able to rewritexsandi, we use the auto-generated theorem.Array.eraseIdx.congr_simp {α : Type u} (xs xs' : Array α) (e_xs : xs = xs') (i i' : Nat) (e_i : i = i') (h : i < xs.size) : xs.eraseIdx i h = xs'.eraseIdx i' ⋯
Instances For
Configuration options for the symbolic computation framework.
- verbose : Bool
When
true, issues are collected during proof search and reported on failure. - enforceUnfoldReducible : Bool
When
true,shareCommonmaintains theSymMinvariant that reducible constants have been eagerly unfolded: if a new term contains one,shareCommonunfolds it before adding the term to the table of maximally shared terms. - enforceFoldProjs : Bool
When
true,shareCommonmaintains theSymMinvariant that kernel projections have been folded into projection function applications: if a new term contains one,shareCommonfolds it before adding the term to the table of maximally shared terms.cbvdisables this check because it processes kernel projections natively.
Instances For
- cache : Std.HashMap Expr Expr
Cache for value-level canonicalization (no type reductions applied).
- cacheInType : Std.HashMap Expr Expr
Cache for type-level canonicalization (reductions applied).
Instances For
Mutable state for the symbolic computation framework.
Maps expressions to their maximal free variable (by declaration index).
maxFVar[e] = some fvarIdmeansfvarIdis the free variable with the largest declaration index occurring ine.maxFVar[e] = nonemeansecontains no free variables (but may contain metavariables).
Recall that if
econtains a metavariable?m, then we assumeemay contain any free variable in the local context associated with?m.This mapping enables O(1) local context compatibility checks during metavariable assignment. Instead of traversing local contexts with
isSubPrefixOf, we check if the maximal free variable in the assigned value is in scope of the metavariable's local context.Note: We considered using a mapping
PHashMap ExprPtr FVarId. However, there is a corner case that is not supported by this representation.econtains a metavariable (with an empty local context), and no free variables.- proofInstInfo : PHashMap Name (Option ProofInstInfo)
Cache for
getLevelresults, keyed by pointer equality.Cache for
isDefEqIresults- extensions : Array SymExtensionState
State for registered
SymExtensions, indexed by extension id. - issues : List MessageData
Issues found during symbolic computation. Accumulated across operations within a
sym =>block and reported when a tactic fails. - canon : Canon.State
Instances registered by satellite modules for types they create themselves (e.g.,
grind linarith's envelope typeIntModule.OfNatModule.Q).Sym.synthInstance?consults this table (keyed by the instance type, structural equality) before running typeclass resolution. This both skips searches whose results are known in advance, and ensures the registered term is used as the canonical representative.We currently use this table to reduce the overhead of type class resolution in
grind.- debug : Bool
Instances For
Auxiliary function for implementing unfoldReducible and unfoldReducibleSimproc.
Performs a single step.
Instances For
Unfolds all reducible declarations occurring in e.
This is meant as a preprocessing step. It does not guarantee maximally shared terms
Instances For
Converts nested Expr.projs into projection applications if possible.
The structural simplifier and pattern matcher do not handle kernel projection
terms; this preprocessing step folds them into projection function applications.
Instances For
Returns the internalized False constant.
Instances For
Returns the internalized Bool.false.
Instances For
Returns true if e is the internalized Bool.false expression.
Instances For
Returns the internalized 0 : Nat numeral.
Instances For
Returns the internalized Ordering.eq.
Instances For
Runs x with the shareCommon kernel-projection check disabled.
Use this to wrap code that temporarily violates the SymM folded-projections
invariant, e.g., a head reducer that exposes kernel projections in intermediate
terms and restores the invariant in its final result.
Instances For
Adds an issue message to the issue tracker.
Instances For
Reports an issue if verbose mode is enabled.
Instances For
Similar to reportIssue!, but only reports issue if sym.debug is set to true.
Instances For
Returns all accumulated issues without clearing them.
Instances For
Runs x with a fresh issue context. Issues reported during x are
prepended to the issues that existed before the call.