Skip to content

fix: do not block on async theorem bodies when iterating local consts#13712

Open
nomeata wants to merge 2 commits into
masterfrom
joachim/issue13705
Open

fix: do not block on async theorem bodies when iterating local consts#13712
nomeata wants to merge 2 commits into
masterfrom
joachim/issue13705

Conversation

@nomeata
Copy link
Copy Markdown
Collaborator

@nomeata nomeata commented May 11, 2026

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 when 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? and
exact? appearing to hang near the top of long files.

Adds Environment.localConstantInfos : BaseIO (Array AsyncConstantInfo), a non-blocking
iterator over the locally-added constants in addition order. It yields each constant on the
current branch and walks into the nested AsyncConsts of every non-theorem decl — so
where-clause helpers inside a def, aux recursors from addAuxRecs, etc. are visible to
exact? — but stops at theorems, whose body is elaborated in its own task and whose nested
decls would be race-visible. Constants are deduplicated by name because nested AsyncConsts
inherit their parent's asyncConstsMap.

Lean.Meta.LazyDiscrTree's callback API now takes AsyncConstantInfo instead of
ConstantInfo; LibrarySearch, Rewrites, and Grind are updated to match. The
library_search_all test is adjusted because its suggestion order depended on the incidental
PHashMap bucket layout.

Closes #13705.

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>
@nomeata nomeata added the changelog-tactics User facing tactics label May 11, 2026
@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented May 11, 2026

!perf

@github-actions github-actions Bot added toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN labels May 11, 2026
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label May 11, 2026
@leanprover-bot
Copy link
Copy Markdown
Collaborator

leanprover-bot commented May 11, 2026

Reference manual CI status:

@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label May 11, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

mathlib-lean-pr-testing Bot commented May 11, 2026

Mathlib CI status (docs):

@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented May 12, 2026

Not quite the right fix, only sees one async branch and seeing all is complicated. Back to drawing board.

@nomeata nomeata closed this May 12, 2026
…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>
@nomeata nomeata reopened this May 12, 2026
@nomeata nomeata marked this pull request as ready for review May 12, 2026 15:29
@nomeata nomeata requested review from kim-em and leodemoura as code owners May 12, 2026 15:29
@nomeata nomeata requested a review from Kha May 12, 2026 16:00
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-manual CI has verified that the Lean Language Reference builds against this PR builds-mathlib CI has verified that Mathlib builds against this PR changelog-tactics User facing tactics mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exact? and grind block on prior async theorem bodies

2 participants