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 lower level optimizations are applied which use
Expr.isShared,Expr.isTaggedPtr, andFnBody.set.
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
- f : FunId
- localCtx : LocalContext
- resultType : IRType
- env : Environment
Instances For
- 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
Instances For
Equations
Instances For
Instances For
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.tobject
Instances For
Equations
- Lean.IR.ExplicitBoxing.getJPParams j = do let localCtx ← Lean.IR.ExplicitBoxing.getLocalContext match localCtx.getJPParams j with | some ys => pure ys | none => pure #[]
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
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
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 Lean.IR.Arg.erased expected k = k Lean.IR.Arg.erased
Instances For
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)
Instances For
Up to this point the type system of IR is quite loose so we can for example encounter situations such as
let y : obj := f x
where f : obj -> uint8. It is the job of the boxing pass to enforce a stricter obj/scalar
separation and as such it needs to correct situations like this.
Equations
- One or more equations did not get rendered due to their size.
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.fap f ys) = do let decl ← Lean.IR.ExplicitBoxing.getDecl f pure decl.resultType
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.pap c ys) = pure Lean.IR.IRType.object
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.uproj i x) = pure Lean.IR.IRType.usize
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.ctor i ys) = pure ty
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.reuse x i updtHeader ys) = pure ty
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.ap x ys) = pure ty
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.lit v) = pure ty
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.sproj n offset x) = pure ty
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.proj i x) = pure ty
- Lean.IR.ExplicitBoxing.tryCorrectVDeclType ty (Lean.IR.Expr.reset n x) = pure ty
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.getEnv pure (Lean.IR.ExplicitBoxing.run env decls)