Skip to content

Commit 4ac2b89

Browse files
committed
Proof step verification using kernel. leanprover-community#5
1 parent 8870e1e commit 4ac2b89

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

REPL/Main.lean

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ def getProofStatus (proofState : ProofSnapshot) : M m String := do
246246

247247
| _ => return "Incomplete: open goals remain"
248248

249+
def replaceWithPrint (f? : Expr → Option Expr) (e : Expr) : MetaM Expr := do
250+
IO.println s!"Processing expression: {e}"
251+
match f? e with
252+
| some eNew => return eNew
253+
| none => match e with
254+
| .forallE _ d b _ => let d ← replaceWithPrint f? d; let b ← replaceWithPrint f? b; return e.updateForallE! d b
255+
| .lam _ d b _ => let d ← replaceWithPrint f? d; let b ← replaceWithPrint f? b; return e.updateLambdaE! d b
256+
| .mdata _ b => let b ← replaceWithPrint f? b; return e.updateMData! b
257+
| .letE _ t v b _ => let t ← replaceWithPrint f? t; let v ← replaceWithPrint f? v; let b ← replaceWithPrint f? b; return e.updateLet! t v b
258+
| .app f a => let f ← replaceWithPrint f? f; let a ← replaceWithPrint f? a; return e.updateApp! f a
259+
| .proj _ _ b => let b ← replaceWithPrint f? b; return e.updateProj! b
260+
| e => return e
249261
/--
250262
Verifies that all goals from the old state are properly handled in the new state.
251263
Returns either "OK" or an error message describing the first failing goal.
@@ -265,6 +277,7 @@ def verifyGoalAssignment (ctx : ContextInfo) (proofState : ProofSnapshot) (oldPr
265277

266278
let (res, _) ← proofState.runMetaM do
267279
-- Check if goal is assigned in new state
280+
-- TODO: maybe we need to check delayed assignment as well
268281
match proofState.metaState.mctx.getExprAssignmentCore? oldGoal with
269282
| none => return s!"Goal {oldGoal.name} was not solved"
270283
| some pf => do
@@ -274,8 +287,23 @@ def verifyGoalAssignment (ctx : ContextInfo) (proofState : ProofSnapshot) (oldPr
274287
-- Check that all MVars in the proof are goals in new state
275288
let (_, mvars) ← ctx.runMetaM proofState.metaContext.lctx ((Meta.collectMVars pf).run {})
276289
-- IO.println s!"Goal {oldGoal.name} = {pf} ({mvars.result.map (·.name)})"
290+
-- for mvar in mvars.result do
291+
-- let assignment? ← getExprMVarAssignment? mvar
292+
-- let delayedAssignment? ← getDelayedMVarAssignment? mvar
293+
-- match assignment?, delayedAssignment? with
294+
-- | some a, _ => IO.println s!"Assignment for {mvar.name}: {a}"
295+
-- | _, some d => IO.println s!"Delayed assignment for {mvar.name}: {d.mvarIdPending.name}"
296+
-- | none, none => IO.println s!"No assignment for {mvar.name}"
297+
277298
let mut pfWithSorries := pf
278299
for mvar in mvars.result do
300+
let assigned ← mvar.isAssigned
301+
let delayedAssigned ← mvar.isDelayedAssigned
302+
-- We only care about the leaf metavariables.
303+
-- TODO: verify this reasoning (especially for delayed assignments)
304+
if assigned || delayedAssigned then
305+
continue
306+
279307
-- If the metavariable in the assignment is a new goal, it's fine.
280308
unless proofState.tacticState.goals.contains mvar do
281309
return s!"Goal {oldGoal.name} assignment contains metavariables"
@@ -285,8 +313,12 @@ def verifyGoalAssignment (ctx : ContextInfo) (proofState : ProofSnapshot) (oldPr
285313
pfWithSorries ← pure $ pfWithSorries.replace (
286314
fun e => if e == mkMVar mvar then some sorryTerm else none
287315
)
316+
-- pfWithSorries ← replaceWithPrint (
317+
-- fun e => if e == mkMVar mvar then some sorryTerm else none
318+
-- ) pfWithSorries
288319
let pf := pfWithSorries
289-
-- IO.println s!"Goal with sorries {oldGoal.name} = {pf}"
320+
let pf ← instantiateMVars pf
321+
IO.println s!"Goal with sorries {oldGoal.name} = {pf}"
290322

291323
-- Check that proof has expected type
292324
let expectedType ← Meta.inferType (mkMVar oldGoal) >>= instantiateMVars

0 commit comments

Comments
 (0)