@@ -194,24 +194,24 @@ def parIterGreedy {α : Type} (jobs : List (CoreM α)) :=
194194
195195/--
196196Runs a list of CoreM computations in parallel and collects results in the original order,
197- including the state after each task completes.
197+ including the saved state after each task completes.
198198
199199Unlike `parIter`, this waits for all tasks to complete and returns results
200200in the same order as the input list, not in completion order.
201201
202- Results are wrapped in `Except Exception (α × Core.State )` so that errors in individual
202+ Results are wrapped in `Except Exception (α × Core.SavedState )` so that errors in individual
203203tasks don't stop the collection - you can observe all results including which tasks failed.
204204
205205The final CoreM state is restored to the initial state (before tasks ran).
206206-/
207- def par {α : Type } (jobs : List (CoreM α)) : CoreM (List (Except Exception (α × Core.State ))) := do
207+ def par {α : Type } (jobs : List (CoreM α)) : CoreM (List (Except Exception (α × Core.SavedState ))) := do
208208 let initialState ← get
209209 let tasks ← jobs.mapM asTask'
210210 let mut results := []
211211 for task in tasks do
212212 let resultWithState ← observing do
213213 let result ← task.get
214- pure (result, (← get ))
214+ pure (result, (← saveState ))
215215 results := resultWithState :: results
216216 set initialState
217217 return results.reverse
@@ -261,25 +261,24 @@ open Std.Iterators
261261
262262/--
263263Runs a list of MetaM computations in parallel and collects results in the original order,
264- including the state after each task completes.
264+ including the saved state after each task completes.
265265
266266Unlike `parIter`, this waits for all tasks to complete and returns results
267267in the same order as the input list, not in completion order.
268268
269- Results are wrapped in `Except Exception (α × Meta.State )` so that errors in individual
269+ Results are wrapped in `Except Exception (α × Meta.SavedState )` so that errors in individual
270270tasks don't stop the collection - you can observe all results including which tasks failed.
271271
272272The final MetaM state is restored to the initial state (before tasks ran).
273- Note: Only Meta.State is captured/reverted, not Core.State or IO effects.
274273-/
275- def par {α : Type } (jobs : List (MetaM α)) : MetaM (List (Except Exception (α × Meta.State ))) := do
274+ def par {α : Type } (jobs : List (MetaM α)) : MetaM (List (Except Exception (α × Meta.SavedState ))) := do
276275 let initialState ← get
277276 let tasks ← jobs.mapM asTask'
278277 let mut results := []
279278 for task in tasks do
280279 let resultWithState ← observing do
281280 let result ← task.get
282- pure (result, (← get ))
281+ pure (result, (← saveState ))
283282 results := resultWithState :: results
284283 set initialState
285284 return results.reverse
@@ -465,27 +464,24 @@ def parIterGreedy {α : Type} (jobs : List (TermElabM α)) :=
465464
466465/--
467466Runs a list of TermElabM computations in parallel and collects results in the original order,
468- including the state after each task completes.
467+ including the saved state after each task completes.
469468
470469Unlike `parIter`, this waits for all tasks to complete and returns results
471470in the same order as the input list, not in completion order.
472471
473- Results are wrapped in `Except Exception (α × Term.State )` so that errors in individual
472+ Results are wrapped in `Except Exception (α × Term.SavedState )` so that errors in individual
474473tasks don't stop the collection - you can observe all results including which tasks failed.
475474
476475The final TermElabM state is restored to the initial state (before tasks ran).
477- Note: Only Term.State is captured/reverted, not Meta.State, Core.State or IO effects.
478476-/
479- def par {α : Type } (jobs : List (TermElabM α)) : TermElabM (List (Except Exception (α × Term.State ))) := do
477+ def par {α : Type } (jobs : List (TermElabM α)) : TermElabM (List (Except Exception (α × Term.SavedState ))) := do
480478 let initialState ← get
481479 let tasks ← jobs.mapM asTask'
482480 let mut results := []
483481 for task in tasks do
484- -- Note: We use try/catch instead of `observing` here because TermElabM's `observing`
485- -- returns `TermElabResult` (not `Except`), which includes SavedState that we don't need.
486482 try
487483 let result ← task.get
488- let taskState ← get
484+ let taskState ← saveState
489485 results := .ok (result, taskState) :: results
490486 catch e =>
491487 results := .error e :: results
@@ -605,27 +601,24 @@ def parIterGreedy {α : Type} (jobs : List (TacticM α)) :=
605601
606602/--
607603Runs a list of TacticM computations in parallel and collects results in the original order,
608- including the state after each task completes.
604+ including the saved state after each task completes.
609605
610606Unlike `parIter`, this waits for all tasks to complete and returns results
611607in the same order as the input list, not in completion order.
612608
613- Results are wrapped in `Except Exception (α × Tactic.State )` so that errors in individual
609+ Results are wrapped in `Except Exception (α × Tactic.SavedState )` so that errors in individual
614610tasks don't stop the collection - you can observe all results including which tasks failed.
615611
616612The final TacticM state is restored to the initial state (before tasks ran).
617- Note: Only Tactic.State is captured/reverted, not Term.State, Meta.State, Core.State or IO effects.
618613-/
619- def par {α : Type } (jobs : List (TacticM α)) : TacticM (List (Except Exception (α × Tactic.State ))) := do
614+ def par {α : Type } (jobs : List (TacticM α)) : TacticM (List (Except Exception (α × Tactic.SavedState ))) := do
620615 let initialState ← get
621616 let tasks ← jobs.mapM asTask'
622617 let mut results := []
623618 for task in tasks do
624- -- Note: We use try/catch instead of `observing` here because TacticM's `observing`
625- -- (inherited from TermElabM) returns `TermElabResult`, not `Except`.
626619 try
627620 let result ← task.get
628- let taskState ← get
621+ let taskState ← Tactic.saveState
629622 results := .ok (result, taskState) :: results
630623 catch e =>
631624 results := .error e :: results
0 commit comments