-
-
Notifications
You must be signed in to change notification settings - Fork 728
refactor(allocator)!: make Address::from_ptr an unsafe method
#16021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(allocator)!: make Address::from_ptr an unsafe method
#16021
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. |
CodSpeed Performance ReportMerging #16021 will not alter performanceComparing Summary
Footnotes
|
Merge activity
|
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.
1b1200a to
12cd060
Compare
There was a problem hiding this 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_ptrunsafe, requiring callers to ensure the pointer is non-null - Updated all call sites in generated code to wrap
from_ptrcalls inunsafeblocks - Optimized
GetAddressimplementation forBox<'_, 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.
12cd060 to
3976e4f
Compare

A further step in refactoring
Addressto make it more robust and performant.Make
Address::from_ptran unsafe method, with the safety invariant that the pointer must be non-null. This:Address::from_ptr-GetAddress::addressorUnstableAddress::unstable_addressshould be used instead.Address's inner type fromusizetoNonZeroUsize, which will reduceOption<Address>from 16 bytes to 8.