refactor: Code simplification

This commit is contained in:
Leni Aniva 2024-04-11 16:25:17 -07:00
parent dc6e79def7
commit e834765896
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
1 changed files with 18 additions and 19 deletions

View File

@ -164,7 +164,6 @@ protected def GoalState.assign (state: GoalState) (goal: MVarId) (expr: Expr):
let messages := (← getThe Core.State).messages.getErrorMessages |>.toList.toArray let messages := (← getThe Core.State).messages.getErrorMessages |>.toList.toArray
let errors ← (messages.map Message.data).mapM fun md => md.toString let errors ← (messages.map Message.data).mapM fun md => md.toString
return .failure errors return .failure errors
else
let prevMCtx := state.savedState.term.meta.meta.mctx let prevMCtx := state.savedState.term.meta.meta.mctx
let nextMCtx ← getMCtx let nextMCtx ← getMCtx
-- Generate a list of mvarIds that exist in the parent state; Also test the -- Generate a list of mvarIds that exist in the parent state; Also test the
@ -346,10 +345,10 @@ protected def GoalState.tryCalc (state: GoalState) (goalId: Nat) (pred: String):
| .ok syn => pure syn | .ok syn => pure syn
| .error error => return .parseError error | .error error => return .parseError error
let calcPrevRhs? := state.calcPrevRhsOf? goalId let calcPrevRhs? := state.calcPrevRhsOf? goalId
try
goal.withContext do
let target ← instantiateMVars (← goal.getDecl).type let target ← instantiateMVars (← goal.getDecl).type
let tag := (← goal.getDecl).userName let tag := (← goal.getDecl).userName
try
goal.withContext do
let mut step ← Elab.Term.elabType <| ← do let mut step ← Elab.Term.elabType <| ← do
if let some prevRhs := calcPrevRhs? then if let some prevRhs := calcPrevRhs? then
@ -377,7 +376,7 @@ protected def GoalState.tryCalc (state: GoalState) (goalId: Nat) (pred: String):
-- The calc tactic either solves the main goal or leaves another relation. -- The calc tactic either solves the main goal or leaves another relation.
-- Replace the main goal, and save the new goal if necessary -- Replace the main goal, and save the new goal if necessary
if ¬(← Meta.isDefEq proofType target) then unless ← Meta.isDefEq proofType target do
let rec throwFailed := let rec throwFailed :=
throwError "'calc' tactic failed, has type{indentExpr proofType}\nbut it is expected to have type{indentExpr target}" throwError "'calc' tactic failed, has type{indentExpr proofType}\nbut it is expected to have type{indentExpr target}"
let some (_, _, rhs) ← Elab.Term.getCalcRelation? proofType | throwFailed let some (_, _, rhs) ← Elab.Term.getCalcRelation? proofType | throwFailed