chore: remove repeat/while macro_rules bootstrap from Init.While#13479
Merged
Conversation
This PR removes the transitional `macro_rules` for `repeat`, `while`, and `repeat ... until` from `Init.While`. After the latest stage0 update, the `@[builtin_macro]` and `@[builtin_doElem_elab]` definitions in `Lean.Elab.BuiltinDo.Repeat` are picked up directly, so the bootstrap duplicates in `Init.While` are no longer needed. `Init.While` now only provides the `Loop` type and its `ForIn` instance. This PR also adjusts `repeat`'s `ControlInfo` to match `for ... in`: its `numRegularExits` is now unconditionally `1` rather than `if info.breaks then 1 else 0`. Reporting `0` when the body has no `break` made callers treat the continuation as dead code, which broke common patterns where the continuation has a non-`Unit` result type (see discussion on #13437).
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
sgraf812
added a commit
that referenced
this pull request
Apr 20, 2026
This PR fixes `inferControlInfoSeq` and `ControlInfo.sequence` to keep aggregating `breaks`/`continues`/`returnsEarly`/`reassigns` past elements whose `ControlInfo` reports `numRegularExits := 0`. Previously the analysis short-circuited at such elements, causing the inferred info to drop any `return`/`break`/`continue` that followed. The elaboration framework only skips subsequent doElems syntactically for top-level `return`/`break`/`continue` (via `elabAsSyntacticallyDeadCode`); for every other `numRegularExits == 0` case (e.g. a `match`/`if`/`try` whose branches all terminate, or a `repeat` without `break`) the elaborator keeps visiting the continuation, and the for/match elaborator then tripped its invariant check with "Early returning ... but the info said there is no early return". With this change the inferred info matches what the elaborator actually sees, which also removes the need for the `numRegularExits := 1` workaround on `repeat` introduced in #13479.
sgraf812
added a commit
that referenced
this pull request
Apr 20, 2026
This PR fixes `inferControlInfoSeq` and `ControlInfo.sequence` to keep aggregating `breaks`/`continues`/`returnsEarly`/`reassigns` past elements whose `ControlInfo` reports `numRegularExits := 0`. Previously the analysis short-circuited at such elements, causing the inferred info to drop any `return`/`break`/`continue` that followed. The elaboration framework only skips subsequent doElems syntactically for top-level `return`/`break`/`continue` (via `elabAsSyntacticallyDeadCode`); for every other `numRegularExits == 0` case (e.g. a `match`/`if`/`try` whose branches all terminate, or a `repeat` without `break`) the elaborator keeps visiting the continuation, and the for/match elaborator then tripped its invariant check with "Early returning ... but the info said there is no early return". With this change the inferred info matches what the elaborator actually sees, which also removes the need for the `numRegularExits := 1` workaround on `repeat` introduced in #13479.
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Apr 20, 2026
…3486) This PR fixes `inferControlInfoSeq` and `ControlInfo.sequence` to keep aggregating `breaks`/`continues`/`returnsEarly`/`reassigns` past elements whose `ControlInfo` reports `numRegularExits := 0`. Previously the analysis short-circuited at such elements, so any trailing `return`/`break`/`continue` was missing from the inferred info. The elaboration framework only skips subsequent doElems syntactically for top-level `return`/`break`/`continue`; for every other `numRegularExits == 0` case (e.g. a `match`/`if`/`try` whose branches all terminate, or a `repeat` without `break`) the elaborator keeps visiting the continuation and the for/match elaborator then tripped its invariant check with `Early returning ... but the info said there is no early return`. With this change the inferred info matches what the elaborator actually sees, which also removes the need for the `numRegularExits := 1` workaround on `repeat` introduced in #13479.
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 removes the transitional
macro_rulesforrepeat,while, andrepeat ... untilfromInit.While. After the latest stage0 update, the@[builtin_macro]and@[builtin_doElem_elab]definitions inLean.Elab.BuiltinDo.Repeatare picked up directly, so the bootstrap duplicates inInit.Whileare no longer needed.Init.Whilenow only provides theLooptype and itsForIninstance.This PR also adjusts
repeat'sControlInfoto matchfor ... in: itsnumRegularExitsis now unconditionally1rather thanif info.breaks then 1 else 0. Reporting0when the body has nobreakcausesinferControlInfoSeq(in any enclosing sequence whoseControlInfois inferred — e.g. a surroundingfor/if/match/trybody) to stop aggregating after therepeatand miss anyreturn/break/continuethat follows. The corresponding elaborator then sees the actual control flow disagree with the inferred info and throws errors likeEarly returning ... but the info said there is no early return. The new test intests/elab/newdo.leanpins down the regression. See #13437 for further discussion.