Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/oxc_allocator/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ impl<'alloc, T: Hash> Hash for Vec<'alloc, T> {
}
}

/// Memory address of an AST node in arena.
///
/// `Address` is generated from a `Box<T>`.
/// AST nodes in a `Box` in an arena are guaranteed to never move in memory,
/// so this address acts as a unique identifier for the duration of the arena's existence.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Address(usize);

impl<'a, T> Box<'a, T> {
#[inline]
pub fn address(&self) -> Address {
Address(ptr::addr_of!(**self) as usize)
}
}

#[cfg(test)]
mod test {
use std::hash::{DefaultHasher, Hash, Hasher};
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod convert;

use bumpalo::Bump;

pub use arena::{Box, String, Vec};
pub use arena::{Address, Box, String, Vec};
pub use clone_in::CloneIn;
pub use convert::{FromIn, IntoIn};

Expand Down