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 | |