WIP: acquire a kernel check slot only when the check can run A check that takes its slot before `uncheckedKernelEnv` is available can hold it while waiting for another check. When the environment falls back to `checked`, e.g. after `replayConsts`, it waits for all earlier declarations, including a theorem whose proof is still being elaborated; four such checks then held all slots and the check of that theorem never got one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
diff --git a/src/Lean/AddDecl.lean b/src/Lean/AddDecl.lean index 2511fe9..0b670f0 100644 --- a/src/Lean/AddDecl.lean +++ b/src/Lean/AddDecl.lean
@@ -274,9 +274,11 @@ catch ex => okPromise.resolve false throw ex - let slot ← acquireKernelCheckSlot - let t ← BaseIO.bindTask slot fun _ => - BaseIO.mapTask (t := env.uncheckedKernelEnv) fun kenv => do + -- The slot must be acquired only when the check can run: a check that held one while waiting + -- for `uncheckedKernelEnv` could keep it from a check that this environment in turn waits for. + let t ← BaseIO.bindTask env.uncheckedKernelEnv fun kenv => do + let slot ← acquireKernelCheckSlot + BaseIO.mapTask (t := slot) fun _ => do let r ← checkAct kenv releaseKernelCheckSlot return r