pub(crate) use crate::machine::gc::StacklessPreOrderHeapIter;
use crate::atom_table::*;
-use crate::machine::cycle_detection::CycleDetectingIter;
+use crate::machine::cycle_detection::*;
use crate::machine::heap::*;
use crate::machine::stack::*;
use crate::types::*;
pub(crate) fn cycle_detecting_stackless_preorder_iter<'a>(
heap: &'a mut [HeapCellValue],
start: usize,
-) -> CycleDetectingIter<'a> {
+) -> CycleDetectingIter<'a, true> {
+ // const generics argument of true so that cycle discovery stops
+ // the iterator.
CycleDetectingIter::new(heap, start)
}
*/
#[derive(Debug)]
-pub(crate) struct CycleDetectingIter<'a> {
+pub(crate) struct CycleDetectingIter<'a, const STOP_AT_CYCLES: bool> {
pub(crate) heap: &'a mut [HeapCellValue],
start: usize,
current: usize,
mark_phase: bool,
}
-impl<'a> CycleDetectingIter<'a> {
+impl<'a, const STOP_AT_CYCLES: bool> CycleDetectingIter<'a, STOP_AT_CYCLES> {
pub(crate) fn new(heap: &'a mut [HeapCellValue], start: usize) -> Self {
heap[start].set_forwarding_bit(true);
let next = heap[start].get_value();
#[inline]
fn cycle_detection_active(&self) -> bool {
- self.mark_phase && !self.cycle_found
+ STOP_AT_CYCLES && self.mark_phase && !self.cycle_found
}
fn backward_and_return(&mut self) -> HeapCellValue {
}
}
-impl<'a> Iterator for CycleDetectingIter<'a> {
+impl<'a, const STOP_AT_CYCLES: bool> Iterator for CycleDetectingIter<'a, STOP_AT_CYCLES> {
type Item = HeapCellValue;
#[inline]
}
-impl<'a> Drop for CycleDetectingIter<'a> {
+impl<'a, const STOP_AT_CYCLES: bool> Drop for CycleDetectingIter<'a, STOP_AT_CYCLES> {
fn drop(&mut self) {
self.invert_marker();