Skip to content

TeX reader: don't reparse a script after an error inside it - #310

Merged
jgm merged 1 commit into
jgm:masterfrom
Lotion-3:tex-reader-script-error-backtracking
Nov 27, 2026
Merged

jgm merged 1 commit into
jgm:masterfrom
Lotion-3:tex-reader-script-error-backtracking

Conversation

@Lotion-3

Copy link
Copy Markdown
Contributor

After 0495533, nested scripts parse in linear time, but not when there is an error inside them: scripted is wrapped in try, so an error in a script argument makes it backtrack, and bareSubSup then parses the same script again, at every level. So the input of nested_scripts_performance.test with a \right) at the innermost level doesn't finish (16 levels already take a second). This removes the try, so an error inside a script is just an error; I checked ~20,000 mutated inputs and the results (parse or error, and the output) are the same as before. Added that input as a test.

scripted was wrapped in try, so an error inside a script argument made
it backtrack, expr returned the base alone, and bareSubSup then parsed
the same script again, at every level: with an error at the innermost
level, nested scripts still took time exponential in the depth (16
levels took 1s, the 29 of the new test didn't finish in 10 minutes),
although 0495533 made the valid case linear. Once a script has
started, an error in it is now an error.
@jgm
jgm merged commit a969e8b into jgm:master Nov 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants