Skip to content

refactor: implement GetAstBuilder on visitor/pass types#10424

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

refactor: implement GetAstBuilder on visitor/pass types#10424
graphite-app[bot] merged 1 commit into
mainfrom
om/07-23-refactor_implement_getastbuilder_on_visitor_pass_types

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Follow-on after #10018 and #10353. Pure refactor.

Implement GetAstBuilder and GetAllocator on visitor/pass/context types which hold an AstBuilder.

AST builder methods take any &B where B: GetAstBuilder, so this allows removing a lot of repetitious boilerplate code at call sites.

Before:

Expression::new_string_literal(
  SPAN,
  Str::from_str_in(id, &self.ast_builder),
  None,
  &self.ast_builder,
)

After:

Expression::new_string_literal(SPAN, Str::from_str_in(id, self), None, self)

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 is a follow-on refactor to reduce AST-construction boilerplate by implementing GetAstBuilder/GetAllocator on visitor/finalizer/context types that already hold an AstBuilder, enabling call sites to pass self directly into oxc per-type constructors.

Changes:

  • Implement GetAstBuilder + GetAllocator for several core visitors/finalizers (PreProcessor, ScopeHoistingFinalizer, HmrAstFinalizer) and plugin visitors.
  • Mechanically update AST-construction call sites to pass self (and use take_in(self) / *_in(..., self) patterns).
  • Minor trait-impl reordering/annotation tweaks (e.g., #[inline]) to match the new usage.

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 Makes PreProcessor implement GetAstBuilder/GetAllocator and updates AST construction to pass self.
crates/rolldown/src/module_finalizers/rename.rs Switches AST construction to pass self (via ScopeHoistingFinalizer traits).
crates/rolldown/src/module_finalizers/mod.rs Adds GetAstBuilder/GetAllocator impls for ScopeHoistingFinalizer and updates numerous builder/allocator call sites to pass self.
crates/rolldown/src/module_finalizers/impl_visit_mut.rs Updates finalizer visit-mutations to use self for allocation / AST building.
crates/rolldown/src/module_finalizers/hmr.rs Updates HMR-related rewrites to use self for AST construction.
crates/rolldown/src/hmr/impl_traverse_for_hmr_ast_finalizer.rs Updates traversal logic to use take_in(self) and build nodes with self.
crates/rolldown/src/hmr/hmr_ast_finalizer.rs Implements GetAstBuilder/GetAllocator for HmrAstFinalizer and updates call sites to pass self.
crates/rolldown/src/ast_scanner/const_eval.rs Reorders/updates GetAstBuilder/GetAllocator impls for ConstEvalCtx (adds #[inline]).
crates/rolldown_plugin_vite_web_worker_post/src/ast_visitor.rs Implements GetAstBuilder/GetAllocator for the visitor and updates node construction to pass self.
crates/rolldown_plugin_vite_build_import_analysis/src/ast_visit.rs Implements GetAstBuilder/GetAllocator for the visitor and updates construction sites to pass self.
crates/rolldown_plugin_vite_build_import_analysis/src/ast_utils.rs Refactors helper builders to pass self into constructors and allocator-taking helpers.
crates/rolldown_plugin_lazy_compilation/src/runtime_injector.rs Implements GetAstBuilder/GetAllocator and simplifies import-expression rewrite construction with self.

@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_implement_getastbuilder_on_visitor_pass_types (6802e7c) with om/07-23-perf_hmr_module_finalizer_reduce_string_allocations (c583ea9)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-perf_hmr_module_finalizer_reduce_string_allocations (6466383) during the generation of this report, so b189ae1 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-perf_hmr_module_finalizer_reduce_string_allocations branch from c583ea9 to 6466383 Compare July 24, 2026 00:02
@overlookmotel
overlookmotel force-pushed the om/07-23-refactor_implement_getastbuilder_on_visitor_pass_types branch from 0b48133 to 6802e7c Compare July 24, 2026 00:02

@IWANABETHATGUY IWANABETHATGUY 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.

This is neat!

@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 and #10353. Pure refactor.

Implement `GetAstBuilder` and `GetAllocator` on visitor/pass/context types which hold an `AstBuilder`.

AST builder methods take any `&B where B: GetAstBuilder`, so this allows removing a lot of repetitious boilerplate code at call sites.

Before:

```rust
Expression::new_string_literal(
  SPAN,
  Str::from_str_in(id, &self.ast_builder),
  None,
  &self.ast_builder,
)
```

After:

```rust
Expression::new_string_literal(SPAN, Str::from_str_in(id, self), None, self)
```
@graphite-app
graphite-app Bot force-pushed the om/07-23-perf_hmr_module_finalizer_reduce_string_allocations branch from 6466383 to 55729bb Compare July 24, 2026 03:46
@graphite-app
graphite-app Bot force-pushed the om/07-23-refactor_implement_getastbuilder_on_visitor_pass_types branch from 6802e7c to 8d87835 Compare July 24, 2026 03:47
graphite-app Bot pushed a commit that referenced this pull request Jul 24, 2026
…er` (#10425)

Continuation of #10424.

`ScopeHoistingFinalizer` has these fields:

```rust
pub struct ScopeHoistingFinalizer<'me, 'ast: 'me> {
  pub alloc: &'ast Allocator,
  pub ast_builder: AstBuilder<'ast>,
  // ... other fields ...
}
```

`AstBuilder<'ast>` already contains an `&'ast Allocator`, so this was duplicating the same reference twice.

#10424 removed most usages of `alloc` field as a by-product of shortening code. This PR removes the remaining usage, and removes the `alloc` field itself.
Base automatically changed from om/07-23-perf_hmr_module_finalizer_reduce_string_allocations to main July 24, 2026 03:58
@graphite-app
graphite-app Bot merged commit 8d87835 into main Jul 24, 2026
32 checks passed
@graphite-app
graphite-app Bot deleted the om/07-23-refactor_implement_getastbuilder_on_visitor_pass_types branch July 24, 2026 03:58
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