]> Repositorios git - scryer-prolog.git/commitdiff
improve cycle detection in detect_list_cycles (#2111)
authorMark <[email protected]>
Sun, 15 Oct 2023 06:58:15 +0000 (00:58 -0600)
committerMark <[email protected]>
Sun, 15 Oct 2023 06:58:19 +0000 (00:58 -0600)
src/machine/gc.rs
src/tests/acyclic_term.pl

index 4b5327c308970a067fdb4df29ee4423efc0ba1f2..7958cf67b55638e1d6bd5ea4756af78a01d951af 100644 (file)
@@ -213,7 +213,7 @@ impl<'a> StacklessPreOrderHeapIter<'a, CycleDetectorUMP> {
             }
 
             if temp == self.start {
-                break;
+                return self.heap[temp].get_value() == self.current as u64;
             }
         }
 
index 7a4676eecba053a1e5aae922cc0852423a7bdc47..fd8ad229ed8c52bfaa7fd8ed4f0e15c3c757a601 100644 (file)
@@ -19,6 +19,11 @@ term4(A) :-
    A=[B|C],
    C=[C|B].
 
+term5(A) :-
+   A=[_B|C],
+   D=[_E|C],
+   A=[C|D].
+
 test("acyclic_term_1", (
     L = [_Y,[M,B],B|M], acyclic_term(L)
 )).
@@ -156,6 +161,10 @@ test("acyclic_term#2111_4", (
     term4(A), \+ acyclic_term(A)
 )).
 
+test("acyclic_term#2111_5", (
+    term5(A), \+ acyclic_term(A)
+)).
+
 test("acyclic_term#2113", (
     A=[]*B,B=[]*B, \+ acyclic_term(A)
 )).
@@ -175,7 +184,7 @@ main_quiet :-
     run_tests_quiet(Tests, Failed),
     (   Failed = [] ->
         format("All tests passed", [])
-    ;   format("Some tests failed: ~w~n", [Failed])
+    ;   format("Some tests failed", [])
     ),
     halt.