Skip to content

Commit 62412c4

Browse files
committed
feat: unpickle proof states using an existing environment
1 parent 8af54e4 commit 62412c4

6 files changed

+61
-6
lines changed

REPL/JSON.lean

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ deriving ToJson, FromJson
164164

165165
structure UnpickleProofState where
166166
unpickleProofStateFrom : System.FilePath
167+
env : Option Nat
167168
deriving ToJson, FromJson
168169

169170
end REPL

REPL/Main.lean

+10-3
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,16 @@ def pickleProofSnapshot (n : PickleProofState) : M m (ProofStepResponse ⊕ Erro
177177
return .inl (← createProofStepReponse proofState)
178178

179179
/-- Unpickle a `ProofSnapshot`, generating a JSON response. -/
180-
def unpickleProofSnapshot (n : UnpickleProofState) : M IO ProofStepResponse := do
181-
let (proofState, _) ← ProofSnapshot.unpickle n.unpickleProofStateFrom
182-
createProofStepReponse proofState
180+
def unpickleProofSnapshot (n : UnpickleProofState) : M IO (ProofStepResponse ⊕ Error) := do
181+
let (cmdSnapshot?, notFound) ← do match n.env with
182+
| none => pure (none, false)
183+
| some i => do match (← get).cmdStates[i]? with
184+
| some env => pure (some env, false)
185+
| none => pure (none, true)
186+
if notFound then
187+
return .inr ⟨"Unknown environment."
188+
let (proofState, _) ← ProofSnapshot.unpickle n.unpickleProofStateFrom cmdSnapshot?
189+
Sum.inl <$> createProofStepReponse proofState
183190

184191
/--
185192
Run a command, returning the id of the new environment, and any messages and sorries.

REPL/Snapshots.lean

+8-3
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,19 @@ def pickle (p : ProofSnapshot) (path : FilePath) : IO Unit := do
259259
/--
260260
Unpickle a `ProofSnapshot`.
261261
-/
262-
def unpickle (path : FilePath) : IO (ProofSnapshot × CompactedRegion) := unsafe do
262+
def unpickle (path : FilePath) (cmd? : Option CommandSnapshot) :
263+
IO (ProofSnapshot × CompactedRegion) := unsafe do
263264
let ((imports, map₂, coreState, coreContext, metaState, metaContext, termState, termContext,
264265
tacticState, tacticContext), region) ←
265266
_root_.unpickle (Array Import × PHashMap Name ConstantInfo × CompactableCoreState ×
266267
Core.Context × Meta.State × CompactableMetaContext × Term.State × CompactableTermContext ×
267268
Tactic.State × Tactic.Context) path
268-
enableInitializersExecution
269-
let env ← (← importModules imports {} 0).replay (HashMap.ofList map₂.toList)
269+
let env ← match cmd? with
270+
| none =>
271+
enableInitializersExecution
272+
(← importModules imports {} 0).replay (HashMap.ofList map₂.toList)
273+
| some cmd =>
274+
cmd.cmdState.env.replay (HashMap.ofList map₂.toList)
270275
let p' : ProofSnapshot :=
271276
{ coreState := { coreState with env }
272277
coreContext

test/import_lean.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"cmd" : "import Lean"}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{"env": 0}
2+
3+
{"sorries":
4+
[{"proofState": 0,
5+
"pos": {"line": 1, "column": 18},
6+
"goal": "⊢ Nat",
7+
"endPos": {"line": 1, "column": 23}}],
8+
"messages":
9+
[{"severity": "warning",
10+
"pos": {"line": 1, "column": 4},
11+
"endPos": {"line": 1, "column": 5},
12+
"data": "declaration uses 'sorry'"}],
13+
"env": 1}
14+
15+
{"proofState": 1, "goals": ["⊢ Nat"]}
16+
17+
{"proofState": 2, "goals": ["⊢ Nat"]}
18+
19+
{"proofState": 3, "goals": ["t : Nat\n⊢ Nat"]}
20+
21+
{"proofState": 4, "goals": ["t : Nat\n⊢ Nat"]}
22+
23+
{"proofState": 5, "goals": ["t : Nat\n⊢ Nat"]}
24+
25+
{"proofState": 6, "goals": []}
26+

test/pickle_proof_state_env.in

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{"cmd" : "import Lean"}
2+
3+
{"cmd" : "def f : Nat := by sorry", "env": 0}
4+
5+
{"pickleTo": "test/c.olean", "proofState": 0}
6+
7+
{"unpickleProofStateFrom": "test/c.olean", "env": 0}
8+
9+
{"tactic": "have t : Nat := 42", "proofState": 2}
10+
11+
{"pickleTo": "test/d.olean", "proofState": 3}
12+
13+
{"unpickleProofStateFrom": "test/d.olean", "env": 0}
14+
15+
{"tactic": "exact t", "proofState": 5}

0 commit comments

Comments
 (0)