8000 fix(napi/parser): cache nodes in lazy deserialization by overlookmotel · Pull Request #11637 · oxc-project/oxc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(napi/parser): cache nodes in lazy deserialization #11637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

overlookmotel
Copy link
Contributor
@overlookmotel overlookmotel commented Jun 12, 2025

In lazy-deserialized AST, cache node objects, so accessing the same field twice returns the same object. Previously assert(binaryExpression.left == binaryExpression.left) would fail, as each access returned a new object.

pos (i.e. memory address) is used as the cache key, with 2 exceptions: RegExp and Program.

RegExp doesn't have a span: Span field, so its first field RegExpPattern has the same memory address as the RegExp. So pos would not be a unique key.

pub struct RegExp<'a> {
    pub pattern: RegExpPattern<'a>,
    pub flags: RegExpFlags,
}

pub struct RegExpPattern<'a> {
    pub text: Atom<'a>,
    pub pattern: Option<Box<'a, Pattern<'a>>>,
}

The codegen identifies these cases, and applies a workaround - pos + 1 is used as the cache key instead of pos, so the parent and child have different cache keys.

@github-actions github-actions bot added A-ast-tools Area - AST tools C-bug Category - Bug labels Jun 12, 2025
Copy link
Contributor Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@overlookmotel overlookmotel force-pushed the 06-12-fix_napi_parser_cache_nodes_in_lazy_deserialization branch 3 times, most recently from 00877a4 to 4b67429 Compare June 12, 2025 13:29
@overlookmotel overlookmotel marked this pull request as ready for review June 12, 2025 13:29
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Jun 12, 2025
Copy link
Contributor Author
overlookmotel commented Jun 12, 2025

Merge activity

In lazy-deserialized AST, cache node objects, so accessing the same field twice returns the same object. Previously `assert(binaryExpression.left == binaryExpression.left)` would fail, as each access returned a new object.

`pos` (i.e. memory address) is used as the cache key, with 2 exceptions: `RegExp` and `Program`.

`RegExp` doesn't have a `span: Span` field, so its first field `RegExpPattern` has the same memory address as the `RegExp`. So `pos` would not be a unique key.

```rs
pub struct RegExp<'a> {
    pub pattern: RegExpPattern<'a>,
    pub flags: RegExpFlags,
}

pub struct RegExpPattern<'a> {
    pub text: Atom<'a>,
    pub pattern: Option<Box<'a, Pattern<'a>>>,
}
```

The codegen identifies these cases, and applies a workaround - `pos + 1` is used as the cache key instead of `pos`, so the parent and child have different cache keys.
@graphite-app graphite-app bot force-pushed the 06-12-fix_napi_parser_cache_nodes_in_lazy_deserialization branch from 4b67429 to 931fc73 Compare June 12, 2025 14:26
@graphite-app graphite-app bot merged commit 931fc73 into main Jun 12, 2025
15 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jun 12, 2025
@graphite-app graphite-app bot deleted the 06-12-fix_napi_parser_cache_nodes_in_lazy_deserialization branch June 12, 2025 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast-tools Area - AST tools C-bug Category - Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0