fix: do not block on async theorem bodies when iterating local consts#13712
Open
nomeata wants to merge 2 commits into
Open
fix: do not block on async theorem bodies when iterating local consts#13712nomeata wants to merge 2 commits into
nomeata wants to merge 2 commits into
Conversation
This PR makes `exact?`, `apply?`, `rw?`, and `grind +locals` no longer wait for prior async theorem bodies in the same file to finish kernel-checking before iterating the current module's declarations. Before, these tactics walked `env.constants.map₂`, which forces `env.checked` and thus blocks on every pending async branch; in an editor session this manifested as `try?`/`exact?` appearing to hang near the top of long files. Adds a non-blocking iterator `Environment.localConstantInfos` over the locally-added constants (yielded as `AsyncConstantInfo`, whose eagerly-committed signature is enough for indexing tasks). Threads `AsyncConstantInfo` through `Lean.Meta.LazyDiscrTree`'s callback API, updates `LibrarySearch`/`Rewrites`/`Grind` callers accordingly, and adjusts a `library_search_all` test whose suggestion order depended on the incidental `PHashMap` bucket layout. Closes #13705. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
!perf |
Collaborator
|
Reference manual CI status:
|
|
Mathlib CI status (docs):
|
Collaborator
Author
|
Not quite the right fix, only sees one async branch and seeing all is complicated. Back to drawing board. |
…theorems This PR makes `Environment.localConstantInfos` recursively descend into the nested `AsyncConsts` of non-theorem constants, so `where`-clause helpers inside a `def` (and similar nested decls) are visible to `exact?`. Theorems are skipped because their body is elaborated asynchronously, so any nested decls — `where` helpers, `match` matchers, aux recursors — would be race-visible. This matches the Sebastian/JB consensus on which 'local' declarations should be deterministically queryable. Constants are deduplicated by name (nested `AsyncConsts` inherit their parent's `asyncConstsMap`, so the naive walk would re-visit ancestors). Adds `tests/elab/issue13705_nested.lean` covering both the where-in-def case (helper found) and the where-in-theorem case (helper hidden). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
May 12, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
May 12, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
May 12, 2026
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 makes
exact?,apply?,rw?, andgrind +localsno longer wait for prior asynctheorem bodies in the same file to finish kernel-checking when iterating the current module's
declarations. Before, these tactics walked
env.constants.map₂, which forcesenv.checkedandthus blocks on every pending async branch; in an editor session this manifested as
try?andexact?appearing to hang near the top of long files.Adds
Environment.localConstantInfos : BaseIO (Array AsyncConstantInfo), a non-blockingiterator over the locally-added constants in addition order. It yields each constant on the
current branch and walks into the nested
AsyncConstsof every non-theorem decl — sowhere-clause helpers inside adef, aux recursors fromaddAuxRecs, etc. are visible toexact?— but stops at theorems, whose body is elaborated in its own task and whose nesteddecls would be race-visible. Constants are deduplicated by name because nested
AsyncConstsinherit their parent's
asyncConstsMap.Lean.Meta.LazyDiscrTree's callback API now takesAsyncConstantInfoinstead ofConstantInfo;LibrarySearch,Rewrites, andGrindare updated to match. Thelibrary_search_alltest is adjusted because its suggestion order depended on the incidentalPHashMapbucket layout.Closes #13705.