Type inference for LCNF #
We use a regular local context to store temporary local declarations created during type inference.
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
- 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
- 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
- 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.
Create lcCast expectedType e : expectedType
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.
- Lean.Compiler.LCNF.Code.inferType (Lean.Compiler.LCNF.Code.let decl k) = Lean.Compiler.LCNF.Code.inferType k
- Lean.Compiler.LCNF.Code.inferType (Lean.Compiler.LCNF.Code.fun decl k) = Lean.Compiler.LCNF.Code.inferType k
- Lean.Compiler.LCNF.Code.inferType (Lean.Compiler.LCNF.Code.jp decl k) = Lean.Compiler.LCNF.Code.inferType k
- Lean.Compiler.LCNF.Code.inferType (Lean.Compiler.LCNF.Code.return fvarId) = Lean.Compiler.LCNF.getType fvarId
- Lean.Compiler.LCNF.Code.inferType (Lean.Compiler.LCNF.Code.unreach type) = pure type
- Lean.Compiler.LCNF.Code.inferType (Lean.Compiler.LCNF.Code.cases c) = pure c.resultType
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Compiler.LCNF.mkAuxLetDecl e prefixName = do let a ← Lean.Compiler.LCNF.mkFreshBinderName prefixName let a_1 ← Lean.Compiler.LCNF.inferType e Lean.Compiler.LCNF.mkLetDecl a a_1 e
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
- Lean.Compiler.LCNF.mkAuxJpDecl params code prefixName = Lean.Compiler.LCNF.mkAuxFunDecl params code prefixName
Equations
- Lean.Compiler.LCNF.mkAuxJpDecl' param code prefixName = let params := #[param]; Lean.Compiler.LCNF.mkAuxFunDecl params code prefixName
Equations
- Lean.Compiler.LCNF.instantiateForall type params = Lean.Compiler.LCNF.instantiateForall.go params type 0
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.
Return true
if type
should be erased. See item 1 in the note above where x ◾ ◾
is
a proposition and should be erased when the universe level parameter is set to 0.
Remark: predVars
is a bitmask that indicates whether de-bruijn variables are predicates or not.
That is, #i
is a predicate if predVars[predVars.size - i - 1] = true
Equations
- Lean.Compiler.LCNF.isErasedCompatible type predVars = Lean.Compiler.LCNF.isErasedCompatible.go type predVars
Quick check for compatibleTypes
. It is not monadic, but it is incomplete
because it does not eta-expand type formers. See comment at compatibleTypes
.
Remark: if the result is true
, then a
and b
are indeed compatible.
If it is false
, we must use the full-check.
Complete check for compatibleTypes
. It eta-expands type formers. See comment at compatibleTypes
.
Equations
- One or more equations did not get rendered due to their size.
Return true if the LCNF types a
and b
are compatible.
Remark: a
and b
can be type formers (e.g., List
, or fun (α : Type) => Nat → Nat × α
)
Remark: We may need to eta-expand type formers to establish whether they are compatible or not. For example, suppose we have
fun (x : B) => Id B ◾ ◾
Id B ◾
We must eta-expand Id B ◾
to fun (x : B) => Id B ◾ x
. Note that, we use x
instead of ◾
to
make the implementation simpler and skip the check whether B
is a type former type. However,
this simplification should not affect correctness since ◾
is compatible with everything.
Remark: see comment at isErasedCompatible
.
Remark: because of "erasure confusion" see note above, we assume ◾
(aka lcErasure
) is compatible with everything.
This is a simplification. We used to use isErasedCompatible
, but this only address item 1.
For item 2, we would have to modify the toLCNFType
function and make sure a type former is erased if the expected
type is not always a type former (see S.mk
type and example in the note above).
Equations
Return true if the LCNF types a
and b
are compatible.
Remark: a
and b
can be type formers (e.g., List
, or fun (α : Type) => Nat → Nat × α
)
Remark: We may need to eta-expand type formers to establish whether they are compatible or not. For example, suppose we have
fun (x : B) => Id B ◾ ◾
Id B ◾
We must eta-expand Id B ◾
to fun (x : B) => Id B ◾ x
. Note that, we use x
instead of ◾
to
make the implementation simpler and skip the check whether B
is a type former type. However,
this simplification should not affect correctness since ◾
is compatible with everything.
Remark: see comment at isErasedCompatible
.
Remark: because of "erasure confusion" see note above, we assume ◾
(aka lcErasure
) is compatible with everything.
This is a simplification. We used to use isErasedCompatible
, but this only address item 1.
For item 2, we would have to modify the toLCNFType
function and make sure a type former is erased if the expected
type is not always a type former (see S.mk
type and example in the note above).
Equations
- One or more equations did not get rendered due to their size.