Skip to content

fix: aggregate ControlInfo past numRegularExits == 0 elements#13486

Merged
sgraf812 merged 1 commit into
masterfrom
sg/infer-control-info-aggregate
Apr 20, 2026
Merged

fix: aggregate ControlInfo past numRegularExits == 0 elements#13486
sgraf812 merged 1 commit into
masterfrom
sg/infer-control-info-aggregate

Conversation

@sgraf812
Copy link
Copy Markdown
Contributor

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.

@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 Apr 20, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-04-20 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-20 20:31:14)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-04-20 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-04-20 20:31:15)

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 sgraf812 force-pushed the sg/infer-control-info-aggregate branch from 2c572ad to 5ddedb0 Compare April 20, 2026 20:54
@sgraf812 sgraf812 marked this pull request as ready for review April 20, 2026 21:12
@sgraf812 sgraf812 enabled auto-merge April 20, 2026 21:12
@sgraf812 sgraf812 added the changelog-language Language features and metaprograms label Apr 20, 2026
@sgraf812 sgraf812 added this pull request to the merge queue Apr 20, 2026
Merged via the queue into master with commit a3cb98b Apr 20, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-language Language features and metaprograms 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.

2 participants