Skip to content

Take oxc 0.160 and carry the parser's stack floor and speculation budget over - #1327

Open
tolgaergin wants to merge 4 commits into
deps/rust-minor-patch-filetime-stdfrom
deps/oxc-0.160
Open

tolgaergin wants to merge 4 commits into
deps/rust-minor-patch-filetime-stdfrom
deps/oxc-0.160

Conversation

@tolgaergin

@tolgaergin tolgaergin commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Moves every oxc crate from 0.158.0 to 0.160.0 in one step and rebases the patched vendor/oxc_parser onto it. Supersedes #1307, #1306 and #1305, which each bumped one oxc crate (0.159.0) and couldn't build alone. 0.160.0 came out on 2026-11-23, after those PRs opened. Taking it now saves rebasing the patch again next week.

The vendored parser (vendor/oxc_parser/LPM-PATCH.md)

Upstream rewrote what the patch hooks into. A parenthesized list is now parsed once (a cover grammar) and turned into arrow parameters or an expression after its ). Checkpoints are O(1) and no longer copy the lexer's diagnostics. The patch was ported by hand and now makes three changes.

Stack floor:

  • Checked before each token in advance, the JSX variants, and advance_to, which eat_if_next and parse_import_statement use to move to a token the lexer has already read.
  • Recursions that read no token check it once per level:
    • AssignmentTarget::cover and SimpleAssignmentTarget::cover;
    • the new cover_expression_to_binding_pattern and cover_assignment_target_to_binding_pattern;
    • the new check_cover_binding and check_cover_binding_target. These take &self, so stack_exhausted is a Cell<bool>: a check at the floor sets it, and the parse stops at its next token and reports it.
  • set_pure_on_call_or_new_expr and jsx_member_expression_eq recursed once per member of a chain the parser reads in a loop. A debug build overflowed its stack on 200,000 members. Both are loops now.

Speculation budget:

  • The lexer counts the bytes it rewinds and skips, and compares them with the budget at every rewind, its own lookaheads' included. Before, it compared only at the parser's rewinds, so a lexer-only lookahead could pass the budget unreported.
  • The diagnostic-copy cost is gone, since 0.160 copies nothing.
  • A parse that reached the floor reports only that, so the caller retries it on a larger stack.

Linear time where upstream 0.160 is quadratic without speculating:

  • ParserState::last_parenthesized lets a chain of parentheses find its innermost expression without walking the chain at each level. 80,000 nested parentheses took 4.1 s in a release build; they now take 3.4 ms.
  • Before parsing the arguments of an async(…) that mention await again as parameters, upstream walked every entry recorded for a [...a,] literal or a CoverInitializedName before them. A 4 MiB file of [...a,]; and async(await)=>0; would have taken about 25 s without reaching the budget. Both maps are BTreeMaps now, and the entries inside the arguments are split off: that file parses in 57 ms.

lpm-stack-floor.patch is regenerated, and applying it to the pristine 0.160.0 crate reproduces the vendored tree byte for byte.

Measurements (release builds):

  • Speculative work across the 370,776 JS/TS files of a local package store: at most 0.75 bytes read again per byte (0.93 on 0.158). No file used over 30% of its budget, and none hit the budget or the floor (parsed with a 240 MiB floor). PARSE_SPECULATION_PER_BYTE = 2 stays.
  • Nesting capacity on a 64 MiB stack, deepest nesting that parses:
    • arrays, objects, calls and functions take 10–30% more stack per level (arrays 99k → 77k);
    • parentheses and arrow bodies take 40–57% less (87k → 144k);
    • real code nests far less than any of these.

AST changes that still compiled

0.160 gives keys written without brackets their own PropertyKey variants: StaticStringLiteral, StaticNumericLiteral and StaticBigIntLiteral. ObjectProperty.computed is gone. The old StringLiteral / NumericLiteral variants now mean computed keys only. Three threat-rule matches used the old variants, so they compiled but silently stopped matching:

  • destructured_methods: const {'rmSync': remove} = require('fs'); remove(os.homedir(), …) was no longer destructiveFilesystem.
  • Ancestry::numeric_property and Bundles::collect: a bundle's numbered module table ({17: (m,e,r) => …}) no longer resolved, which lost the environment-upload finding through a bundled class.

