fix bugs in marker algorithm iterator

This commit is contained in:
Mark
2023-10-12 11:22:57 -06:00
parent 1ea397a807
commit 8aadc99f1d
3 changed files with 507 additions and 396 deletions

View File

@@ -1,5 +1,4 @@
#[cfg(test)]
pub(crate) use crate::machine::gc::{IteratorUMP, StacklessPreOrderHeapIter};
pub(crate) use crate::machine::gc::{CycleDetectorUMP, IteratorUMP, StacklessPreOrderHeapIter};
use crate::atom_table::*;
use crate::machine::heap::*;
@@ -504,15 +503,23 @@ impl<'a, ElideLists: ListElisionPolicy> Iterator for StackfulPreOrderHeapIter<'a
}
}
#[cfg(test)]
#[inline(always)]
pub(crate) fn stackless_preorder_iter(
heap: &mut Vec<HeapCellValue>,
cell: HeapCellValue,
start: usize,
) -> StacklessPreOrderHeapIter<IteratorUMP> {
StacklessPreOrderHeapIter::<IteratorUMP>::new(heap, cell)
StacklessPreOrderHeapIter::<IteratorUMP>::new(heap, start)
}
pub(crate) fn cycle_detecting_stackless_preorder_iter(
heap: &mut Heap,
start: usize,
) -> StacklessPreOrderHeapIter<CycleDetectorUMP> {
StacklessPreOrderHeapIter::<CycleDetectorUMP>::new(heap, start)
}
#[inline(always)]
pub(crate) fn stackful_preorder_iter<'a, ElideLists: ListElisionPolicy>(
heap: &'a mut Vec<HeapCellValue>,
@@ -663,9 +670,9 @@ pub(crate) type RightistPostOrderHeapIter<'a> =
#[inline]
pub(crate) fn stackless_post_order_iter<'a>(
heap: &'a mut Heap,
cell: HeapCellValue,
start: usize,
) -> RightistPostOrderHeapIter<'a> {
PostOrderIterator::new(stackless_preorder_iter(heap, cell))
PostOrderIterator::new(stackless_preorder_iter(heap, start))
}
#[cfg(test)]
@@ -685,8 +692,10 @@ mod tests {
.heap
.extend(functor!(f_atom, [atom(a_atom), atom(b_atom)]));
wam.machine_st.heap.push(str_loc_as_cell!(0));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 3);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -718,8 +727,10 @@ mod tests {
]
));
wam.machine_st.heap.push(str_loc_as_cell!(0));
for _ in 0..20 {
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 5);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -762,7 +773,7 @@ mod tests {
));
for _ in 0..200000 {
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -793,7 +804,7 @@ mod tests {
{
wam.machine_st.heap.push(heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -814,7 +825,7 @@ mod tests {
wam.machine_st.heap.push(empty_list_as_cell!());
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -849,7 +860,7 @@ mod tests {
wam.machine_st.heap.push(heap_loc_as_cell!(0));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -883,8 +894,10 @@ mod tests {
put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
let pstr_cell = wam.machine_st.heap[pstr_var_cell.get_value() as usize];
wam.machine_st.heap.push(pstr_loc_as_cell!(0));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 2);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
assert_eq!(
@@ -898,8 +911,7 @@ mod tests {
assert_eq!(wam.machine_st.heap[0], pstr_cell);
assert_eq!(wam.machine_st.heap[1], heap_loc_as_cell!(1));
wam.machine_st.heap.pop();
wam.machine_st.heap.push(pstr_loc_as_cell!(2));
wam.machine_st.heap[1] = pstr_loc_as_cell!(3);
let pstr_second_var_cell =
put_partial_string(&mut wam.machine_st.heap, "def", &wam.machine_st.atom_tbl);
@@ -907,36 +919,40 @@ mod tests {
let pstr_second_cell = wam.machine_st.heap[pstr_second_var_cell.get_value() as usize];
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 2);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
heap_loc_as_cell!(3),
heap_loc_as_cell!(4),
);
assert!(iter.next().is_none());
}
assert_eq!(wam.machine_st.heap[0], pstr_cell);
assert_eq!(wam.machine_st.heap[1], pstr_loc_as_cell!(2));
assert_eq!(wam.machine_st.heap[2], pstr_second_cell);
assert_eq!(wam.machine_st.heap[3], heap_loc_as_cell!(3));
assert_eq!(wam.machine_st.heap[1], pstr_loc_as_cell!(3));
assert_eq!(wam.machine_st.heap[2], pstr_loc_as_cell!(0));
assert_eq!(wam.machine_st.heap[3], pstr_second_cell);
assert_eq!(wam.machine_st.heap[4], heap_loc_as_cell!(4));
wam.machine_st.heap.pop();
wam.machine_st.heap.push(pstr_loc_as_cell!(4));
wam.machine_st.heap.push(pstr_loc_as_cell!(5));
wam.machine_st.heap.push(pstr_offset_as_cell!(0));
wam.machine_st
.heap
.push(fixnum_as_cell!(Fixnum::build_with(2)));
wam.machine_st.heap[2] = heap_loc_as_cell!(4);
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(4));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 2);
let pstr_offset_cell = pstr_offset_as_cell!(0);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_offset_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), fixnum_as_cell!(Fixnum::build_with(2)));
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
@@ -946,19 +962,19 @@ mod tests {
assert_eq!(unmark_cell_bits!(wam.machine_st.heap[0]), pstr_cell);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[1]),
pstr_loc_as_cell!(2)
);
assert_eq!(unmark_cell_bits!(wam.machine_st.heap[2]), pstr_second_cell);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[3]),
pstr_loc_as_cell!(4)
pstr_loc_as_cell!(3)
);
assert_eq!(unmark_cell_bits!(wam.machine_st.heap[3]), pstr_second_cell);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[4]),
pstr_offset_as_cell!(0)
pstr_loc_as_cell!(5)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[5]),
pstr_offset_as_cell!(0)
);
assert_eq!(
unmark_cell_bits!(wam.machine_st.heap[6]),
fixnum_as_cell!(Fixnum::build_with(2))
);
@@ -974,31 +990,31 @@ mod tests {
.heap
.push(fixnum_as_cell!(Fixnum::build_with(0i64)));
wam.machine_st.heap.push(pstr_loc_as_cell!(0));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 6);
let pstr_offset_cell = pstr_offset_as_cell!(0);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_loc_as_cell!(4));
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_offset_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_offset_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), fixnum_as_cell!(Fixnum::build_with(0)));
assert_eq!(iter.next(), None);
}
all_cells_unmarked(&wam.machine_st.heap);
wam.machine_st.heap.pop();
wam.machine_st
.heap
.push(fixnum_as_cell!(Fixnum::build_with(1i64)));
wam.machine_st.heap[5] = fixnum_as_cell!(Fixnum::build_with(1i64));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 6);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_loc_as_cell!(4));
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1008,13 +1024,17 @@ mod tests {
unmark_cell_bits!(iter.next().unwrap()),
pstr_offset_as_cell!(0)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
fixnum_as_cell!(Fixnum::build_with(1))
);
assert_eq!(iter.next(), None);
assert_eq!(iter.heap[4], pstr_offset_as_cell!(0));
assert_eq!(iter.heap[5], fixnum_as_cell!(Fixnum::build_with(1i64)));
}
assert_eq!(wam.machine_st.heap[4], pstr_offset_as_cell!(0));
assert_eq!(wam.machine_st.heap[5], fixnum_as_cell!(Fixnum::build_with(1i64)));
all_cells_unmarked(&wam.machine_st.heap);
wam.machine_st.heap.clear();
@@ -1030,7 +1050,7 @@ mod tests {
wam.machine_st.heap.extend(functor);
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1067,26 +1087,13 @@ mod tests {
atom_as_cell!(f_atom, 3)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(b_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(b_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(a_atom)
);
assert_eq!(iter.next(), None);
}
all_cells_unmarked(&wam.machine_st.heap);
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1133,7 +1140,7 @@ mod tests {
assert_eq!(wam.machine_st.heap[4], empty_list_as_cell!());
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1165,7 +1172,7 @@ mod tests {
wam.machine_st.heap[4] = list_loc_as_cell!(1);
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1203,19 +1210,6 @@ mod tests {
atom_as_cell!(f_atom, 3)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(b_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(b_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(a_atom)
);
assert_eq!(iter.next(), None);
}
@@ -1227,12 +1221,12 @@ mod tests {
wam.machine_st.heap.push(heap_loc_as_cell!(2));
wam.machine_st.heap.push(heap_loc_as_cell!(3));
wam.machine_st.heap.push(heap_loc_as_cell!(3));
wam.machine_st.heap.push(heap_loc_as_cell!(0));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 4);
assert_eq!(iter.next().unwrap(), heap_loc_as_cell!(3));
assert_eq!(iter.next(), None);
}
@@ -1263,7 +1257,7 @@ mod tests {
wam.machine_st.heap.push(list_loc_as_cell!(1));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
assert_eq!(
@@ -1272,9 +1266,6 @@ mod tests {
);
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
// this is what happens! this next line! We would like it not to happen though.
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
assert_eq!(iter.next(), None);
}
@@ -1310,9 +1301,10 @@ mod tests {
wam.machine_st.heap.push(attr_var_as_cell!(11)); // linked from 7.
wam.machine_st.heap.push(heap_loc_as_cell!(12));
wam.machine_st.heap.push(heap_loc_as_cell!(0));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 13);
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
@@ -1351,6 +1343,7 @@ mod tests {
let clpz_atom = atom!("clpz");
let p_atom = atom!("p");
wam.machine_st.heap.pop();
wam.machine_st.heap.pop();
wam.machine_st.heap.push(heap_loc_as_cell!(13)); // 12
@@ -1365,9 +1358,10 @@ mod tests {
wam.machine_st.heap.push(empty_list_as_cell!()); // 21
wam.machine_st.heap.push(atom_as_cell!(p_atom, 1)); // 22
wam.machine_st.heap.push(heap_loc_as_cell!(23)); // 23
wam.machine_st.heap.push(heap_loc_as_cell!(0));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 24);
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
@@ -1502,10 +1496,9 @@ mod tests {
wam.machine_st.heap.clear();
{
let mut iter = stackless_preorder_iter(
&mut wam.machine_st.heap,
fixnum_as_cell!(Fixnum::build_with(0)),
);
wam.machine_st.heap.push(fixnum_as_cell!(Fixnum::build_with(0)));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1517,8 +1510,6 @@ mod tests {
all_cells_unmarked(&wam.machine_st.heap);
assert_eq!(wam.machine_st.heap.len(), 0);
wam.machine_st.heap.clear();
wam.machine_st.heap.push(str_loc_as_cell!(1));
@@ -1528,7 +1519,7 @@ mod tests {
wam.machine_st.heap.push(atom_as_cell!(atom!("y")));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(1));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1540,7 +1531,7 @@ mod tests {
atom_as_cell!(atom!("y"))
);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), str_loc_as_cell!(1));
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), heap_loc_as_cell!(0));
assert!(iter.next().is_none());
}
@@ -1552,9 +1543,10 @@ mod tests {
wam.machine_st.heap.push(atom_as_cell!(atom!("g"), 2));
wam.machine_st.heap.push(str_loc_as_cell!(0));
wam.machine_st.heap.push(atom_as_cell!(atom!("y")));
wam.machine_st.heap.push(str_loc_as_cell!(0));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 3);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1587,7 +1579,7 @@ mod tests {
wam.machine_st.heap.push(empty_list_as_cell!());
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(7));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 7);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1645,9 +1637,10 @@ mod tests {
wam.machine_st.heap.push(atom_as_cell!(atom!("f"), 2));
wam.machine_st.heap.push(heap_loc_as_cell!(1));
wam.machine_st.heap.push(heap_loc_as_cell!(1));
wam.machine_st.heap.push(str_loc_as_cell!(0));
{
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
let mut iter = stackless_preorder_iter(&mut wam.machine_st.heap, 3);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -1674,38 +1667,68 @@ mod tests {
wam.machine_st.heap.clear();
// representation of one of the heap terms as in issue #1384.
/*
wam.machine_st.heap.push(list_loc_as_cell!(7));
wam.machine_st.heap.push(list_loc_as_cell!(7)); // 0
wam.machine_st.heap.push(heap_loc_as_cell!(0)); // 1
wam.machine_st.heap.push(list_loc_as_cell!(3)); // 2
wam.machine_st.heap.push(list_loc_as_cell!(5)); // 3
wam.machine_st.heap.push(empty_list_as_cell!()); // 4
wam.machine_st.heap.push(heap_loc_as_cell!(2)); // 5
wam.machine_st.heap.push(heap_loc_as_cell!(2)); // 6
wam.machine_st.heap.push(empty_list_as_cell!()); // 7
wam.machine_st.heap.push(heap_loc_as_cell!(3)); // 8
wam.machine_st.heap.push(heap_loc_as_cell!(0));
wam.machine_st.heap.push(list_loc_as_cell!(3));
wam.machine_st.heap.push(list_loc_as_cell!(5));
wam.machine_st.heap.push(empty_list_as_cell!());
wam.machine_st.heap.push(heap_loc_as_cell!(2));
wam.machine_st.heap.push(heap_loc_as_cell!(2));
wam.machine_st.heap.push(empty_list_as_cell!());
wam.machine_st.heap.push(heap_loc_as_cell!(3));
{
let mut iter = stackless_preorder_iter(
&mut wam.machine_st.heap,
heap_loc_as_cell!(0),
9,
);
/*
while let Some(_) = iter.next() {
print_heap_terms(iter.heap.iter(), 0);
println!("");
}
*/
/*
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(atom!("f"), 2)
list_loc_as_cell!(7)
);
assert!(iter.next().is_none());
*/
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
list_loc_as_cell!(5)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
heap_loc_as_cell!(2)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
list_loc_as_cell!(3)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
empty_list_as_cell!()
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
heap_loc_as_cell!(2)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
empty_list_as_cell!()
);
assert_eq!(iter.next(), None);
}
*/
}
#[test]
@@ -2797,8 +2820,10 @@ mod tests {
.heap
.extend(functor!(f_atom, [atom(a_atom), atom(b_atom)]));
wam.machine_st.heap.push(str_loc_as_cell!(0));
{
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 3);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -2828,8 +2853,10 @@ mod tests {
]
));
wam.machine_st.heap.push(str_loc_as_cell!(0));
for _ in 0..20 {
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, str_loc_as_cell!(0));
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 5);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), str_loc_as_cell!(0));
@@ -2860,7 +2887,7 @@ mod tests {
wam.machine_st.heap.push(heap_loc_as_cell!(0));
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
stackless_post_order_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -2876,8 +2903,7 @@ mod tests {
wam.machine_st.heap.push(heap_loc_as_cell!(1));
wam.machine_st.heap.push(heap_loc_as_cell!(0));
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -2903,7 +2929,7 @@ mod tests {
{
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
stackless_post_order_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -2936,7 +2962,7 @@ mod tests {
{
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
stackless_post_order_iter(&mut wam.machine_st.heap, 0);
// the cycle will be iterated twice before being detected.
assert_eq!(
@@ -2965,7 +2991,7 @@ mod tests {
{
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
stackless_post_order_iter(&mut wam.machine_st.heap, 0);
// cut the iteration short to check that all cells are
// unmarked and unforwarded by the Drop instance of
@@ -2999,9 +3025,11 @@ mod tests {
put_partial_string(&mut wam.machine_st.heap, "abc ", &wam.machine_st.atom_tbl);
let pstr_cell = wam.machine_st.heap[pstr_var_cell.get_value() as usize];
wam.machine_st.heap.push(pstr_loc_as_cell!(0));
{
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
stackless_post_order_iter(&mut wam.machine_st.heap, 2);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -3013,6 +3041,7 @@ mod tests {
assert_eq!(iter.next(), None);
}
wam.machine_st.heap.pop();
wam.machine_st.heap.pop();
wam.machine_st.heap.push(pstr_loc_as_cell!(2));
@@ -3021,9 +3050,10 @@ mod tests {
let pstr_second_cell = wam.machine_st.heap[pstr_second_var_cell.get_value() as usize];
wam.machine_st.heap.push(pstr_loc_as_cell!(0));
{
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 4);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -3048,9 +3078,10 @@ mod tests {
.heap
.push(fixnum_as_cell!(Fixnum::build_with(0)));
wam.machine_st.heap.push(pstr_loc_as_cell!(0));
{
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 7);
let mut pstr_loc_cell = pstr_loc_as_cell!(0);
pstr_loc_cell.set_forwarding_bit(true);
@@ -3058,11 +3089,7 @@ mod tests {
// assert_eq!(iter.next().unwrap(), fixnum_as_cell!(Fixnum::build_with(0i64)));
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
pstr_offset_as_cell!(0)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
pstr_offset_as_cell!(0)
heap_loc_as_cell!(3)
);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
@@ -3073,28 +3100,27 @@ mod tests {
all_cells_unmarked(&wam.machine_st.heap);
wam.machine_st.heap.pop();
wam.machine_st.heap.pop();
wam.machine_st
.heap
.push(fixnum_as_cell!(Fixnum::build_with(1)));
wam.machine_st.heap.push(pstr_loc_as_cell!(0));
{
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, pstr_loc_as_cell!(0));
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 7);
//assert_eq!(iter.next().unwrap(), fixnum_as_cell!(Fixnum::build_with(1)));
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
pstr_offset_as_cell!(0)
heap_loc_as_cell!(3)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
pstr_offset_as_cell!(0)
pstr_second_cell
);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_second_cell);
assert_eq!(unmark_cell_bits!(iter.next().unwrap()), pstr_cell);
assert_eq!(iter.next(), None);
}
@@ -3110,9 +3136,10 @@ mod tests {
wam.machine_st.heap.extend(functor);
wam.machine_st.heap.push(heap_loc_as_cell!(0));
{
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 9);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -3142,18 +3169,6 @@ mod tests {
list_loc_as_cell!(3)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(b_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(b_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(a_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(f_atom, 3)
@@ -3172,8 +3187,7 @@ mod tests {
wam.machine_st.heap[4] = list_loc_as_cell!(1);
{
let mut iter =
stackless_post_order_iter(&mut wam.machine_st.heap, heap_loc_as_cell!(0));
let mut iter = stackless_post_order_iter(&mut wam.machine_st.heap, 0);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
@@ -3193,25 +3207,15 @@ mod tests {
atom_as_cell!(f_atom, 3)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(b_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(b_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(a_atom)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
atom_as_cell!(f_atom, 3)
);
assert_eq!(iter.next().unwrap(), list_loc_as_cell!(1));
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),
list_loc_as_cell!(1)
);
assert_eq!(
unmark_cell_bits!(iter.next().unwrap()),

File diff suppressed because it is too large Load Diff

View File

@@ -430,6 +430,7 @@ impl HeapCellValue {
HeapCellValueTag::Cons
| HeapCellValueTag::F64
| HeapCellValueTag::Fixnum
| HeapCellValueTag::CutPoint
| HeapCellValueTag::Char
| HeapCellValueTag::CStr => true,
HeapCellValueTag::Atom => cell_as_atom_cell!(self).get_arity() == 0,