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 = n.mkStr "_boxed"
Equations
- Lean.IR.ExplicitBoxing.isBoxedName (pre.str "_boxed") = true
- Lean.IR.ExplicitBoxing.isBoxedName name = false
@[reducible, inline]
Equations
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.
Equations
Equations
- One or more equations did not get rendered due to their size.
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.
- f : FunId
- localCtx : LocalContext
- resultType : IRType
- env : Environment
- nextIdx : Index
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.
- nextAuxId : Nat
@[reducible, inline]
Equations
- Lean.IR.ExplicitBoxing.getVarType x = do let localCtx ← Lean.IR.ExplicitBoxing.getLocalContext match localCtx.getType x with | some t => pure t | none => pure Lean.IR.IRType.object
Equations
- Lean.IR.ExplicitBoxing.getJPParams j = do let localCtx ← Lean.IR.ExplicitBoxing.getLocalContext match localCtx.getJPParams j with | some ys => pure ys | none => pure #[]
@[inline]
def
Lean.IR.ExplicitBoxing.withJDecl
{α : Type}
(j : JoinPointId)
(xs : Array Param)
(v : FnBody)
(k : M α)
:
M α
Equations
- One or more equations did not get rendered due to their size.
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.
@[inline]
Equations
- Lean.IR.ExplicitBoxing.castArgIfNeeded (Lean.IR.Arg.var x_2) expected k = Lean.IR.ExplicitBoxing.castVarIfNeeded x_2 expected fun (x : Lean.IR.VarId) => k (Lean.IR.Arg.var x)
- Lean.IR.ExplicitBoxing.castArgIfNeeded x expected k = k x
Equations
- One or more equations did not get rendered due to their size.
- Lean.IR.ExplicitBoxing.visitVDeclExpr x ty e b = pure (Lean.IR.FnBody.vdecl x ty e b)
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.IR.explicitBoxing decls = do let env ← Lean.IR.getEnv pure (Lean.IR.ExplicitBoxing.run env decls)