refactor(allocator): Box::new_in take &GetAllocator#23756
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
Updates oxc_allocator::Box::new_in to accept a generic allocator accessor (&A where A: GetAllocator<'a>) instead of requiring a direct &'a Allocator, aligning Box construction ergonomics with the earlier Vec changes and unblocking upcoming AstBuilder API work (#23043).
Changes:
- Refactors
Box::new_into take&GetAllocatorand allocates viaallocator.allocator().alloc(value). - Updates codegen and call sites to pass allocator accessors directly (e.g.
self,ctx) or use&&Allocatorwhen the only available value is&Allocator. - Adjusts docs/tests and supporting helper code (
FromIn,TakeIn,CloneIn, arenaVecconstructors) to the new API.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tasks/ast_tools/src/generators/ast_builder.rs | Updates generator to emit ArenaBox::new_in(..., &self) for alloc methods. |
| crates/oxc_regular_expression/src/parser/pattern_parser/pattern_parser_impl.rs | Switches allocations to pass self (as a GetAllocator implementor). |
| crates/oxc_react_compiler/src/convert_ast_reverse.rs | Updates a boxed allocation to pass &&Allocator (&self.allocator). |
| crates/oxc_minifier/src/peephole/replace_known_methods.rs | Uses ctx as the allocator accessor for regex pattern boxing. |
| crates/oxc_ast/src/generated/ast_builder.rs | Regenerates alloc methods to pass &self into ArenaBox::new_in. |
| crates/oxc_ast/src/ast_builder_impl.rs | Updates AstBuilder::alloc to call ArenaBox::new_in(value, &self). |
| crates/oxc_allocator/src/vec.rs | Adjusts internal Box::new_in usage to the new accessor-based signature. |
| crates/oxc_allocator/src/take_in.rs | Updates take_in_box and Dummy for Box to pass &&Allocator. |
| crates/oxc_allocator/src/convert.rs | Updates FromIn impls to pass &&Allocator (and adds a lint expectation). |
| crates/oxc_allocator/src/clone_in.rs | Updates cloning helpers to pass &&Allocator. |
| crates/oxc_allocator/src/boxed.rs | Implements the new Box::new_in<A: GetAllocator> signature and updates docs/tests accordingly. |
5650ee7 to
0294e4e
Compare
2b69778 to
54bd54b
Compare
Merge activity
|
Part of #23043. Same as #23755, but for `Box`. `Box::new_in` previously took an `&'a Allocator`. Instead make it take an `&A where A: GetAllocator<'a>`. This makes it more flexible - you can pass a reference to any type which implements `GetAllocator` e.g. `ParserImpl`, `TraverseCtx` etc. ```rust // Before (`ctx` here is `&mut TraverseCtx`) let boxed = Box::new_in(value, ctx.ast.allocator); // After let boxed = Box::new_in(value, ctx); ``` The main motivation is to make it a workable replacement for `AstBuilder::alloc`, which will be removed in the new `AstBuilder`: ```rust // Before (`ctx` here is `&mut TraverseCtx`) let boxed = ctx.ast.alloc(value); // After let boxed = ArenaBox::new_in(value, ctx); // Instead of let boxed = ArenaBox::new_in(value, ctx.ast.allocator); ``` This has the same advantages and disadvantages as `Vec` methods - see #23755.
0294e4e to
5201522
Compare
54bd54b to
163ed51
Compare
Part of #23043. Same as #23755, but for `Box`. `Box::new_in` previously took an `&'a Allocator`. Instead make it take an `&A where A: GetAllocator<'a>`. This makes it more flexible - you can pass a reference to any type which implements `GetAllocator` e.g. `ParserImpl`, `TraverseCtx` etc. ```rust // Before (`ctx` here is `&mut TraverseCtx`) let boxed = Box::new_in(value, ctx.ast.allocator); // After let boxed = Box::new_in(value, ctx); ``` The main motivation is to make it a workable replacement for `AstBuilder::alloc`, which will be removed in the new `AstBuilder`: ```rust // Before (`ctx` here is `&mut TraverseCtx`) let boxed = ctx.ast.alloc(value); // After let boxed = ArenaBox::new_in(value, ctx); // Instead of let boxed = ArenaBox::new_in(value, ctx.ast.allocator); ``` This has the same advantages and disadvantages as `Vec` methods - see #23755.

Part of #23043.
Same as #23755, but for
Box.Box::new_inpreviously took an&'a Allocator. Instead make it take an&A where A: GetAllocator<'a>.This makes it more flexible - you can pass a reference to any type which implements
GetAllocatore.g.ParserImpl,TraverseCtxetc.The main motivation is to make it a workable replacement for
AstBuilder::alloc, which will be removed in the newAstBuilder:This has the same advantages and disadvantages as
Vecmethods - see #23755.