Skip to content

Compute initial IELR lookaheads in item dependency order - #879

Merged
ydah merged 1 commit into
masterfrom
fix/compute-initial-ielr-item-lookaheads
Nov 24, 2026
Merged

ydah merged 1 commit into
masterfrom
fix/compute-initial-ielr-item-lookaheads

Conversation

@ydah

@ydah ydah commented Nov 24, 2026

Copy link
Copy Markdown
Member

When predecessor states form a cycle, Lrama could read an unfinished item's lookahead as an empty set. This made the generated IELR parser reject valid input such as caad in the regression grammar.

Compute each item's lookahead after the items it depends on. Each predecessor item has its dot one position earlier in the same rule, so processing the collected items in increasing dot position also handles recursive grammars.

Correctness check Before After
Inputs accepted by the regression parser (21,845 tested) 23 32
Initial lookahead sets differing from an independent calculation (25,624 checked across 250 recursive grammars) 413 0

On the regression grammar, the generated parser agrees with Bison 3.8.2's IELR and canonical LR parsers on every input over a–d through length seven. Ruby's parse.y produces identical C and --report=all output.

Measured on Ruby 4.0.9, arm64 macOS, with YJIT disabled. Each timing block used 12 paired runs in balanced, randomized order.

Ruby parse.y (IELR) Before (70e68ec) After (04e7170)
CLI elapsed time, first block 1.455 s 1.515 s
CLI elapsed time, repeat 1.468 s 1.492 s
Warm CPU time 1.289 s 1.315 s
Warm allocated objects 3,840,155 3,862,629

The paired CLI slowdown was 4.18% in the first block (bootstrap 95% CI +1.86% to +6.88%) and 1.73% in the repeat (−0.55% to +4.11%). The corrected lookaheads produce 37,885 annotations for parse.y, up from 36,583.

@ydah
ydah merged commit 5d79308 into master Nov 24, 2026
45 checks passed
@ydah
ydah deleted the fix/compute-initial-ielr-item-lookaheads branch November 24, 2026 08:19
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.

1 participant