Add explicit boxing and unboxing instructions. Recall that the Lean to λ_pure compiler produces code without these instructions.
Assumptions:
- This transformation is applied before explicit RC instructions (
inc
,dec
) are inserted. - This transformation is applied before
FnBody.case
has been simplified andAlt.default
is used. Reason: if there is noAlt.default
branch, then we can decide whetherx
atFnBody.case x alts
is an enumeration type by simply inspecting theCtorInfo
values atalts
. - This transformation is applied before lower level optimizations are applied which use
Expr.isShared
,Expr.isTaggedPtr
, andFnBody.set
. - This transformation is applied after
reset
andreuse
instructions have been added. Reason:resetreuse.lean
ignoresbox
andunbox
instructions.
Equations
- Lean.IR.ExplicitBoxing.mkBoxedName n = Lean.Name.mkStr n "_boxed"
Instances For
Equations
- Lean.IR.ExplicitBoxing.isBoxedName name = match name with | Lean.Name.str pre "_boxed" => true | x => false
Instances For
@[inline, reducible]
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
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Infer scrutinee type using case
alternatives.
This can be done whenever alts
does not contain an Alt.default _
value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.IR.ExplicitBoxing.eqvTypes t₁ t₂ = (Lean.IR.IRType.isScalar t₁ == Lean.IR.IRType.isScalar t₂ && (!Lean.IR.IRType.isScalar t₁ || t₁ == t₂))
Instances For
- f : Lean.IR.FunId
- localCtx : Lean.IR.LocalContext
- resultType : Lean.IR.IRType
- decls : Array Lean.IR.Decl
- env : Lean.Environment
Instances For
- nextIdx : Lean.IR.Index
- auxDecls : Array Lean.IR.Decl
We create auxiliary declarations when boxing constant and literals. The idea is to avoid code such as
let x1 := Uint64.inhabited; let x2 := box x1; ...
We currently do not cache these declarations in an environment extension, but we use auxDeclCache to avoid creating equivalent auxiliary declarations more than once when processing the same IR declaration.
- auxDeclCache : Lean.AssocList Lean.IR.FnBody Lean.IR.Expr
- nextAuxId : Nat
Instances For
@[inline, reducible]
Equations
Instances For
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
- Lean.IR.ExplicitBoxing.getDecl fid = do let ctx ← read match Lean.IR.findEnvDecl' ctx.env fid ctx.decls with | some decl => pure decl | none => pure default
Instances For
@[inline]
def
Lean.IR.ExplicitBoxing.withParams
{α : Type}
(xs : Array Lean.IR.Param)
(k : Lean.IR.ExplicitBoxing.M α)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[inline]
def
Lean.IR.ExplicitBoxing.withVDecl
{α : Type}
(x : Lean.IR.VarId)
(ty : Lean.IR.IRType)
(v : Lean.IR.Expr)
(k : Lean.IR.ExplicitBoxing.M α)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[inline]
def
Lean.IR.ExplicitBoxing.withJDecl
{α : Type}
(j : Lean.IR.JoinPointId)
(xs : Array Lean.IR.Param)
(v : Lean.IR.FnBody)
(k : Lean.IR.ExplicitBoxing.M α)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Lean.IR.ExplicitBoxing.mkCast
(x : Lean.IR.VarId)
(xType : Lean.IR.IRType)
(expectedType : Lean.IR.IRType)
:
Auxiliary function used by castVarIfNeeded.
It is used when the expected type does not match xType
.
If xType
is scalar, then we need to "box" it. Otherwise, we need to "unbox" it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[inline]
def
Lean.IR.ExplicitBoxing.castVarIfNeeded
(x : Lean.IR.VarId)
(expected : Lean.IR.IRType)
(k : Lean.IR.VarId → Lean.IR.ExplicitBoxing.M Lean.IR.FnBody)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[inline]
def
Lean.IR.ExplicitBoxing.castArgIfNeeded
(x : Lean.IR.Arg)
(expected : Lean.IR.IRType)
(k : Lean.IR.Arg → Lean.IR.ExplicitBoxing.M Lean.IR.FnBody)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Lean.IR.ExplicitBoxing.castArgsIfNeededAux
(xs : Array Lean.IR.Arg)
(typeFromIdx : Nat → Lean.IR.IRType)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[inline]
def
Lean.IR.ExplicitBoxing.castArgsIfNeeded
(xs : Array Lean.IR.Arg)
(ps : Array Lean.IR.Param)
(k : Array Lean.IR.Arg → Lean.IR.ExplicitBoxing.M Lean.IR.FnBody)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[inline]
def
Lean.IR.ExplicitBoxing.boxArgsIfNeeded
(xs : Array Lean.IR.Arg)
(k : Array Lean.IR.Arg → Lean.IR.ExplicitBoxing.M Lean.IR.FnBody)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Lean.IR.ExplicitBoxing.unboxResultIfNeeded
(x : Lean.IR.VarId)
(ty : Lean.IR.IRType)
(e : Lean.IR.Expr)
(b : Lean.IR.FnBody)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Lean.IR.ExplicitBoxing.castResultIfNeeded
(x : Lean.IR.VarId)
(ty : Lean.IR.IRType)
(e : Lean.IR.Expr)
(eType : Lean.IR.IRType)
(b : Lean.IR.FnBody)
:
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Lean.IR.ExplicitBoxing.visitVDeclExpr
(x : Lean.IR.VarId)
(ty : Lean.IR.IRType)
(e : Lean.IR.Expr)
(b : Lean.IR.FnBody)
:
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
- Lean.IR.explicitBoxing decls = do let env ← Lean.IR.getEnv pure (Lean.IR.ExplicitBoxing.run env decls)