Pickling #95

Open
opened 2024-09-06 22:38:16 -07:00 by aniva · 0 comments
Owner

We should have this wonderful feature, pickling from, REPL:

import REPL.Util.Pickle
import Lean.Replay

open System (FilePath)

namespace Lean.Environment

/--
Pickle an `Environment` to disk.

We only store:
* the list of imports
* the new constants from `Environment.constants`
and when unpickling, we build a fresh `Environment` from the imports,
and then add the new constants.
-/
def pickle (env : Environment) (path : FilePath) : IO Unit :=
  _root_.pickle path (env.header.imports, env.constants.map₂)

/--
Unpickle an `Environment` from disk.

We construct a fresh `Environment` with the relevant imports,
and then replace the new constants.
-/
def unpickle (path : FilePath) : IO (Environment × CompactedRegion) := unsafe do
  let ((imports, map₂), region) ← _root_.unpickle (Array Import × PHashMap Name ConstantInfo) path
  let env ← importModules imports {} 0
  return (← env.replay (HashMap.ofList map₂.toList), region)

end Lean.Environment
We should have this wonderful feature, pickling from, [REPL](https://github.com/leanprover-community/repl/blob/adbbfcb9d4e61c12db96c45d227de92f21cc17dd/REPL/Lean/Environment.lean): ```lean import REPL.Util.Pickle import Lean.Replay open System (FilePath) namespace Lean.Environment /-- Pickle an `Environment` to disk. We only store: * the list of imports * the new constants from `Environment.constants` and when unpickling, we build a fresh `Environment` from the imports, and then add the new constants. -/ def pickle (env : Environment) (path : FilePath) : IO Unit := _root_.pickle path (env.header.imports, env.constants.map₂) /-- Unpickle an `Environment` from disk. We construct a fresh `Environment` with the relevant imports, and then replace the new constants. -/ def unpickle (path : FilePath) : IO (Environment × CompactedRegion) := unsafe do let ((imports, map₂), region) ← _root_.unpickle (Array Import × PHashMap Name ConstantInfo) path let env ← importModules imports {} 0 return (← env.replay (HashMap.ofList map₂.toList), region) end Lean.Environment ```
aniva added the
part/Environemnt
category
feature
labels 2024-09-06 22:38:16 -07:00
aniva self-assigned this 2024-09-06 22:38:16 -07:00
aniva added this to the 0.3 milestone 2024-09-08 13:48:58 -07:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: aniva/Pantograph#95
No description provided.