Documentation

Lean.Compiler.LCNF.Simp.ConstantFold

@[reducible, inline]

A constant folding monad, the additional state stores auxiliary declarations required to build the new constant.

Equations
Instances For
    @[reducible, inline]

    A constant folder for a specific function, takes all the arguments of a certain function and produces a new Expr + auxiliary declarations in the FolderM monad on success. If the folding fails it returns none.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      A typeclass for detecting and producing literals of arbitrary types inside of LCNF.

      • getLit : FVarId → CompilerM (Option α)

        Attempt to turn the provided Expr into a value of type α if it is whatever concept of a literal α has. Note that this function does assume that the provided Expr does indeed have type α.

      • mkLit : α → FolderM (LetValue Purity.pure)

        Turn a value of type α into a series of auxiliary LetDecls + a final Expr putting them all together into a literal of type α, where again the idea of what a literal is depends on α.

      Instances

        A wrapper around LCNF.mkAuxLetDecl that will automatically store the LetDecl in the state of FolderM.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          def Lean.Compiler.LCNF.Simp.ConstantFold.mkAuxLit {α : Type} [Literal α] (x : α) (prefixName : Name := `_x) :

          A wrapper around mkAuxLetDecl that also calls mkLit.

          Equations
          Instances For
            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  @[instance_reducible]
                  def Lean.Compiler.LCNF.Simp.ConstantFold.mkUIntInstance {α : Type} (matchLit : LitValue → Option α) (litValueCtor : α → LitValue) :
                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    @[instance_reducible]
                    Equations
                    • One or more equations did not get rendered due to their size.
                    @[instance_reducible]
                    Equations
                    • One or more equations did not get rendered due to their size.
                    @[instance_reducible]
                    Equations
                    • One or more equations did not get rendered due to their size.
                    @[instance_reducible]
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      Turns an expression chain of the form

                      let _x.1 := @List.nil _
                      let _x.2 := @List.cons _ a _x.1
                      let _x.3 := @List.cons _ b _x.2
                      let _x.4 := @List.cons _ c _x.3
                      let _x.5 := @List.cons _ d _x.4
                      let _x.6 := @List.cons _ e _x.5
                      

                      into: [a, b, c, d ,e] + The type contained in the list

                      Equations
                      Instances For

                        Turn an #[a, b, c] into:

                        let _x.12 := 3
                        let _x.8 := @Array.mkEmpty _ _x.12
                        let _x.22 := @Array.push _ _x.8 x
                        let _x.24 := @Array.push _ _x.22 y
                        let _x.26 := @Array.push _ _x.24 z
                        _x.26
                        
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Evaluate array literals at compile time, that is turn:

                          let _x.1 := @List.nil _
                          let _x.2 := @List.cons _ z _x.1
                          let _x.3 := @List.cons _ y _x.2
                          let _x.4 := @List.cons _ x _x.3
                          let _x.5 := @List.toArray _ _x.4
                          

                          To its array form:

                          let _x.12 := 3
                          let _x.8 := @Array.mkEmpty _ _x.12
                          let _x.22 := @Array.push _ _x.8 x
                          let _x.24 := @Array.push _ _x.22 y
                          let _x.26 := @Array.push _ _x.24 z
                          
                          Instances For
                            def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.mkUnary {α β : Type} [Literal α] [Literal β] (folder : α → β) :

                            Turn a unary function such as Nat.succ into a constant folder.

                            Instances For
                              def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.mkBinary {α β γ : Type} [Literal α] [Literal β] [Literal γ] (folder : α → β → γ) :

                              Turn a binary function such as Nat.add into a constant folder.

                              Instances For
                                def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.mkBinaryDecisionProcedure {α β : Type} [Literal α] [Literal β] {r : α → β → Prop} (folder : (a : α) → (b : β) → Decidable (r a b)) :
                                Instances For
                                  def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.mkBinaryUSizeDecisionProcedure {r64 : UInt64 → UInt64 → Prop} {r32 : UInt32 → UInt32 → Prop} (f64 : (a b : UInt64) → Decidable (r64 a b)) (f32 : (a b : UInt32) → Decidable (r32 a b)) :
                                  Instances For
                                    Instances For
                                      Instances For
                                        def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.leftNeutral {α : Type} [Literal α] [BEq α] (neutral : α) (op : α → α → α) (_h : ∀ (x : α), op neutral x = x := by simp) :

                                        Provide a folder for an operation with a left neutral element.

                                        Instances For
                                          def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.rightNeutral {α : Type} [Literal α] [BEq α] (neutral : α) (op : α → α → α) (_h : ∀ (x : α), op x neutral = x := by simp) :

                                          Provide a folder for an operation with a right neutral element.

                                          Instances For
                                            def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.leftAnnihilator {α γ : Type} {β : Sort u_1} [Literal α] [BEq α] [Literal γ] (annihilator : α) (zero : γ) (op : α → β → γ) (_h : ∀ (x : β), op annihilator x = zero := by simp) :

                                            Provide a folder for an operation with a left annihilator.

                                            Instances For
                                              def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.rightAnnihilator {β γ : Type} {α : Sort u_1} [Literal β] [BEq β] [Literal γ] (annihilator : β) (zero : γ) (op : α → β → γ) (_h : ∀ (x : α), op x annihilator = zero := by simp) :

                                              Provide a folder for an operation with a right annihilator. The result type may differ from the operand types, e.g. Nat.blt x 0 = false.

                                              Instances For
                                                def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.sameArg {γ : Type} {α : Sort u_1} [Literal γ] (zero : γ) (op : α → α → γ) (_h : ∀ (x : α), op x x = zero := by simp) :
                                                Instances For
                                                  def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.idempotent {α : Sort u_1} (op : α → α → α) (_h : ∀ (x : α), op x x = x := by simp) :
                                                  Instances For
                                                    def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.divShift {α : Type} [Literal α] [BEq α] (shiftRight : Name) (pow2 log2 : α → α) :
                                                    Instances For
                                                      def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.mulRhsShift {α : Type} [Literal α] [BEq α] (shiftLeft : Name) (pow2 log2 : α → α) :
                                                      Instances For
                                                        def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.mulLhsShift {α : Type} [Literal α] [BEq α] (shiftLeft : Name) (pow2 log2 : α → α) :
                                                        Instances For

                                                          Pick the first folder out of folders that succeeds.

                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For
                                                            def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.leftRightNeutral {α : Type} [Literal α] [BEq α] (neutral : α) (op : α → α → α) (_h1 : ∀ (x : α), op neutral x = x := by simp) (_h2 : ∀ (x : α), op x neutral = x := by simp) :

                                                            Provide a folder for an operation that has the same left and right neutral element.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              Provide a folder for a USize operation that has the same left and right neutral element.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For
                                                                def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.leftRightAnnihilator {α : Type} [Literal α] [BEq α] (annihilator zero : α) (op : α → α → α) (_h1 : ∀ (x : α), op annihilator x = zero := by simp) (_h2 : ∀ (x : α), op x annihilator = zero := by simp) :

                                                                Provide a folder for an operation that has the same left and right annihilator.

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For
                                                                  def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.leftRightAnnihilatorUSize (annihilator64 : UInt64) (annihilator32 : UInt32) (zero64 : UInt64) (zero32 : UInt32) :

                                                                  Provide a folder for a USize operation that has the same left and right annihilator.

                                                                  Equations
                                                                  • One or more equations did not get rendered due to their size.
                                                                  Instances For
                                                                    def Lean.Compiler.LCNF.Simp.ConstantFold.Folder.mulShift {α : Type} [Literal α] [BEq α] (shiftLeft : Name) (pow2 log2 : α → α) :
                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For
                                                                      Equations
                                                                      • One or more equations did not get rendered due to their size.
                                                                      Instances For

                                                                        Folds Nat.shiftLeft on literals when the shift amount is below natShiftLeftThreshold. The threshold must fit in 32 bits: the runtime implementation of Nat.shiftLeft aborts the process on larger shift amounts.

                                                                        Instances For

                                                                          Folder for ofNat operations on fixed-sized integer types.

                                                                          Instances For

                                                                            Folder for ofNatLT operations on fixed-sized integer types. The bound is a proof and carries no runtime content, so only the numeral matters.

                                                                            Instances For
                                                                              Equations
                                                                              • One or more equations did not get rendered due to their size.
                                                                              Instances For

                                                                                All arithmetic folders.

                                                                                Equations
                                                                                • One or more equations did not get rendered due to their size.
                                                                                Instances For
                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.
                                                                                  Instances For
                                                                                    Equations
                                                                                    • One or more equations did not get rendered due to their size.
                                                                                    Instances For

                                                                                      All string folders.

                                                                                      Equations
                                                                                      • One or more equations did not get rendered due to their size.
                                                                                      Instances For

                                                                                        Apply all known folders to decl.

                                                                                        Equations
                                                                                        • One or more equations did not get rendered due to their size.
                                                                                        Instances For
                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          Instances For
                                                                                            Instances For
                                                                                              Equations
                                                                                              • One or more equations did not get rendered due to their size.
                                                                                              Instances For