Documentation

Lean.Meta.Tactic.Lets

Tactics to manipulate let expressions #

let extraction #

Extracting lets means to locate let/letFuns 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/letFuns toward the root of a term.

Instances For
    • givenNames : List Name

      Names to use for local definitions for the extracted lets.

    • Saved declarations for the extracted lets.

    • Map from let values to fvars. To support the merge option.

    Instances For
      @[reducible, inline]
      Equations
        Instances For

          Returns true if nextName? would return a name.

          Equations
            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

                      Returns 'true' if e does not depend on any of the fvars in fvars.

                      Equations
                        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
                            Instances For

                              Adds the decl to the decls list. Assumes that decl is an ldecl.

                              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 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

                                          1. The goal contains the decls in its local context, violating the assumption.
                                          2. We need to use true lets in that case, since tactics may zeta-delta reduce these declarations.
                                          Equations
                                            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 letFun.

                                              Equations
                                                Instances For
                                                  def Lean.Meta.ExtractLets.withDeclInContext {α : Type} (fvarId : FVarId) (k : M α) :
                                                  M α

                                                  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 letFun (this does not verify that the letFuns are well-formed). Its purpose is to be a check for whether a subexpression can be skipped.

                                                          Equations
                                                            Instances For
                                                              partial def Lean.Meta.ExtractLets.extractCore (fvars : List Expr) (e : Expr) (topLevel : Bool := false) :

                                                              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. Extracted lets 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.

                                                              partial def Lean.Meta.ExtractLets.extractCore.extractBinder (fvars : List Expr) (n : Name) (t b : Expr) (i : BinderInfo) (mk : ExprExprExpr) :
                                                              partial def Lean.Meta.ExtractLets.extractCore.extractLetLike (fvars : List Expr) (isLet : Bool) (n : Name) (t v b : Expr) (mk : ExprExprExprM Expr) (topLevel : Bool) :
                                                              partial def Lean.Meta.ExtractLets.extractCore.extractLetFun (fvars : List Expr) (e : Expr) (topLevel : Bool) :

                                                              e is the letFun expression

                                                              Equations
                                                                Instances For

                                                                  Main entry point for extracting lets.

                                                                  Equations
                                                                    Instances For
                                                                      def Lean.Meta.extractLets {m : TypeType u_1} {α : Type} [Monad m] [MonadControlT MetaM m] (es : Array Expr) (givenNames : List Name) (k : Array FVarIdArray ExprList Namem α) (config : ExtractLetsConfig := { }) :
                                                                      m α

                                                                      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 and config.onlyGivenNames is true) then uses a hygienic name based on the existing binder name.
                                                                      Equations
                                                                        Instances For

                                                                          Lifts let and letFun expressions in the given expression as far out as possible.

                                                                          Equations
                                                                            Instances For

                                                                              Extracts let and letFun expressions from the target, returning FVarIds 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 and config.onlyGivenNames is true) then uses a hygienic name based on the existing binder name.
                                                                              Equations
                                                                                Instances For
                                                                                  def Lean.MVarId.extractLetsLocalDecl (mvarId : MVarId) (fvarId : FVarId) (givenNames : List Name) (config : Meta.ExtractLetsConfig := { }) :

                                                                                  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 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
                                                                                        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