File: .lake/packages/lean4/src/lean/Lean/Compiler/LCNF/ElimDeadBranches.lean

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.choice
code: /--
The abstract domain of the interpreter. Representing sets of values
of a certain type.
-/
inductive Value where
  /--
  Undefined, could be anything we have no information.
  -/
  | bot
  /--
  All values are possible.
  -/
  | top
  /--
  A certain constructor with a certain sets of parameters is possible.
  -/
  | ctor (i : Name) (vs : Array Value)
  /--
  A set of values are possible.
  -/
  | choice (vs : List Value)
  deriving Inhabited, Repr
goal: Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value
code: /--
The abstract domain of the interpreter. Representing sets of values
of a certain type.
-/
inductive Value where
  /--
  Undefined, could be anything we have no information.
  -/
  | bot
  /--
  All values are possible.
  -/
  | top
  /--
  A certain constructor with a certain sets of parameters is possible.
  -/
  | ctor (i : Name) (vs : Array Value)
  /--
  A set of values are possible.
  -/
  | choice (vs : List Value)
  deriving Inhabited, Repr
goal: Type

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.bot
code: /--
The abstract domain of the interpreter. Representing sets of values
of a certain type.
-/
inductive Value where
  /--
  Undefined, could be anything we have no information.
  -/
  | bot
  /--
  All values are possible.
  -/
  | top
  /--
  A certain constructor with a certain sets of parameters is possible.
  -/
  | ctor (i : Name) (vs : Array Value)
  /--
  A set of values are possible.
  -/
  | choice (vs : List Value)
  deriving Inhabited, Repr
goal: Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.instReprValue
code: /--
The abstract domain of the interpreter. Representing sets of values
of a certain type.
-/
inductive Value where
  /--
  Undefined, could be anything we have no information.
  -/
  | bot
  /--
  All values are possible.
  -/
  | top
  /--
  A certain constructor with a certain sets of parameters is possible.
  -/
  | ctor (i : Name) (vs : Array Value)
  /--
  A set of values are possible.
  -/
  | choice (vs : List Value)
  deriving Inhabited, Repr
goal: Repr Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.instInhabitedValue
code: /--
The abstract domain of the interpreter. Representing sets of values
of a certain type.
-/
inductive Value where
  /--
  Undefined, could be anything we have no information.
  -/
  | bot
  /--
  All values are possible.
  -/
  | top
  /--
  A certain constructor with a certain sets of parameters is possible.
  -/
  | ctor (i : Name) (vs : Array Value)
  /--
  A set of values are possible.
  -/
  | choice (vs : List Value)
  deriving Inhabited, Repr
goal: Inhabited Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.top
code: /--
The abstract domain of the interpreter. Representing sets of values
of a certain type.
-/
inductive Value where
  /--
  Undefined, could be anything we have no information.
  -/
  | bot
  /--
  All values are possible.
  -/
  | top
  /--
  A certain constructor with a certain sets of parameters is possible.
  -/
  | ctor (i : Name) (vs : Array Value)
  /--
  A set of values are possible.
  -/
  | choice (vs : List Value)
  deriving Inhabited, Repr
goal: Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.ctor
code: /--
The abstract domain of the interpreter. Representing sets of values
of a certain type.
-/
inductive Value where
  /--
  Undefined, could be anything we have no information.
  -/
  | bot
  /--
  All values are possible.
  -/
  | top
  /--
  A certain constructor with a certain sets of parameters is possible.
  -/
  | ctor (i : Name) (vs : Array Value)
  /--
  A set of values are possible.
  -/
  | choice (vs : List Value)
  deriving Inhabited, Repr
goal: Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.maxValueDepth
code: def maxValueDepth 
goal: Nat

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.beq
code: protected partial def beq : Value → Value → Bool

goal: Lean.Compiler.LCNF.UnreachableBranches.Value → Lean.Compiler.LCNF.UnreachableBranches.Value → Bool

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.instBEq
code: instance : BEq Value 
goal: BEq Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.truncate.go
code: /--
Make sure constructors of recursive inductive datatypes can only occur once in each path.
Values at depth > `maxValueDepth` are also approximated at `top`.
We use this function to implement a simple widening operation for our abstract interpreter.
Recall the widening functions is used to ensure termination in abstract interpreters.
-/
partial def truncate (env : Environment) (v : Value) : Value 
goal: Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.truncate
code: /--
Make sure constructors of recursive inductive datatypes can only occur once in each path.
Values at depth > `maxValueDepth` are also approximated at `top`.
We use this function to implement a simple widening operation for our abstract interpreter.
Recall the widening functions is used to ensure termination in abstract interpreters.
-/
partial def truncate (env : Environment) (v : Value) : Value 
goal: Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.widening
code: /-- Widening operator that guarantees termination in our abstract interpreter. -/
def widening (env : Environment) (v1 v2 : Value) : Value 
goal: Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.containsCtor
code: /--
Check whether a certain constructor is part of a `Value` by name.
Note that both `top` and `bot` will always true here. For bot this is
because we have no information about the `Value` so just to be sure
we don't claim the absence of a certain constructor.
-/
partial def containsCtor : Value → Name → Bool

goal: Lean.Compiler.LCNF.UnreachableBranches.Value → Lean.Name → Bool

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.getCtorArgs
code: /--
Obtain the arguments of a certain constructor within the `Value`.
-/
partial def getCtorArgs : Value → Name → Option (Array Value)

goal: Lean.Compiler.LCNF.UnreachableBranches.Value → Lean.Name → Option (Array Lean.Compiler.LCNF.UnreachableBranches.Value)

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.ofNat.goSmall
code: partial def ofNat (n : Nat) : Value 
goal: Nat → Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.ofNat.goBig
code: partial def ofNat (n : Nat) : Value 
goal: Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.ofNat
code: partial def ofNat (n : Nat) : Value 
goal: Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.ofLCNFLit
code: def ofLCNFLit : LCNF.LitValue → Value

goal: Lean.Compiler.LCNF.LitValue → Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.proj
code: partial def proj : Value → Nat → Value

goal: Lean.Compiler.LCNF.UnreachableBranches.Value → Nat → Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.isLiteral
code: /--
We say that a `Value` is a literal iff it is only a tree of `Value.ctor`
nodes.
-/
partial def isLiteral : Value → Bool

goal: Lean.Compiler.LCNF.UnreachableBranches.Value → Bool

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.getLiteral.getNatConstant
code: /--
Attempt to turn a `Value` that is representing a literal into a set of
auxiliary declarations + the final `FVarId` of the declaration that
contains the actual literal. If it is not a literal return none.
-/
partial def getLiteral (v : Value) : CompilerM (Option ((Array CodeDecl) × FVarId)) 
goal: Lean.Compiler.LCNF.UnreachableBranches.Value → Nat

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.getLiteral.go
code: /--
Attempt to turn a `Value` that is representing a literal into a set of
auxiliary declarations + the final `FVarId` of the declaration that
contains the actual literal. If it is not a literal return none.
-/
partial def getLiteral (v : Value) : CompilerM (Option ((Array CodeDecl) × FVarId)) 
goal: Lean.Compiler.LCNF.UnreachableBranches.Value →
  Lean.Compiler.LCNF.CompilerM (Array Lean.Compiler.LCNF.CodeDecl × Lean.FVarId)

full_name: Lean.Compiler.LCNF.UnreachableBranches.Value.getLiteral
code: /--
Attempt to turn a `Value` that is representing a literal into a set of
auxiliary declarations + the final `FVarId` of the declaration that
contains the actual literal. If it is not a literal return none.
-/
partial def getLiteral (v : Value) : CompilerM (Option ((Array CodeDecl) × FVarId)) 
goal: Lean.Compiler.LCNF.CompilerM (Option (Array Lean.Compiler.LCNF.CodeDecl × Lean.FVarId))

full_name: Lean.Compiler.LCNF.UnreachableBranches.FunctionSummaries
code: /--
A map from function names to the `Value` that the abstract interpreter
produced for them.
-/
abbrev FunctionSummaries 
goal: Type

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.LCNF.ElimDeadBranches.0.Lean.Compiler.LCNF.UnreachableBranches.decLt
code: private abbrev decLt (a b : Name × Value) : Bool 
goal: Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.LCNF.ElimDeadBranches.0.Lean.Compiler.LCNF.UnreachableBranches.findAtSorted?
code: private abbrev findAtSorted? (entries : Array (Name × Value)) (fid : Name) : Option Value 
goal: Option Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.functionSummariesExt
code: /--
Storing `FunctionSummaries` for all functions in a `.olean`.
-/
builtin_initialize functionSummariesExt : SimplePersistentEnvExtension (Name × Value) FunctionSummaries ←
  registerSimplePersistentEnvExtension {
    addImportedFn := fun _ => {}
    addEntryFn := fun s ⟨e, n⟩ => s.insert e n
    toArrayFn := fun s => s.toArray.qsort decLt
  }
goal: Lean.SimplePersistentEnvExtension (Lean.Name × Lean.Compiler.LCNF.UnreachableBranches.Value)
  Lean.Compiler.LCNF.UnreachableBranches.FunctionSummaries

full_name: Lean.Compiler.LCNF.UnreachableBranches.initFn._@..lake.packages.lean4.src.lean.Lean.Compiler.LCNF.ElimDeadBranches._hyg.1934
code: /--
Storing `FunctionSummaries` for all functions in a `.olean`.
-/
builtin_initialize functionSummariesExt : SimplePersistentEnvExtension (Name × Value) FunctionSummaries ←
  registerSimplePersistentEnvExtension {
    addImportedFn := fun _ => {}
    addEntryFn := fun s ⟨e, n⟩ => s.insert e n
    toArrayFn := fun s => s.toArray.qsort decLt
  }
goal: IO
  (Lean.SimplePersistentEnvExtension (Lean.Name × Lean.Compiler.LCNF.UnreachableBranches.Value)
    Lean.Compiler.LCNF.UnreachableBranches.FunctionSummaries)

full_name: Lean.Compiler.LCNF.UnreachableBranches.addFunctionSummary
code: /--
Add a `Value` for a function name.
-/
def addFunctionSummary (env : Environment) (fid : Name) (v : Value) : Environment 
goal: Lean.Environment

full_name: Lean.Compiler.LCNF.UnreachableBranches.getFunctionSummary?
code: /--
Obtain the `Value` for a function name if possible.
-/
def getFunctionSummary? (env : Environment) (fid : Name) : Option Value 
goal: Option Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.Assignment
code: /--
A map from variable identifiers to the `Value` produced by the abstract
interpreter for them.
-/
abbrev Assignment 
goal: Type

full_name: Lean.Compiler.LCNF.UnreachableBranches.InterpContext.decls
code: /--
The context of `InterpM`.
-/
structure InterpContext where
  /--
  The list of `Decl`s we are operating on in `InterpM`. This can be
  a single declaration or a mutual block of declarations where their
  analysis might influence each other as we approach the fixpoint.
  -/
  decls     : Array Decl
  /--
  The index of the function we are currently operating on in `decls.`
  -/
  currFnIdx : Nat := 0
goal: Array Lean.Compiler.LCNF.Decl

full_name: Lean.Compiler.LCNF.UnreachableBranches.InterpContext
code: /--
The context of `InterpM`.
-/
structure InterpContext where
  /--
  The list of `Decl`s we are operating on in `InterpM`. This can be
  a single declaration or a mutual block of declarations where their
  analysis might influence each other as we approach the fixpoint.
  -/
  decls     : Array Decl
  /--
  The index of the function we are currently operating on in `decls.`
  -/
  currFnIdx : Nat := 0
goal: Type

full_name: Lean.Compiler.LCNF.UnreachableBranches.InterpContext.currFnIdx
code: /--
The context of `InterpM`.
-/
structure InterpContext where
  /--
  The list of `Decl`s we are operating on in `InterpM`. This can be
  a single declaration or a mutual block of declarations where their
  analysis might influence each other as we approach the fixpoint.
  -/
  decls     : Array Decl
  /--
  The index of the function we are currently operating on in `decls.`
  -/
  currFnIdx : Nat := 0
goal: Nat

full_name: Lean.Compiler.LCNF.UnreachableBranches.InterpState.assignments
code: structure InterpState where
  /--
  `Assignment`s of functions in the `InterpContext`.
  -/
  assignments : Array Assignment
  /--
  `Value`s of functions in the `InterpContext` use during computation of
  the fixpoint. Afterwards they are stored into the `Environment`.
  -/
  funVals     : PArray Value
goal: Array Lean.Compiler.LCNF.UnreachableBranches.Assignment

full_name: Lean.Compiler.LCNF.UnreachableBranches.InterpState
code: structure InterpState where
  /--
  `Assignment`s of functions in the `InterpContext`.
  -/
  assignments : Array Assignment
  /--
  `Value`s of functions in the `InterpContext` use during computation of
  the fixpoint. Afterwards they are stored into the `Environment`.
  -/
  funVals     : PArray Value
goal: Type

full_name: Lean.Compiler.LCNF.UnreachableBranches.InterpState.funVals
code: structure InterpState where
  /--
  `Assignment`s of functions in the `InterpContext`.
  -/
  assignments : Array Assignment
  /--
  `Value`s of functions in the `InterpContext` use during computation of
  the fixpoint. Afterwards they are stored into the `Environment`.
  -/
  funVals     : PArray Value
goal: Lean.PArray Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.InterpM
code: /--
The monad which powers the abstract interpreter.
-/
abbrev InterpM 
goal: Type

full_name: Lean.Compiler.LCNF.UnreachableBranches.getAssignment
code: /--
Get the variable `Assignment` of the current function.
-/
def getAssignment : InterpM Assignment 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Lean.Compiler.LCNF.UnreachableBranches.Assignment

full_name: Lean.Compiler.LCNF.UnreachableBranches.getFunVal
code: /--
Get the `Value` of a certain function in the current block by index.
-/
def getFunVal (funIdx : Nat) : InterpM Value 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.findFunVal?
code: def findFunVal? (declName : Name) : InterpM (Option Value) 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM (Option Lean.Compiler.LCNF.UnreachableBranches.Value)

