diff --git a/src/run/linker.rs b/src/run/linker.rs index 31d67b26..82b1091a 100644 --- a/src/run/linker.rs +++ b/src/run/linker.rs @@ -371,8 +371,8 @@ impl RedexQueue { self.fast.is_empty() && self.slow.is_empty() } #[inline(always)] - pub fn take(&mut self) -> impl Iterator { - std::mem::take(&mut self.fast).into_iter().chain(std::mem::take(&mut self.slow)) + pub fn drain(&mut self) -> impl Iterator + '_ { + self.fast.drain(..).chain(self.slow.drain(..)) } #[inline(always)] pub fn iter(&self) -> impl Iterator { @@ -392,7 +392,6 @@ impl RedexQueue { // Returns whether a redex does not allocate memory fn redex_would_shrink(a: &Port, b: &Port) -> bool { (*a == Port::ERA || *b == Port::ERA) - || (!(a.tag() == Tag::Ref || b.tag() == Tag::Ref) - && (((a.tag() == Tag::Ctr && b.tag() == Tag::Ctr) || a.lab() == b.lab()) - || (a.tag() == Tag::Num || b.tag() == Tag::Num))) + || (a.tag() == Tag::Ctr && b.tag() == Tag::Ctr && a.lab() == b.lab()) + || (!(a.tag() == Tag::Ref || b.tag() == Tag::Ref) && (a.tag() == Tag::Num || b.tag() == Tag::Num)) } diff --git a/src/run/net.rs b/src/run/net.rs index edd73b35..d4da5068 100644 --- a/src/run/net.rs +++ b/src/run/net.rs @@ -4,7 +4,7 @@ use super::*; /// An interaction combinator net. pub struct Net<'a, M: Mode> { - linker: Linker<'a, M>, + pub(super) linker: Linker<'a, M>, pub tid: usize, // thread id pub tids: usize, // thread count pub trgs: Box<[MaybeUninit]>, diff --git a/src/run/parallel.rs b/src/run/parallel.rs index aec41c3d..65e4acf8 100644 --- a/src/run/parallel.rs +++ b/src/run/parallel.rs @@ -3,14 +3,17 @@ use super::*; impl<'h, M: Mode> Net<'h, M> { /// Forks the net into `tids` child nets, for parallel operation. pub fn fork(&mut self, tids: usize) -> impl Iterator + '_ { - let redexes_len = self.redexes.len(); - let mut redexes = self.redexes.take(); + let redexes_len = self.linker.redexes.len(); + let mut redexes = self.linker.redexes.drain(); + let heap = &self.linker.allocator.heap; + let next = &self.linker.allocator.next; + let root = &self.root; (0 .. tids).map(move |tid| { - let heap_size = (self.heap.0.len() / tids) & !63; // round down to needed alignment + let heap_size = (heap.0.len() / tids) & !63; // round down to needed alignment let heap_start = heap_size * tid; - let area = unsafe { std::mem::transmute(&self.heap.0[heap_start .. heap_start + heap_size]) }; - let mut net = Net::new_with_root(area, self.root.clone()); - net.next = self.next.saturating_sub(heap_start); + let area = unsafe { std::mem::transmute(&heap.0[heap_start .. heap_start + heap_size]) }; + let mut net = Net::new_with_root(area, root.clone()); + net.next = next.saturating_sub(heap_start); net.head = if tid == 0 { net.head } else { Addr::NULL }; net.tid = tid; net.tids = tids; @@ -71,7 +74,6 @@ impl<'h, M: Mode> Net<'h, M> { } }); - // Clear redexes and sum stats delta.add_to(&mut self.rwts); // Main reduction loop