Skip to content

Parse statements individually to prevent parser hangs#322

Merged
nlothian merged 4 commits into
mainfrom
codex/fix-parser-hang-on-lists.pl
Dec 6, 2025
Merged

Parse statements individually to prevent parser hangs#322
nlothian merged 4 commits into
mainfrom
codex/fix-parser-hang-on-lists.pl

Conversation

@nlothian

@nlothian nlothian commented Dec 5, 2025

Copy link
Copy Markdown
Owner

Summary

  • parse each clause or directive separately to avoid Earley parser state blow-ups
  • allow direct parsing of clause and directive start rules for faster single-statement handling
  • preserve PlDoc association by adjusting meta positions per statement

Testing

  • uv run pytest tests/test_parser.py::TestBasicParsing::test_parse_fact_with_atom
  • uv run python - <<'PY'
    import signal, sys, time
    from vibeprolog.parser import PrologParser

parser = PrologParser()
with open('library/lists.pl') as f:
content = f.read()

signal.signal(signal.SIGALRM, lambda s,f: sys.exit(1))
signal.alarm(30)
start = time.time()
try:
res = parser.parse(content)
print('parsed', len(res), 'in', time.time()-start)
finally:
signal.alarm(0)
PY


Codex Task

@kilo-code-bot kilo-code-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No Issues Found

1 files reviewed | Confidence: 95% | Recommendation: Merge

Review Details

Files: vibeprolog/parser.py (1 change)

Checked: Security, bugs, performance, error handling, code clarity

Summary: The change implements individual statement parsing to prevent Earley parser state explosion on large files. Code correctly handles position adjustments for PlDoc comments and maintains backward compatibility. No issues found.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant performance and stability improvement by parsing Prolog statements individually, which is an effective strategy to prevent parser hangs on large files. The implementation is well-thought-out, especially in how it preserves PlDoc comment associations by adjusting metadata positions. I have one suggestion to further improve the robustness of the new parsing loop. Overall, this is a solid enhancement.

Comment thread vibeprolog/parser.py Outdated

@kilo-code-bot kilo-code-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No New Issues

Changes since last review look good. Previous issue with statement relocation fallback has been addressed by raising RuntimeError instead.

@kilo-code-bot kilo-code-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No New Issues

Changes since last review look good. The RuntimeError for statement relocation failure is appropriate and addresses the previous fallback issue.

@kilo-code-bot kilo-code-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No New Issues

Changes since last review look good. The new commit adds Edinburgh radix token handling and resets module predicate tracking, both implemented correctly without introducing issues.

Recommendation: Merge

@nlothian
nlothian merged commit 0cb87c1 into main Dec 6, 2025
2 checks passed
@nlothian
nlothian deleted the codex/fix-parser-hang-on-lists.pl branch December 6, 2025 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser: Earley parser hangs on library/lists.pl causing cascade failures across 26+ libraries

1 participant