feat: Prograde tactics #83

Merged
aniva merged 24 commits from tactic/eval into dev 2024-08-31 20:04:39 -07:00
1 changed files with 6 additions and 6 deletions
Showing only changes of commit 0c469027c6 - Show all commits

View File

@ -4,7 +4,8 @@ open Lean
namespace Pantograph.Tactic namespace Pantograph.Tactic
def assign (goal: MVarId) (expr: Expr): MetaM (List MVarId) := do /-- WARNING: This should be used with a function like `elabTermWithHoles` that properly collects the mvar information from `expr`. -/
def assign (goal: MVarId) (expr: Expr) (nextGoals: List MVarId): MetaM (List MVarId) := do
goal.checkNotAssigned `Pantograph.Tactic.assign goal.checkNotAssigned `Pantograph.Tactic.assign
-- This run of the unifier is critical in resolving mvars in passing -- This run of the unifier is critical in resolving mvars in passing
@ -12,19 +13,18 @@ def assign (goal: MVarId) (expr: Expr): MetaM (List MVarId) := do
let goalType ← goal.getType let goalType ← goal.getType
unless ← Meta.isDefEq goalType exprType do unless ← Meta.isDefEq goalType exprType do
throwError s!"{← Meta.ppExpr expr} : {← Meta.ppExpr exprType} ≠ {← Meta.ppExpr goalType}" throwError s!"{← Meta.ppExpr expr} : {← Meta.ppExpr exprType} ≠ {← Meta.ppExpr goalType}"
-- FIXME: Use `withCollectingNewGoalsFrom`. Think about how this interacts with elaboration ...
let nextGoals ← Meta.getMVarsNoDelayed expr
goal.assign expr goal.assign expr
nextGoals.toList.filterM (not <$> ·.isAssigned) nextGoals.filterM (not <$> ·.isAssigned)
def evalAssign : Elab.Tactic.Tactic := fun stx => Elab.Tactic.withMainContext do def evalAssign : Elab.Tactic.Tactic := fun stx => Elab.Tactic.withMainContext do
let target ← Elab.Tactic.getMainTarget let target ← Elab.Tactic.getMainTarget
let goal ← Elab.Tactic.getMainGoal
goal.checkNotAssigned `Pantograph.Tactic.evalAssign
let (expr, nextGoals) ← Elab.Tactic.elabTermWithHoles stx let (expr, nextGoals) ← Elab.Tactic.elabTermWithHoles stx
(expectedType? := .some target) (expectedType? := .some target)
(tagSuffix := .anonymous ) (tagSuffix := .anonymous )
(allowNaturalHoles := true) (allowNaturalHoles := true)
(← Elab.Tactic.getMainGoal).assign expr goal.assign expr
Elab.Tactic.setGoals nextGoals Elab.Tactic.setGoals nextGoals