This PR adds “non-branching case statements”: For each inductive
constructor `T.con` this adds a function `T.con.with` that is similar
`T.casesOn`, but has only one arm (the one for `con`), and an additional
`t.toCtorIdx = 12` assumption.
For example:
```lean
inductive Vec (α : Type) : Nat → Type where
| nil : Vec α 0
| cons {n} : α → Vec α n → Vec α (n + 1)
/--
info: @[reducible] protected def Vec.cons.elim.{u} : {α : Type} →
{motive : (a : Nat) → Vec α a → Sort u} →
{a : Nat} →
(t : Vec α a) →
t.ctorIdx = 1 → ({n : Nat} → (a : α) → (a_1 : Vec α n) → motive (n + 1) (Vec.cons a a_1)) → motive a t
-/
#guard_msgs in
#print sig Vec.cons.elim
```
This is a building block for non-quadratic implementations of `BEq` and
`DecidableEq` etc.
Builds on top of #9951.
The compiled code for a these functions could presumably, without
branching on the inductive value, directly access the fields. Achieving
this optimization (and achieving it without a quadratic compilation
cost) is not in scope for this PR.
17 lines
379 B
Text
17 lines
379 B
Text
-- This triggered a bug in the linear-size `noConfusionType` construction
|
||
-- which confused the kernel when producing the `noConfusion` lemma.
|
||
|
||
-- set_option debug.skipKernelTC true
|
||
set_option pp.universes true
|
||
|
||
-- Works
|
||
|
||
inductive S where
|
||
| a {α : Sort u} {β : Type v} (f : α → β)
|
||
| b
|
||
|
||
-- Didn't work
|
||
|
||
inductive T where
|
||
| a {α : Sort u} {β : Sort v} (f : α → β)
|
||
| b
|