pub struct Arena {
bump: Bump,
}Expand description
Bump-allocator arena owning all AST node storage for a single parse.
Methods that allocate return references whose lifetime is tied to
&self; consumers commonly re-bind that lifetime as the parsed
tree’s 'src parameter.
Fields§
§bump: BumpImplementations§
Source§impl Arena
impl Arena
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Empty arena with at least capacity bytes pre-reserved. Use
when the source size is known to be large — e.g., the lex
driver might call Arena::with_capacity(source.len() / 4) to
avoid early growth allocations on a multi-MB document.
Sourcepub fn alloc<T>(&self, value: T) -> &T
pub fn alloc<T>(&self, value: T) -> &T
Allocate value in the arena, returning a borrowed reference
that is valid for &self’s lifetime.
Sourcepub fn alloc_str(&self, s: &str) -> &str
pub fn alloc_str(&self, s: &str) -> &str
Allocate a copy of s in the arena. Used when the lex layer
produces a new (synthesised or rewritten) string that does not
directly point into the source buffer.
Sourcepub fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> &[T]
pub fn alloc_slice_copy<T: Copy>(&self, slice: &[T]) -> &[T]
Allocate a slice copy of slice in the arena. Restricted to
Copy types because the borrowed AST contains only Copy
data (refs, primitives, Copy enums) — see the borrowed
module docs.
Sourcepub fn alloc_slice_fill_iter<T, I>(&self, iter: I) -> &[T]
pub fn alloc_slice_fill_iter<T, I>(&self, iter: I) -> &[T]
Allocate a slice from an iterator. Useful for assembling a
Content::Segments payload from a builder loop.
Sourcepub fn allocated_bytes(&self) -> usize
pub fn allocated_bytes(&self) -> usize
Bytes currently allocated to chunks (committed memory). For diagnostic / benchmarking use only.
Sourcepub fn bump(&self) -> &Bump
pub fn bump(&self) -> &Bump
Borrow the inner [Bump] allocator. Used by structures that
need to hold their own arena-backed storage (e.g. the
super::Interner’s probe table, which is itself a
BumpVec allocated inside the arena).
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Drop every allocation without releasing the underlying chunks.
The next alloc* call reuses the same memory pages — saving
the mmap syscall a fresh Arena::new would pay.
&mut self enforces at compile time that no live borrow into
the arena exists at reset time: every alloc-returned &T
borrows from &self, so a caller holding such a reference
can never simultaneously call &mut self. Trying to do so is
a borrow-checker error, not a runtime UAF.
Used by long-running workers (rayon parallel corpus sweep, the
LSP daemon, etc.) that parse many documents in succession and
would otherwise pay one mmap per parse.
Sourcepub fn reset_with_hint(&mut self, target_capacity: usize)
pub fn reset_with_hint(&mut self, target_capacity: usize)
Reset and pre-size: drop every allocation, then ensure the
retained chunk capacity is at least target_capacity bytes
before returning.
Behaviour:
- When the arena’s existing chunk capacity already meets the
target, this is identical to
Arena::reset— no syscall, no fresh allocation. - When the target exceeds current capacity, the underlying
bump is replaced with a freshly-allocated one of at least
target_capacitybytes. The previous chunks are released to the system allocator; the new bump mmaps one chunk at the requested size.
The replace path costs one mmap per growth event, not per
parse. Steady-state workloads (corpus sweep on similar-sized
docs) hit the no-op fast path after the first parse on each
worker thread; only docs whose AST exceeds the high-water mark
pay the syscall. Compared to plain Arena::reset +
chunk-grow-on-demand, the cost is identical (same number of
mmaps) but moved out of the parse hot path: the syscall fires
before lex_into_arena rather than inside it, removing one
source of intra-parse latency variance.
Used by long-running workers (rayon corpus sweep, LSP daemon)
that have a per-source size hint available — typically
source.len() * 4 for the borrowed AST shape.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Arena
impl !RefUnwindSafe for Arena
impl Send for Arena
impl !Sync for Arena
impl Unpin for Arena
impl UnsafeUnpin for Arena
impl !UnwindSafe for Arena
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more