Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Nov 24, 2025

A further step in refactoring Address to make it more robust and performant.

Make Address::from_ptr an unsafe method, with the safety invariant that the pointer must be non-null. This:

  1. Further discourages use of Address::from_ptr - GetAddress::address or UnstableAddress::unstable_address should be used instead.
  2. Opens the door to changing Address's inner type from usize to NonZeroUsize, which will reduce Option<Address> from 16 bytes to 8.

@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Nov 24, 2025
Copy link
Member Author


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 hot fixes, skip the queue and merge this PR next

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.

@overlookmotel overlookmotel marked this pull request as ready for review November 24, 2025 01:44
Copilot AI review requested due to automatic review settings November 24, 2025 01:44
@overlookmotel overlookmotel self-assigned this Nov 24, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 24, 2025

CodSpeed Performance Report

Merging #16021 will not alter performance

Comparing 11-24-refactor_allocator_make_address_from_ptr_an_unsafe_method (1b1200a) with main (3fe5225)1

Summary

✅ 42 untouched
⏩ 3 skipped2

Footnotes

  1. No successful run was found on main (b8bf404) during the generation of this report, so 3fe5225 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 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.

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Nov 24, 2025
Copy link
Member Author

overlookmotel commented Nov 24, 2025

Merge activity

Copilot finished reviewing on behalf of overlookmotel November 24, 2025 01:46
graphite-app bot pushed a commit that referenced this pull request Nov 24, 2025
A further step in refactoring `Address` to make it more robust and performant.

Make `Address::from_ptr` an unsafe method, with the safety invariant that the pointer must be non-null. This:

1. Further discourages use of `Address::from_ptr` - `GetAddress::address` or `UnstableAddress::unstable_address` should be used instead.
2. Opens the door to changing `Address`'s inner type from `usize` to `NonZeroUsize`, which will reduce `Option<Address>` from 16 bytes to 8.
@graphite-app graphite-app bot force-pushed the 11-24-refactor_allocator_make_address_from_ptr_an_unsafe_method branch from 1b1200a to 12cd060 Compare November 24, 2025 01:46
Copy link
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 the Address API by making Address::from_ptr an unsafe method with a non-null pointer safety invariant. This change discourages direct use of from_ptr and paves the way for future optimization where Address could use NonZeroUsize internally, reducing Option<Address> from 16 to 8 bytes.

  • Made Address::from_ptr unsafe, requiring callers to ensure the pointer is non-null
  • Updated all call sites in generated code to wrap from_ptr calls in unsafe blocks
  • Optimized GetAddress implementation for Box<'_, T> to avoid redundant unsafe block

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
crates/oxc_allocator/src/address.rs Modified from_ptr signature to be unsafe, added safety documentation, and optimized GetAddress impl for Box<'_, T> by using NonNull::addr().get() directly
crates/oxc_traverse/src/generated/ancestor.rs Updated all GetAddress implementations for *Without* types to wrap Address::from_ptr(self.0) calls in unsafe blocks
crates/oxc_traverse/scripts/lib/ancestor.mjs Updated code generator to emit unsafe { Address::from_ptr(self.0) } in generated GetAddress implementations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

A further step in refactoring `Address` to make it more robust and performant.

Make `Address::from_ptr` an unsafe method, with the safety invariant that the pointer must be non-null. This:

1. Further discourages use of `Address::from_ptr` - `GetAddress::address` or `UnstableAddress::unstable_address` should be used instead.
2. Opens the door to changing `Address`'s inner type from `usize` to `NonZeroUsize`, which will reduce `Option<Address>` from 16 bytes to 8.
@graphite-app graphite-app bot force-pushed the 11-24-refactor_allocator_make_address_from_ptr_an_unsafe_method branch from 12cd060 to 3976e4f Compare November 24, 2025 01:51
@graphite-app graphite-app bot merged commit 3976e4f into main Nov 24, 2025
21 checks passed
@graphite-app graphite-app bot deleted the 11-24-refactor_allocator_make_address_from_ptr_an_unsafe_method branch November 24, 2025 01:57
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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