full_name: Lean.Compiler.LCNF.UnreachableBranches.modifyAssignment
code: /--
Run `f` on the variable `Assignment` of the current function.
-/
def modifyAssignment (f : Assignment → Assignment) : InterpM Unit 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.findVarValue
code: /--
Obtain the `Value` associated with `var` from the context of `InterpM`.
If none is available return `Value.bot`.
-/
def findVarValue (var : FVarId) : InterpM Value 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.findArgValue
code: /--
Find the value of `arg` using the logic of `findVarValue`.
-/
def findArgValue (arg : Arg) : InterpM Value 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.updateVarAssignment
code: /--
Update the assignment of `var` by merging the current value with `newVal`.
-/
def updateVarAssignment (var : FVarId) (newVal : Value) : InterpM Unit 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.resetVarAssignment
code: /--
Set the value of `var` to `bot`.
-/
def resetVarAssignment (var : FVarId) : InterpM Unit 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.updateCurrFnSummary
code: /--
Widen the value of the current function by `v`.
-/
def updateCurrFnSummary (v : Value) : InterpM Unit 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.updateFunDeclParamsAssignment
code: /--
Return true if the assignment of at least one parameter has been updated.
Furthermore if we see that `params.size != args.size` we know that this is
a partial application and set the values of the remaining parameters to
`top` since it is impossible to track what will happen with them from here on.
-/
def updateFunDeclParamsAssignment (params : Array Param) (args : Array Arg) : InterpM Bool 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.LCNF.ElimDeadBranches.0.Lean.Compiler.LCNF.UnreachableBranches.resetNestedFunDeclParams
code: private partial def resetNestedFunDeclParams : Code → InterpM Unit

goal: Lean.Compiler.LCNF.Code → Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.interpCode
code: /--
The actual abstract interpreter on a block of `Code`.
-/
partial def interpCode : Code → InterpM Unit

goal: Lean.Compiler.LCNF.Code → Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.interpCode.handleFunVar
code: /--
The actual abstract interpreter on a block of `Code`.
-/
partial def interpCode : Code → InterpM Unit

goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.interpCode.handleFunArg
code: /--
The actual abstract interpreter on a block of `Code`.
-/
partial def interpCode : Code → InterpM Unit

goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.interpCode.interpFunCall
code: /--
The actual abstract interpreter on a block of `Code`.
-/
partial def interpCode : Code → InterpM Unit

goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.interpCode.interpLetValue
code: /--
The actual abstract interpreter on a block of `Code`.
-/
partial def interpCode : Code → InterpM Unit

goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Lean.Compiler.LCNF.UnreachableBranches.Value

full_name: Lean.Compiler.LCNF.UnreachableBranches.inferStep
code: /--
Rerun the abstract interpreter on all declarations except of the unsafe
ones. Return whether any `Value` got updated in the process.
-/
def inferStep : InterpM Bool 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Bool

full_name: Lean.Compiler.LCNF.UnreachableBranches.inferMain
code: /--
Run `inferStep` until it reaches a fix point.
-/
partial def inferMain : InterpM Unit 
goal: Lean.Compiler.LCNF.UnreachableBranches.InterpM Unit

full_name: Lean.Compiler.LCNF.UnreachableBranches.elimDead
code: /--
Use the information produced by the abstract interpreter to:
- Eliminate branches that we know cannot be hit
- Eliminate values that we know have to be constants.
-/
partial def elimDead (assignment : Assignment) (decl : Decl) : CompilerM Decl 
goal: Lean.Compiler.LCNF.CompilerM Lean.Compiler.LCNF.Decl

full_name: Lean.Compiler.LCNF.UnreachableBranches.elimDead.go
code: /--
Use the information produced by the abstract interpreter to:
- Eliminate branches that we know cannot be hit
- Eliminate values that we know have to be constants.
-/
partial def elimDead (assignment : Assignment) (decl : Decl) : CompilerM Decl 
goal: Lean.Compiler.LCNF.CompilerM Lean.Compiler.LCNF.Code

full_name: Lean.Compiler.LCNF.Decl.elimDeadBranches
code: def Decl.elimDeadBranches (decls : Array Decl) : CompilerM (Array Decl) 
goal: Lean.Compiler.LCNF.CompilerM (Array Lean.Compiler.LCNF.Decl)

full_name: Lean.Compiler.LCNF.elimDeadBranches
code: def elimDeadBranches : Pass 
goal: Lean.Compiler.LCNF.Pass

full_name: Lean.Compiler.LCNF.initFn._@..lake.packages.lean4.src.lean.Lean.Compiler.LCNF.ElimDeadBranches._hyg.6172
code: builtin_initialize
  registerTraceClass `Compiler.elimDeadBranches (inherited := true)
goal: IO Unit