Skip to main content

ParsedTree

Struct ParsedTree 

pub struct ParsedTree {
    pub root: NodeValue,
    pub arena: Vec<NodeValue>,
    pub token_arena: TiVec<TokenArenaIdx, Token>,
    pub meta_arena: Vec<Meta>,
    pub arena_trivial_drop: bool,
}
Expand description

A finished parse: root + arenas (POC-proven layout — children in one growing buffer, tokens in another; meta_arena parallel, empty in off-mode).

Fields§

§root: NodeValue§arena: Vec<NodeValue>§token_arena: TiVec<TokenArenaIdx, Token>§meta_arena: Vec<Meta>§arena_trivial_drop: bool

True iff arena is proven free of the two non-trivially-droppable NodeValue variants — Splice (owns a Vec + boxed span) and Foreign (owns an Arc) — so it holds only Token/Tree/None, every one of which is plain-old-data (no heap, no refcount). When set, Drop frees the arena buffer without the out-of-line per-element drop_in_place::<NodeValue> loop. The default tree-building (non-transform) LALR parse sets it: Splice never reaches the arena (finish_in_place asserts it) and Foreign is produced only by a transform hook. Conservative: false (the safe default) always runs the normal per-element drop, so a wrong false merely forgoes the speedup — it is set true only where the POD invariant is proven, never under transform, Earley, or interactive parses.

Footgun (pub field). This is pub, so nothing stops out-of-crate code from building a ParsedTree with arena_trivial_drop: true while arena still holds a Splice (owns a Vec + boxed span) or Foreign (owns an Arc) element. That is not undefined behaviour — Drop only set_len(0)s (forgets, never reads freed memory) — but it leaks those elements’ heap/refcount. External constructors must uphold the POD invariant themselves; leave it false (the safe default) unless you have proven every arena element is Token/Tree/None. Mirrors the same caveat on directly populating arena/token_arena out-of-crate.

Implementations§

§

impl ParsedTree

pub fn children_of<'a>(&'a self, tree: &Tree) -> &'a [NodeValue]

pub fn token_of(&self, idx: TokenArenaIdx) -> &Token

pub fn meta_of(&self, tree: &Tree) -> Option<&Meta>

Trait Implementations§

§

impl Drop for ParsedTree

§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.