Skip to content

refactor: pass arrays to AST builder methods#10419

Merged
graphite-app[bot] merged 1 commit into
mainfrom
om/07-23-refactor_pass_arrays_to_ast_builder_methods
Jul 24, 2026
Merged

refactor: pass arrays to AST builder methods#10419
graphite-app[bot] merged 1 commit into
mainfrom
om/07-23-refactor_pass_arrays_to_ast_builder_methods

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Follow-on after #10018.

The new AST builder methods allow passing arrays where a Vec is required. Use this facility to remove a lot of repetitious boilerplate.

Before:

FunctionBody::new(
  SPAN,
  oxc::allocator::Vec::new_in(&self.ast_builder),
  oxc::allocator::Vec::from_value_in(try_stmt, &self.ast_builder),
  &self.ast_builder,
)

After:

FunctionBody::new(SPAN, [], [try_stmt], &self.ast_builder)

Note: Like #10418, diff is quite large, but these changes were almost entirely produced using the same deterministic codemod we used to migrate Oxc repo to new AST builder, with only some final tweaks by an LLM. I've reviewed it all and, even though I'm unfamiliar with Rolldown's codebase, I'm pretty confident it looks correct.

overlookmotel commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the AST-construction refactor (follow-on after #10018) by leveraging oxc’s updated per-type AST constructors that accept array literals where an arena Vec was previously required, reducing boilerplate and improving readability at many call sites.

Changes:

  • Replaces oxc::allocator::Vec::{new_in, from_value_in, from_array_in} usages at constructor call sites with [] / [...] array literals where supported.
  • Simplifies construction of common AST nodes (calls, function bodies/params, object expressions, programs) across finalizers, HMR codegen, and plugins.
  • Keeps existing arena-allocated Vec usage where mutation/capacity management is still needed.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/rolldown/src/utils/tweak_ast_for_scanning.rs Uses [] / [...] when constructing export decls and call arguments during preprocessing rewrites.
crates/rolldown/src/module_finalizers/mod.rs Replaces many arena Vec constructions with array literals in scope-hoisting finalizer AST generation.
crates/rolldown/src/module_finalizers/impl_visit_mut.rs Simplifies ImportMeta rewrite to an empty object literal via new_object_expression(SPAN, [], ...).
crates/rolldown/src/hmr/utils.rs Uses array literals for object properties and call arguments in HMR runtime registration AST.
crates/rolldown/src/hmr/impl_traverse_for_hmr_ast_finalizer.rs Simplifies try/finally wrapper block/function construction using [] / [...].
crates/rolldown/src/hmr/hmr_ast_finalizer.rs Converts multiple call/sequence/function-body argument lists to array literals in HMR finalization logic.
crates/rolldown_plugin_vite_web_worker_post/src/ast_visitor.rs Uses array literal for the single-property importMeta object expression.
crates/rolldown_plugin_vite_build_import_analysis/src/ast_utils.rs Uses array literals for pattern properties and small single-item declaration lists.
crates/rolldown_plugin_lazy_compilation/src/runtime_injector.rs Uses array literals for .then(...) args, formal params, and var decls in injected helper/function bodies.
crates/rolldown_ecmascript/src/ecma_compiler.rs Builds a program from a parsed expression using [] / [...] for directives/comments/body.
crates/rolldown_ecmascript_utils/src/ast_factory.rs Updates factory helpers to pass [] / [...] for params/bodies/args and keeps mutable arena Vec where needed.
crates/rolldown_common/src/ecmascript/json_to_program.rs Builds a minimal program from JSON using array literals for directives/comments/body.

@codspeed-hq

codspeed-hq Bot commented Jul 23, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing om/07-23-refactor_pass_arrays_to_ast_builder_methods (d5762eb) with om/07-23-refactor_shorten_ast_builder_code (4e5b677)2

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on om/07-23-refactor_shorten_ast_builder_code (8e20bae) during the generation of this report, so e803c3a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel
overlookmotel force-pushed the om/07-23-refactor_pass_arrays_to_ast_builder_methods branch from de7535b to d5762eb Compare July 24, 2026 00:02
@overlookmotel
overlookmotel force-pushed the om/07-23-refactor_shorten_ast_builder_code branch from 4e5b677 to 8e20bae Compare July 24, 2026 00:02

@hyfdev hyfdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

— Review by @hyfdev, assisted by GPT-5

@graphite-app

graphite-app Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Merge activity

Follow-on after #10018.

The new AST builder methods allow passing arrays where a `Vec` is required. Use this facility to remove a lot of repetitious boilerplate.

Before:

```rust
FunctionBody::new(
  SPAN,
  oxc::allocator::Vec::new_in(&self.ast_builder),
  oxc::allocator::Vec::from_value_in(try_stmt, &self.ast_builder),
  &self.ast_builder,
)
```

After:

```rust
FunctionBody::new(SPAN, [], [try_stmt], &self.ast_builder)
```

Note: Like #10418, diff is quite large, but these changes were almost entirely produced using the same [deterministic codemod](https://github.com/oxc-project/oxc/tree/overlookmotel/ast-builder-codemod) we used to migrate Oxc repo to new AST builder, with only some final tweaks by an LLM. I've reviewed it all and, even though I'm unfamiliar with Rolldown's codebase, I'm pretty confident it looks correct.
@graphite-app
graphite-app Bot force-pushed the om/07-23-refactor_shorten_ast_builder_code branch from 8e20bae to 9886244 Compare July 24, 2026 03:43
@graphite-app
graphite-app Bot force-pushed the om/07-23-refactor_pass_arrays_to_ast_builder_methods branch from d5762eb to 4240c14 Compare July 24, 2026 03:44
Base automatically changed from om/07-23-refactor_shorten_ast_builder_code to main July 24, 2026 03:50
@graphite-app
graphite-app Bot merged commit 4240c14 into main Jul 24, 2026
32 checks passed
@graphite-app
graphite-app Bot deleted the om/07-23-refactor_pass_arrays_to_ast_builder_methods branch July 24, 2026 03:54
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.

3 participants