fix: correctly handle constructor params in elimDeadBranches (#9209)
This PR changes the `getLiteral` helper function of `elimDeadBranches` to correctly handle inductives with constructors. This function is not used as often as it could be, which makes this issue rare to hit outside of targeted test cases.
This commit is contained in:
parent
12536d2015
commit
149fc2173c
2 changed files with 17 additions and 4 deletions
|
|
@ -216,11 +216,13 @@ where
|
|||
let val := getNatConstant val + 1
|
||||
let decl ← mkAuxLetDecl <| .lit <| .nat <| val
|
||||
return (#[.let decl], decl.fvarId)
|
||||
| .ctor i vs => do
|
||||
let args ← vs.mapM go
|
||||
| .ctor ctorName vs => do
|
||||
let some (.ctorInfo ctorInfo) := (← getEnv).find? ctorName | unreachable!
|
||||
let fields ← vs.mapM go
|
||||
let flatten acc := fun (decls, var) => (acc.fst ++ decls, acc.snd.push <| .fvar var)
|
||||
let (decls, params) := args.foldl (init := (#[], Array.mkEmpty args.size)) flatten
|
||||
let letVal : LetValue := .const i [] params
|
||||
let (decls, args) :=
|
||||
fields.foldl (init := (#[], Array.replicate ctorInfo.numParams .erased)) flatten
|
||||
let letVal : LetValue := .const ctorName [] args
|
||||
let letDecl ← mkAuxLetDecl letVal
|
||||
return (decls.push <| .let letDecl, letDecl.fvarId)
|
||||
| _ => unreachable!
|
||||
|
|
|
|||
11
tests/lean/run/elimDeadBranchesCtorParams.lean
Normal file
11
tests/lean/run/elimDeadBranchesCtorParams.lean
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
@[noinline]
|
||||
def f (_ : Unit) : Prod Unit Unit :=
|
||||
Prod.mk ⟨⟩ ⟨⟩
|
||||
|
||||
@[noinline]
|
||||
def g (a : Unit) : Prod (Prod Unit Unit) (Prod Unit Unit) :=
|
||||
Prod.mk (f a) (f a)
|
||||
|
||||
def h (a : Unit) : Prod Unit Unit :=
|
||||
match g a with
|
||||
| ⟨_, y⟩ => y
|
||||
Loading…
Add table
Reference in a new issue