Flat token buffer: lexer-fused parsing, flat mbe transcription, view-backed macro args [-1.07% incl tt-heavy] - #57
Draft
xmakro wants to merge 5 commits into
Draft
Flat token buffer: lexer-fused parsing, flat mbe transcription, view-backed macro args [-1.07% incl tt-heavy]#57xmakro wants to merge 5 commits into
xmakro wants to merge 5 commits into
Conversation
xmakro
force-pushed
the
perf/flat-token-cursor
branch
from
July 27, 2026 21:37
655edfd to
6728659
Compare
The parser consumes tokens from a pre-flattened entry buffer: advancing is an index increment, lookahead is direct indexing, and parser snapshots clone two Arcs instead of a cursor stack.
Lexing a source file now produces the flat entry buffer without building a token tree first. The few cold callers that still need a TokenStream rebuild it from the buffer.
mbe transcription writes open/close entries and match indices through FlatSink. Captured tt fragments splice as buffer slices instead of being rebuilt as trees and re-flattened on every expansion.
Macro invocation arguments flow to the matcher as views of the source buffer, materialized to trees only on first tree-level access. Debug output is bounded to the viewed range and the pre-expansion KeywordIdents lint scans flat entries, so neither defeats the laziness by materializing every invocation in the crate.
The parser runs entirely on FlatTokenCursor, so the old tree-walking TokenCursor and its TokenTreeCursor are unreferenced. Delete both and retarget the stale break_up_float FIXME at the cursor that now exists.
xmakro
force-pushed
the
perf/flat-token-cursor
branch
from
August 1, 2026 08:44
6728659 to
7646199
Compare
This was referenced Aug 1, 2026
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.
The full flat-token architecture. Five commits:
from_str, cmdline attrs, diagnostics fake streams) rebuild it from the buffer. Delimiter-recovery diagnostics are preserved byte-for-byte.$x:ttfragments splice as buffer slices, restoring the Arc-clone-class sharing the old cursor had atparse_token_tree.Performance (ThinLTO stage2, instructions:u, full scenario, measured on top of the whole perf stack):
Correctness, validated standalone on this branch (no stack):
x check compilerandsrc/librustdocpass; tests/pretty 110/110.Remaining follow-ups (not blockers): proc-macro output still arrives as a tree and pays one flatten per expansion (bridge-side flat emission is the next lever); mbe attr/derive rules materialize a tree at the boundary.