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
impl ExpressionArena
Sourcepub fn from_root(root: Expression) -> Self
pub fn from_root(root: Expression) -> Self
Builds an arena from an expression tree.
Sourcepub fn root(&self) -> ExpressionNodeId
pub fn root(&self) -> ExpressionNodeId
Returns the root node id.
Sourcepub fn expression(&self, id: ExpressionNodeId) -> &Expression
pub fn expression(&self, id: ExpressionNodeId) -> &Expression
Returns the expression payload stored at id.
Sourcepub fn parent(&self, id: ExpressionNodeId) -> Option<ExpressionNodeId>
pub fn parent(&self, id: ExpressionNodeId) -> Option<ExpressionNodeId>
Returns the parent of id, or None for the root.
Sourcepub fn children(&self, id: ExpressionNodeId) -> &[ExpressionNodeId]
pub fn children(&self, id: ExpressionNodeId) -> &[ExpressionNodeId]
Returns the direct expression children of id.
Sourcepub fn is_reachable(&self, id: ExpressionNodeId) -> bool
pub fn is_reachable(&self, id: ExpressionNodeId) -> bool
Returns whether id is still reachable from the current root.
Sourcepub fn depth(&self, id: ExpressionNodeId) -> usize
pub fn depth(&self, id: ExpressionNodeId) -> usize
Returns the depth of id below the root.
Sourcepub fn preorder_path(&self, id: ExpressionNodeId) -> Vec<usize>
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.
Sourcepub fn generation(&self, id: ExpressionNodeId) -> u32
pub fn generation(&self, id: ExpressionNodeId) -> u32
Returns the generation counter for id.
Sourcepub fn bump_generation(&mut self, id: ExpressionNodeId)
pub fn bump_generation(&mut self, id: ExpressionNodeId)
Records that rewrite-relevant content at id has changed.
Sourcepub fn replace_subtree(&mut self, id: ExpressionNodeId, replacement: Expression)
pub fn replace_subtree(&mut self, id: ExpressionNodeId, replacement: Expression)
Replaces the subtree at id while preserving id itself.
Sourcepub fn add_root_children(
&mut self,
children: Vec<Expression>,
) -> Vec<ExpressionNodeId>
pub fn add_root_children( &mut self, children: Vec<Expression>, ) -> Vec<ExpressionNodeId>
Appends top-level constraints to the root expression.
Sourcepub fn rebuild_payload_from_children(&mut self, id: ExpressionNodeId)
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.
Sourcepub fn sync_payload_for_changed_child(
&mut self,
parent_id: ExpressionNodeId,
child_id: ExpressionNodeId,
)
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).
Sourcepub fn into_root_expression(self) -> Expression
pub fn into_root_expression(self) -> Expression
Rebuilds the expression tree reachable from the arena root.
Sourcepub fn expression_from(&self, id: ExpressionNodeId) -> Expression
pub fn expression_from(&self, id: ExpressionNodeId) -> Expression
Rebuilds the expression tree reachable from id.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of slots currently allocated in the arena.
This includes unreachable slots left behind by subtree replacement.
Sourcepub fn reachable_subtree_ids(
&self,
id: ExpressionNodeId,
) -> Vec<ExpressionNodeId>
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
impl Clone for ExpressionArena
Source§fn clone(&self) -> ExpressionArena
fn clone(&self) -> ExpressionArena
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ExpressionArena
impl !UnwindSafe for ExpressionArena
impl Freeze for ExpressionArena
impl Send for ExpressionArena
impl Sync for ExpressionArena
impl Unpin for ExpressionArena
impl UnsafeUnpin for ExpressionArena
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreimpl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
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