Skip to main content

RewriteEngine

Struct RewriteEngine 

Source
pub struct RewriteEngine {
    pub max_iterations: u32,
    pub max_nodes_per_pass: u64,
    /* private fields */
}
Expand description

Applies a set of RewriteRules to a TLExpr tree until a fixed point.

Rules are attempted in the order they were added. Within a single node visit the first firing rule wins and the engine moves on; no other rules are tried for the same node in the same pass.

The engine iterates until either:

  • a full pass completes with zero rule firings (fixed point), or
  • max_iterations is reached.

Fields§

§max_iterations: u32

Maximum number of full-tree passes before stopping (default: 64).

§max_nodes_per_pass: u64

Soft limit on node visits per pass (default: 1_000_000). If exceeded, the engine finishes the current pass but does not start a new one.

Implementations§

Source§

impl RewriteEngine

Source

pub fn new() -> Self

Create a new engine with no rules and default limits.

Source

pub fn with_max_iterations(self, n: u32) -> Self

Set the maximum number of fixed-point iterations (builder pattern).

Source

pub fn add_rule(self, rule: Box<dyn RewriteRule>) -> Self

Add one rule to the engine (builder pattern).

Source

pub fn add_all_builtin_rules(self) -> Self

Register all five built-in rules (builder pattern).

Source

pub fn rewrite(&self, expr: TLExpr) -> (TLExpr, RewriteStats)

Apply all rules to expr until a fixed point is reached.

Returns the final expression together with accumulated RewriteStats.

Trait Implementations§

Source§

impl Default for RewriteEngine

Source§

fn default() -> Self

Returns the “default value” for a type. 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 = Infallible

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.