File: .lake/packages/lean4/src/lean/Lean/Compiler/IR/ResetReuse.lean

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.mayReuse
code: private def mayReuse (c₁ c₂ : CtorInfo) (relaxedReuse : Bool) : Bool 
goal: Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.S.go
code: /--
Replace `ctor` applications with `reuse` applications if compatible.
`w` contains the "memory cell" being reused.
-/
private partial def S (w : VarId) (c : CtorInfo) (relaxedReuse : Bool) (b : FnBody) : FnBody 
goal: Lean.IR.FnBody → Lean.IR.FnBody

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.S
code: /--
Replace `ctor` applications with `reuse` applications if compatible.
`w` contains the "memory cell" being reused.
-/
private partial def S (w : VarId) (c : CtorInfo) (relaxedReuse : Bool) (b : FnBody) : FnBody 
goal: Lean.IR.FnBody

full_name: Lean.IR.ResetReuse.Context.lctx
code: structure Context where
  lctx      : LocalContext := {}
  /--
  Contains all variables in `cases` statements in the current path
  and variables that are already in `reset` statements when we
  invoke `R`.

  We use this information to prevent double-reset in code such as
  ```
  case x_i : obj of
  Prod.mk →
    case x_i : obj of
    Prod.mk →
    ...
  ```

  A variable can already be in a `reset` statement when we
  invoke `R` because we execute it with and without `relaxedReuse`.
  -/
  alreadyFound : PHashSet VarId := {}
  /--
  If `relaxedReuse := true`, then allow memory cells from different
  constructors to be reused. For example, we can reuse a `PSigma.mk`
  to allocate a `Prod.mk`. To avoid counterintuitive behavior,
  we first try `relaxedReuse := false`, and then `relaxedReuse := true`.
  -/
  relaxedReuse : Bool := false
goal: Lean.IR.LocalContext

full_name: Lean.IR.ResetReuse.Context.alreadyFound
code: structure Context where
  lctx      : LocalContext := {}
  /--
  Contains all variables in `cases` statements in the current path
  and variables that are already in `reset` statements when we
  invoke `R`.

  We use this information to prevent double-reset in code such as
  ```
  case x_i : obj of
  Prod.mk →
    case x_i : obj of
    Prod.mk →
    ...
  ```

  A variable can already be in a `reset` statement when we
  invoke `R` because we execute it with and without `relaxedReuse`.
  -/
  alreadyFound : PHashSet VarId := {}
  /--
  If `relaxedReuse := true`, then allow memory cells from different
  constructors to be reused. For example, we can reuse a `PSigma.mk`
  to allocate a `Prod.mk`. To avoid counterintuitive behavior,
  we first try `relaxedReuse := false`, and then `relaxedReuse := true`.
  -/
  relaxedReuse : Bool := false
goal: Lean.PHashSet Lean.IR.VarId

full_name: Lean.IR.ResetReuse.Context.relaxedReuse
code: structure Context where
  lctx      : LocalContext := {}
  /--
  Contains all variables in `cases` statements in the current path
  and variables that are already in `reset` statements when we
  invoke `R`.

  We use this information to prevent double-reset in code such as
  ```
  case x_i : obj of
  Prod.mk →
    case x_i : obj of
    Prod.mk →
    ...
  ```

  A variable can already be in a `reset` statement when we
  invoke `R` because we execute it with and without `relaxedReuse`.
  -/
  alreadyFound : PHashSet VarId := {}
  /--
  If `relaxedReuse := true`, then allow memory cells from different
  constructors to be reused. For example, we can reuse a `PSigma.mk`
  to allocate a `Prod.mk`. To avoid counterintuitive behavior,
  we first try `relaxedReuse := false`, and then `relaxedReuse := true`.
  -/
  relaxedReuse : Bool := false
goal: Bool

full_name: Lean.IR.ResetReuse.Context
code: structure Context where
  lctx      : LocalContext := {}
  /--
  Contains all variables in `cases` statements in the current path
  and variables that are already in `reset` statements when we
  invoke `R`.

  We use this information to prevent double-reset in code such as
  ```
  case x_i : obj of
  Prod.mk →
    case x_i : obj of
    Prod.mk →
    ...
  ```

  A variable can already be in a `reset` statement when we
  invoke `R` because we execute it with and without `relaxedReuse`.
  -/
  alreadyFound : PHashSet VarId := {}
  /--
  If `relaxedReuse := true`, then allow memory cells from different
  constructors to be reused. For example, we can reuse a `PSigma.mk`
  to allocate a `Prod.mk`. To avoid counterintuitive behavior,
  we first try `relaxedReuse := false`, and then `relaxedReuse := true`.
  -/
  relaxedReuse : Bool := false
goal: Type

full_name: Lean.IR.ResetReuse.M
code: /-- We use `Context` to track join points in scope. -/
abbrev M 
goal: Type

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.mkFresh
code: private def mkFresh : M VarId 
goal: Lean.IR.ResetReuse.M Lean.IR.VarId

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.tryS
code: /--
Helper function for applying `S`. We only introduce a `reset` if we managed
to replace a `ctor` withe `reuse` in `b`.
-/
private def tryS (x : VarId) (c : CtorInfo) (b : FnBody) : M FnBody 
goal: Lean.IR.ResetReuse.M Lean.IR.FnBody

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.Dfinalize
code: private def Dfinalize (x : VarId) (c : CtorInfo) : FnBody × Bool → M FnBody
  
goal: Lean.IR.FnBody × Bool → Lean.IR.ResetReuse.M Lean.IR.FnBody

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.argsContainsVar
code: private def argsContainsVar (ys : Array Arg) (x : VarId) : Bool 
goal: Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.isCtorUsing
code: private def isCtorUsing (b : FnBody) (x : VarId) : Bool 
goal: Bool

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.Dmain
code: /--
Given `Dmain b`, the resulting pair `(new_b, flag)` contains the new body `new_b`,
and `flag == true` if `x` is live in `b`.

Note that, in the function `D` defined in the paper, for each `let x := e; F`,
`D` checks whether `x` is live in `F` or not. This is great for clarity but it
is expensive: `O(n^2)` where `n` is the size of the function body. -/
private partial def Dmain (x : VarId) (c : CtorInfo) (e : FnBody) : M (FnBody × Bool) 
goal: Lean.IR.ResetReuse.M (Lean.IR.FnBody × Bool)

full_name: _private.«.lake».packages.lean4.src.lean.Lean.Compiler.IR.ResetReuse.0.Lean.IR.ResetReuse.D
code: private def D (x : VarId) (c : CtorInfo) (b : FnBody) : M FnBody 
goal: Lean.IR.ResetReuse.M Lean.IR.FnBody

full_name: Lean.IR.ResetReuse.R
code: partial def R (e : FnBody) : M FnBody 
goal: Lean.IR.ResetReuse.M Lean.IR.FnBody

full_name: Lean.IR.ResetReuse.N
code: abbrev N 
goal: Type

full_name: Lean.IR.ResetReuse.collectResets
code: partial def collectResets (e : FnBody) : N Unit 
goal: Lean.IR.ResetReuse.N Unit

full_name: Lean.IR.Decl.insertResetReuseCore
code: def Decl.insertResetReuseCore (d : Decl) (relaxedReuse : Bool) : Decl 
goal: Lean.IR.Decl

full_name: Lean.IR.Decl.insertResetReuse
code: def Decl.insertResetReuse (d : Decl) : Decl 
goal: Lean.IR.Decl