refactor(napi/parser): raw transfer store source text at end of buffer#22392
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR aligns napi/parser’s raw-transfer buffer layout with Oxlint by placing the UTF-8 source text at the end of the active buffer region and passing an explicit sourceStartPos through the JS/Rust deserialization pipeline, simplifying the shared deserializeStr logic and reducing fragile/UB-prone layout assumptions.
Changes:
- Update raw-transfer JS deserializers (parser + Oxlint) to accept
sourceStartPosand treat source-backed string slices as buffer offsets relative to that start. - Update
napi/parserRust raw-transfer entrypoints to acceptsource_startand initialize the arena cursor before the source region so AST data is written “above” it. - Refresh allocator safety commentary related to fixed-size arenas and externally owned buffers.
Reviewed changes
Copilot reviewed 8 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tasks/ast_tools/src/generators/raw_transfer.rs | Updates eager deserializer generator to use sourceStartPos and source-at-end string slicing logic. |
| tasks/ast_tools/src/generators/raw_transfer_lazy.rs | Updates lazy deserializer generator for the new source positioning. |
| napi/parser/src/raw_transfer.rs | Extends N-API raw-transfer parse functions with source_start and adjusts arena cursor/source slicing accordingly. |
| napi/parser/src-js/raw-transfer/common.js | Writes source bytes near the end of the active region and threads sourceStartPos through parse/convert calls. |
| napi/parser/src-js/raw-transfer/eager.js | Updates eager raw-transfer deserializer invocation signature to include sourceStartPos. |
| napi/parser/src-js/raw-transfer/lazy.js | Stores sourceStartPos on the lazy AST wrapper object and updates construction signature. |
| napi/parser/src-js/generated/lazy/constructors.js | Regenerates lazy constructors with updated string/source handling. |
| napi/parser/src-js/generated/deserialize/js.js | Regenerates JS eager deserializer with sourceStartPos-based source string slicing. |
| napi/parser/src-js/generated/deserialize/js_parent.js | Same as above for parent-enabled variant. |
| napi/parser/src-js/generated/deserialize/js_range.js | Same as above for range-enabled variant. |
| napi/parser/src-js/generated/deserialize/js_range_parent.js | Same as above for range+parent variant. |
| napi/parser/src-js/generated/deserialize/ts.js | Regenerates TS eager deserializer with sourceStartPos-based source string slicing. |
| napi/parser/src-js/generated/deserialize/ts_parent.js | Same as above for parent-enabled variant. |
| napi/parser/src-js/generated/deserialize/ts_range.js | Same as above for range-enabled variant. |
| napi/parser/src-js/generated/deserialize/ts_range_parent.js | Same as above for range+parent variant. |
| crates/oxc_allocator/src/arena/fixed_size/windows.rs | Updates comments about fixed-size arena growth safety with externally owned buffers. |
| crates/oxc_allocator/src/arena/alloc_impl.rs | Updates comments describing when is_fixed_size can be true and expected behavior. |
| apps/oxlint/src-js/generated/deserialize.js | Updates Oxlint JS deserializer signature/plumbing to match the new sourceStartPos flow. |
fc55390 to
62e44cc
Compare
62e44cc to
7e21af0
Compare
053c1c6 to
74a046f
Compare
0f1fb87 to
eebf4df
Compare
74a046f to
60033f6
Compare
Merge activity
|
#22392) Oxlint's raw transfer implementation stores the source text at end of the buffer. Prior to this PR `napi/parser` stored source text at the start of the buffer. Bring `napi/parser` into line with Oxlint, by also storing source text at end of the buffer. Making all versions of raw transfer that we use align with each other removes complication (all versions now have the same implementation of `deserializeStr`) and also removes some fragile code where it'd be easy to accidentally trigger UB (see the updated comments in `arena/fixed_size/windows.rs` and `arena/alloc_impl.rs`). Unfortunately, storing source at end of buffer is slightly less efficient than storing it at the start. We'll switch all implementations to storing source at start of buffer when we move to storing all strings (source text and all other strings) together in a single contiguous block. But in meantime, this slight inefficiency is outweighed by the gain in safety.
60033f6 to
4ab57eb
Compare
eebf4df to
c2c8f80
Compare

Oxlint's raw transfer implementation stores the source text at end of the buffer. Prior to this PR
napi/parserstored source text at the start of the buffer.Bring
napi/parserinto line with Oxlint, by also storing source text at end of the buffer.Making all versions of raw transfer that we use align with each other removes complication (all versions now have the same implementation of
deserializeStr) and also removes some fragile code where it'd be easy to accidentally trigger UB (see the updated comments inarena/fixed_size/windows.rsandarena/alloc_impl.rs).Unfortunately, storing source at end of buffer is slightly less efficient than storing it at the start. We'll switch all implementations to storing source at start of buffer when we move to storing all strings (source text and all other strings) together in a single contiguous block. But in meantime, this slight inefficiency is outweighed by the gain in safety.