@@ -6,29 +6,25 @@ Authors: Leonardo de Moura
66module
77
88prelude
9- public import Lean.Meta.Tactic.Subst
10- public import Lean.Meta.Match.Value
11-
12- public section
9+ public import Lean.Meta.Basic
10+ public import Lean.Meta.Tactic.FVarSubst
11+ import Lean.Meta.Tactic.Subst
1312
1413namespace Lean.Meta
1514
1615structure CaseValueSubgoal where
1716 mvarId : MVarId
1817 newH : FVarId
19- subst : FVarSubst := {}
2018 deriving Inhabited
2119
2220/--
2321 Split goal `... |- C x` into two subgoals
24- `..., (h : x = value) |- C value `
22+ `..., (h : x = value) |- C x `
2523 `..., (h : x != value) |- C x`
2624 where `fvarId` is `x`s id.
2725 The type of `x` must have decidable equality.
28-
29- Remark: `subst` field of the second subgoal is equal to the input `subst`. -/
30- private def caseValueAux (mvarId : MVarId) (fvarId : FVarId) (value : Expr) (hName : Name := `h)
31- (subst : FVarSubst := {})
26+ -/
27+ def caseValue (mvarId : MVarId) (fvarId : FVarId) (value : Expr) (hName : Name := `h)
3228 : MetaM (CaseValueSubgoal × CaseValueSubgoal) :=
3329 mvarId.withContext do
3430 let tag ← mvarId.getTag
@@ -43,18 +39,16 @@ private def caseValueAux (mvarId : MVarId) (fvarId : FVarId) (value : Expr) (hNa
4339 let val ← mkAppOptM `dite #[none, xEqValue, none, thenMVar, elseMVar]
4440 mvarId.assign val
4541 let (elseH, elseMVarId) ← elseMVar.mvarId!.intro1P
46- let elseSubgoal := { mvarId := elseMVarId, newH := elseH, subst := subst : CaseValueSubgoal }
42+ let elseSubgoal := { mvarId := elseMVarId, newH := elseH }
4743 let (thenH, thenMVarId) ← thenMVar.mvarId!.intro1P
4844 thenMVarId.withContext do
49- trace[Meta] "subst domain: {subst.domain.map (·.name)}"
50- let thenH := (subst.get thenH).fvarId!
5145 trace[Meta] "searching for decl"
5246 let _ ← thenH.getDecl
5347 trace[Meta] "found decl"
54- let thenSubgoal := { mvarId := thenMVarId, newH := (subst.get thenH).fvarId!, subst : CaseValueSubgoal }
48+ let thenSubgoal := { mvarId := thenMVarId, newH := thenH }
5549 pure (thenSubgoal, elseSubgoal)
5650
57- structure CaseValuesSubgoal where
51+ public structure CaseValuesSubgoal where
5852 mvarId : MVarId
5953 newHs : Array FVarId := #[]
6054 subst : FVarSubst := {}
@@ -75,18 +69,14 @@ structure CaseValuesSubgoal where
7569
7670 If `substNewEqs = true`, then the new `h_i` equality hypotheses are substituted in the first `n` cases.
7771-/
78- def caseValues (mvarId : MVarId) (fvarId : FVarId) (values : Array Expr) (hNamePrefix := `h) : MetaM (Array CaseValuesSubgoal) :=
72+ public def caseValues (mvarId : MVarId) (fvarId : FVarId) (values : Array Expr) (hNamePrefix := `h) : MetaM (Array CaseValuesSubgoal) :=
7973 let rec loop : Nat → MVarId → List Expr → Array FVarId → Array CaseValuesSubgoal → MetaM (Array CaseValuesSubgoal)
8074 | _, mvarId, [], _, _ => throwTacticEx `caseValues mvarId "list of values must not be empty"
8175 | i, mvarId, v::vs, hs, subgoals => do
82- let (thenSubgoal, elseSubgoal) ← caseValueAux mvarId fvarId v (hNamePrefix.appendIndexAfter i) {}
76+ let (thenSubgoal, elseSubgoal) ← caseValue mvarId fvarId v (hNamePrefix.appendIndexAfter i)
8377 appendTagSuffix thenSubgoal.mvarId ((`case).appendIndexAfter i)
84- let thenMVarId ← hs.foldlM
85- (fun thenMVarId h => match thenSubgoal.subst.get h with
86- | Expr.fvar fvarId => thenMVarId.tryClear fvarId
87- | _ => pure thenMVarId)
88- thenSubgoal.mvarId
89- let (subst, mvarId) ← substCore thenMVarId thenSubgoal.newH (symm := false ) thenSubgoal.subst (clearH := true )
78+ let thenMVarId ← thenSubgoal.mvarId.tryClearMany hs
79+ let (subst, mvarId) ← substCore thenMVarId thenSubgoal.newH (symm := false ) {} (clearH := true )
9080 let subgoals := subgoals.push { mvarId := mvarId, newHs := #[], subst := subst }
9181 match vs with
9282 | [] => do
0 commit comments