Type check for withPtrEq #
withPtrEq a b k h is logically equal to k (), but the compiler implements it by
withPtrEqUnsafe, which returns true without calling k if a and b are pointer-equal. This
is only correct if pointer equality implies equality for values of the type of a and b.
The compiler erases proofs as well as values whose type is a sort or a type former. Erasing proofs
is harmless because of proof irrelevance, but two values that differ only in an erased type may be
represented by the same object at runtime. checkWithPtrEqType therefore checks conservatively that
values of the given type cannot contain types or type formers:
- proofs are accepted;
- sorts and type formers are rejected;
- a function type is accepted if its codomain is accepted: then a closure determines the result for each argument, and hence the function by function extensionality;
- an inductive type is accepted if the types of all constructor fields are accepted, where occurrences of an inductive type that is already being checked are accepted (this is sound by induction on values);
- a quotient is accepted if the underlying type is accepted;
- everything else, in particular type variables, opaque types and types whose definition is not accessible in the current module, is rejected.
Checks that pointer equality implies equality for values of type, which is required for
compiling withPtrEq at type, and throws an error otherwise. See the module docstring for
details.
Equations
- Lean.Compiler.LCNF.checkWithPtrEqType type = Lean.Meta.withTransparency Lean.Meta.TransparencyMode.all ((ReaderT.run (Lean.Compiler.LCNF.WithPtrEq.check✝ type) { rootType := type }).run' ∅)