@@ -246,6 +246,18 @@ def getProofStatus (proofState : ProofSnapshot) : M m String := do
246
246
247
247
| _ => return "Incomplete: open goals remain"
248
248
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
249
261
/--
250
262
Verifies that all goals from the old state are properly handled in the new state.
251
263
Returns either "OK" or an error message describing the first failing goal.
@@ -265,6 +277,7 @@ def verifyGoalAssignment (ctx : ContextInfo) (proofState : ProofSnapshot) (oldPr
265
277
266
278
let (res, _) ← proofState.runMetaM do
267
279
-- Check if goal is assigned in new state
280
+ -- TODO: maybe we need to check delayed assignment as well
268
281
match proofState.metaState.mctx.getExprAssignmentCore? oldGoal with
269
282
| none => return s! "Goal { oldGoal.name} was not solved"
270
283
| some pf => do
@@ -274,8 +287,23 @@ def verifyGoalAssignment (ctx : ContextInfo) (proofState : ProofSnapshot) (oldPr
274
287
-- Check that all MVars in the proof are goals in new state
275
288
let (_, mvars) ← ctx.runMetaM proofState.metaContext.lctx ((Meta.collectMVars pf).run {})
276
289
-- 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
+
277
298
let mut pfWithSorries := pf
278
299
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
+
279
307
-- If the metavariable in the assignment is a new goal, it's fine.
280
308
unless proofState.tacticState.goals.contains mvar do
281
309
return s! "Goal { oldGoal.name} assignment contains metavariables"
@@ -285,8 +313,12 @@ def verifyGoalAssignment (ctx : ContextInfo) (proofState : ProofSnapshot) (oldPr
285
313
pfWithSorries ← pure $ pfWithSorries.replace (
286
314
fun e => if e == mkMVar mvar then some sorryTerm else none
287
315
)
316
+ -- pfWithSorries ← replaceWithPrint (
317
+ -- fun e => if e == mkMVar mvar then some sorryTerm else none
318
+ -- ) pfWithSorries
288
319
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} "
290
322
291
323
-- Check that proof has expected type
292
324
let expectedType ← Meta.inferType (mkMVar oldGoal) >>= instantiateMVars
0 commit comments