Skip to content

Commit fd16358

Browse files
committed
parser: keep the adoption cache across recovery attempts (#45)
The recovery second pass re-runs the entry rule under a growing bar set, up to 33 attempts. Each attempt cleared adoptPath/adoptBase — the descent cache into the PRE-EDIT tree — and rebuilt it from the root. That reset is redundant: adoptRoot is the pre-edit tree, fixed for the whole loop, so the cache stays valid across attempts; adoptSeek already self-truncates to the prefix that still contains the current token, and the bars change the adoption DECISION (re-checked per call), not the navigation. Dropping the per-attempt reset lets a later attempt reuse the descent past the memo-reused bar-free prefix. Only the per-attempt run-extension state still resets. recovery / incremental-verify / exhaustive-edits confirm every recovered tree stays byte-identical.
1 parent b41ee24 commit fd16358

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/emit-parser.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3950,8 +3950,11 @@ ${e.soa ? String.raw` // ── M1: WINDOWED re-lex ──
39503950
for (let i = 0; i < lexSnap.length; i++) docLex.push(lexSnap[i]);
39513951
recoverBars = bars;
39523952
memoGenCur++;
3953-
adoptPath.length = 0;
3954-
adoptBase.length = 0;
3953+
// adoptPath/adoptBase PERSIST across recovery attempts (C4): adoptRoot is the
3954+
// pre-edit tree, fixed for the whole loop, so the navigation cache stays valid;
3955+
// adoptSeek self-truncates to the prefix containing the new q. Bars change the
3956+
// adoption DECISION (re-evaluated per call), not the cache. Only the per-attempt
3957+
// run-extension state resets.
39553958
adoptRunPos = -1;
39563959
scn = 0;
39573960
root = runParse(entryRule);
@@ -3970,8 +3973,11 @@ ${e.soa ? String.raw` // ── M1: WINDOWED re-lex ──
39703973
docLex.length = 0;
39713974
for (let i = 0; i < lexSnap.length; i++) docLex.push(lexSnap[i]);
39723975
memoGenCur++;
3973-
adoptPath.length = 0;
3974-
adoptBase.length = 0;
3976+
// adoptPath/adoptBase PERSIST across recovery attempts (C4): adoptRoot is the
3977+
// pre-edit tree, fixed for the whole loop, so the navigation cache stays valid;
3978+
// adoptSeek self-truncates to the prefix containing the new q. Bars change the
3979+
// adoption DECISION (re-evaluated per call), not the cache. Only the per-attempt
3980+
// run-extension state resets.
39753981
adoptRunPos = -1;
39763982
scn = 0;
39773983
root = runParse(entryRule);

0 commit comments

Comments
 (0)