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
Equations
Instances For
Equations
Instances For
Returns true if nextName? would return a name.
Equations
- Lean.Meta.ExtractLets.hasNextName = do let __do_lift ← read let __do_lift_1 ← get pure (!__do_lift.onlyGivenNames || !__do_lift_1.givenNames.isEmpty)
Instances For
Gets the next name to use for extracted lets
Equations
- One or more equations did not get rendered due to their size.
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
- One or more equations did not get rendered due to their size.
Instances For
Returns 'true' if e does not depend on any of the fvars in fvars.
Equations
- Lean.Meta.ExtractLets.extractable fvars e = !e.hasAnyFVar fun (x : Lean.FVarId) => fvars.contains (Lean.Expr.fvar x)
Instances For
Returns whether a let-like expression with the given type and value is extractable,
given the list fvars of binders that inhibit extraction.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Removes and returns all local declarations that (transitively) depend on fvar.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ensures that the given local declarations are in context. Runs k in that context.
Equations
- One or more equations did not get rendered due to their size.
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
- One or more equations did not get rendered due to their size.
Instances For
Makes sure the declaration for fvarId is marked with isLet := true.
Used in lift + merge mode to ensure that, after merging, if any version was a let then it's a let rather than a have.
Equations
- One or more equations did not get rendered due to their size.
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
- One or more equations did not get rendered due to their size.
Instances For
Initializes the valueMap with all the local definitions that aren't implementation details.
Used for merge feature when useContext is enabled.
Equations
- One or more equations did not get rendered due to their size.
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
- Lean.Meta.ExtractLets.containsLet e = (Lean.Expr.find? (fun (x : Lean.Expr) => x.isLet) e).isSome
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.
Equations
Instances For
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
- One or more equations did not get rendered due to their size.
Instances For
Lifts let and have expressions in the given expression as far out as possible.
Equations
- One or more equations did not get rendered due to their size.
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
- One or more equations did not get rendered due to their size.
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
- One or more equations did not get rendered due to their size.
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
- One or more equations did not get rendered due to their size.
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
- One or more equations did not get rendered due to their size.
Instances For
Let-to-have transformation #
A meta tactic version of Lean.Meta.letToHave.