Documentation

Lean.Meta.LetToHave

Transforming nondependent lets into haves #

A let expression let x : t := v; b is nondependent if fun x : t => b is type correct. Nondependent lets are those that can be transformed into have x := v; b. This module has a procedure that detects which lets are nondependent and does the transformation, attempting to do so efficiently.

Dependence checking is approximated using the withTrackingZetaDelta technique: given let x := v; b, we add a x := v declaration to the local context, and then type check b with withTrackingZetaDelta enabled to record whether x is unfolded. If x is not unfolded, then we know that b does not depend on v. This is a conservative check, since isDefEq may unfold local definitions unnecessarily.

We do not use Lean.Meta.check directly. A naive algorithm would be to do Meta.check (b.instantiate1 x) for each let body, which would involve rechecking subexpressions multiple times when there are nested lets, and furthermore we do not need to fully typecheck the body when evaluating dependence. Instead, we re-implement a type checking algorithm here to be able to interleave checking and transformation.

The trace class trace.Meta.letToHave reports statistics.

The transformation has very limited support for metavariables. Any let that contains a metavariable remains a let for now.

Optimizations, present and future:

Transforms nondependent let expressions into have expressions. If e is not type correct, returns e. The Meta.letToHave trace class logs errors and messages.

Equations
  • One or more equations did not get rendered due to their size.
Instances For