Tactics to manipulate let
expressions #
let
extraction #
Extracting let
s means to locate let
/letFun
s 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
/letFun
s toward the root of a term.
Names to use for local definitions for the extracted lets.
- decls : Array LocalDecl'
Saved declarations for the extracted
let
s. - valueMap : ExprStructMap FVarId
Map from
let
values to fvars. To support themerge
option.
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 let
s
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 letFun
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
let
s 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
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 letFun
(this does not verify that the letFun
s are well-formed).
Its purpose is to be a check for whether a subexpression can be skipped.
Equations
- Lean.Meta.ExtractLets.containsLet e = (Lean.Expr.find? (fun (e' : Lean.Expr) => e'.isLet || e'.isConstOf `letFun) e).isSome
Instances For
Extracts lets from e
.
fvars
is an array of all the local variables from going under binders, used to detect whether an expression is extractable. Extractedlet
s 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.topLevel
is 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 letFun
expressions into local definitions,
evaluating k
at the post-extracted expressions and the extracted fvarids, within a context containing those local declarations.
- The
givenNames
is a list of explicit names to use for extracted local declarations. If a name is_
(or if there is no provided given name andconfig.onlyGivenNames
is 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 letFun
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 letFun
expressions from the target,
returning FVarId
s for the extracted let declarations along with the new goal.
- The
givenNames
is a list of explicit names to use for extracted local declarations. If a name is_
(or if there is no provided given name andconfig.onlyGivenNames
is 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 letFun
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.