oxc-project / oxc-project/backlog

Give `Address` a niche

Open
#181 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
7
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Address is the memory address of an AST node. Currently it's a wrapper around a usize.

But an AST node in the arena cannot have a null address. Therefore we could make Address:

#[repr(transparent)]
pub struct Address(NonZeroUsize);

This would make Option<Address> 8 bytes (currently it's 16).

This is trivial to do for impl<T> GetAddress for Box<'_, T>.

But would need to change the signature of Address:from_ptr to take a NonNull<T> instead of *const T. This would break all cases where we pass a &T to Address::from_ptr, because &T does not auto-deref to NonNull<T> the way it does to *const T.

That might well not be a bad thing - Address:from_ptr is not recommended usage, so making you jump through more hoops to use it could be helpful. And it doesn't require unsafe code from the caller - Address::from_ptr(&x) -> Address::from_ptr(NonNull::from(&x)).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Address definition, its from_ptr method, the GetAddress implementation for Box, and call sites that pass references. Check how AST nodes are allocated in the arena and inspect existing tests or size assertions if present. Done means Address uses NonZeroUsize, Option

is 8 bytes, and all affected call sites compile with the updated from_ptr signature.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.