refactor(allocator): remove conversions to/from NonNull pointers#21737
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
Refactors oxc_allocator::arena pointer handling to reduce unsafe complexity by avoiding round-trip conversions between NonNull<T> and raw pointers while keeping allocation semantics unchanged.
Changes:
- Replace several raw-pointer operations (
ptr::eq,ptr::write,ptr::copy*,slice_from_raw_parts_mut) withNonNull-native APIs (from_ref,write,copy_from*,slice_from_raw_parts). - Introduce
round_nonnull_ptr_up_to_uncheckedto perform alignment rounding directly onNonNull<u8>. - Simplify chunk footer creation/initialization by keeping pointer arithmetic in
NonNullspace.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_allocator/src/arena/utils.rs | Adds round_nonnull_ptr_up_to_unchecked to align NonNull<u8> without converting to/from raw pointers. |
| crates/oxc_allocator/src/arena/mod.rs | Uses NonNull::from_ref equality for empty-chunk sentinel detection. |
| crates/oxc_allocator/src/arena/from_raw_parts.rs | Switches cursor validation to NonNull comparisons and shared alignment helper. |
| crates/oxc_allocator/src/arena/create.rs | Builds footer/cursor pointers and writes ChunkFooter using NonNull methods. |
| crates/oxc_allocator/src/arena/chunks.rs | Uses NonNull-based pointer math/ordering for chunk iteration and length computation. |
| crates/oxc_allocator/src/arena/alloc_impl.rs | Replaces raw pointer arithmetic and ptr::copy* with NonNull equivalents; updates allocator slice construction. |
| crates/oxc_allocator/src/arena/alloc.rs | Uses NonNull writing/slice construction helpers to reduce raw pointer usage during initialization/copying. |
Merge activity
|
…21737) Refactor to `Arena`. Simplify code and reduce unsafe by avoiding round-trip conversions between `NonNull` and `*mut` pointers.
98805a7 to
3aadfcd
Compare

Refactor to
Arena. Simplify code and reduce unsafe by avoiding round-trip conversions betweenNonNulland*mutpointers.