refactor(allocator): remove sentinel empty chunk#21775
refactor(allocator): remove sentinel empty chunk#21775graphite-app[bot] merged 1 commit intomainfrom
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR refactors oxc_allocator::arena::Arena’s chunk linked-list termination from a static sentinel footer to Option<NonNull<ChunkFooter>>, making an empty arena explicitly represented by None and using a dangling aligned pointer for start_ptr/cursor_ptr in the empty state.
Changes:
- Replaces the static empty chunk sentinel with
None-terminated chunk links (current_chunk_footer_ptrandprevious_chunk_footer_ptrbecomeOption). - Introduces
EMPTY_ARENA_DATA_PTRas the empty-arena sentinel forstart_ptr/cursor_ptrand adjusts constructors/iterators/drop/reset accordingly. - Updates raw-parts helpers and tests to work with the new
Option-based representation.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_allocator/src/arena/tests_alloc.rs | Updates test arena construction to use Some(footer_ptr) for the current chunk. |
| crates/oxc_allocator/src/arena/mod.rs | Changes Arena and ChunkFooter pointer fields to Option, removes the static empty footer, adds EMPTY_ARENA_DATA_PTR. |
| crates/oxc_allocator/src/arena/from_raw_parts.rs | Adjusts raw-parts initialization and pointer accessors for Option footer pointers and empty-arena behavior. |
| crates/oxc_allocator/src/arena/drop.rs | Updates reset/drop chunk traversal and deallocation to stop at None rather than a sentinel footer. |
| crates/oxc_allocator/src/arena/create.rs | Refactors new_impl/new_chunk APIs for the new representation and updates constructors. |
| crates/oxc_allocator/src/arena/chunks.rs | Updates accounting and iterators to traverse until None and changes iterator state to Option. |
| crates/oxc_allocator/src/arena/alloc_impl.rs | Updates slow-path chunk growth and retirement logic to handle empty arenas (None) safely. |
7e57e6e to
f37bdbc
Compare
dac3cb8 to
c3cb15b
Compare
Merge activity
|
The chunks in an `Arena` form a linked list. Previously the list was terminated with a canonical empty chunk, defined as a `static`. Now that we store `start_ptr` and `cursor_ptr` in `Arena` itself (#21483), an empty `Arena` doesn't need to have a pointer to a chunk. Remove the empty chunk, and use `None` to signify the end of the linked list instead. This makes checking "is this chunk the last?" a little cheaper (comparison to 0, not a 64-bit static value), and feels less hacky, and more explicit. It also removes the potential hazard of accidentally mutating the immutable `static` empty chunk.
c3cb15b to
33f5535
Compare
f37bdbc to
f9ba289
Compare

The chunks in an
Arenaform a linked list. Previously the list was terminated with a canonical empty chunk, defined as astatic.Now that we store
start_ptrandcursor_ptrinArenaitself (#21483), an emptyArenadoesn't need to have a pointer to a chunk.Remove the empty chunk, and use
Noneto signify the end of the linked list instead.This makes checking "is this chunk the last?" a little cheaper (comparison to 0, not a 64-bit static value), and feels less hacky, and more explicit. It also removes the potential hazard of accidentally mutating the immutable
staticempty chunk.