refactor(allocator): get pointer address with .addr() not as usize#21730
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR refactors pointer address and alignment checks in oxc_allocator’s arena implementation to use Rust’s strict-provenance APIs (.addr()) and the existing is_pointer_aligned_to helper, reducing reliance on ptr as usize casts.
Changes:
- Replace raw pointer-to-
usizecasts (ptr as usize) withptr.addr()across arena utilities and tests. - Use
is_pointer_aligned_tofor debug alignment checks instead of modulo arithmetic in allocator code paths. - Update docs/tests to compare pointer addresses via
.addr()and use clearer alignment assertions.
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 | Switches alignment/address logic to ptr.addr() while preserving provenance-sensitive pointer rounding behavior. |
| crates/oxc_allocator/src/arena/tests_alloc.rs | Updates address and alignment assertions to use .addr() / is_multiple_of. |
| crates/oxc_allocator/src/arena/tests.rs | Updates realloc-related pointer address comparisons to .addr(). |
| crates/oxc_allocator/src/arena/from_raw_parts.rs | Uses is_pointer_aligned_to for start_ptr alignment debug assertion. |
| crates/oxc_allocator/src/arena/create.rs | Uses is_pointer_aligned_to for debug pointer alignment checks; updates docs to .addr(). |
| crates/oxc_allocator/src/arena/chunks.rs | Computes chunk capacity via .addr() subtraction instead of pointer casts. |
| crates/oxc_allocator/src/arena/alloc_impl.rs | Updates comments and debug assertions to use .addr()/is_pointer_aligned_to. |
Merge activity
|
#21730) Avoid conversion of pointers to `usize` addresses using `ptr as usize`. `ptr.addr()` is more idiomatic. Also, use the existing `is_pointer_aligned_to` helper function for alignment checks instead of `ptr.addr() % align == 0`. The former is clearer, and also checks in debug builds that `align` is a valid power of 2.
9ea06ef to
a2104e5
Compare
e528523 to
236d03c
Compare

Avoid conversion of pointers to
usizeaddresses usingptr as usize.ptr.addr()is more idiomatic.Also, use the existing
is_pointer_aligned_tohelper function for alignment checks instead ofptr.addr() % align == 0. The former is clearer, and also checks in debug builds thatalignis a valid power of 2.