perf: type check constants from nested realizations only once This PR makes the kernel type check a constant created by a nested realization only once. For example, the equation theorems of a function request the equations of its `match`, and the kernel checked each of those theorems twice, or three times when they requested further theorems themselves. Generating the equations of a `String → Nat` function with 128 literal alternatives is about 25% faster. It also fixes repeated error messages: a kernel error in such a constant was reported once per nesting level, and is now reported once. A realization runs with the kernel disabled, and `Environment.realizeConst` type checks its constants when the result is added to the environment that requested it. When that environment belongs to another realization, the constants are also part of the result of that realization and were checked again when it was added to its own requester. `realizeConst` now adds them without type checking when the requester is itself realizing (`env.isRealizing`), so the only check is the one in the outermost requester. The new test `realizeConstNestedKernelCheck.lean` creates an ill-typed theorem in a realization nested at depth 2 and at depth 3: the kernel still rejects it, and the `declaration type mismatch` error, which was printed 2 and 3 times, is printed once. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This is the repository for Lean 4.
See Install Lean.
Please read our Contribution Guidelines first.
See Building Lean.