Pickling #95

Open
opened 2024-09-06 22:38:16 -07:00 by aniva · 1 comment
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/Environment
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
aniva added a new dependency 2024-11-14 23:10:49 -08:00
aniva modified the milestone from 0.3 to 0.2.21 2024-11-15 23:10:44 -08:00
Author
Owner

Pickling of environments was implemented in #120. Tests are pending.

Pickling of environments was implemented in #120. Tests are pending.
aniva added the
part/Serial
part/REPL
labels 2024-11-19 01:29:35 -08: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.

Reference: aniva/Pantograph#95
No description provided.