Tactics to manipulate let expressions #
let extraction #
Extracting lets means to locate let/haves in a term and to extract them
from the term, extending the local context with new declarations in the process.
A related process is lifting lets, which means to move let/haves toward the root of a term.
Names to use for local definitions for the extracted lets.
- decls : Array LocalDecl'
Saved declarations for the extracted
lets. - valueMap : ExprStructMap FVarId
Map from
letvalues to fvars. To support themergeoption.
Instances For
Gets the next name to use for extracted lets
Equations
Instances For
Generate a name to use for a new local declaration, derived possibly from the given binder name.
Returns none iff hasNextName is false.
Equations
Instances For
Removes and returns all local declarations that (transitively) depend on fvar.
Equations
Instances For
Ensures that the given local declarations are in context. Runs k in that context.
Equations
Instances For
Closes all the local declarations in e, creating let and have expressions.
Does not require that any of the declarations are in context.
Assumes that e contains no metavariables with local contexts that contain any of these metavariables
(the extraction procedure creates no new metavariables, so this is the case).
This should not be used when closing lets for new goal metavariables, since
- The goal contains the decls in its local context, violating the assumption.
- We need to use true
lets in that case, since tactics may zeta-delta reduce these declarations.
Equations
Instances For
Ensures that the given fvarId is in context by adding decls from the state.
Simplification: since we are not recording which decls depend on which, but we do know all dependencies
come before a particular decl, we add all the decls up to and including fvarId.
Used for merge feature.
Equations
Instances For
Initializes the valueMap with all the local definitions that aren't implementation details.
Used for merge feature when useContext is enabled.
Equations
Instances For
Returns true if the expression contains a let expression or a have.
Its purpose is to be a check for whether a subexpression can be skipped.
Equations
Instances For
Extracts lets from e.
fvarsis an array of all the local variables from going under binders, used to detect whether an expression is extractable. Extractedlets do not have their fvarids in this list. This is not part of the cache key since it's an optimization and in principle derivable.topLevelis whether we are still looking at the top-level expression. The body of an extracted top-level let is also considered to be top-level. This is part of the cache key since it affects what is extracted.
Note: the return value may refer to fvars that are not in the current local context, but they are in the decls list.
Extracts let and have expressions into local definitions,
evaluating k at the post-extracted expressions and the extracted fvarids, within a context containing those local declarations.
- The
givenNamesis a list of explicit names to use for extracted local declarations. If a name is_(or if there is no provided given name andconfig.onlyGivenNamesis true) then uses a hygienic name based on the existing binder name.
Equations
Instances For
Lifts let and have expressions in the given expression as far out as possible.
Equations
Instances For
Extracts let and have expressions from the target,
returning FVarIds for the extracted let declarations along with the new goal.
- The
givenNamesis a list of explicit names to use for extracted local declarations. If a name is_(or if there is no provided given name andconfig.onlyGivenNamesis true) then uses a hygienic name based on the existing binder name.
Equations
Instances For
Like Lean.MVarId.extractLets but extracts lets from a local declaration.
If the local declaration has a value, then both its type and value are modified.
Equations
Instances For
Lifts let and have expressions in target as far out as possible.
Throws an exception if nothing is lifted.
Like Lean.MVarId.extractLets, but top-level lets are not added to the local context.
Equations
Instances For
Like Lean.MVarId.liftLets but lifts lets in a local declaration.
If the local declaration has a value, then both its type and value are modified.
Equations
Instances For
Let-to-have transformation #
A meta tactic version of Lean.Meta.letToHave.