Skip to content

perf: replay tactics when only trailing whitespace is changed - #11958

Merged
Kha merged 8 commits into
leanprover:masterfrom
Kha:push-wmmkumntttqs
Jul 8, 2026
Merged

Kha merged 8 commits into
leanprover:masterfrom
Kha:push-wmmkumntttqs

Conversation

@Kha

@Kha Kha commented Jan 9, 2026 •

Copy link
Copy Markdown
Member

This PR adjusts the elaborator and snapshot tree system so as not to rerun tactics when whitespace directly following them is changed, preventing loss of progress when preparing to type the next tactic.

We do this by removing the trailing whitespace before passing a tactic from the tactic block elaborator to evalTactic. The removed whitespace is saved in the snapshot tree and reapplied on access such that no consumers have to be adapted.

@Kha Kha added the changelog-server Language server, widgets, and IDE extensions label Jan 9, 2026
@Kha

Kha commented Jan 9, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jan 9, 2026 •

Copy link
Copy Markdown

Benchmark results for d23b858 against d92cdae are in! @Kha

Small changes (4🟥)
  • 🟥 build/module/Lean.Elab.Tactic.BuiltinTactic//instructions: +80.3M (+0.3%)
  • 🟥 build/module/Lean.Server.FileWorker.RequestHandling//instructions: +123.1M (+0.7%)
  • 🟥 build/module/Lean.Server.InfoUtils//instructions: +127.5M (+1.8%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Server.Requests//instructions: +124.0M (+1.5%)

@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jan 9, 2026
ghost pushed a commit to leanprover-community/batteries that referenced this pull request Jan 9, 2026
@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Jan 9, 2026
ghost pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jan 9, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jan 9, 2026
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Jan 9, 2026
@leanprover-bot

leanprover-bot commented Jan 9, 2026 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ✅ Reference manual branch lean-pr-testing-11958 has successfully built against this PR. (2026-01-09 22:39:57) View Log
  • 🟡 Reference manual branch lean-pr-testing-11958 build against this PR didn't complete normally. (2026-01-09 22:42:10) View Log
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-05-03 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-05-13 09:37:43)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-06-16 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-06-24 10:55:47)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-06-24 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-06-24 12:07:19)

@ghost ghost added the builds-mathlib CI has verified that Mathlib builds against this PR label Jan 10, 2026
@ghost

ghost commented Jan 10, 2026

Copy link
Copy Markdown

Mathlib CI status (docs):

@Kha
Kha force-pushed the push-wmmkumntttqs branch 3 times, most recently from 1b4ea22 to f8fff06 Compare May 13, 2026 08:28
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request May 13, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request May 13, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented May 13, 2026 •

Copy link
Copy Markdown

Mathlib CI status (docs):

@Kha
Kha force-pushed the push-wmmkumntttqs branch from f8fff06 to 6ace07b Compare June 24, 2026 09:51
@Kha
Kha marked this pull request as ready for review June 24, 2026 09:51
@Kha
Kha requested review from kim-em and mhuisi as code owners June 24, 2026 09:51
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jun 24, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 24, 2026
@Kha

Kha commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jun 24, 2026 •

Copy link
Copy Markdown

Benchmark results for 0c2b5e1 against 4792cd2 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +8.4G (+0.07%)

Large changes (9🟥)

  • 🟥 compiled/incr_header_load//instructions: +435.1M (+70.43%)
  • 🟥 compiled/incr_header_load//maxrss: +68MiB (+12.67%)
  • 🟥 misc/re-elab Init.Data.BitVec.Lemmas//maxrss: +2GiB (+278.99%)
  • 🟥 misc/re-elab Init.Data.BitVec.Lemmas//task-clock: +12s (+11.88%)
  • 🟥 misc/re-elab Init.Data.BitVec.Lemmas//wall-clock: +10s (+36.95%)
  • 🟥 misc/re-elab Init.Data.List.Basic//instructions: +16.9G (+12.07%)
  • 🟥 misc/re-elab Init.Data.List.Basic//wall-clock: +2s (+21.41%)
  • 🟥 misc/re-elab Init.Data.List.Sublist//wall-clock: +2s (+38.82%)
  • 🟥 misc/re-elab watchdog Init.Data.List.Sublist//wall-clock: +2s (+11.81%)

Medium changes (3🟥)

  • 🟥 misc/re-elab Init.Data.BitVec.Lemmas//instructions: +74.1G (+9.16%)
  • 🟥 misc/re-elab Init.Data.List.Sublist//instructions: +17.9G (+12.85%)
  • 🟥 misc/re-elab Init.Data.List.Sublist//task-clock: +3s (+15.04%)

Small changes (2✅, 17🟥)

  • 🟥 build//task-clock: +57s (+2.81%)
  • 🟥 build//wall-clock: +4s (+2.95%)
  • 🟥 build/module/Lean.Elab.DefView//instructions: +38.1M (+1.15%)
  • ✅ build/module/Lean.Elab.InfoTree.Main//instructions: -611.8M (-15.19%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Elab.Tactic.Basic//instructions: +38.0M (+0.32%)
  • 🟥 build/module/Lean.Elab.Tactic.BuiltinTactic//instructions: +78.8M (+0.43%)
  • 🟥 build/module/Lean.Elab.Term.TermElabM//instructions: +934.0M (+3.73%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Language.Basic//instructions: +277.0M (+12.14%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Language.Lean.Types//instructions: +81.4M (+7.05%)
  • ✅ build/module/Lean.Server.InfoUtils//instructions: -69.2M (-1.58%)
  • 🟥 build/module/Lean.Syntax//instructions: +53.0M (+1.23%)
  • 🟥 build/profile/blocked (unaccounted)//wall-clock: +6s (+5.17%)
  • 🟥 build/profile/compilation (LCNF base)//wall-clock: +16s (+6.30%)
  • 🟥 compiled/incr_header_load//task-clock: +68ms (+68.40%)
  • 🟥 compiled/incr_header_load//wall-clock: +76ms (+118.60%)
  • 🟥 elab/bv_decide_realworld//wall-clock: +49ms (+4.34%)
  • 🟥 misc/re-elab Init.Data.List.Basic//task-clock: +2s (+11.33%)
  • 🟥 misc/re-elab watchdog Init.Data.List.Sublist//instructions: +18.2G (+3.84%)
  • 🟥 misc/re-elab watchdog Init.Data.List.Sublist//task-clock: +3s (+6.27%)

mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 24, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jun 24, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 24, 2026
@Kha

Kha commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

This comment was marked as outdated.

@Kha

Kha commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

This comment was marked as outdated.

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jun 25, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 25, 2026
@Kha
Kha force-pushed the push-wmmkumntttqs branch from a3276b5 to 7cfe500 Compare June 25, 2026 14:51
@Kha

Kha commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jun 25, 2026 •

Copy link
Copy Markdown

Benchmark results for 7cfe500 against 0a8abcb are in. There are significant results. @Kha

  • 🟥 build//instructions: +3.9G (+0.03%)

Large changes (1✅, 1🟥)

  • ✅ vcgen/GetThrowSet/200/kernel//wall-clock: -3ms (-6.12%)
  • 🟥 vcgen/GetThrowSet/200/vcgen//wall-clock: +3ms (+8.33%)

Medium changes (1✅, 2🟥)

  • 🟥 interpreted/identifier_completion//instructions: +1.3G (+2.04%)
  • 🟥 misc/re-elab Init.Data.List.Sublist//task-clock: +2s (+10.53%)
  • ✅ vcgen/MatchIota/1000/kernel//wall-clock: -70ms (-15.98%)

Small changes (6✅, 27🟥)

Too many entries to display here. View the full report on radar instead.

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jun 25, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 25, 2026
@Kha

Kha commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 8, 2026 •

Copy link
Copy Markdown

Benchmark results for 40157b1 against 0a8abcb are in. No significant results found. @Kha

  • 🟥 build//instructions: +4.1G (+0.04%)

Medium changes (1🟥)

  • 🟥 interpreted/identifier_completion//instructions: +763.4M (+1.16%)

Small changes (6✅, 7🟥)

  • 🟥 build/module/Lean.Elab.DefView//instructions: +42.6M (+1.27%)
  • ✅ build/module/Lean.Elab.InfoTree.Main//instructions: -601.8M (-14.95%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Elab.Tactic.Basic//instructions: +36.8M (+0.31%)
  • 🟥 build/module/Lean.Elab.Tactic.BuiltinTactic//instructions: +90.4M (+0.49%)
  • 🟥 build/module/Lean.Elab.Term.TermElabM//instructions: +919.8M (+3.69%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Language.Basic//instructions: +328.3M (+14.32%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Language.Lean.Types//instructions: +81.0M (+6.79%)
  • ✅ build/module/Lean.Server.InfoUtils//instructions: -66.1M (-1.51%)
  • 🟥 build/module/Lean.Syntax//instructions: +53.3M (+1.24%)
  • ✅ vcgen/GetThrowSet/200/kernel//wall-clock: -3ms (-6.12%)
  • ✅ vcgen/MatchIota/1000/kernel//wall-clock: -72ms (-16.44%)
  • ✅ vcgen/MatchIota/1500/kernel//wall-clock: -173ms (-18.68%)
  • ✅ vcgen/MatchIota/500/kernel//wall-clock: -19ms (-13.19%)

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 8, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 8, 2026
`InfoTree.addTrailing` now returns the original tree when a subtree is unchanged, so only nodes whose syntax actually changes are reallocated. Changed children are updated via `PersistentArray.set`, keeping unchanged leaf chunks of the children array shared as well. This removes most of the allocation and refcounting overhead of reapplying trailing whitespace on snapshot tree walks and in the tactic block elaborator, and restores structural sharing between tactic snapshot info trees and the surrounding command info tree.
@Kha
Kha force-pushed the push-wmmkumntttqs branch from 40157b1 to b571f85 Compare July 8, 2026 11:05
@Kha
Kha enabled auto-merge July 8, 2026 11:21
@Kha
Kha added this pull request to the merge queue Jul 8, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 8, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 8, 2026
Merged via the queue into leanprover:master with commit 8554442 Jul 8, 2026
15 checks passed
Rob23oba pushed a commit to Rob23oba/lean4 that referenced this pull request Sep 10, 2026
…tree (leanprover#15093)

This PR fixes the goal view showing the state after the enclosing tactic
instead of the nested block's goal on the line after the last tactic of
a nested `have ... := by` block or `·` bullet, e.g. after an empty `·`
where the next tactic is about to be typed (leanprover#15053).

Tactic steps are elaborated without the trailing whitespace of their
last token for incremental reuse (leanprover#11958), which is re-added to the
resulting info trees afterwards. `InfoTree.addTrailing?` passed each
node's own trailing whitespace to its children instead of the trailing
being added, which cut off propagation at the `by` token node that `have
... := by tacs` expands to via `with_annotate_state`, so the last nested
tactic never regained its whitespace. Term-level blocks ending a tactic
step additionally hide behind an unsubstituted info hole at that point,
so `evalSepTactics` now substitutes holes before re-adding.

Co-authored-by: Claude Fable 5.1 <[email protected]>
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-server Language server, widgets, and IDE extensions 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.

3 participants