fix: add checkSystem calls to hasAssignableMVar#13219
Merged
Merged
Conversation
Collaborator
Author
|
!radar |
|
Benchmark results for 512b52a against 67b6e81 are in. Significant changes detected! @nomeata
No significant changes detected. |
This PR moves `isLevelMVarAssignable`, `hasAssignableLevelMVar`, and `hasAssignableMVar` from `Lean.MetavarContext` (where they were generic over `[Monad m] [MonadMCtx m]`) to a new `Lean.Meta.HasAssignableMVar` module where they are specialized to `MetaM`. This allows adding `checkSystem` calls in the recursive traversal, enabling cancellation and heartbeat checking during what can be a very expensive operation on large expressions (e.g. category theory proofs with many universe metavariables). All callers were already in `MetaM` or a monad extending it, so the type change is compatible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
512b52a to
0e229d7
Compare
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
Collaborator
Author
|
!radar |
|
Benchmark results for 0e229d7 against 67b6e81 are in. There are no significant changes. @nomeata
Small changes (8✅)
|
This was referenced Mar 31, 2026
volodeyka
pushed a commit
that referenced
this pull request
Apr 16, 2026
This PR moves `hasAssignableMVar`, `hasAssignableLevelMVar`, and `isLevelMVarAssignable` from `MetavarContext.lean` to a new `Lean.Meta.HasAssignableMVar` module, changing them from generic `[Monad m] [MonadMCtx m]` functions to `MetaM` functions. This enables adding `checkSystem` calls in the recursive traversal, which ensures cancellation and heartbeat checks happen during what can be a very expensive computation. All callers of these functions were already in `MetaM`, so this change is safe. The motivating case is the `4595_slowdown.lean` test, where `hasAssignableMVar` (with `PersistentHashMap.find?` lookups on `mctx.lDepth`) was the dominant CPU cost during elaboration of category theory definitions. Without `checkSystem` calls, cancellation requests could be delayed by over 2 seconds. The test file `4595_slowdown.lean` gets a slightly increased `maxHeartbeats` limit because `checkSystem` now detects heartbeat exhaustion mid-traversal rather than after the function returns. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR moves
hasAssignableMVar,hasAssignableLevelMVar, andisLevelMVarAssignablefromMetavarContext.leanto a newLean.Meta.HasAssignableMVarmodule, changing them from generic[Monad m] [MonadMCtx m]functions toMetaMfunctions. This enables addingcheckSystemcalls in the recursive traversal, which ensures cancellation and heartbeat checks happen during what can be a very expensive computation.All callers of these functions were already in
MetaM, so this change is safe. The motivating case is the4595_slowdown.leantest, wherehasAssignableMVar(withPersistentHashMap.find?lookups onmctx.lDepth) was the dominant CPU cost during elaboration of category theory definitions. WithoutcheckSystemcalls, cancellation requests could be delayed by over 2 seconds.The test file
4595_slowdown.leangets a slightly increasedmaxHeartbeatslimit becausecheckSystemnow detects heartbeat exhaustion mid-traversal rather than after the function returns.