Skip to content

Commit d9296c0

Browse files
committed
Documentation
1 parent ee61032 commit d9296c0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Lean/Meta/Constructions/NoConfusionLinear.lean

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@ import Lean.AddDecl
88
import Lean.Meta.AppBuilder
99
import Lean.Meta.CompletionName
1010

11+
/-!
12+
This module produces a construction for the `noConfusionType` that is linear in size in the number of
13+
constructors of the inductive type. This is in contrast to the previous construction (definde in
14+
`no_confusion.cpp`), that is quadratic in size due to nested `.brecOn` applications.
15+
16+
We still use the old construction when processing the prelude, for the few inductives that we need
17+
until below (`Nat`, `Bool`, `Decidable`).
18+
19+
The main trick is to use a `withCtor` helper that is like a match with one constructor pattern and
20+
one catch-all pattern, and thus linear in size. And the helper itself is a single function
21+
definition, rather than one for each constructor, using a `withCtorType` helper in the function.
22+
23+
See the `linearNoConfusion.lean` test for exemplary output of this translation (checked to be
24+
up-to-date).
25+
26+
The `withCtor` functions could be generally useful, but for that they should probably eliminate into
27+
`Sort _` rather than `Type _`, and then writing the `withCtorType` function runs into universe level
28+
confusion, which may be solvable if the kernel had more complete univere level normalization.
29+
Until then we put these helper in the `noConfusionType` namespace to indicate that they are not
30+
general purpose.
31+
32+
This module is written in a rather manual style, constructing the `Expr` directly. It's best
33+
read with the expected output to the side.
34+
-/
35+
1136
namespace Lean
1237

1338
open Meta

tests/lean/run/linearNoConfusion.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ This test tests and also explains the noConfusionType construction.
33
44
It contains copies of the definitions of the constructions, for manual experimentation with
55
the code, and uses `#guard_msgs` and `rfl` to compare them to the generated ones.
6+
7+
This also serves as documentation to the `NoConfusionLinear` module, so do not delete or remove
8+
from this file without updating that module's docstring.
69
-/
710

811
inductive Vec.{u} (α : Type) : Nat → Type u where

0 commit comments

Comments
 (0)