Skip to content

Fix preprocessor endless loop with no-op UDC replacements#1963

Merged
RobertvanderHulst merged 2 commits into
mainfrom
copilot/fix-endless-loop-issue
May 29, 2026
Merged

Fix preprocessor endless loop with no-op UDC replacements#1963
RobertvanderHulst merged 2 commits into
mainfrom
copilot/fix-endless-loop-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

The preprocessor loops infinitely when a UDC rule's replacement is textually identical to its input, e.g. #xcommand ENDSEQUENCE [<*any*>] => ENDSEQUENCE. The existing PPUsedRules.isDuplicate() recursion guard fails to catch this case.

#xcommand NOTHING [<*any*>]  => NOTHING
NOTHING   // infinite loop

This also affects the XPP dialect's ENDSEQUENCE rule (XbasePPCmd.xh), triggered by BEGIN SEQUENCE / ENDSEQUENCE.

Changes

  • Added isResultUnchanged() — compares token lists before/after doReplace() by count and text (case-insensitive)
  • doProcessCommands() and doProcessTranslates() now break immediately when the replacement produces identical output, before re-entering the matching loop
  • Applied to both Compiler and MacroCompiler preprocessor implementations

@RobertvanderHulst RobertvanderHulst marked this pull request as ready for review May 29, 2026 16:21
Copilot AI review requested due to automatic review settings May 29, 2026 16:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

… output

Add no-op detection in doProcessCommands() and doProcessTranslates() to
break the processing loop when a UDC rule replacement produces tokens
textually identical to its input. This prevents infinite loops with rules
like `#xcommand NOTHING [<*any*>] => NOTHING` or `#xcommand ENDSEQUENCE
[<*any*>] => ENDSEQUENCE` where the output matches the input pattern.

Applied to both Compiler and MacroCompiler preprocessor implementations.
@RobertvanderHulst RobertvanderHulst merged commit ed5d57e into main May 29, 2026
@RobertvanderHulst RobertvanderHulst deleted the copilot/fix-endless-loop-issue branch May 29, 2026 16:24
Copilot AI changed the title [WIP] Fix endless loop caused by #xcommand NOTHING Fix preprocessor endless loop with no-op UDC replacements May 29, 2026
Copilot stopped work on behalf of RobertvanderHulst due to an error May 29, 2026 16:24
Copilot AI requested a review from RobertvanderHulst May 29, 2026 16:24
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.

Preprocessor enters endless loop with #xcommand NOTHING [<*any*>] => NOTHING

3 participants