]> Repositorios git - scryer-prolog.git/commitdiff
simplify stackless iterator is_cyclic (#2111)
authorMark <[email protected]>
Sun, 15 Oct 2023 05:56:46 +0000 (23:56 -0600)
committerMark <[email protected]>
Sun, 15 Oct 2023 05:56:46 +0000 (23:56 -0600)
src/machine/gc.rs
src/tests/acyclic_term.pl

index d7837395b30d298bf05ba4ccaaa5770cc3679c33..4b5327c308970a067fdb4df29ee4423efc0ba1f2 100644 (file)
@@ -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()
         }
     }
 
index a7354a3f4623025896602a704c21e5936da5e1b0..7a4676eecba053a1e5aae922cc0852423a7bdc47 100644 (file)
@@ -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),