fix: format choice nodes from duplicate syntax without uncaught backtrack - #14696
Open
jcreinhold wants to merge 1 commit into
Open
fix: format choice nodes from duplicate syntax without uncaught backtrack#14696jcreinhold wants to merge 1 commit into
choice nodes from duplicate syntax without uncaught backtrack#14696jcreinhold wants to merge 1 commit into
Conversation
…ktrack This PR fixes the pretty printer throwing `format: uncaught backtrack exception` on commands with a binder whose whole type is a doubly-declared notation (leanprover#14611), and `sepByIndent` sequences (e.g. tactic blocks) being silently truncated when the same backtrack was swallowed by a separator. A `choice` node packs every successful parse of one byte range as siblings, and the two choice branches each broke the traversal protocol differently: `categoryFormatterCore` left the cursor on another alternative instead of past the choice, and `orelse.formatter` re-ran its own productions on a bare alternative whose required siblings live outside the choice. Add `visitChosenChoice`, which formats the last alternative and restores the cursor to the choice's left sibling, and let the `orelse` branch fall back to running its right side at the choice itself, routing ambiguous inner choices to their own formatter.
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
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 the pretty printer throwing
format: uncaught backtrack exceptionon binders whose type is a doubly-declared notation (fixes #14611), and fixes tactic blocks and othersepByIndentsequences being silently truncated when a separator swallowed the same failure.Declaring the same notation tokens twice (e.g. mathlib's
⊨) makes the parser pack both parses into achoicenode. The twochoicebranches inFormatter.leaneach mishandled it:categoryFormatterCoreleft the cursor on the previous alternative instead of past thechoice, so the enclosing walk looked for the next token (e.g. a binder's:) in the wrong place.orelse.formatterre-ran its own productions on the bare alternative. Those productions expect siblings that live outside thechoice, so this always backtracked — unless the choice was theorelse's own (an antiquot choice), the case the branch exists for.The fix adds
visitChosenChoice, which formats the last alternative and restores the cursor to thechoice's left sibling. Theorelsebranch falls back to running its right-hand production at thechoiceitself, routing the choice to its own position's formatter. The "format only last choice" heuristic and the output of all previously-successful inputs are unchanged.Adds
tests/elab/formatChoiceNode.leancovering the binder crash, the previously-working positions, and the silent truncation.