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_iterationsis reached.
Fields§
§max_iterations: u32Maximum number of full-tree passes before stopping (default: 64).
max_nodes_per_pass: u64Soft 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
impl RewriteEngine
Sourcepub fn with_max_iterations(self, n: u32) -> Self
pub fn with_max_iterations(self, n: u32) -> Self
Set the maximum number of fixed-point iterations (builder pattern).
Sourcepub fn add_rule(self, rule: Box<dyn RewriteRule>) -> Self
pub fn add_rule(self, rule: Box<dyn RewriteRule>) -> Self
Add one rule to the engine (builder pattern).
Sourcepub fn add_all_builtin_rules(self) -> Self
pub fn add_all_builtin_rules(self) -> Self
Register all five built-in rules (builder pattern).
Sourcepub fn rewrite(&self, expr: TLExpr) -> (TLExpr, RewriteStats)
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.