Skip to content

Commit b9c90bf

Browse files
committed
Proof step verification using kernel. leanprover-community#2
1 parent d1995df commit b9c90bf

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

REPL/Main.lean

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,22 @@ def getProofStatus (proofState : ProofSnapshot) : M m String := do
247247
| _ => return "Incomplete: open goals remain"
248248

249249
/--
250-
Returns a list of pairs of metavariables and their assignments from a proof state.
251-
Each pair contains the MVarId and its assigned Expr.
250+
Returns a list of newly assigned metavariables and their expressions,
251+
comparing the current proof state with an optional old proof state.
252+
If no old state is provided, returns all assigned MVars.
252253
-/
253-
def getAssignedMVars (proofState : ProofSnapshot) : M m (List (MVarId × Expr)) := do
254+
def getNewlyAssignedMVars (proofState : ProofSnapshot) (oldProofState? : Option ProofSnapshot := none) :
255+
M m (List (MVarId × Expr)) := do
256+
-- Get all goals from both states
257+
let allGoals := match oldProofState? with
258+
| none => proofState.tacticState.goals
259+
| some oldState =>
260+
(proofState.tacticState.goals ++ oldState.tacticState.goals).eraseDups
261+
262+
-- Check which have assignments in new state
254263
let (assignments, _) ← proofState.runMetaM do
255264
let mut assignments := []
256-
for goalId in proofState.tacticState.goals do
265+
for goalId in allGoals do
257266
match proofState.metaState.mctx.getExprAssignmentCore? goalId with
258267
| none => continue
259268
| some pf => do
@@ -262,31 +271,6 @@ def getAssignedMVars (proofState : ProofSnapshot) : M m (List (MVarId × Expr))
262271
return assignments
263272
return assignments
264273

265-
/--
266-
Returns a list of newly assigned metavariables and their expressions,
267-
comparing the current proof state with an optional old proof state.
268-
If no old state is provided, returns all assigned MVars.
269-
Returns assignments from both states, preferring new assignments in case of conflicts.
270-
-/
271-
def getNewlyAssignedMVars (proofState : ProofSnapshot) (oldProofState? : Option ProofSnapshot := none) :
272-
M m (List (MVarId × Expr)) := do
273-
let newAssignments ← getAssignedMVars proofState
274-
match oldProofState? with
275-
| none => return newAssignments
276-
| some oldState => do
277-
let oldAssignments ← getAssignedMVars oldState
278-
-- Get all assignments from both states, preferring new assignments
279-
let mut result := []
280-
-- First add all new assignments
281-
for assignment in newAssignments do
282-
result := assignment :: result
283-
-- Then add old assignments that don't have a corresponding new one
284-
for (mvarId, expr) in oldAssignments do
285-
if !newAssignments.any (·.1 == mvarId) then
286-
result := (mvarId, expr) :: result
287-
288-
return result
289-
290274
/--
291275
Verifies that all assigned goals in the proof state have valid assignments that type check.
292276
Returns either "OK" or an error message describing the first failing goal.

0 commit comments

Comments
 (0)