From 7875b96956890d268af7b95b0b24ecdc9ea2b2fd Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 14 Oct 2023 23:56:46 -0600 Subject: [PATCH] simplify stackless iterator is_cyclic (#2111) --- src/machine/gc.rs | 9 ++------- src/tests/acyclic_term.pl | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/machine/gc.rs b/src/machine/gc.rs index d7837395..4b5327c3 100644 --- a/src/machine/gc.rs +++ b/src/machine/gc.rs @@ -272,14 +272,9 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { #[inline] fn is_cyclic(&self, var_current: usize, var_next: usize) -> bool { if self.heap[var_next].is_var() { - var_current != var_next && self.current + 1 != var_current - } else if self.heap[var_next].is_ref() { - // the cell var_next in the second branch contains its original - // value whether var_next is marked or unmarked, meaning the - // is_compound check is well-founded in either case. - self.heap[var_next].get_forwarding_bit() + !self.heap[var_next].get_forwarding_bit() && var_current != var_next } else { - false + self.heap[var_next].is_ref() } } diff --git a/src/tests/acyclic_term.pl b/src/tests/acyclic_term.pl index a7354a3f..7a4676ee 100644 --- a/src/tests/acyclic_term.pl +++ b/src/tests/acyclic_term.pl @@ -15,6 +15,10 @@ term3(A) :- D=[C|_E], A=[C|D]. +term4(A) :- + A=[B|C], + C=[C|B]. + test("acyclic_term_1", ( L = [_Y,[M,B],B|M], acyclic_term(L) )). @@ -123,6 +127,19 @@ test("acyclic_term_26", ( T = [[T, _], 1], \+ acyclic_term(T) )). +test("acyclic_term_27", ( + T = str(A,A), acyclic_term(T) +)). + +test("acyclic_term_28", ( + T = str(A,A,A), acyclic_term(T) +)). + +test("acyclic_term_29", ( + A = s(B, d(Y)), Y = B, acyclic_term(A), + acyclic_term(B), acyclic_term(Y) +)). + test("acyclic_term#2111_1", ( term1(A), \+ acyclic_term(A) )). @@ -135,6 +152,10 @@ test("acyclic_term#2111_3", ( term3(A), \+ acyclic_term(A) )). +test("acyclic_term#2111_4", ( + term4(A), \+ acyclic_term(A) +)). + test("acyclic_term#2113", ( A=[]*B,B=[]*B, \+ acyclic_term(A) )). @@ -143,14 +164,6 @@ test("acyclic_term#2114", ( A=B*B, acyclic_term(A) )). -test("acyclic_term_27", ( - T = str(A,A), acyclic_term(T) -)). - -test("acyclic_term_28", ( - T = str(A,A,A), acyclic_term(T) -)). - main :- findall(test(Name, Goal), test(Name, Goal), Tests), run_tests(Tests, Failed), -- 2.54.0