emit-portable: windowed relexing for stateless lexers (S3, #57)#64
Merged
Conversation
Extend doc edit resync with windowed relex step and S3 suffix handling across TS, Go, and Rust targets; update portable-targets coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Slice 3 of #57 (portable incremental
edit). Builds on the S2 alignment window (#63) — this slice makesDoc.edit()actually reuse tokens instead of relexing the whole document:edit()now performs windowed relexing: keep the old token prefix up to a restart anchor (last token ending strictly before the edit, minus one token of maximal-munch guard), scan fresh tokens from that boundary, and resync once a scanned token past the edit region matches an old token shifted by the byte-length delta — the remaining old suffix is adopted with offsets shifted, no rescan.lexFrom(src, pos, pendingNl, acc, limit)with a byte-identical loop body;lex()delegates to it from(0, false). Stateful lexer codegen is untouched.edit(), the doc compares its token stream against a full fresh relex (streamEq). Theedit-sessionstderr JSON grows to{oldN, newN, prefix, suffix, relexed, streamEq}. The self-check deliberately cancels the perf win for now — this slice ships the correctness mechanism; the perf switch comes with later slices.streamEq === trueeverywhere,relexed ≤ 8/5/8bounds on calc large-doc scenarios (measured: 2–4 tokens relexed on ~1.2k-char docs), andrelexed === newNon all fallback scenarios.Parse is still a full reparse — tree reuse is future work.
Validation
node test/portable-targets.ts— calc 8/8 + javascript 5/5 + envspec 1/1 edit-sessions and token-alignments, × 3 targetsnode test/check.ts emit-parity— 5/5 gatesnode test/newline-mode.ts— 29/29;npx tsc --noEmit— cleanstreamEq:false+ alignment mismatches (self-check has teeth), reverted before commitnlflags, insert-before-first — all parity with oracle-derived expectations, windowed path staying atrelexed2–4 on large docs