[−][src]Struct egg::SimpleRunner
A reasonable default Runner
.
SimpleRunner
is a Runner
, so it runs rewrites over an EGraph
.
This implementation offers several conveniences to prevent rewriting
from behaving badly and eating your computer:
-
Saturation checking
SimpleRunner
checks to see if any of the rules added anything new to theEGraph
. If none did, then it stops, returningSimpleRunnerError::Saturated
. -
Iteration limits
You can set a upper limit of iterations to do in case the search doesn't stop for some other reason. If this limit is hit, it stops with
SimpleRunnerError::IterationLimit
. -
EGraph
size limitYou can set a upper limit on the number of enodes in the egraph. If this limit is hit, it stops with
SimpleRunnerError::NodeLimit
. -
Time limit
You can set a time limit on the runner. If this limit is hit, it stops with
SimpleRunnerError::TimeLimit
. -
Rule backoff
Some rules enable themselves, blowing up the
EGraph
and preventing other rewrites from running as many times. To prevent this,SimpleRunner
implements exponentional rule backoff.For each rewrite, there exists a configurable initial match limit. If a rewrite search yield more than this limit, then we ban this rule for number of iterations, double its limit, and double the time it will be banned next time.
This seems effective at preventing explosive rules like associativity from taking an unfair amount of resources.
Example
use egg::{*, rewrite as rw}; define_language! { enum SimpleLanguage { Num(i32), Add = "+", Mul = "*", Symbol(String), } } let rules: &[Rewrite<SimpleLanguage, ()>] = &[ rw!("commute-add"; "(+ ?a ?b)" => "(+ ?b ?a)"), rw!("commute-mul"; "(* ?a ?b)" => "(* ?b ?a)"), rw!("add-0"; "(+ ?a 0)" => "?a"), rw!("mul-0"; "(* ?a 0)" => "0"), rw!("mul-1"; "(* ?a 1)" => "?a"), ]; let start = "(+ 0 (* 1 foo))".parse().unwrap(); // SimpleRunner is customizable in the builder pattern style. let (egraph, report) = SimpleRunner::default() .with_iter_limit(10) .with_node_limit(10_000) .run_expr(start, &rules); println!( "Stopped after {} iterations, reason: {:?}", report.iterations.len(), report.stop_reason );
Methods
impl SimpleRunner
[src]
pub fn with_iter_limit(self, iter_limit: usize) -> Self
[src]
Sets the iteration limit. Default: 30
pub fn with_node_limit(self, node_limit: usize) -> Self
[src]
Sets the egraph size limit (in enodes). Default: 10,000
pub fn with_time_limit(self, time_limit: Duration) -> Self
[src]
Sets the runner time limit. Default: 60 seconds
pub fn with_initial_match_limit(self, initial_match_limit: usize) -> Self
[src]
Sets the initial match limit before a rule is banned. Default: 1,000
Setting this to a really big number will effectively disable rule backoff.
Trait Implementations
impl Default for SimpleRunner
[src]
impl<L, M> Runner<L, M> for SimpleRunner where
L: Language,
M: Metadata<L>,
[src]
L: Language,
M: Metadata<L>,
type Error = SimpleRunnerError
The type of an error that should stop the runner. Read more
fn pre_step(&mut self, egraph: &mut EGraph<L, M>) -> Result<(), Self::Error>
[src]
fn during_step(&mut self, egraph: &EGraph<L, M>) -> Result<(), Self::Error>
[src]
fn post_step(
&mut self,
iteration: &Iteration,
_egraph: &mut EGraph<L, M>
) -> Result<(), Self::Error>
[src]
&mut self,
iteration: &Iteration,
_egraph: &mut EGraph<L, M>
) -> Result<(), Self::Error>
fn search_rewrite(
&mut self,
egraph: &mut EGraph<L, M>,
rewrite: &Rewrite<L, M>
) -> Vec<SearchMatches>
[src]
&mut self,
egraph: &mut EGraph<L, M>,
rewrite: &Rewrite<L, M>
) -> Vec<SearchMatches>
fn apply_rewrite(
&mut self,
egraph: &mut EGraph<L, M>,
rewrite: &Rewrite<L, M>,
matches: Vec<SearchMatches>
) -> usize
[src]
&mut self,
egraph: &mut EGraph<L, M>,
rewrite: &Rewrite<L, M>,
matches: Vec<SearchMatches>
) -> usize
fn step(
&mut self,
egraph: &mut EGraph<L, M>,
rules: &[Rewrite<L, M>]
) -> Result<Iteration, Self::Error>
[src]
&mut self,
egraph: &mut EGraph<L, M>,
rules: &[Rewrite<L, M>]
) -> Result<Iteration, Self::Error>
fn run(
&mut self,
egraph: &mut EGraph<L, M>,
rules: &[Rewrite<L, M>]
) -> (Vec<Iteration>, Self::Error)
[src]
&mut self,
egraph: &mut EGraph<L, M>,
rules: &[Rewrite<L, M>]
) -> (Vec<Iteration>, Self::Error)
fn run_expr(
&mut self,
initial_expr: RecExpr<L>,
rules: &[Rewrite<L, M>]
) -> (EGraph<L, M>, RunReport<L, Self::Error>)
[src]
&mut self,
initial_expr: RecExpr<L>,
rules: &[Rewrite<L, M>]
) -> (EGraph<L, M>, RunReport<L, Self::Error>)
Auto Trait Implementations
impl RefUnwindSafe for SimpleRunner
impl Send for SimpleRunner
impl Sync for SimpleRunner
impl Unpin for SimpleRunner
impl UnwindSafe for SimpleRunner
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,