You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I read the full article and mapped all of its proposals against the current Rust generation/runtime path.
Main conclusion
There are three reusable source-rewrite families worth pursuing, but they need a new pre-ANTLR stage first. antlr4-rust-gen currently receives .interp after ANTLR has already constructed the ATN; --grammar is used for semantic metadata/actions and cannot change prediction structure.
The distinction between tree/API preserving and recognition preserving is essential. This target exposes one public method per parser rule plus typed contexts/listener events. A rewrite can preserve the accepted token language while still breaking generated APIs, tree shape, labels, action timing, alternative numbers, diagnostics, or recovery.
Merging call categories is only automatable where the result is algebraically language-equivalent. The article's generalized examples can widen accepted argument forms; that semantic generalization is not included.
Not filed as new optimization issues:
Two-stage SLL then LL (15.2%) is runtime policy, not .g4 preprocessing. This runtime already exposes PredictionMode::Sll and BailErrorStrategy, and generated adaptive decisions perform SLL prediction before full-context escalation. Any whole-parse retry convenience should be justified separately, not mixed into the grammar pass.
Parser reuse is already supported by generated recognizer reset/re-feed APIs (the article also measured no meaningful gain).
Semantic-predicate merging regressed the article workload by 6%; adding runtime predicates is particularly harmful to prediction and is excluded.
Operator merging/grouping and left-recursive variable-access factoring require knowledge of intended precedence and associativity. ANTLR encodes precedence through left-recursive alternative order; a heuristic cannot assume separately ordered operators were intended to share a level.
Outsourcing built-in validation to visitors changes the grammar's accepted language and moves cost/behavior into application code. It is not a semantics-preserving codegen optimization.
Comment character-class correction ([\n|\r] to [\r\n]) is a correctness change that removes literal |; intent cannot be inferred safely and it was not a parse-time win.
Heap sizing, explicit lexer rules, whitespace/newline consolidation, subrule reordering, another declaration factorization, concrete EBNF substitutions, expression reordering, and manual left-recursion elimination were reported as neutral or ineffective. Several can also change token channels, ambiguity ordering, or precedence.
Speedy ANTLR is an alternative native backend strategy, not grammar preprocessing.
Visitor/listener caching is application-specific and the article provides no generic runtime transformation to implement.
Evidence standard
The article's 85.6% headline is the combined result for one Rula grammar using a generated Python parser, with some visitor changes. It is not an expected result for this Rust target, whose generated parser already performs LL(1)/SLL/adaptive specialization. Each pass therefore needs same-machine generated-Rust A/B evidence and before/after ATN/adaptive-decision metrics; shorter source or generated line count alone is insufficient.
Activity
tinovyatkin commentedon Jul 19, 2026
I read the full article and mapped all of its proposals against the current Rust generation/runtime path.
Main conclusion
There are three reusable source-rewrite families worth pursuing, but they need a new pre-ANTLR stage first.
antlr4-rust-gencurrently receives.interpafter ANTLR has already constructed the ATN;--grammaris used for semantic metadata/actions and cannot change prediction structure.I created these ordered sub-issues:
P X | P, shared call prefixes/suffixes, etc.)The distinction between tree/API preserving and recognition preserving is essential. This target exposes one public method per parser rule plus typed contexts/listener events. A rewrite can preserve the accepted token language while still breaking generated APIs, tree shape, labels, action timing, alternative numbers, diagnostics, or recovery.
How the article maps
Applicable under conservative eligibility:
.key()merge (1.4%), call factorization (>1%), and the non-left-recursive parts of the variable-access rewrites reduce to common structural factoring: perf(codegen): left-factor pure parser alternatives and optional tails #129.Not filed as new optimization issues:
.g4preprocessing. This runtime already exposesPredictionMode::SllandBailErrorStrategy, and generated adaptive decisions perform SLL prediction before full-context escalation. Any whole-parse retry convenience should be justified separately, not mixed into the grammar pass.[\n|\r]to[\r\n]) is a correctness change that removes literal|; intent cannot be inferred safely and it was not a parse-time win.Evidence standard
The article's 85.6% headline is the combined result for one Rula grammar using a generated Python parser, with some visitor changes. It is not an expected result for this Rust target, whose generated parser already performs LL(1)/SLL/adaptive specialization. Each pass therefore needs same-machine generated-Rust A/B evidence and before/after ATN/adaptive-decision metrics; shorter source or generated line count alone is insufficient.