Skip to content

refactor: shorten AST builder code#10418

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

refactor: shorten AST builder code#10418
graphite-app[bot] merged 1 commit into
mainfrom
om/07-23-refactor_shorten_ast_builder_code

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Follow-on after #10018.

First of a series of PRs all grouped around 2 themes:

  1. Shorten code using AST builder methods.
  2. Reduce string allocations.

The new AST builder methods allow shortened syntax. Utilize the shorter methods wherever possible.

Before:

ast::Statement::ExpressionStatement(ast::ExpressionStatement::boxed(span, call_expr, &self.ast_builder))

After:

ast::Statement::new_expression_statement(span, call_expr, &self.ast_builder)

Note: 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.

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.

@netlify

netlify Bot commented Jul 23, 2026

Copy link
Copy Markdown

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 9886244
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6a62df739ea6aa00083cfe84

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 oxc 0.138 AST-construction migration by refactoring call sites to use the newer shortened new_* constructors (e.g. Expression::new_call_expression, Statement::new_expression_statement) instead of manual enum wrapping + ::boxed(...). The goal is primarily to reduce verbosity while keeping generated AST identical.

Changes:

  • Replaced many EnumVariant(Type::boxed(...)) AST constructions with Type::new_* / Enum::new_* helpers across core, HMR, and plugin crates.
  • Updated common AST utility helpers (ast_factory, binding pattern/property extensions) to use the shortened construction APIs.
  • Adjusted JSON-to-AST object property key construction to use PropertyKey::new_string_literal directly.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/rolldown/src/utils/tweak_ast_for_scanning.rs Switches statement/expression construction to Statement::new_* / Expression::new_* helpers.
crates/rolldown/src/stages/link_stage/generate_lazy_export.rs Uses shortened PropertyKey construction for object properties.
crates/rolldown/src/module_finalizers/rename.rs Simplifies assignment-target identifier construction.
crates/rolldown/src/module_finalizers/mod.rs Large set of AST-construction refactors for finalizer-generated code paths (imports/exports/runtime helpers).
crates/rolldown/src/module_finalizers/impl_visit_mut.rs Refactors statement construction in VisitMut transformations.
crates/rolldown/src/hmr/utils.rs Uses shortened constructors for HMR-injected AST fragments.
crates/rolldown/src/hmr/impl_traverse_for_hmr_ast_finalizer.rs Refactors traversal-produced AST nodes to use new_* helpers (try stmt, calls, literals).
crates/rolldown/src/hmr/hmr_ast_finalizer.rs Refactors HMR finalizer AST building to shortened constructors.
crates/rolldown_plugin_vite_web_worker_post/src/ast_visitor.rs Updates plugin’s AST visitor to shortened member/object/property constructors.
crates/rolldown_plugin_vite_build_import_analysis/src/ast_visit.rs Refactors import-helper insertion to use Statement::new_import_declaration.
crates/rolldown_plugin_vite_build_import_analysis/src/ast_utils.rs Updates preload-call construction and related AST helpers to use new_* APIs.
crates/rolldown_plugin_lazy_compilation/src/runtime_injector.rs Refactors lazy-compilation runtime injection helper AST construction.
crates/rolldown_ecmascript_utils/src/extensions/ast_ext/binding_property_ext.rs Refactors binding-property → assignment-target-property conversion to new constructors.
crates/rolldown_ecmascript_utils/src/extensions/ast_ext/binding_pattern_ext.rs Refactors binding-pattern conversions and expression emission to new constructors.
crates/rolldown_ecmascript_utils/src/ast_factory.rs Refactors shared AST factory helpers (then/arrow/call/member/property/statement builders) to new constructors.
crates/rolldown_common/src/ecmascript/json_to_program.rs Uses PropertyKey::new_string_literal directly for JSON object keys.

Comment thread crates/rolldown/src/module_finalizers/mod.rs Outdated
@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_shorten_ast_builder_code (8e20bae) with main (4de88b1)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 main (99948b5) during the generation of this report, so 4de88b1 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_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.

First of a series of PRs all grouped around 2 themes:

1. Shorten code using AST builder methods.
2. Reduce string allocations.

The new AST builder methods allow shortened syntax. Utilize the shorter methods wherever possible.

Before:

```rust
ast::Statement::ExpressionStatement(ast::ExpressionStatement::boxed(span, call_expr, &self.ast_builder))
```

After:

```rust
ast::Statement::new_expression_statement(span, call_expr, &self.ast_builder)
```

Note: 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 Bot pushed a commit that referenced this pull request Jul 24, 2026
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 merged commit 9886244 into main Jul 24, 2026
35 checks passed
@graphite-app
graphite-app Bot deleted the om/07-23-refactor_shorten_ast_builder_code branch July 24, 2026 03:50
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.

4 participants