Skip to content

refactor(allocator): get pointer address with .addr() not as usize#21730

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/04-24-refactor_allocator_get_pointer_address_with_.addr_not_as_usize_
Apr 24, 2026
Merged

refactor(allocator): get pointer address with .addr() not as usize#21730
graphite-app[bot] merged 1 commit intomainfrom
om/04-24-refactor_allocator_get_pointer_address_with_.addr_not_as_usize_

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Apr 24, 2026

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.

Copy link
Copy Markdown
Member Author

overlookmotel commented Apr 24, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of 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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 24, 2026

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing om/04-24-refactor_allocator_get_pointer_address_with_.addr_not_as_usize_ (236d03c) with main (83b91f5)2

Open in CodSpeed

Footnotes

  1. 3 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 main (236d03c) during the generation of this report, so 83b91f5 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel self-assigned this Apr 24, 2026
@overlookmotel overlookmotel added C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior A-allocator Area - Allocator labels Apr 24, 2026
@overlookmotel overlookmotel marked this pull request as ready for review April 24, 2026 19:53
Copilot AI review requested due to automatic review settings April 24, 2026 19:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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-usize casts (ptr as usize) with ptr.addr() across arena utilities and tests.
  • Use is_pointer_aligned_to for 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.

@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app Bot commented Apr 24, 2026

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.
@graphite-app graphite-app Bot force-pushed the om/04-24-refactor_allocator_make_arena_is_last_allocation_a_safe_method branch from 9ea06ef to a2104e5 Compare April 24, 2026 21:16
@graphite-app graphite-app Bot force-pushed the om/04-24-refactor_allocator_get_pointer_address_with_.addr_not_as_usize_ branch from e528523 to 236d03c Compare April 24, 2026 21:16
Base automatically changed from om/04-24-refactor_allocator_make_arena_is_last_allocation_a_safe_method to main April 24, 2026 21:21
@graphite-app graphite-app Bot merged commit 236d03c into main Apr 24, 2026
37 checks passed
@graphite-app graphite-app Bot deleted the om/04-24-refactor_allocator_get_pointer_address_with_.addr_not_as_usize_ branch April 24, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-allocator Area - Allocator C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants