Repository navigation
feat: require indentation in commands, allow empty tactic sequences - #13229
Merged
Merged
Conversation
Collaborator
|
Reference manual CI status:
|
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 1, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 1, 2026
|
Mathlib CI status (docs):
|
|
Mathlib CI status (docs):
|
|
Mathlib CI status (docs):
|
|
Mathlib CI status (docs):
|
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 1, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 1, 2026
|
Mathlib CI status (docs):
|
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 1, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 1, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 1, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 1, 2026
|
Mathlib CI status (docs):
|
|
Mathlib CI status (docs):
|
…approach) This uses `withPosition commandParser` at the top level to enforce indentation in `by` blocks, combined with an empty-by fallback for better error messages. Compare with checkColPosGt approach in #13217. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
This adds a `notFollowedBy checkColGt` guard on the empty-by fallback in
`tacticSeqIndentGt`. When indented non-tactic content follows `by`, this
produces a tactic-level parse error ("expected '{' or tactic") rather than
silently producing an empty tactic sequence. Also adds a comparison test
for first-line vs second-line non-tactic errors.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
This reverts the `notFollowedBy checkColGt` guard on the empty-by fallback. Indented non-tactic content now consistently gets "unsolved goals" + "unexpected token; expected command", matching the behavior when non-tactic content appears on subsequent lines after a valid tactic. Co-Authored-By: Claude Opus 4.6 <[email protected]>
This adds server_interactive hover tests verifying that goal display works correctly when the empty-by `pushNone` fallback fires. Tests hovering on `by`, after `by`, and below an empty `by` block. Co-Authored-By: Claude Opus 4.6 <[email protected]>
nomeata
marked this pull request as ready for review
April 3, 2026 06:37
mhuisi
approved these changes
Apr 8, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Apr 8, 2026
nomeata
enabled auto-merge
April 8, 2026 13:47
wkrozowski
pushed a commit
to wkrozowski/lean4
that referenced
this pull request
Apr 10, 2026
…eanprover#13229) This PR wraps the top-level command parser with `withPosition` to enforce indentation in `by` blocks, combined with an empty-by fallback for better error messages. This subsumes leanprover#3215 (which introduced `withPosition commandParser` but without the empty-by fallback). It is also related to leanprover#9524, which explores elaboration with empty tactic sequences — this PR reuses that idea for the empty-by fallback, so that a `by` not followed by an indented tactic produces an elaboration error (unsolved goals) rather than a parse error. **Changes:** - `topLevelCommandParserFn` now uses `(withPosition commandParser).fn`, setting the saved position at the start of each top-level command - `tacticSeqIndentGt` gains an empty tactic sequence fallback (`pushNone`) so that missing indentation produces an elaboration error (unsolved goals) instead of a parse error - `isEmptyBy` in `goalsAt?` removed: with strict `by` indentation, empty `by` blocks parse successfully via `pushNone` (producing empty nodes) rather than producing `.missing` syntax, making the `isEmptyBy` check dead code. The `isEmpty` helper in `isSyntheticTacticCompletion` continues to work correctly because it handles both `.missing` and empty nodes from `pushNone` (via the vacuously-true `args.all isEmpty` on `#[]`) - Test files updated to indent `by` blocks and expression continuations that were previously at column 0 **Behavior:** - Top-level `by` blocks now require indentation (column > 0 for commands at column 0) - Commands indented inside `section` require proofs to be indented past the command's column - `#guard_msgs in example : True := by` works because tactic indentation is checked against the outermost command's column - Expression continuations (not just `by`) must also be indented past the command, which is slightly more strict but more consistent - `have : True := by` followed by a dedent now correctly puts `this` in scope in the outer tactic block (the `have` is structurally complete with an unsolved-goal error, rather than a parse error) **Code changes observed in practice (lean4 test suite + Mathlib):** - `by` blocks: top-level `theorem ... := by` / `decreasing_by` followed by tactics at column 0 must be indented - `variable` continuations: `variable {A : Type*} [Foo A]\n{B : Type*}` where the second line starts at column 0 must be indented (most common category in Mathlib) - Expression continuations: `def f : T :=\nexpr` or `#synth Foo\n[args]` where the body/arguments start at column 0 - Structure literals: `.symm\n{ toFun := ...` where the struct literal starts at column 0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Apr 15, 2026
This PR fixes a bug where tactic auto-completion would produce tactic completion items in the entire trailing whitespace of an empty tactic block. Since #13229 further restricted top-level `by` blocks to be indentation- sensitive, this PR adjusts the logic to only display completion items at a "proper" indentation level. Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
volodeyka
pushed a commit
that referenced
this pull request
Apr 16, 2026
…13229) This PR wraps the top-level command parser with `withPosition` to enforce indentation in `by` blocks, combined with an empty-by fallback for better error messages. This subsumes #3215 (which introduced `withPosition commandParser` but without the empty-by fallback). It is also related to #9524, which explores elaboration with empty tactic sequences — this PR reuses that idea for the empty-by fallback, so that a `by` not followed by an indented tactic produces an elaboration error (unsolved goals) rather than a parse error. **Changes:** - `topLevelCommandParserFn` now uses `(withPosition commandParser).fn`, setting the saved position at the start of each top-level command - `tacticSeqIndentGt` gains an empty tactic sequence fallback (`pushNone`) so that missing indentation produces an elaboration error (unsolved goals) instead of a parse error - `isEmptyBy` in `goalsAt?` removed: with strict `by` indentation, empty `by` blocks parse successfully via `pushNone` (producing empty nodes) rather than producing `.missing` syntax, making the `isEmptyBy` check dead code. The `isEmpty` helper in `isSyntheticTacticCompletion` continues to work correctly because it handles both `.missing` and empty nodes from `pushNone` (via the vacuously-true `args.all isEmpty` on `#[]`) - Test files updated to indent `by` blocks and expression continuations that were previously at column 0 **Behavior:** - Top-level `by` blocks now require indentation (column > 0 for commands at column 0) - Commands indented inside `section` require proofs to be indented past the command's column - `#guard_msgs in example : True := by` works because tactic indentation is checked against the outermost command's column - Expression continuations (not just `by`) must also be indented past the command, which is slightly more strict but more consistent - `have : True := by` followed by a dedent now correctly puts `this` in scope in the outer tactic block (the `have` is structurally complete with an unsolved-goal error, rather than a parse error) **Code changes observed in practice (lean4 test suite + Mathlib):** - `by` blocks: top-level `theorem ... := by` / `decreasing_by` followed by tactics at column 0 must be indented - `variable` continuations: `variable {A : Type*} [Foo A]\n{B : Type*}` where the second line starts at column 0 must be indented (most common category in Mathlib) - Expression continuations: `def f : T :=\nexpr` or `#synth Foo\n[args]` where the body/arguments start at column 0 - Structure literals: `.symm\n{ toFun := ...` where the struct literal starts at column 0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
volodeyka
pushed a commit
that referenced
this pull request
Apr 16, 2026
This PR fixes a bug where tactic auto-completion would produce tactic completion items in the entire trailing whitespace of an empty tactic block. Since #13229 further restricted top-level `by` blocks to be indentation- sensitive, this PR adjusts the logic to only display completion items at a "proper" indentation level. Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
kim-em
added a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
May 4, 2026
* Update lean-toolchain for testing leanprover/lean4#13086 * feat: add `Lean.Grind.PowIdentity` instance for finite fields This provides a `PowIdentity K (Fintype.card K)` instance for any finite field, based on `FiniteField.pow_card` (Fermat's little theorem). This allows the `grind` ring solver to reduce high-degree polynomials over finite fields. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * Update lean-toolchain for testing leanprover/lean4#13132 * Update lean-toolchain for leanprover/lean4#13132 * Update lean-toolchain for leanprover/lean4#13132 * Update lean-toolchain for testing leanprover/lean4#13223 * Update lean-toolchain for testing leanprover/lean4#13229 * chore: indent tactic blocks after `by` and `decreasing_by` Adapt to leanprover/lean4#13217 which requires indented tactic sequences after `by` and `decreasing_by`. Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: indent tactic block in EmptyLine test Adapt to leanprover/lean4#13217. Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: indent expression continuations at column 0 Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: indent expression continuations at column 0 Co-Authored-By: Claude Opus 4.6 <[email protected]> * Update lean-toolchain for leanprover/lean4#13229 * Update lean-toolchain for leanprover/lean4#13223 * Update lean-toolchain for leanprover/lean4#13229 * Update lean-toolchain for leanprover/lean4#13229 * Update lean-toolchain for leanprover/lean4#13229 * Update lean-toolchain for leanprover/lean4#13223 * chore: fix linter tests * lake update * fix hash command linter * fix bad merge * fixes * fixes * unpleasant fix. * touch for CI * cleanup of adaptation notes * chore: adaptations for nightly-2026-04-06 * chore: bump to nightly-2026-04-07 * chore: adaptations for nightly-2026-04-07 * chore: bump to nightly-2026-04-08 * Update lean-toolchain for testing leanprover/lean4#13262 * Update lean-toolchain for leanprover/lean4#13262 * universe fixes * chore: bump to nightly-2026-04-09 * Update lean-toolchain for testing leanprover/lean4#13346 * Update lean-toolchain for leanprover/lean4#13346 * lake update * fixes * fix tests * ci: skip inputRev validation on nightly-testing branch Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * chore: bump to nightly-2026-04-10 * fix * chore(nolints): add docBlame exceptions for auto-generated `instInhabited.default` Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix(lint-style): filter out duplicate `Init` from `Mathlib.lean` imports `Lean.parseImports'` now emits `Init` more than once for module-system files such as `Mathlib.lean`, but `findImportsFromSource` (in importGraph) only `.erase`s the first occurrence. The remaining `Init` was treated as a module to lint, producing `uncaught exception: no such file or directory ... file: Init.lean` and breaking the `lint-style` CI job on `nightly-testing`. Defensively filter out any remaining `Init` after `findImportsFromSource`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix * fix plausible * Update lean-toolchain for leanprover/lean4#13346 * chore: update importGraph, remove duplicate Init workaround Updates importGraph to pick up leanprover-community/import-graph#115, which fixes `findImportsFromSource` to filter (not just erase) `Init`. This removes the need for the defensive `.filter (· != `Init)` we added to `lint-style.lean`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * chore: bump to nightly-2026-04-11 * silence linter * broken test: still broken, but doesn't stop the build. * fix: exempt files registering initializers from the `privateModule` linter * Revert "silence linter" This reverts commit 8da25c3. * chore: remove unused sections in front of lone `declare_aesop_rule_sets` * chore: restore `initialize` test for `privateModule` linter with correct wording * chore: restore `privateModule` `initialize` test with linter turned on * fixes * fix from nightly-testing * importGraph has been fixed * chore: bump to nightly-2026-04-13 * Update lean-toolchain for testing leanprover/lean4#13325 * Update lean-toolchain for leanprover/lean4#13325 * chore: silence simp `varHead` and `varOther` warnings * chore: silence `varHead` warning * chore: fix `globalAtrtributeIn` test * chore: fix `Archive` build * Update lean-toolchain for leanprover/lean4#13325 * Update lean-toolchain for leanprover/lean4#13325 * fix from nightly-testing * chore: bump to nightly-2026-04-14 * chore: bump to nightly-2026-04-15 * adapt to lean4#13363: canUnfoldAtMatcher allowlist changes Adapt proofs to lean4#13363 which replaces the transparency bump from `.reducible` to `.instances` in `whnfMatcher` with an explicit allowlist in `canUnfoldAtMatcher`. Class projections that were previously unfolded automatically in match discriminants now need explicit unfolding. * fix lint errors from lean4#13363 adaptation - Add doc string to `WithZero.withZeroSup` - Add `nolint simpNF` to auto-generated equation lemmas for `RegularExpression.matches'` and `RegularExpression.map` - Add `nolint simpNF` to `orderLHom_leSymb` * fixes * fix * fixes * chore: bump to nightly-2026-04-16 * fix tests * fix upstreamed import * chore: bump to nightly-2026-04-17 * set_option * Update lean-toolchain for testing leanprover/lean4#13441 * chore: adaptations for leanprover/lean4#13389 * fixes * fixes * fixes * fix Init filter in MinImports * fix test * add set_options * chore: bump to nightly-2026-04-19 * chore: bump to nightly-2026-04-20 * fix bad merge * fix #guard_msgs output * chore: bump to nightly-2026-04-22 * chore: bump to nightly-2026-04-23 * cleanup * revert an unnecessary change * revert unnecessary changes * add adaptation notes * minor fixes, whitespace and PR links * two improvements * improvements * slightly improve the proof in Limits/Shapes/Equalizers.lean * More * chore: bump to nightly-2026-04-24 * adapt to lean4#13363: canUnfoldAtMatcher allowlist changes Adapt proofs to lean4#13363 which replaces the transparency bump from `.reducible` to `.instances` in `whnfMatcher` with an explicit allowlist in `canUnfoldAtMatcher`. Class projections like `CategoryStruct.comp`, `CategoryStruct.id`, `Stream.next?`, `Min.min` etc. are no longer auto-unfolded in match discriminants and need explicit unfolding in proofs. Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: remove unused helper lemmas from Ordinal/Notation adaptation Remove `zero_zero_eq`, `one_one_eq`, `repr_zero'`, and `ofNat_unfold` which were added during the lean4#13363 adaptation but are not used in any proofs. Co-Authored-By: Claude Opus 4.6 <[email protected]> * Update lean-toolchain for leanprover/lean4#13363 * adapt Limits/Shapes/ConcreteCategory to lean4#13363 Use `WalkingMulticospan.Hom.id_eq_id` and `Functor.map_id` to reduce stuck matches on `𝟙` in WalkingMulticospan naturality proofs. Co-Authored-By: Claude Opus 4.6 <[email protected]> * Bump batteries * Update lean-toolchain for leanprover/lean4#13363 * chore: bump to nightly-2026-04-25 * satisfy linter * chore: bump to nightly-2026-04-27 * Apply suggestion from @kim-em * Apply suggestion from @kim-em --------- Co-authored-by: leanprover-community-mathlib4-bot <[email protected]> Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]> Co-authored-by: Joachim Breitner <[email protected]> Co-authored-by: Wojciech Rozowski <[email protected]> Co-authored-by: mathlib-nightly-testing[bot] <mathlib-nightly-testing[bot]@users.noreply.github.com> Co-authored-by: mathlib4-bot <[email protected]> Co-authored-by: Kyle Miller <[email protected]> Co-authored-by: Sebastian Ullrich <[email protected]> Co-authored-by: thorimur <[email protected]> Co-authored-by: Julia Markus Himmel <[email protected]>
nomeata
added a commit
that referenced
this pull request
May 7, 2026
This PR fixes a latent bug from #13229 (empty tactic sequences). When `evalSepTactics` is invoked on an empty sequence it returns at the very top, never resolving the `tacSnap` promise that `MutualDef.mkTacTask` sets up for `:= by ...` bodies. The promise stays dangling for the lifetime of the elab tree, blocking any consumer that walks the snapshot tree (e.g. the language server's `getInteractiveTermGoal`) until the cancellation token fires. In typical use the cancellation token fires shortly after elaboration, so the bug is invisible — but when a slow async snapshot task in the same command keeps things alive (as the implicit `try?` on an empty `by` does), the editor's "Messages" view appears to hang until that work completes. Resolving the promise eagerly in the early-return branch keeps the fix next to the code that's normally responsible for resolving it. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
github-merge-queue Bot
pushed a commit
that referenced
this pull request
May 11, 2026
This PR makes an empty `by` block run `try?` in the background and surface its suggestions, while still producing the usual unsolved-goals diagnostic. The implicit `try?` is informational only — it does not change elaboration behavior beyond emitting messages. Behaviour is controlled by a new option `tactic.tryOnEmptyBy`, disabled by default for now; set it to `true` to opt in. The default may flip in a future release. Behaviour summary, when the option is enabled: * The empty `by` reports unsolved goals immediately, before the (possibly slow) `try?` has finished. * The `try?` work is spawned as an asynchronous snapshot task (`Term.wrapAsyncAsSnapshot` + `Core.logSnapshotTask`), so subsequent elaboration is not blocked and the suggestions arrive when ready. * `try?` is gated on its parser infrastructure being available, so working on the prelude (before `Init.Try` is imported) keeps the regular empty-`by` behaviour. * No effect when the empty `by` appears inside a backtracking combinator (e.g. `first | exact (by) | …`) or when `try?` finds no applicable suggestion. Implementation notes: * `elabEmptyByAsTry` (in `Lean.Elab.Tactic.Try`) is registered as a second `@[builtin_term_elab byTactic]`, alongside the existing `elabByTactic` in `Lean.Elab.BuiltinTerm`. The gate `shouldElabEmptyByAsTry` is checked in both elaborators so the empty-`by` path takes the `try?` route while non-empty `by` follows the regular path. The body shared between them is factored as `elabByTacticCore`. The two-elaborator setup avoids a circular module dependency between `BuiltinTerm.lean` and `Tactic/Try.lean`; an inline comment in `Try.lean` explains this. * A latent bug from #13229 is fixed along the way: `evalSepTactics` returned at the very top for an empty tactic sequence without resolving the `tacSnap` promise that `MutualDef.mkTacTask` sets up for `:= by …` bodies. The dangling promise was harmless in typical use because the cmd's cancellation token would fire shortly after elaboration and drop it, but with a slow async snapshot task in the same command (as the implicit `try?` here) the language-server info-tree walk would block on it and the editor's Messages view would only update once the task finished. Resolved at the early-return in `evalSepTactics`. * The test infrastructure in `Lean.Server.Test.Cancel` gains a label-keyed `testTasksRef` registry plus `mkTestTask` / `wait_for_test_task`. The pre-existing `block_until_cancelled` is reimplemented on top of `mkTestTask` and the redundant `blockUntilCancelledOnce` ref is removed. Tests: * `tests/elab/tryOnEmptyBy.lean`, `tests/elab/try_prelude.lean` — feature behaviour and prelude gating. * `tests/server_interactive/cancellation_empty_by.lean` — verifies that on document re-elaboration `cancelRec` reaches the empty-`by` snapshot's cancel token registered with `Core.logSnapshotTask`. A `[try_suggestion]` generator wires the outer cancel token's `onSet` to resolve a `mkTestTask "T_outer"` promise, and the candidate `wait_for_test_task "T_outer"` waits on it. If `cancelTk? := none` is passed to `Core.logSnapshotTask`, `cancelRec` cannot reach the token, the wait blocks, and the runner times out. If `cancelTk? := none` is also passed to `wrapAsyncAsSnapshot`, no `onSet` resolver is registered, the promise drops without resolution, and `wait_for_test_task` surfaces a `"task dropped"` diagnostic on stderr. * `tests/server_interactive/cancellation_try_plain.lean` — verifies cancellation of plain `try?` (no `=>`) when its `[try_suggestion]` candidate runs synchronously inside `expandUserTactic`, by chaining through `wait_for_cancel_once_async`'s shared promise. Breaking `SnapshotTask.cancelRec` to skip walking children causes a runner timeout. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
nomeata
added a commit
that referenced
this pull request
May 13, 2026
…13229) This PR wraps the top-level command parser with `withPosition` to enforce indentation in `by` blocks, combined with an empty-by fallback for better error messages. This subsumes #3215 (which introduced `withPosition commandParser` but without the empty-by fallback). It is also related to #9524, which explores elaboration with empty tactic sequences — this PR reuses that idea for the empty-by fallback, so that a `by` not followed by an indented tactic produces an elaboration error (unsolved goals) rather than a parse error. **Changes:** - `topLevelCommandParserFn` now uses `(withPosition commandParser).fn`, setting the saved position at the start of each top-level command - `tacticSeqIndentGt` gains an empty tactic sequence fallback (`pushNone`) so that missing indentation produces an elaboration error (unsolved goals) instead of a parse error - `isEmptyBy` in `goalsAt?` removed: with strict `by` indentation, empty `by` blocks parse successfully via `pushNone` (producing empty nodes) rather than producing `.missing` syntax, making the `isEmptyBy` check dead code. The `isEmpty` helper in `isSyntheticTacticCompletion` continues to work correctly because it handles both `.missing` and empty nodes from `pushNone` (via the vacuously-true `args.all isEmpty` on `#[]`) - Test files updated to indent `by` blocks and expression continuations that were previously at column 0 **Behavior:** - Top-level `by` blocks now require indentation (column > 0 for commands at column 0) - Commands indented inside `section` require proofs to be indented past the command's column - `#guard_msgs in example : True := by` works because tactic indentation is checked against the outermost command's column - Expression continuations (not just `by`) must also be indented past the command, which is slightly more strict but more consistent - `have : True := by` followed by a dedent now correctly puts `this` in scope in the outer tactic block (the `have` is structurally complete with an unsolved-goal error, rather than a parse error) **Code changes observed in practice (lean4 test suite + Mathlib):** - `by` blocks: top-level `theorem ... := by` / `decreasing_by` followed by tactics at column 0 must be indented - `variable` continuations: `variable {A : Type*} [Foo A]\n{B : Type*}` where the second line starts at column 0 must be indented (most common category in Mathlib) - Expression continuations: `def f : T :=\nexpr` or `#synth Foo\n[args]` where the body/arguments start at column 0 - Structure literals: `.symm\n{ toFun := ...` where the struct literal starts at column 0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
nomeata
pushed a commit
that referenced
this pull request
May 13, 2026
This PR fixes a bug where tactic auto-completion would produce tactic completion items in the entire trailing whitespace of an empty tactic block. Since #13229 further restricted top-level `by` blocks to be indentation- sensitive, this PR adjusts the logic to only display completion items at a "proper" indentation level. Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
nomeata
added a commit
that referenced
this pull request
May 13, 2026
This PR makes an empty `by` block run `try?` in the background and surface its suggestions, while still producing the usual unsolved-goals diagnostic. The implicit `try?` is informational only — it does not change elaboration behavior beyond emitting messages. Behaviour is controlled by a new option `tactic.tryOnEmptyBy`, disabled by default for now; set it to `true` to opt in. The default may flip in a future release. Behaviour summary, when the option is enabled: * The empty `by` reports unsolved goals immediately, before the (possibly slow) `try?` has finished. * The `try?` work is spawned as an asynchronous snapshot task (`Term.wrapAsyncAsSnapshot` + `Core.logSnapshotTask`), so subsequent elaboration is not blocked and the suggestions arrive when ready. * `try?` is gated on its parser infrastructure being available, so working on the prelude (before `Init.Try` is imported) keeps the regular empty-`by` behaviour. * No effect when the empty `by` appears inside a backtracking combinator (e.g. `first | exact (by) | …`) or when `try?` finds no applicable suggestion. Implementation notes: * `elabEmptyByAsTry` (in `Lean.Elab.Tactic.Try`) is registered as a second `@[builtin_term_elab byTactic]`, alongside the existing `elabByTactic` in `Lean.Elab.BuiltinTerm`. The gate `shouldElabEmptyByAsTry` is checked in both elaborators so the empty-`by` path takes the `try?` route while non-empty `by` follows the regular path. The body shared between them is factored as `elabByTacticCore`. The two-elaborator setup avoids a circular module dependency between `BuiltinTerm.lean` and `Tactic/Try.lean`; an inline comment in `Try.lean` explains this. * A latent bug from #13229 is fixed along the way: `evalSepTactics` returned at the very top for an empty tactic sequence without resolving the `tacSnap` promise that `MutualDef.mkTacTask` sets up for `:= by …` bodies. The dangling promise was harmless in typical use because the cmd's cancellation token would fire shortly after elaboration and drop it, but with a slow async snapshot task in the same command (as the implicit `try?` here) the language-server info-tree walk would block on it and the editor's Messages view would only update once the task finished. Resolved at the early-return in `evalSepTactics`. * The test infrastructure in `Lean.Server.Test.Cancel` gains a label-keyed `testTasksRef` registry plus `mkTestTask` / `wait_for_test_task`. The pre-existing `block_until_cancelled` is reimplemented on top of `mkTestTask` and the redundant `blockUntilCancelledOnce` ref is removed. Tests: * `tests/elab/tryOnEmptyBy.lean`, `tests/elab/try_prelude.lean` — feature behaviour and prelude gating. * `tests/server_interactive/cancellation_empty_by.lean` — verifies that on document re-elaboration `cancelRec` reaches the empty-`by` snapshot's cancel token registered with `Core.logSnapshotTask`. A `[try_suggestion]` generator wires the outer cancel token's `onSet` to resolve a `mkTestTask "T_outer"` promise, and the candidate `wait_for_test_task "T_outer"` waits on it. If `cancelTk? := none` is passed to `Core.logSnapshotTask`, `cancelRec` cannot reach the token, the wait blocks, and the runner times out. If `cancelTk? := none` is also passed to `wrapAsyncAsSnapshot`, no `onSet` resolver is registered, the promise drops without resolution, and `wait_for_test_task` surfaces a `"task dropped"` diagnostic on stderr. * `tests/server_interactive/cancellation_try_plain.lean` — verifies cancellation of plain `try?` (no `=>`) when its `[try_suggestion]` candidate runs synchronously inside `expandUserTactic`, by chaining through `wait_for_cancel_once_async`'s shared promise. Breaking `SnapshotTask.cancelRec` to skip walking children causes a runner timeout. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
meerkatone
pushed a commit
to meerkatone/lean4
that referenced
this pull request
Sep 4, 2026
This PR removes the `withPosition` marker from the body of `macro` and `elab` declarations. We typically always use `withPosition` on parts of the syntax that are always layouted to the start of a line so as to not induce visual alignment constraints on a sub-term, only a relative indentation constraint. Since bodies of declarations often start with a piece of "sticky" syntax that we append after the separation token before the body of a declaration (e.g. `do`, `by`, `fun`, etc.), declaration bodies are not always layouted to the start of a line, which in turn forces a strange visual alignment constraint on the body. The `withPosition` was originally added because of this issue, where they body of a macro would keep parsing after the command: [#lean4 > Command terminator @ 💬](https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Command.20terminator/near/257674790) However, this has since been made obsolete by leanprover#13229.
yermakoffivan
pushed a commit
to yermakoffivan/lean4
that referenced
this pull request
Sep 9, 2026
…the enclosing tactic (leanprover#15095) This PR fixes the goal view showing the state after `have` instead of the goal of an empty nested `have ... := by` block on the following line, where the next tactic is about to be typed (leanprover#15053, regression of leanprover#1927 from leanprover#13229). The `isEmptyBy` heuristic in `InfoTree.goalsAt?` was removed in leanprover#13229 because empty `by` blocks no longer produce `.missing` syntax. Instead of checking for emptiness, `by` blocks and tokens are now flagged as `hangingBy`, and whether they count as indented is decided by the enclosing tactic by comparing the hover column with its own column, which matches where the parser would put a tactic typed at that position. Co-authored-by: Claude Fable 5.1 <[email protected]>
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 wraps the top-level command parser with
withPositionto enforce indentation inbyblocks, combined with an empty-by fallback for better error messages.This subsumes #3215 (which introduced
withPosition commandParserbut without the empty-by fallback). It is also related to #9524, which explores elaboration with empty tactic sequences — this PR reuses that idea for the empty-by fallback, so that abynot followed by an indented tactic produces an elaboration error (unsolved goals) rather than a parse error.Changes:
topLevelCommandParserFnnow uses(withPosition commandParser).fn, setting the saved position at the start of each top-level commandtacticSeqIndentGtgains an empty tactic sequence fallback (pushNone) so that missing indentation produces an elaboration error (unsolved goals) instead of a parse errorisEmptyByingoalsAt?removed: with strictbyindentation, emptybyblocks parse successfully viapushNone(producing empty nodes) rather than producing.missingsyntax, making theisEmptyBycheck dead code. TheisEmptyhelper inisSyntheticTacticCompletioncontinues to work correctly because it handles both.missingand empty nodes frompushNone(via the vacuously-trueargs.all isEmptyon#[])byblocks and expression continuations that were previously at column 0Behavior:
byblocks now require indentation (column > 0 for commands at column 0)sectionrequire proofs to be indented past the command's column#guard_msgs in example : True := byworks because tactic indentation is checked against the outermost command's columnby) must also be indented past the command, which is slightly more strict but more consistenthave : True := byfollowed by a dedent now correctly putsthisin scope in the outer tactic block (thehaveis structurally complete with an unsolved-goal error, rather than a parse error)Code changes observed in practice (lean4 test suite + Mathlib):
byblocks: top-leveltheorem ... := by/decreasing_byfollowed by tactics at column 0 must be indentedvariablecontinuations:variable {A : Type*} [Foo A]\n{B : Type*}where the second line starts at column 0 must be indented (most common category in Mathlib)def f : T :=\nexpror#synth Foo\n[args]where the body/arguments start at column 0.symm\n{ toFun := ...where the struct literal starts at column 0🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 [email protected]