mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
1.93k stars 116 forks source link

CLPZ: Internal error: Aborted (core dumped) #2395

Closed flexoron closed 2 months ago

flexoron commented 2 months ago
$ scryer-prolog -f
?- use_module(library(clpz)).
   true.
?- assertz(clpz:test).  % Begin with assertz,
   true.
?- asserta(clpz:test).  % then asserta, ok
   true.
?- halt.

$ scryer-prolog -f
?- use_module(library(clpz)).
   true.
?- asserta(clpz:test). % Begin with asserta,
   true.
?- assertz(clpz:test). % then assertz

thread 'main' panicked at src/indexing.rs:122:21:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at src/indexing.rs:698:24:
index out of bounds: the len is 5 but the index is 5
stack backtrace:
   0:     0x56098b3f94f9 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h410d4c66be4e37f9
   1:     0x56098af40e60 - core::fmt::write::he40921d4802ce2ac
   2:     0x56098b3c6c22 - std::io::Write::write_fmt::h5de5a4e7037c9b20
   3:     0x56098b3fb22e - std::sys_common::backtrace::print::h11c067a88e3bdb22
   4:     0x56098b3fa9c0 - std::panicking::default_hook::{{closure}}::h8c832ecb03fde8ea
   5:     0x56098b3fbb5b - std::panicking::rust_panic_with_hook::hb164d19c0c1e71d4
   6:     0x56098b3fb580 - std::panicking::begin_panic_handler::{{closure}}::h0369088c533c20e9
   7:     0x56098b3fb4d6 - std::sys_common::backtrace::__rust_end_short_backtrace::hc11d910daf35ac2e
   8:     0x56098b3fb4c3 - rust_begin_unwind
   9:     0x56098af0a404 - core::panicking::panic_fmt::ha6effc2775a0749c
  10:     0x56098af0a501 - core::panicking::panic_bounds_check::h5aa5e8a957e001f9
  11:     0x56098b336fde - scryer_prolog::indexing::remove_constant_indices::h895364fef23480c4
  12:     0x56098b29cb7c - <scryer_prolog::machine::loader::Loader<LS> as core::ops::drop::Drop>::drop::h60e346921cdf9732
  13:     0x56098b1aa9d4 - scryer_prolog::machine::loader::<impl scryer_prolog::machine::Machine>::compile_assert::hbc30e6063a7d56e0
  14:     0x56098b10f324 - scryer_prolog::machine::Machine::run_module_predicate::hc45d285bf605cb99
  15:     0x56098af31d02 - scryer_prolog::main::{{closure}}::h4a9d656181fdadb8
  16:     0x56098b0f76d4 - scryer_prolog::main::hb2e9327ae058b01b
  17:     0x56098b0f4023 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5b0e262292dc8f66
  18:     0x56098b0f53f2 - main
  19:     0x7fb9aa23d088 - __libc_start_call_main
  20:     0x7fb9aa23d14b - __libc_start_main_impl
  21:     0x56098af30325 - _start
  22:                0x0 - <unknown>
thread 'main' panicked at library/core/src/panicking.rs:163:5:
panic in a destructor during cleanup
thread caused non-unwinding panic. aborting.
Aborted (core dumped)
$
triska commented 2 months ago

What an incredible catch!

flexoron commented 2 months ago
Incredible because other libraries do not trigger the abort:

$ scryer-prolog -f
?- use_module(library(lists)).
   true.
?- asserta(lists:test).
   true.
?- assertz(lists:test).
   true.
?- lists:test.
   true
;  true.
?- 
triska commented 2 months ago

@mthom: Thank you a lot! Why is it that we can only produce this issue with library(clpz)? For instance, with d.pl, everything seems to work as expected:

:- module(d, []).

:- dynamic(d/0).

Yielding:

$ scryer-prolog
?- use_module(d).
   true.
?- asserta(d:d).
   true.
?- assertz(d:d).
   true.
mthom commented 2 months ago

It had to do with clpz's internal '$clause'/2 an extensible but non-dynamic predicate.

flexoron commented 2 months ago

Maybe thats why we see this issue: #2390

$ scryer-prolog -f
?- assertz(clpz:test).
   true.
?- use_module(library(clpz)).
% Warning: overwriting $clause/2 because the clauses are discontiguous
   true.
?- retract(clpz:test).
   error(permission_error(modify,static_procedure,test/0),retract/1).
?- halt.

$ scryer-prolog -f
?- use_module(library(clpz)).
   true.
?- assertz(clpz:test).
   true.
?- retract(clpz:test).
   true.
?- 

Aborted (core dumped) issue fixed!