feat: Conv tactic mode
This commit is contained in:
parent
d50720f622
commit
19d2f5ff3f
|
@ -253,21 +253,15 @@ protected def GoalState.tryConv (state: GoalState) (goalId: Nat):
|
||||||
| .none => return .indexError goalId
|
| .none => return .indexError goalId
|
||||||
let tacticM : Elab.Tactic.TacticM Elab.Tactic.SavedState:= do
|
let tacticM : Elab.Tactic.TacticM Elab.Tactic.SavedState:= do
|
||||||
state.restoreTacticM goal
|
state.restoreTacticM goal
|
||||||
--let mm ← Meta.matchEq? (← goal.getType)
|
|
||||||
--if let .some (_, _, rhs) := mm then
|
-- TODO: Fail if this is already in conv
|
||||||
-- if rhs.getAppFn.isMVar then
|
|
||||||
-- IO.println "isMVar ok"
|
-- See Lean.Elab.Tactic.Conv.convTarget
|
||||||
-- else
|
Elab.Tactic.withMainContext do
|
||||||
-- IO.println "isMVar failed"
|
-- TODO: Memorize this `rhs` as a conv resultant goal
|
||||||
--else
|
let (rhs, newGoal) ← Elab.Tactic.Conv.mkConvGoalFor (← Elab.Tactic.getMainTarget)
|
||||||
-- IO.println "matchEq? failed"
|
Elab.Tactic.setGoals [newGoal.mvarId!]
|
||||||
IO.println s!"Old goals: {(← Elab.Tactic.getGoals).map (λ x => x.name.toString)}"
|
--Elab.Tactic.liftMetaTactic1 fun mvarId => mvarId.replaceTargetEq rhs proof
|
||||||
--Elab.Tactic.Conv.remarkAsConvGoal
|
|
||||||
let goalNew ← Elab.Tactic.Conv.markAsConvGoal goal
|
|
||||||
-- TODO: Error if `goal == goalNew`
|
|
||||||
Elab.Tactic.setGoals [goalNew]
|
|
||||||
--Elab.Tactic.Conv.remarkAsConvGoal
|
|
||||||
IO.println s!"New goals: {(← Elab.Tactic.getGoals).map (λ x => x.name.toString)}"
|
|
||||||
MonadBacktrack.saveState
|
MonadBacktrack.saveState
|
||||||
let nextSavedState ← tacticM { elaborator := .anonymous } |>.run' state.savedState.tactic
|
let nextSavedState ← tacticM { elaborator := .anonymous } |>.run' state.savedState.tactic
|
||||||
let prevMCtx := state.savedState.term.meta.meta.mctx
|
let prevMCtx := state.savedState.term.meta.meta.mctx
|
||||||
|
@ -293,7 +287,7 @@ protected def GoalState.tryConvTactic (state: GoalState) (goalId: Nat) (convTact
|
||||||
| .error error => return .parseError error
|
| .error error => return .parseError error
|
||||||
let tacticM : Elab.Tactic.TacticM Elab.Tactic.SavedState:= do
|
let tacticM : Elab.Tactic.TacticM Elab.Tactic.SavedState:= do
|
||||||
state.restoreTacticM goal
|
state.restoreTacticM goal
|
||||||
Elab.Tactic.Conv.evalConvTactic convTactic
|
Elab.Tactic.evalTactic convTactic
|
||||||
MonadBacktrack.saveState
|
MonadBacktrack.saveState
|
||||||
let nextSavedState ← tacticM { elaborator := .anonymous } |>.run' state.savedState.tactic
|
let nextSavedState ← tacticM { elaborator := .anonymous } |>.run' state.savedState.tactic
|
||||||
let nextMCtx := nextSavedState.term.meta.meta.mctx
|
let nextMCtx := nextSavedState.term.meta.meta.mctx
|
||||||
|
|
|
@ -401,7 +401,7 @@ def test_conv: TestM Unit := do
|
||||||
addTest $ assertUnreachable $ other.toString
|
addTest $ assertUnreachable $ other.toString
|
||||||
return ()
|
return ()
|
||||||
addTest $ LSpec.check "conv => ..." ((← state2.serializeGoals (options := ← read)).map (·.devolatilize) =
|
addTest $ LSpec.check "conv => ..." ((← state2.serializeGoals (options := ← read)).map (·.devolatilize) =
|
||||||
#[{ buildGoal [("a", "Nat"), ("b", "Nat"), ("c", "Nat")] "a + b + c" with isConversion := true }])
|
#[{ buildGoal [("a", "Nat"), ("b", "Nat"), ("c", "Nat")] "a + b + c = b + a + c" with isConversion := true }])
|
||||||
|
|
||||||
let convTactic := "lhs"
|
let convTactic := "lhs"
|
||||||
let state3L ← match ← state2.tryConvTactic (goalId := 0) (convTactic := convTactic) with
|
let state3L ← match ← state2.tryConvTactic (goalId := 0) (convTactic := convTactic) with
|
||||||
|
|
Loading…
Reference in New Issue