Skip to content

Comments

feat(allocator, ast): introduce UnstableAddress trait#15700

Merged
graphite-app[bot] merged 1 commit intomainfrom
11-13-feat_allocator_ast_introduce_unstableaddress_trait
Nov 14, 2025
Merged

feat(allocator, ast): introduce UnstableAddress trait#15700
graphite-app[bot] merged 1 commit intomainfrom
11-13-feat_allocator_ast_introduce_unstableaddress_trait

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Nov 14, 2025

Address::from_ptr is hard to use correctly (as evidenced by rolldown/rolldown#6961).

Introduce a new trait UnstableAddress which has a few more guardrails.

Migration

We should swap all usage of Address::from_ptr for UnstableAddress::unstable_address.

When Address::from_ptr is being used correctly, it can easily be swapped out:

- let address = Address::from_ptr(node);
+ let address = node.unstable_address();

But if Address::from_ptr was being used incorrectly, migrating to unstable_address will reveal that problem with a compilation error.

unstable_address (as the name suggests) does not give the same guarantees about the stability of the Address it returns as GetAddress::address does. The name of the method makes that explicit.

More details in the doc comment in this PR.

Migration plan

@github-actions github-actions bot added A-ast Area - AST A-ast-tools Area - AST tools C-enhancement Category - New feature or request labels Nov 14, 2025
Copy link
Member Author

overlookmotel commented Nov 14, 2025


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.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 14, 2025

CodSpeed Performance Report

Merging #15700 will not alter performance

Comparing 11-13-feat_allocator_ast_introduce_unstableaddress_trait (8a61cfd) with main (e01c551)1

Summary

✅ 37 untouched

Footnotes

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

@overlookmotel overlookmotel marked this pull request as ready for review November 14, 2025 14:07
Copilot AI review requested due to automatic review settings November 14, 2025 14:07
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 introduces the UnstableAddress trait as a safer alternative to Address::from_ptr, providing better guardrails for obtaining memory addresses of AST nodes. The trait is designed to reduce errors while still allowing controlled access to unstable addresses when necessary.

  • Adds the UnstableAddress trait with a single unstable_address() method
  • Implements the trait for all AST struct types via code generation
  • Updates documentation to reference the new trait alongside existing methods

Reviewed Changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tasks/ast_tools/src/main.rs Registers the new DeriveUnstableAddress derive in the AST tools
tasks/ast_tools/src/derives/unstable_address.rs Implements the code generator for the UnstableAddress trait derivation
tasks/ast_tools/src/derives/mod.rs Exports the new derive module
crates/oxc_ast_macros/src/generated/derived_traits.rs Adds trait metadata for the macro system
crates/oxc_ast/src/lib.rs Includes the generated unstable_address module
crates/oxc_ast/src/generated/derive_unstable_address.rs Auto-generated implementations of UnstableAddress for all AST types
crates/oxc_ast/src/ast/ts.rs Adds UnstableAddress to the imports and #[generate_derive] attributes for TypeScript AST types
crates/oxc_ast/src/ast/literal.rs Adds UnstableAddress to the imports and #[generate_derive] attributes for literal AST types
crates/oxc_ast/src/ast/jsx.rs Adds UnstableAddress to the imports and #[generate_derive] attributes for JSX AST types
crates/oxc_ast/src/ast/js.rs Adds UnstableAddress to the imports and #[generate_derive] attributes for JavaScript AST types
crates/oxc_allocator/src/lib.rs Exports the new UnstableAddress trait from the allocator module
crates/oxc_allocator/src/address.rs Defines the UnstableAddress trait with extensive documentation and safety guidelines

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

@overlookmotel
Copy link
Member Author

@camc314 @Dunqing I've assigned this stack to both of you because I think someone should take a look, but I'm not sure who. Whoever wants to, please merge it. Or say if you don't like this change!

@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 14, 2025

Merge activity

`Address::from_ptr` is hard to use correctly (as evidenced by rolldown/rolldown#6961).

Introduce a new trait `UnstableAddress` which has a few more guardrails.

### Migration

We should swap all usage of `Address::from_ptr` for `UnstableAddress::unstable_address`.

When `Address::from_ptr` is being used correctly, it can easily be swapped out:

```diff
- let address = Address::from_ptr(node);
+ let address = node.unstable_address();
```

But if `Address::from_ptr` was being used incorrectly, migrating to `unstable_address` will reveal that problem with a compilation error.

`unstable_address` (as the name suggests) does not give the same guarantees about the stability of the `Address` it returns as `GetAddress::address` does. The name of the method makes that explicit.

More details in the doc comment in this PR.

### Migration plan

* #15701 migrates all usage of `Address::from_ptr` and `Address::from_ref` in Oxc's codebase to `unstable_address` (except in `oxc_traverse`, which has particular requirements around aliasing, and can't use `unstable_address`).
* #15702 removes `Address::from_ref`.
* Once this PR lands in an Oxc release, we can migrate Rolldown to `unstable_address`.
* In next Oxc release after that, we'll make `Address::from_ptr` an unsafe method, to discourage its use.
* At a future date, we can migrate `oxc_traverse` to using `NonNull` pointers instead of `*const` pointers, and get rid of `Address::from_ptr` entirely.
@graphite-app graphite-app bot force-pushed the 11-13-feat_allocator_ast_introduce_unstableaddress_trait branch from 29dacc6 to 8a61cfd Compare November 14, 2025 14:59
@graphite-app graphite-app bot merged commit 8a61cfd into main Nov 14, 2025
29 checks passed
@graphite-app graphite-app bot deleted the 11-13-feat_allocator_ast_introduce_unstableaddress_trait branch November 14, 2025 15:07
graphite-app bot pushed a commit that referenced this pull request Nov 17, 2025
### 💥 BREAKING CHANGES

- ea51b0b napi: [**BREAKING**] Standardize function naming with sync suffixes (#15661) (Boshen)

### 🚀 Features

- 77efb76 parser: Improve error message for invalid switch clauses (#15728) (sapphi-red)
- 5691727 parser: Improve `import source` `from` error message (#15727) (sapphi-red)
- b7404bc parser: Improve error message for missing function body (#15726) (sapphi-red)
- 71c2fb0 parser: Improve error message when JSX is found while not enabled (#15725) (sapphi-red)
- 56e7e44 minifier: Disable removal of unnecessary `use strict` directives for DCE (#15691) (sapphi-red)
- 8a61cfd allocator, ast: Introduce `UnstableAddress` trait (#15700) (overlookmotel)
- f5ce55a napi: Export all options using wildcard exports (Boshen)
- 68703b9 minifier: Rotate binary expressions to remove parentheses (#15473) (sapphi-red)

### 🐛 Bug Fixes

- c023ba6 semantic: Do not duplicate statements in temp `Vec` when binding `TSModuleDeclaration`s (#15724) (overlookmotel)
- d60ca81 parser: Reject `import something 'source'` (#15746) (sapphi-red)
- e0728fa ast: Exclude comment end position from `is_inside_comment` check (#15753) (camc314)
- 9f54a36 semantic: Error on `\00` in strict mode (#15743) (sapphi-red)
- 440a977 ast: Include rest properties when using `get_binding_identifiers` (#15710) (camc314)

### ⚡ Performance

- 1f09d3c parser: Faster checking for invalid modifiers (#15717) (overlookmotel)
- d8d4e31 ast: Use loop instead of recursion in `TSModuleDeclarationBody::as_module_block_mut` (#15713) (overlookmotel)

### 📚 Documentation

- e033d50 ast: Clarify behavior of `TSModuleDeclaration::has_use_strict_directive` (#15730) (overlookmotel)
- 9eda70f allocator: Improve docs for `Address` methods (#15697) (overlookmotel)
overlookmotel pushed a commit that referenced this pull request Nov 17, 2025
### 💥 BREAKING CHANGES

- ea51b0b napi: [**BREAKING**] Standardize function naming with sync
suffixes (#15661) (Boshen)

### 🚀 Features

- 77efb76 parser: Improve error message for invalid switch clauses
(#15728) (sapphi-red)
- 5691727 parser: Improve `import source` `from` error message (#15727)
(sapphi-red)
- b7404bc parser: Improve error message for missing function body
(#15726) (sapphi-red)
- 71c2fb0 parser: Improve error message when JSX is found while not
enabled (#15725) (sapphi-red)
- 56e7e44 minifier: Disable removal of unnecessary `use strict`
directives for DCE (#15691) (sapphi-red)
- 8a61cfd allocator, ast: Introduce `UnstableAddress` trait (#15700)
(overlookmotel)
- f5ce55a napi: Export all options using wildcard exports (Boshen)
- 68703b9 minifier: Rotate binary expressions to remove parentheses
(#15473) (sapphi-red)

### 🐛 Bug Fixes

- c023ba6 semantic: Do not duplicate statements in temp `Vec` when
binding `TSModuleDeclaration`s (#15724) (overlookmotel)
- d60ca81 parser: Reject `import something 'source'` (#15746)
(sapphi-red)
- e0728fa ast: Exclude comment end position from `is_inside_comment`
check (#15753) (camc314)
- 9f54a36 semantic: Error on `\00` in strict mode (#15743) (sapphi-red)
- 440a977 ast: Include rest properties when using
`get_binding_identifiers` (#15710) (camc314)

### ⚡ Performance

- 1f09d3c parser: Faster checking for invalid modifiers (#15717)
(overlookmotel)
- d8d4e31 ast: Use loop instead of recursion in
`TSModuleDeclarationBody::as_module_block_mut` (#15713) (overlookmotel)

### 📚 Documentation

- e033d50 ast: Clarify behavior of
`TSModuleDeclaration::has_use_strict_directive` (#15730) (overlookmotel)
- 9eda70f allocator: Improve docs for `Address` methods (#15697)
(overlookmotel)
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…15700)

`Address::from_ptr` is hard to use correctly (as evidenced by rolldown/rolldown#6961).

Introduce a new trait `UnstableAddress` which has a few more guardrails.

### Migration

We should swap all usage of `Address::from_ptr` for `UnstableAddress::unstable_address`.

When `Address::from_ptr` is being used correctly, it can easily be swapped out:

```diff
- let address = Address::from_ptr(node);
+ let address = node.unstable_address();
```

But if `Address::from_ptr` was being used incorrectly, migrating to `unstable_address` will reveal that problem with a compilation error.

`unstable_address` (as the name suggests) does not give the same guarantees about the stability of the `Address` it returns as `GetAddress::address` does. The name of the method makes that explicit.

More details in the doc comment in this PR.

### Migration plan

* oxc-project#15701 migrates all usage of `Address::from_ptr` and `Address::from_ref` in Oxc's codebase to `unstable_address` (except in `oxc_traverse`, which has particular requirements around aliasing, and can't use `unstable_address`).
* oxc-project#15702 removes `Address::from_ref`.
* Once this PR lands in an Oxc release, we can migrate Rolldown to `unstable_address`.
* In next Oxc release after that, we'll make `Address::from_ptr` an unsafe method, to discourage its use.
* At a future date, we can migrate `oxc_traverse` to using `NonNull` pointers instead of `*const` pointers, and get rid of `Address::from_ptr` entirely.
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
### 💥 BREAKING CHANGES

- ea51b0b napi: [**BREAKING**] Standardize function naming with sync
suffixes (oxc-project#15661) (Boshen)

### 🚀 Features

- 77efb76 parser: Improve error message for invalid switch clauses
(oxc-project#15728) (sapphi-red)
- 5691727 parser: Improve `import source` `from` error message (oxc-project#15727)
(sapphi-red)
- b7404bc parser: Improve error message for missing function body
(oxc-project#15726) (sapphi-red)
- 71c2fb0 parser: Improve error message when JSX is found while not
enabled (oxc-project#15725) (sapphi-red)
- 56e7e44 minifier: Disable removal of unnecessary `use strict`
directives for DCE (oxc-project#15691) (sapphi-red)
- 8a61cfd allocator, ast: Introduce `UnstableAddress` trait (oxc-project#15700)
(overlookmotel)
- f5ce55a napi: Export all options using wildcard exports (Boshen)
- 68703b9 minifier: Rotate binary expressions to remove parentheses
(oxc-project#15473) (sapphi-red)

### 🐛 Bug Fixes

- c023ba6 semantic: Do not duplicate statements in temp `Vec` when
binding `TSModuleDeclaration`s (oxc-project#15724) (overlookmotel)
- d60ca81 parser: Reject `import something 'source'` (oxc-project#15746)
(sapphi-red)
- e0728fa ast: Exclude comment end position from `is_inside_comment`
check (oxc-project#15753) (camc314)
- 9f54a36 semantic: Error on `\00` in strict mode (oxc-project#15743) (sapphi-red)
- 440a977 ast: Include rest properties when using
`get_binding_identifiers` (oxc-project#15710) (camc314)

### ⚡ Performance

- 1f09d3c parser: Faster checking for invalid modifiers (oxc-project#15717)
(overlookmotel)
- d8d4e31 ast: Use loop instead of recursion in
`TSModuleDeclarationBody::as_module_block_mut` (oxc-project#15713) (overlookmotel)

### 📚 Documentation

- e033d50 ast: Clarify behavior of
`TSModuleDeclaration::has_use_strict_directive` (oxc-project#15730) (overlookmotel)
- 9eda70f allocator: Improve docs for `Address` methods (oxc-project#15697)
(overlookmotel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-ast-tools Area - AST tools C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants