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
2 changed files with 26 additions and 2 deletions
Showing only changes of commit e3b62dfeec - Show all commits

View File

@ -123,7 +123,9 @@ def goalStatePickle (goalState : GoalState) (path : System.FilePath) (background
}, },
meta, meta,
} }
«elab», «elab» := «elab»@{
syntheticMVars, ..
},
}, },
tactic tactic
} }
@ -131,12 +133,18 @@ def goalStatePickle (goalState : GoalState) (path : System.FilePath) (background
parentMVars, parentMVars,
fragments, fragments,
} := goalState } := goalState
let syntheticMVars : MVarIdMap _ := syntheticMVars.fold (init := .empty) λ acc key val =>
let kind := match val.kind with
| .typeClass _ => .typeClass .none
| .coe header? expectedType e f? _ => .coe header? expectedType e f? .none
| k => k
acc.insert key { val with kind }
pickle path ( pickle path (
distillEnvironment env background?, distillEnvironment env background?,
({ nextMacroScope, ngen } : CompactCoreState), ({ nextMacroScope, ngen } : CompactCoreState),
meta, meta,
«elab», { «elab» with syntheticMVars },
tactic, tactic,
root, root,

View File

@ -96,6 +96,21 @@ def test_pickling_env_extensions : TestM Unit := do
return () return ()
/-- Synthetic mvars in this case creates closures. These cannot be pickled. -/
def test_pickling_synthetic_mvars : TestM Unit := do
let coreSrc : Core.State := { env := ← getEnv }
IO.FS.withTempFile λ _ statePath => do
let stateGenerate : MetaM GoalState := runTermElabMInMeta do
let type ← Elab.Term.elabTerm (← `(term|(0 : Nat) < 1)) .none
let state ← GoalState.create type
let .success state _ ← state.tryHave .unfocus "h" "0 < 2" | unreachable!
assert! state.savedState.term.elab.syntheticMVars.size > 0
return state
let ((), _) ← runCoreM coreSrc do
let state ← stateGenerate.run'
goalStatePickle state statePath
structure Test where structure Test where
name : String name : String
routine: TestM Unit routine: TestM Unit
@ -115,6 +130,7 @@ def suite (env : Environment): List (String × IO LSpec.TestSeq) :=
let tests: List Test := [ let tests: List Test := [
{ name := "environment", routine := test_pickling_environment, }, { name := "environment", routine := test_pickling_environment, },
{ name := "goal simple", routine := test_goal_state_simple, }, { name := "goal simple", routine := test_goal_state_simple, },
{ name := "goal synthetic mvars", routine := test_pickling_synthetic_mvars, },
{ name := "extensions", routine := test_pickling_env_extensions, }, { name := "extensions", routine := test_pickling_env_extensions, },
] ]
tests.map (fun test => (test.name, test.run env)) tests.map (fun test => (test.name, test.run env))