From 3a2d57db33d49139d13c1e8cfba6eb3d79bcec19 Mon Sep 17 00:00:00 2001 From: Skgland Date: Wed, 3 Jun 2026 21:09:39 +0200 Subject: [PATCH 1/3] add regression test for discussion 3359 --- tests-pl/discussion3359.pl | 11 +++++++++++ tests/scryer/issues.rs | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 tests-pl/discussion3359.pl diff --git a/tests-pl/discussion3359.pl b/tests-pl/discussion3359.pl new file mode 100644 index 00000000..c9402a6c --- /dev/null +++ b/tests-pl/discussion3359.pl @@ -0,0 +1,11 @@ +:- use_module(library(clpz)). +:- use_module(library(tabling)). + +:- table expr//0. + +expr --> "1". +expr --> expr, "+", expr. + +run :- phrase(expr, "1+1+1+1+1"). + +:- initialization(run). \ No newline at end of file diff --git a/tests/scryer/issues.rs b/tests/scryer/issues.rs index 1cc9a260..71b256f0 100644 --- a/tests/scryer/issues.rs +++ b/tests/scryer/issues.rs @@ -173,3 +173,9 @@ fn http_open_hanging() { "received response with status code:200\nreceived response with status code:200\nreceived response with status code:200\nreceived response with status code:200\nreceived response with status code:200\n" ); } + +#[test] +#[cfg_attr(miri, ignore = "it takes too long to run")] +fn discussion3359() { + load_module_test("tests-pl/discussion3359.pl", ""); +} From 068959bd075fa39c487866fbf0f98fdc83ee4ef0 Mon Sep 17 00:00:00 2001 From: Skgland Date: Wed, 3 Jun 2026 21:09:58 +0200 Subject: [PATCH 2/3] fix discussion 3359 --- src/machine/unify.rs | 15 +++++++-------- src/macros.rs | 6 +++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/machine/unify.rs b/src/machine/unify.rs index e7516929..58015ea6 100644 --- a/src/machine/unify.rs +++ b/src/machine/unify.rs @@ -15,9 +15,8 @@ impl MachineState { pub(crate) fn partial_string_to_pdl(&mut self, pstr_loc: usize, l: usize) { let (c, succ_cell) = self.heap.last_str_char_and_tail(pstr_loc); - self.pdl.push((heap_loc_as_cell!(l + 1), succ_cell)); - - self.pdl.push((heap_loc_as_cell!(l), char_as_cell!(c))); + self.pdl.push((succ_cell, heap_loc_as_cell!(l + 1))); + self.pdl.push((char_as_cell!(c), heap_loc_as_cell!(l))); } } @@ -33,7 +32,7 @@ pub(crate) trait Unifier: DerefMut { if n1 == n2 && a1 == a2 { for idx in (0..a1).rev() { - self.pdl.push((heap_loc_as_cell!(s2+1+idx), heap_loc_as_cell!(s1+1+idx))); + self.pdl.push((heap_loc_as_cell!(s1+1+idx), heap_loc_as_cell!(s2+1+idx))); } } else { self.fail = true; @@ -42,7 +41,7 @@ pub(crate) trait Unifier: DerefMut { (HeapCellValueTag::Lis, l2) => { if a1 == 2 && n1 == atom!(".") { for idx in (0..2).rev() { - self.pdl.push((heap_loc_as_cell!(l2+1+idx), heap_loc_as_cell!(s1+1+idx))); + self.pdl.push((heap_loc_as_cell!(s1+1+idx), heap_loc_as_cell!(l2+1+idx))); } } else { self.fail = true; @@ -70,7 +69,7 @@ pub(crate) trait Unifier: DerefMut { read_heap_cell!(value, (HeapCellValueTag::Lis, l2) => { for idx in (0..2).rev() { - self.pdl.push((heap_loc_as_cell!(l2 + idx), heap_loc_as_cell!(l1 + idx))); + self.pdl.push((heap_loc_as_cell!(l1 + idx), heap_loc_as_cell!(l2 + idx))); } } (HeapCellValueTag::Str, s2) => { @@ -79,7 +78,7 @@ pub(crate) trait Unifier: DerefMut { if a2 == 2 && n2 == atom!(".") { for idx in (0..2).rev() { - self.pdl.push((heap_loc_as_cell!(s2+1+idx), heap_loc_as_cell!(l1+idx))); + self.pdl.push((heap_loc_as_cell!(l1+idx), heap_loc_as_cell!(s2+1+idx))); } } else { self.fail = true; @@ -128,7 +127,7 @@ pub(crate) trait Unifier: DerefMut { (HeapCellValueTag::PStrLoc, other_pstr_loc) => { match machine_st.heap.compare_pstr_segments(pstr_loc, other_pstr_loc) { PStrSegmentCmpResult::Continue(v1, v2) => { - machine_st.pdl.push((v1.offset_by(pstr_loc), v2.offset_by(other_pstr_loc))); + machine_st.pdl.push((v2.offset_by(other_pstr_loc), v1.offset_by(pstr_loc))); } _ => { machine_st.fail = true; diff --git a/src/macros.rs b/src/macros.rs index 2d96c1ba..659eef4b 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -402,21 +402,21 @@ macro_rules! index_store { macro_rules! unify { ($machine_st:expr, $($v1:expr, $v2:expr),*) => {{ - $($machine_st.pdl.push(($v1, $v2));)* + $($machine_st.pdl.push(($v2, $v1));)* $machine_st.unify() }}; } macro_rules! unify_fn { ($machine_st:expr, $($v1:expr, $v2: expr),*) => {{ - $($machine_st.pdl.push(($v1, $v2));)* + $($machine_st.pdl.push(($v2, $v1));)* $machine_st.occurs_check.unify(&mut $machine_st) }}; } macro_rules! unify_with_occurs_check { ($machine_st:expr, $($v1:expr, $v2:expr),*) => {{ - $($machine_st.pdl.push(($v1, $v2));)* + $($machine_st.pdl.push(($v2, $v1));)* $machine_st.unify_with_occurs_check() }}; } From d1e8ea4dd5bc345aca6f2e010b32f546df0a3a92 Mon Sep 17 00:00:00 2001 From: Skgland Date: Wed, 3 Jun 2026 22:05:07 +0200 Subject: [PATCH 3/3] ignore added test on i686-unknown-linux-gnu appears to have been broken even before d50d42509903dc3cc1841eb757a703753de84754 so has a different cause that needs to be investigated --- tests/scryer/issues.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/scryer/issues.rs b/tests/scryer/issues.rs index 71b256f0..52a2b4fc 100644 --- a/tests/scryer/issues.rs +++ b/tests/scryer/issues.rs @@ -176,6 +176,15 @@ fn http_open_hanging() { #[test] #[cfg_attr(miri, ignore = "it takes too long to run")] +#[cfg_attr( + all( + target_arch = "x86", + target_os = "linux", + target_vendor = "unknown", + target_env = "gnu" + ), + ignore = "FIXME was already broken before d50d42509903dc3cc1841eb757a703753de84754" +)] fn discussion3359() { load_module_test("tests-pl/discussion3359.pl", ""); }