pub fn optimise_with_iter_limit(
        &mut self,
        passes: &[Mutex<Pass>],
        query: &Query,
        limit: usize,
    ) {
        let mut last_size = self.size();
        log::debug!("Initial graph size: {:?}", last_size);
        let mut iter_count = 0;
        loop {
            // Run every optimisation pass
            for p in passes {
                // TODO: Find a better locking system, or remove the `FnMut` bound so that locking
                // is unnecessary.  I think that this system can deadlock if multiple threads are
                // optimising graphs in parallel using the same set of passes.
                p.lock().unwrap().run(self, query);
            }
            // Stop optimising if the limit has been reached
            if iter_count > limit {
                log::warn!(
                    "Graph optimisation limit reached, but more progress could have been made."
                );
                break;
            }
            iter_count += 1;
            // Stop optimising if the graph has stopped getting smaller
            let new_size = self.size();
            log::debug!("New size: {:?}", new_size);
            match new_size.cmp(&last_size) {
                // If graph got smaller, then keep optimising in case more optimisation is possible
                Ordering::Less => {}
                // If the last optimisation pass couldn't make `self` smaller, then assume no
                // changes has been made and further optimisation is impossible
                Ordering::Equal => {
                    log::debug!(
                        "Finished optimisation after {} iters of every pass",
                        iter_count
                    );
                    break;
                }
                // Optimisation passes shouldn't increase the graph size
                Ordering::Greater => unreachable!("Optimisation should never increase graph size"),
            }
            last_size = new_size;
        }
    }
/// Repeatedly apply a sequence of [`Pass`]es until the graph either becomes static, or `limit`
/// many iterations are performed.
Repeatedly apply a sequence of [`Pass`]es until the graph either becomes static, or `limit`
many iterations are performed.
Repeatedly apply a sequence of [ ` Pass ` ] es until the graph either becomes static or ` limit ` many iterations are performed .
pub fn optimise_with_iter_limit(
        &mut self,
        passes: &[Mutex<Pass>],
        query: &Query,
        limit: usize,
    ) {
        let mut last_size = self.size();
        log::debug!("Initial graph size: {:?}", last_size);
        let mut iter_count = 0;
        loop {
            // Run every optimisation pass
            for p in passes {
                // TODO: Find a better locking system, or remove the `FnMut` bound so that locking
                // is unnecessary.  I think that this system can deadlock if multiple threads are
                // optimising graphs in parallel using the same set of passes.
                p.lock().unwrap().run(self, query);
            }
            // Stop optimising if the limit has been reached
            if iter_count > limit {
                log::warn!(
                    "Graph optimisation limit reached, but more progress could have been made."
                );
                break;
            }
            iter_count += 1;
            // Stop optimising if the graph has stopped getting smaller
            let new_size = self.size();
            log::debug!("New size: {:?}", new_size);
            match new_size.cmp(&last_size) {
                // If graph got smaller, then keep optimising in case more optimisation is possible
                Ordering::Less => {}
                // If the last optimisation pass couldn't make `self` smaller, then assume no
                // changes has been made and further optimisation is impossible
                Ordering::Equal => {
                    log::debug!(
                        "Finished optimisation after {} iters of every pass",
                        iter_count
                    );
                    break;
                }
                // Optimisation passes shouldn't increase the graph size
                Ordering::Greater => unreachable!("Optimisation should never increase graph size"),
            }
            last_size = new_size;
        }
    }
pub fn optimise_with_iter_limit ( & mut self , passes : & [ Mutex < Pass > ] , query : & Query , limit : usize , ) { let mut last_size = self . size ( ) ; log :: debug ! ( " " last_size ) ; let mut iter_count = 0 ; loop { // Run every optimisation pass for p in passes { // TODO: Find a better locking system, or remove the `FnMut` bound so that locking // is unnecessary.  I think that this system can deadlock if multiple threads are // optimising graphs in parallel using the same set of passes. p . lock ( ) . unwrap ( ) . run ( self , query ) ; } // Stop optimising if the limit has been reached if iter_count > limit { log :: warn ! ( " " ) ; break ; } iter_count += 1 ; // Stop optimising if the graph has stopped getting smaller let new_size = self . size ( ) ; log :: debug ! ( " " new_size ) ; match new_size . cmp ( & last_size ) { // If graph got smaller, then keep optimising in case more optimisation is possible Ordering :: Less => { } // If the last optimisation pass couldn't make `self` smaller, then assume no // changes has been made and further optimisation is impossible Ordering :: Equal => { log :: debug ! ( " " iter_count ) ; break ; } // Optimisation passes shouldn't increase the graph size Ordering :: Greater => unreachable ! ( " " ) , } last_size = new_size ; } }
Repeatedly apply a sequence of [`Pass`]es until the graph either becomes static, or `limit`
many iterations are performed.
Repeatedly apply a sequence of [ ` Pass ` ] es until the graph either becomes static or ` limit ` many iterations are performed .
&mut self
passes
&[Mutex<Pass>]
query
&Query
limit
usize
&mut self
passes
&[Mutex<Pass>]
query
&Query
limit
usize