Both now match the plain and the computed form, as 0.158 did. destructured_methods also reads a template key without substitutions ([`rmSync`]:), which 0.158 missed too. static_name() covers the same keys as before.

oxc_semantic 0.160 gives catch(e){var e=…} a separate var binding. Compared with 0.158, the only difference in findings is an extra shell tag for e.exec() after such a try, which throws at run time anyway.

Tests

  • Rule regressions:

    • aliased_filesystem_methods_keep_their_imported_identity covers rmSync, 'rmSync', ['rmSync'] and [`rmSync`].
    • bundled_class_helper_preserves_the_environment_upload_flow covers 17: and [17]:.

    Each failed before its fix.

  • Floor test: renamed to parenthesized_lists_parsed_just_above_the_floor_become_parameters_or_expressions_without_overflowing.

    • It adds shapes that reach => (arrays, objects, defaults, rests, async, TypeScript return types and annotations) and ((a))=0.
    • It asserts that a parse which didn't stop at the floor read the valid source with no errors.
    • It also passes, in debug and release, without the new floor checks: at today's frame sizes the conversions use less stack per level than the parse that built the nodes. The checks are kept as the patch's rule for every token-free recursion.
  • Parser timing tests (syntax.rs), each failing before its fix:

    • parentheses_nested_tens_of_thousands_of_levels_deep_parse_in_linear_time: 1.28 s against 15 ms before.
    • async_arrow_heads_parsed_again_after_many_spread_literals_parse_in_linear_time: 5.8 s against 147 ms before.
    • pure_comments_and_jsx_names_on_member_chains_of_any_length_parse_without_overflowing: aborted before.
    • lookahead_that_reads_past_the_speculation_budget_stops_the_parse.
  • Budget tests: 0.160 no longer speculates on nested parenthesized lists, so parenthesized_lists_nested_in_defaults_are_parsed_in_linear_time now expects those sources parsed. The budget is tested with shapes 0.160 still parses twice per level, and each test asserts the budget stopped the parse (syntax::exhausts_the_speculation_budget):

    • TypeScript generic arrow heads in defaults (x=<T>(a=<T>(a=…))));
    • a long string inside them;
    • JavaScript async(…) heads that mention await (x=async(a=async(a=…await 0)=>0)=>0).

    All three fail with the budget turned off.

  • Deep-calls timing test: calls_nested_thousands_of_levels_deep_are_analyzed_in_one_pass runs on a 256 MiB stack. A debug build of 0.160 fits 6,724 levels of its object-and-arrow shape in 64 MiB (0.158: 8,173), below the test's 8,000. Release builds fit 30,943.

Dependabot now proposes all oxc_* crates as one group, above rust-minor-and-patch, like windows-rs.

Review

Reviewed by Sol 6.2, Fable 5.2 and Opus 5.5. Every finding above was verified against the code and fixed test-first. A Gemini 4 Neon performance review is running.

Checks run locally (macOS, this branch)

  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
  • cargo fmt --check: clean.
  • cargo test -p lpm-security: 854 pass.
  • cargo test -p lpm-runner: 652 pass.
  • Full workspace nextest gate (hermetic wrapper): 20,032 tests run, 20,030 passed. The two failures are the machine-specific ones described in Take the Rust, dashboard and Actions minor updates, and set file times with std #1326 (a stale local docs checkout and an injected GIT_CONFIG_KEY_0).

🤖 Generated with Claude Code

@tolgaergin
tolgaergin added this pull request to stack #1328 November 25, 2026 01:16
tolgaergin and others added 4 commits November 25, 2026 01:52
…get over

Moves every oxc crate from 0.158.0 to 0.160.0 in one step, as the shared
AST types and the vendored parser require, and rebases
vendor/oxc_parser on 0.160.0.

0.160 parses a parenthesized list once and turns its elements into arrow
parameters or an expression after its `)`. The patch now also checks the
stack floor in advance_to, which moves to a token the lexer has already
read, and in the new conversions and checks that turn those elements into
parameters. The checks borrow the parser, so the stop is kept in a Cell
and reported even when no further token is read. Checkpoints no longer
copy the lexer's diagnostics, so the budget counts only bytes read again
after rewinds. Across the 370,776 JavaScript and TypeScript files of a
local package store, the most any file read again was 0.75 bytes per
byte, and none used more than 30% of its budget.

0.160 gives a key written without brackets its own PropertyKey variants:
StaticStringLiteral, StaticNumericLiteral and StaticBigIntLiteral. The
threat rules matched `"name":` and `17:` keys by the old variants, which
still compiled but no longer matched. That missed `rm` of the home
directory through `const {'rmSync': remove} = require('fs')` and an
environment upload through a bundle's numbered module table. They now
match both forms.

Tests:
- Parenthesized lists that 0.158 parsed twice now parse in linear time.
- The budget tests use TypeScript generic arrow heads nested in defaults,
  which 0.160 still parses twice per level.
- The floor test now parses lists that become arrow parameters.
- The deep-calls timing test runs on a 256 MiB stack, because a debug
  build of 0.160 parses its deepest source in more than 64 MiB.

Dependabot proposes oxc crates as one group from now on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y lexer rewind

oxc 0.160 walked every parenthesis inside a closing one to find where the
expression innermost in them starts, so `((((…a…))))` was quadratic
without speculating: 80,000 levels, which fit on a 64 MiB stack, took
four seconds in a release build. ParserState::last_parenthesized keeps the
innermost start of the ParenthesizedExpression built last, so each level
reads it instead of walking the chain. 80,000 levels now take 3 ms.

The speculation budget was compared only at the parser's rewinds, so a
lookahead that rewinds only the lexer, such as deciding whether `(` starts
a function type, could pass the budget without the parse stopping or
reporting it. The lexer now compares at every rewind and keeps the stop,
and a parse that reached the stack floor still reports only that.

The budget tests now assert that their sources exhaust the budget, not
only that they end up read without parsing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t::cover, and test the async speculation

The parser reads a member chain in a loop, so it uses no stack per
member. Two functions then recursed once per member:
set_pure_on_call_or_new_expr, for `/*#__PURE__*/a.b.c…`, and
jsx_member_expression_eq, which compares `<a.b.c…>` with its closing
tag. A debug build overflowed its stack on 200,000 members, and a release
build relied on the optimizer turning the tail calls into loops. Both are
loops now. SimpleAssignmentTarget::cover, which nested parentheses
recurse through without passing AssignmentTarget::cover, checks the floor
too.

The arguments of an `async(…)` that mention `await` are parsed again as
parameters when `=>` follows, so nesting such heads in their defaults
still makes JavaScript speculate quadratically: 500 bytes read again per
byte at 1,000 levels. The budget stops it. A test now covers it, and the
budget's documentation no longer says only TypeScript speculates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, and match template keys

Before parsing the arguments of an `async(…)` that mention `await` again
as parameters, oxc 0.160 walked every entry recorded for a literal ending
in a spread and a comma, or for a CoverInitializedName, anywhere before
them, while reading almost nothing again. Neither map forgets entries no
conversion consumes, so a 4 MiB file of `[...a,];` and `async(await)=>0;`
took about 25 seconds without reaching the speculation budget. Both maps
are ordered now, and the entries inside the arguments are split off: that
file parses in 57 ms.

destructured_methods also reads a key written as a template without
substitutions, so `const {[`rmSync`]: remove} = require('fs')` keeps its
method.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tolgaergin
tolgaergin marked this pull request as ready for review November 25, 2026 03:39

This branch has not been deployed

No deployments
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