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: boolTrue 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.