From 3fb2e451a21d33be8c7ba7a88a4ba661e787457e Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 15 Oct 2023 00:58:15 -0600 Subject: [PATCH] improve cycle detection in detect_list_cycles (#2111) --- src/machine/gc.rs | 2 +- src/tests/acyclic_term.pl | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/machine/gc.rs b/src/machine/gc.rs index 4b5327c3..7958cf67 100644 --- a/src/machine/gc.rs +++ b/src/machine/gc.rs @@ -213,7 +213,7 @@ impl<'a> StacklessPreOrderHeapIter<'a, CycleDetectorUMP> { } if temp == self.start { - break; + return self.heap[temp].get_value() == self.current as u64; } } diff --git a/src/tests/acyclic_term.pl b/src/tests/acyclic_term.pl index 7a4676ee..fd8ad229 100644 --- a/src/tests/acyclic_term.pl +++ b/src/tests/acyclic_term.pl @@ -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. -- 2.54.0