Documentation

Lean.Compiler.LCNF.CompilerM

The pipeline phase a certain Pass is supposed to happen in.

  • base : Phase

    Here we still carry most of the original type information, most of the dependent portion is already (partially) erased though.

  • mono : Phase

    In this phase polymorphism has been eliminated.

  • impure : Phase
Instances For
    @[reducible]
    Instances For

      The state managed by the CompilerM Monad.

      • lctx : LCtx

        A LocalContext to store local declarations from let binders and other constructs in as we move through Exprs.

      • nextIdx : Nat

        Next auxiliary variable suffix

      Instances For
        @[reducible, inline]
        Instances For
          @[implicit_reducible, always_inline]
          @[inline]
          def Lean.Compiler.LCNF.withPhase {α : Type} (phase : Phase) (x : CompilerM α) :
          Instances For
            Instances For
              Instances For
                Instances For
                  Instances For
                    Instances For
                      Instances For
                        @[inline]
                        Instances For
                          def Lean.Compiler.LCNF.eraseFunDecl {pu : Purity} (decl : FunDecl pu) (recursive : Bool := true) :
                          Instances For
                            Instances For
                              Instances For
                                Instances For

                                  Erase all free variables occurring in decls from the local context.

                                  Instances For
                                    Instances For
                                      @[reducible, inline]
                                      Instances For
                                        @[reducible, inline]

                                        A free variable substitution. We use these substitutions when inlining definitions and "internalizing" LCNF code into CompilerM. During the internalization process, we ensure all free variables in the LCNF code do not collide with existing ones at the CompilerM local context. Remark: in LCNF, (computationally relevant) data is in A-normal form, but this is not the case for types and type formers. So, when inlining we often want to replace a free variable with a type or type former.

                                        The substitution contains entries fvarId ↦ e s.t., e is a valid LCNF argument. That is, it is a free variable, a type (or type former), or lcErased.

                                        Check.lean contains a substitution validator.

                                        Instances For

                                          Result type for normFVar and normFVarImp.

                                          • fvar (fvarId : FVarId) : NormFVarResult

                                            New free variable.

                                          • erased : NormFVarResult

                                            Free variable has been erased. This can happen when instantiating polymorphic code with computationally irrelevant stuff.

                                          Instances For
                                            partial def Lean.Compiler.LCNF.normFVarImp {pu : Purity} (s : FVarSubst pu) (fvarId : FVarId) (translator : Bool) :

                                            Normalize the given free variable. See normExprImp for documentation on the translator parameter. This function is meant to be used in contexts where the input free-variable is computationally relevant. This function panics if the substitution is mapping fvarId to an expression that is not another free variable. That is, it is not a type (or type former), nor lcErased. Recall that a valid FVarSubst contains only expressions that are free variables, lcErased, or type formers.

                                            Interface for monads that have a free substitutions.

                                            Instances
                                              @[implicit_reducible]
                                              Instances
                                                @[inline]
                                                def Lean.Compiler.LCNF.addSubst {m : TypeType} {pu : Purity} [MonadFVarSubstState m pu] (fvarId : FVarId) (arg : Arg pu) :

                                                Add the substitution fvarId ↦ e, e must be a valid LCNF Arg.

                                                See Check.lean for the free variable substitution checker.

                                                Instances For
                                                  @[inline]
                                                  def Lean.Compiler.LCNF.addFVarSubst {m : TypeType} {ph : Purity} [MonadFVarSubstState m ph] (fvarId fvarId' : FVarId) :

                                                  Add the entry fvarId ↦ fvarId' to the free variable substitution.

                                                  Instances For
                                                    @[inline]
                                                    def Lean.Compiler.LCNF.normFVar {m : TypeType} {pu : Purity} {t : Bool} [MonadFVarSubst m pu t] [Monad m] (fvarId : FVarId) :

                                                    Normalize the given free variable. See normExprImp for documentation on the translator parameter. This function is meant to be used in contexts where the input free-variable is computationally relevant. This function panics if the substitution is mapping fvarId to an expression that is not another free variable. That is, it is not a type (or type former), nor lcErased. Recall that a valid FVarSubst contains only expressions that are free variables, lcErased, or type formers.

                                                    Instances For
                                                      @[inline]
                                                      def Lean.Compiler.LCNF.normExpr {m : TypeType} {pu : Purity} {t : Bool} [MonadFVarSubst m pu t] [Monad m] (e : Expr) :

                                                      Replace the free variables in e using the given substitution.

                                                      If translator = true, then we assume the free variables occurring in the range of the substitution are in another local context. For example, translator = true during internalization where we are making sure all free variables in a given expression are replaced with new ones that do not collide with the ones in the current local context.

                                                      If translator = false, we assume the substitution contains free variable replacements in the same local context, and given entries such as x₁ ↦ x₂, x₂ ↦ x₃, ..., xₙ₋₁ ↦ xₙ, and the expression f x₁ x₂, we want the resulting expression to be f xₙ xₙ. We use this setting, for example, in the simplifier.

                                                      Instances For
                                                        @[inline]
                                                        def Lean.Compiler.LCNF.normArg {m : TypeType} {pu : Purity} {t : Bool} [MonadFVarSubst m pu t] [Monad m] (arg : Arg pu) :
                                                        m (Arg pu)

                                                        Replace the free variables in arg using the given substitution.

                                                        See normExprImp

                                                        Instances For
                                                          @[inline]
                                                          def Lean.Compiler.LCNF.normLetValue {m : TypeType} {pu : Purity} {t : Bool} [MonadFVarSubst m pu t] [Monad m] (e : LetValue pu) :
                                                          m (LetValue pu)

                                                          Replace the free variables in e using the given substitution.

                                                          See normExprImp

                                                          Instances For
                                                            @[inline]
                                                            def Lean.Compiler.LCNF.normExprCore {pu : Purity} (s : FVarSubst pu) (e : Expr) (translator : Bool) :

                                                            Replace the free variables in e using the given substitution.

                                                            If translator = true, then we assume the free variables occurring in the range of the substitution are in another local context. For example, translator = true during internalization where we are making sure all free variables in a given expression are replaced with new ones that do not collide with the ones in the current local context.

                                                            If translator = false, we assume the substitution contains free variable replacements in the same local context, and given entries such as x₁ ↦ x₂, x₂ ↦ x₃, ..., xₙ₋₁ ↦ xₙ, and the expression f x₁ x₂, we want the resulting expression to be f xₙ xₙ. We use this setting, for example, in the simplifier.

                                                            Instances For
                                                              def Lean.Compiler.LCNF.normArgs {m : TypeType} {pu : Purity} {t : Bool} [MonadFVarSubst m pu t] [Monad m] (args : Array (Arg pu)) :
                                                              m (Array (Arg pu))

                                                              Normalize the given arguments using the current substitution.

                                                              Instances For
                                                                Instances For
                                                                  Instances For

                                                                    Helper functions for creating LCNF local declarations.

                                                                    def Lean.Compiler.LCNF.mkParam {pu : Purity} (binderName : Name) (type : Expr) (borrow : Bool) :
                                                                    Instances For
                                                                      def Lean.Compiler.LCNF.mkLetDecl {pu : Purity} (binderName : Name) (type : Expr) (value : LetValue pu) :
                                                                      Instances For
                                                                        def Lean.Compiler.LCNF.mkFunDecl {pu : Purity} (binderName : Name) (type : Expr) (params : Array (Param pu)) (value : Code pu) :
                                                                        Instances For
                                                                          @[implemented_by _private.Lean.Compiler.LCNF.CompilerM.0.Lean.Compiler.LCNF.updateParamImp]
                                                                          opaque Lean.Compiler.LCNF.Param.update {pu : Purity} (p : Param pu) (type : Expr) :
                                                                          @[implemented_by _private.Lean.Compiler.LCNF.CompilerM.0.Lean.Compiler.LCNF.updateParamBorrowImp]
                                                                          opaque Lean.Compiler.LCNF.Param.updateBorrow {pu : Purity} (p : Param pu) (borrow : Bool) :
                                                                          @[implemented_by _private.Lean.Compiler.LCNF.CompilerM.0.Lean.Compiler.LCNF.updateLetDeclImp]
                                                                          opaque Lean.Compiler.LCNF.LetDecl.update {pu : Purity} (decl : LetDecl pu) (type : Expr) (value : LetValue pu) :
                                                                          Instances For
                                                                            @[implemented_by _private.Lean.Compiler.LCNF.CompilerM.0.Lean.Compiler.LCNF.updateFunDeclImp]
                                                                            opaque Lean.Compiler.LCNF.FunDecl.update {pu : Purity} (decl : FunDecl pu) (type : Expr) (params : Array (Param pu)) (value : Code pu) :
                                                                            @[reducible, inline]
                                                                            abbrev Lean.Compiler.LCNF.FunDecl.update' {pu : Purity} (decl : FunDecl pu) (type : Expr) (value : Code pu) :
                                                                            Instances For
                                                                              @[reducible, inline]
                                                                              abbrev Lean.Compiler.LCNF.FunDecl.updateValue {pu : Purity} (decl : FunDecl pu) (value : Code pu) :
                                                                              Instances For
                                                                                @[inline]
                                                                                def Lean.Compiler.LCNF.normParam {m : TypeType} {pu : Purity} {t : Bool} [MonadLiftT CompilerM m] [Monad m] [MonadFVarSubst m pu t] (p : Param pu) :
                                                                                m (Param pu)
                                                                                Instances For
                                                                                  def Lean.Compiler.LCNF.normParams {m : TypeType} {pu : Purity} {t : Bool} [MonadLiftT CompilerM m] [Monad m] [MonadFVarSubst m pu t] (ps : Array (Param pu)) :
                                                                                  m (Array (Param pu))
                                                                                  Instances For
                                                                                    def Lean.Compiler.LCNF.normLetDecl {m : TypeType} {pu : Purity} {t : Bool} [MonadLiftT CompilerM m] [Monad m] [MonadFVarSubst m pu t] (decl : LetDecl pu) :
                                                                                    m (LetDecl pu)
                                                                                    Instances For
                                                                                      @[reducible, inline]
                                                                                      abbrev Lean.Compiler.LCNF.NormalizerM (pu : Purity) (_translator : Bool) (α : Type) :
                                                                                      Instances For
                                                                                        @[implicit_reducible]
                                                                                        @[inline]
                                                                                        def Lean.Compiler.LCNF.withNormFVarResult {m : TypeType u_1} {pu : Purity} [MonadLiftT CompilerM m] [Monad m] (result : NormFVarResult) (x : FVarIdm (Code pu)) :
                                                                                        m (Code pu)

                                                                                        If result is .fvar fvarId, then return x fvarId. Otherwise, it is .erased, and method returns let _x.i := .erased; return _x.i.

                                                                                        Instances For
                                                                                          partial def Lean.Compiler.LCNF.normFunDeclImp {pu : Purity} {t : Bool} (decl : FunDecl pu) :
                                                                                          partial def Lean.Compiler.LCNF.normCodeImp {pu : Purity} {t : Bool} (code : Code pu) :
                                                                                          NormalizerM pu t (Code pu)
                                                                                          @[inline]
                                                                                          def Lean.Compiler.LCNF.normFunDecl {m : TypeType} {pu : Purity} {t : Bool} [MonadLiftT CompilerM m] [Monad m] [MonadFVarSubst m pu t] (decl : FunDecl pu) :
                                                                                          m (FunDecl pu)
                                                                                          Instances For
                                                                                            @[inline]
                                                                                            def Lean.Compiler.LCNF.normCode {m : TypeType} {pu : Purity} {t : Bool} [MonadLiftT CompilerM m] [Monad m] [MonadFVarSubst m pu t] (code : Code pu) :
                                                                                            m (Code pu)

                                                                                            Similar to internalize, but does not refresh FVarIds.

                                                                                            Instances For
                                                                                              def Lean.Compiler.LCNF.replaceExprFVars {pu : Purity} (e : Expr) (s : FVarSubst pu) (translator : Bool) :
                                                                                              Instances For
                                                                                                def Lean.Compiler.LCNF.replaceFVars {pu : Purity} (code : Code pu) (s : FVarSubst pu) (translator : Bool) :
                                                                                                Instances For
                                                                                                  def Lean.Compiler.LCNF.mkAuxParam {pu : Purity} (type : Expr) (borrow : Bool := false) :
                                                                                                  Instances For
                                                                                                    def Lean.Compiler.LCNF.CompilerM.run {α : Type} (x : CompilerM α) (s : State := { }) (phase : Phase := Phase.base) :
                                                                                                    Instances For

                                                                                                      Environment extension for local caching of key-value pairs, not persisted in .olean files.

                                                                                                      Instances For
                                                                                                        def Lean.Compiler.LCNF.instInhabitedCacheExtension.default {a✝ a✝¹ : Type} {a✝² : BEq a✝} {a✝³ : Hashable a✝} :
                                                                                                        CacheExtension a✝ a✝¹
                                                                                                        Instances For
                                                                                                          @[implicit_reducible]
                                                                                                          instance Lean.Compiler.LCNF.instInhabitedCacheExtension {a✝ a✝¹ : Type} {a✝² : BEq a✝} {a✝³ : Hashable a✝} :
                                                                                                          def Lean.Compiler.LCNF.CacheExtension.insert {α β : Type} [BEq α] [Hashable α] [Inhabited β] (ext : CacheExtension α β) (a : α) (b : β) :
                                                                                                          Instances For
                                                                                                            def Lean.Compiler.LCNF.CacheExtension.find? {α β : Type} [BEq α] [Hashable α] [Inhabited β] (ext : CacheExtension α β) (a : α) :
                                                                                                            Instances For