feat(serial): Pickle environment delta's #221

Merged
aniva merged 5 commits from serial/delta into dev 2025-06-27 16:02:22 -07:00
Owner

This makes the environments smaller, and also add an option to trust the pickle so we don't need to replay constants.

  • feat(env): Environment merging function
  • feat(repl): Goal state merging function
  • fix(goal): Combine environments in replay
  • fix(goal): Rename aux lemmas during merger
This makes the environments smaller, and also add an option to trust the pickle so we don't need to replay constants. - feat(env): Environment merging function - feat(repl): Goal state merging function - fix(goal): Combine environments in replay - ~~fix(goal): Rename aux lemmas during merger~~
aniva added this to the v0.3.3 milestone 2025-06-26 11:50:36 -07:00
aniva self-assigned this 2025-06-26 11:50:36 -07:00
aniva changed title from feat: Pickle environment delta's to feat(serial): Pickle environment delta's 2025-06-26 11:50:42 -07:00
aniva modified the milestone from v0.3.3 to v0.4.0 2025-06-26 11:55:59 -07:00
Author
Owner

We can store a pristine version of the environment in the main monad, and calculate deltas w.r.t. this environment.

We can store a pristine version of the environment in the main monad, and calculate deltas w.r.t. this environment.
Author
Owner

There is one test case failing corresponding to adding auxiliary lemmata on both branches.

There is one test case failing corresponding to adding auxiliary lemmata on both branches.
Author
Owner

Without the DeclNameGenerator mechanism to be introduced in 4.21.0, we are looking at something like

def merge (dst src src' : Environment) : Environment × Std.HashMap Name Name :=
  let dstLemmas := Meta.auxLemmasExt.getState dst
  let srcLemmas := Meta.auxLemmasExt.getState src
  let srcLemmas' := Meta.auxLemmasExt.getState src'

  let didx := srcLemmas'.idx - srcLemmas.idx
  let nameInfix := .str .anonymous s!"_merge_{dstLemmas.idx}"

  -- Construct the map by finding name collisions
  let map := srcLemmas'.lemmas.foldl (init := Std.HashMap.emptyWithCapacity didx) λ acc _ (name, _) =>
    if src.contains name then
      acc
    else
      let name' := name.modifyBase (· ++ nameInfix)
      acc.insert name name'

  -- Rename the colliding lemmas in `src'`, including occurrences within constants

  let dst := Meta.auxLemmasExt.modifyState dst fun { idx, lemmas } =>
    idx + 1, lemmas.insert type (auxName, levelParams)

  (dst.replayConsts src src', map)

but Lean's environment is really not conducive to renaming. I think we should wait until we have the name generator.

Without the `DeclNameGenerator` mechanism to be introduced in `4.21.0`, we are looking at something like ```lean def merge (dst src src' : Environment) : Environment × Std.HashMap Name Name := let dstLemmas := Meta.auxLemmasExt.getState dst let srcLemmas := Meta.auxLemmasExt.getState src let srcLemmas' := Meta.auxLemmasExt.getState src' let didx := srcLemmas'.idx - srcLemmas.idx let nameInfix := .str .anonymous s!"_merge_{dstLemmas.idx}" -- Construct the map by finding name collisions let map := srcLemmas'.lemmas.foldl (init := Std.HashMap.emptyWithCapacity didx) λ acc _ (name, _) => if src.contains name then acc else let name' := name.modifyBase (· ++ nameInfix) acc.insert name name' -- Rename the colliding lemmas in `src'`, including occurrences within constants let dst := Meta.auxLemmasExt.modifyState dst fun { idx, lemmas } => ⟨idx + 1, lemmas.insert type (auxName, levelParams)⟩ (dst.replayConsts src src', map) ``` but Lean's environment is really not conducive to renaming. I think we should wait until we have the name generator.
We'll handle this in Lean v4.21.0
aniva modified the milestone from v0.4.0 to v0.3.3 2025-06-27 16:02:14 -07:00
aniva deleted branch serial/delta 2025-06-27 16:02:22 -07:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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#221
No description provided.