fix(serial): Erase closures in synthetic mvars #240

Merged
aniva merged 4 commits from bug/synthetic-mvar-closure into dev 2025-07-13 23:00:22 -07:00
1 changed files with 9 additions and 2 deletions
Showing only changes of commit e58becd14a - Show all commits

View File

@ -106,11 +106,17 @@ structure CompactCoreState where
-- env : Environment -- env : Environment
nextMacroScope : MacroScope := firstFrontendMacroScope + 1 nextMacroScope : MacroScope := firstFrontendMacroScope + 1
ngen : NameGenerator := {} ngen : NameGenerator := {}
auxDeclNGen : DeclNameGenerator := {}
-- traceState : TraceState := {} -- traceState : TraceState := {}
-- cache : Cache := {} -- cache : Cache := {}
-- messages : MessageLog := {} -- messages : MessageLog := {}
-- infoState : Elab.InfoState := {} -- infoState : Elab.InfoState := {}
/-- Pickles a goal state by taking its diff relative to a background
environment. This function eliminates all `MessageData` from synthetic
metavariables, because these `MessageData` objects frequently carry closures,
which cannot be pickled. If there is no synthetic metavariable, this would not
cause a difference. -/
@[export pantograph_goal_state_pickle_m] @[export pantograph_goal_state_pickle_m]
def goalStatePickle (goalState : GoalState) (path : System.FilePath) (background? : Option Environment := .none) def goalStatePickle (goalState : GoalState) (path : System.FilePath) (background? : Option Environment := .none)
: IO Unit := : IO Unit :=
@ -119,7 +125,7 @@ def goalStatePickle (goalState : GoalState) (path : System.FilePath) (background
term := { term := {
meta := { meta := {
core := { core := {
env, nextMacroScope, ngen, .. env, nextMacroScope, ngen, auxDeclNGen, ..
}, },
meta, meta,
} }
@ -133,6 +139,7 @@ def goalStatePickle (goalState : GoalState) (path : System.FilePath) (background
parentMVars, parentMVars,
fragments, fragments,
} := goalState } := goalState
-- Delete `MessageData`s
let syntheticMVars : MVarIdMap _ := syntheticMVars.fold (init := .empty) λ acc key val => let syntheticMVars : MVarIdMap _ := syntheticMVars.fold (init := .empty) λ acc key val =>
let kind := match val.kind with let kind := match val.kind with
| .typeClass _ => .typeClass .none | .typeClass _ => .typeClass .none
@ -142,7 +149,7 @@ def goalStatePickle (goalState : GoalState) (path : System.FilePath) (background
pickle path ( pickle path (
distillEnvironment env background?, distillEnvironment env background?,
({ nextMacroScope, ngen } : CompactCoreState), ({ nextMacroScope, ngen, auxDeclNGen } : CompactCoreState),
meta, meta,
{ «elab» with syntheticMVars }, { «elab» with syntheticMVars },
tactic, tactic,