fix: aggregate ControlInfo past numRegularExits == 0 elements#13486
Merged
Conversation
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
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.
2c572ad to
5ddedb0
Compare
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 fixes
inferControlInfoSeqandControlInfo.sequenceto keep aggregatingbreaks/continues/returnsEarly/reassignspast elements whoseControlInforeportsnumRegularExits := 0. Previously the analysis short-circuited at such elements, so any trailingreturn/break/continuewas missing from the inferred info. The elaboration framework only skips subsequent doElems syntactically for top-levelreturn/break/continue; for every othernumRegularExits == 0case (e.g. amatch/if/trywhose branches all terminate, or arepeatwithoutbreak) the elaborator keeps visiting the continuation and the for/match elaborator then tripped its invariant check withEarly 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 thenumRegularExits := 1workaround onrepeatintroduced in #13479.