Skip to main content

ExpressionArena

Struct ExpressionArena 

Source
pub struct ExpressionArena { /* private fields */ }
Expand description

Arena-backed representation of an Expression tree.

The arena keeps direct parent/child links so callers can jump to known nodes without walking down from the root each time. Subtree replacement preserves the replaced node’s id and appends the replacement descendants; descendants of the old subtree become unreachable from the root.

Implementations§

Source§

impl ExpressionArena

Source

pub fn from_root(root: Expression) -> ExpressionArena

Builds an arena from an expression tree.

Source

pub fn root(&self) -> ExpressionNodeId

Returns the root node id.

Source

pub fn expression(&self, id: ExpressionNodeId) -> &Expression

Returns the expression payload stored at id.

Source

pub fn parent(&self, id: ExpressionNodeId) -> Option<ExpressionNodeId>

Returns the parent of id, or None for the root.

Source

pub fn children(&self, id: ExpressionNodeId) -> &[ExpressionNodeId]

Returns the direct expression children of id.

Source

pub fn is_reachable(&self, id: ExpressionNodeId) -> bool

Returns whether id is still reachable from the current root.

Source

pub fn depth(&self, id: ExpressionNodeId) -> usize

Returns the depth of id below the root.

Source

pub fn preorder_path(&self, id: ExpressionNodeId) -> Vec<usize>

Builds the current preorder path of id.

Lexicographic ordering of these paths is the model preorder used by the rewriter. Paths are only materialised for the relatively rare ordering operations; storing one on every node makes building a deep arena quadratic in the tree depth.

Source

pub fn generation(&self, id: ExpressionNodeId) -> u32

Returns the generation counter for id.

Source

pub fn bump_generation(&mut self, id: ExpressionNodeId)

Records that rewrite-relevant content at id has changed.

Source

pub fn replace_subtree(&mut self, id: ExpressionNodeId, replacement: Expression)

Replaces the subtree at id while preserving id itself.

Source

pub fn add_root_children( &mut self, children: Vec<Expression>, ) -> Vec<ExpressionNodeId>

Appends top-level constraints to the root expression.

Source

pub fn rebuild_payload_from_children(&mut self, id: ExpressionNodeId)

Rebuilds the stored expression payload at id from its direct arena children.

Only children whose generation changed are copied into the payload, so refreshing a wide expression does not clone its unchanged siblings. Ancestor repair should walk upward so deeper nodes are refreshed first.

Source

pub fn sync_payload_for_changed_child( &mut self, parent_id: ExpressionNodeId, child_id: ExpressionNodeId, )

Syncs the parent payload after a direct child changed.

Uses Uniplate::try_replace_child_at so same-arity updates avoid cloning siblings. The child’s stored slot gives its position in the parent in O(1). Falls back to a full rebuild if the child is missing or in-place replace fails (e.g. arity mismatch).

Source

pub fn into_root_expression(self) -> Expression

Rebuilds the expression tree reachable from the arena root.

Source

pub fn expression_from(&self, id: ExpressionNodeId) -> Expression

Rebuilds the expression tree reachable from id.

Source

pub fn len(&self) -> usize

Returns the number of slots currently allocated in the arena.

This includes unreachable slots left behind by subtree replacement.

Source

pub fn is_empty(&self) -> bool

Returns true when the arena contains no nodes.

Source

pub fn reachable_subtree_ids( &self, id: ExpressionNodeId, ) -> Vec<ExpressionNodeId>

Returns reachable node ids under id in rewriter preorder.

Trait Implementations§

Source§

impl Clone for ExpressionArena

Source§

fn clone(&self) -> ExpressionArena

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExpressionArena

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

§

fn into_ast(self, _a: &A) -> A

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, !>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 32 bytes