Skip to content

Commit 3481f43

Browse files
authored
fix: FunInd: strip MData when creating the unfolding theorem (#8354)
This PR makes sure that when generating the unfolding functional induction theorem, `mdata` does not get in the way.
1 parent 528fe0b commit 3481f43

File tree

3 files changed

+9
-33
lines changed

3 files changed

+9
-33
lines changed

src/Lean/Meta/Tactic/FunInd.lean

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,9 @@ def rwLetWith (h : Expr) (e : Expr) : MetaM Simp.Result := do
641641
return { expr := e.letBody!.instantiate1 h }
642642
return { expr := e }
643643

644+
def rwMData (e : Expr) : MetaM Simp.Result := do
645+
return { expr := e.consumeMData }
646+
644647
def rwHaveWith (h : Expr) (e : Expr) : MetaM Simp.Result := do
645648
if let some (_n, t, _v, b) := e.letFun? then
646649
if (← isDefEq t (← inferType h)) then
@@ -674,11 +677,12 @@ def rwMatcher (altIdx : Nat) (e : Expr) : MetaM Simp.Result := do
674677
return { expr := e }
675678
else
676679
unless (← isMatcherApp e) do
680+
trace[Meta.FunInd] "Not a matcher application:{indentExpr e}"
677681
return { expr := e }
678682
let matcherDeclName := e.getAppFn.constName!
679683
let eqns ← Match.genMatchCongrEqns matcherDeclName
680684
unless altIdx < eqns.size do
681-
trace[Tactic.FunInd] "When trying to reduce arm {altIdx}, only {eqns.size} equations for {.ofConstName matcherDeclName}"
685+
trace[Meta.FunInd] "When trying to reduce arm {altIdx}, only {eqns.size} equations for {.ofConstName matcherDeclName}"
682686
return { expr := e }
683687
let eqnThm := eqns[altIdx]!
684688
try
@@ -865,7 +869,8 @@ partial def buildInductionBody (toErase toClear : Array FVarId) (goal : Expr)
865869

866870
-- we look through mdata
867871
if e.isMData then
868-
let b ← buildInductionBody toErase toClear goal oldIH newIH isRecCall e.mdataExpr!
872+
let b ← withRewrittenMotiveArg goal (rwMData) fun goal' =>
873+
buildInductionBody toErase toClear goal' oldIH newIH isRecCall e.mdataExpr!
869874
return e.updateMData! b
870875

871876
if let .letE n t v b _ := e then

tests/lean/run/funind_unfolding.lean

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -572,19 +572,8 @@ info: binaryWithMatch.induct_unfolding (motive : Nat → Nat → Nat → Prop)
572572
(case1 :
573573
∀ (a b : Nat),
574574
decide (a < b) = true →
575-
motive (a - 1) (b - 1) (binaryWithMatch (a - 1) (b - 1)) →
576-
motive a b
577-
(match h : decide (a < b) with
578-
| true => 1 + binaryWithMatch (a - 1) (b - 1)
579-
| false => 0))
580-
(case2 :
581-
∀ (a b : Nat),
582-
decide (a < b) = false →
583-
motive a b
584-
(match h : decide (a < b) with
585-
| true => 1 + binaryWithMatch (a - 1) (b - 1)
586-
| false => 0))
587-
(a b : Nat) : motive a b (binaryWithMatch a b)
575+
motive (a - 1) (b - 1) (binaryWithMatch (a - 1) (b - 1)) → motive a b (1 + binaryWithMatch (a - 1) (b - 1)))
576+
(case2 : ∀ (a b : Nat), decide (a < b) = false → motive a b 0) (a b : Nat) : motive a b (binaryWithMatch a b)
588577
-/
589578
#guard_msgs in
590579
#check binaryWithMatch.induct_unfolding

tests/lean/run/grind_congrArg.lean

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)