Skip to content

Commit

Permalink
fix: do not force snapshot tree too early (#5752)
Browse files Browse the repository at this point in the history
This turns out to be the issue behind #5736, though really it is yet
another indicator of a general thread pool weakness.

(cherry picked from commit fc5e3cc)
  • Loading branch information
Kha authored and kim-em committed Oct 21, 2024
1 parent bfd4b64 commit 480d731
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Lean/Language/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,16 @@ instance : ToSnapshotTree SnapshotLeaf where
structure DynamicSnapshot where
/-- Concrete snapshot value as `Dynamic`. -/
val : Dynamic
/-- Snapshot tree retrieved from `val` before erasure. -/
tree : SnapshotTree
/--
Snapshot tree retrieved from `val` before erasure. We do thunk even the first level as accessing
it too early can create some unnecessary tasks from `toSnapshotTree` that are otherwise avoided by
`(sync := true)` when accessing only after elaboration has finished. Early access can even lead to
deadlocks when later forcing these unnecessary tasks on a starved thread pool.
-/
tree : Thunk SnapshotTree

instance : ToSnapshotTree DynamicSnapshot where
toSnapshotTree s := s.tree
toSnapshotTree s := s.tree.get

/-- Creates a `DynamicSnapshot` from a typed snapshot value. -/
def DynamicSnapshot.ofTyped [TypeName α] [ToSnapshotTree α] (val : α) : DynamicSnapshot where
Expand Down

0 comments on commit 480d731

Please sign in to comment.