Skip to content

Commit 8870e1e

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

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

REPL/JSON.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ structure MetavarDecl.Json where
185185
userName : String
186186
type : String
187187
mvarsInType : List MVarId
188+
value : Option String
188189
deriving ToJson, FromJson
189190

190191
structure MetavarContext.Json where
@@ -200,6 +201,7 @@ def MetavarContext.toJson (mctx : MetavarContext) (ctx : ContextInfo) : IO Metav
200201
userName := toString decl.userName
201202
type := (← ctx.ppExpr {} decl.type).pretty
202203
mvarsInType := typeMVars.result.toList
204+
value := (mctx.getExprAssignmentCore? mvarId).map toString
203205
}
204206
return { decls }
205207

REPL/Main.lean

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,26 @@ def verifyGoalAssignment (ctx : ContextInfo) (proofState : ProofSnapshot) (oldPr
269269
| none => return s!"Goal {oldGoal.name} was not solved"
270270
| some pf => do
271271
let pf ← instantiateMVars pf
272+
let pft ← Meta.inferType pf >>= instantiateMVars
272273

273274
-- Check that all MVars in the proof are goals in new state
274-
-- let mvars ← Meta.getMVars pf
275275
let (_, mvars) ← ctx.runMetaM proofState.metaContext.lctx ((Meta.collectMVars pf).run {})
276-
IO.println s!"Goal {oldGoal.name} = {pf} ({mvars.result.map (·.name)})"
276+
-- IO.println s!"Goal {oldGoal.name} = {pf} ({mvars.result.map (·.name)})"
277+
let mut pfWithSorries := pf
277278
for mvar in mvars.result do
278279
-- If the metavariable in the assignment is a new goal, it's fine.
279280
unless proofState.tacticState.goals.contains mvar do
280281
return s!"Goal {oldGoal.name} assignment contains metavariables"
281282

283+
-- If the metavariable is a new goal, replace it with sorry so that we can check the proof.
284+
let sorryTerm ← Meta.mkSorry pft false
285+
pfWithSorries ← pure $ pfWithSorries.replace (
286+
fun e => if e == mkMVar mvar then some sorryTerm else none
287+
)
288+
let pf := pfWithSorries
289+
-- IO.println s!"Goal with sorries {oldGoal.name} = {pf}"
290+
282291
-- Check that proof has expected type
283-
let pft ← Meta.inferType pf >>= instantiateMVars
284292
let expectedType ← Meta.inferType (mkMVar oldGoal) >>= instantiateMVars
285293
unless (← Meta.isDefEq pft expectedType) do
286294
return s!"Error: proof has type {pft} but goal has type {expectedType}"

0 commit comments

Comments
 (0)