trealla-prolog/trealla

segmentation fault in warehouse test

Closed this issue · 5 comments

Got a segmentation fault in a warehouse test:

$ ./tpl -v
Trealla Prolog (c) Infradig 2020-2023, v2.50.35
$ ./tpl
?- ['bench2.p'].
   true.
?- time(test).
Segmentation fault

The test case reads:

:- dynamic(foo/2).

test :-
   retractall(foo(_,_)),
   warehouse(1000000, 1, 18884).

warehouse(0, _, _) :- !.
warehouse(N, X, Y) :-
   assertz(foo(Y, bar)),
   (retract(foo(X, bar)) -> true; true),
   zx81(X, Z), zx81(Y, T),
   M is N-1,
   warehouse(M, Z, T).

zx81(X, Y) :- Y is (X*75+74) mod 65537.
Strange enough I get the segfault with this:

$ tpl
?- time(test).
% Time elapsed 4.133s, 11000004 Inferences, 2.662 MLips
   true.
?- time(test).
Segmentation fault (core dumped)
$

but not if applied so:
$ tpl
?- test.
   true.
?- test.
   true.
?- test.
   true.
?- test.
   true.
?- time(test).
% Time elapsed 4.391s, 11000004 Inferences, 2.505 MLips
   true.
?- time(test).
% Time elapsed 4.437s, 11000004 Inferences, 2.479 MLips
   true.
?- time(test).
% Time elapsed 4.416s, 11000004 Inferences, 2.491 MLips
   true.
?- time(test).
% Time elapsed 4.451s, 11000004 Inferences, 2.471 MLips
   true.
?-

Using retractall/1 instead of retract/1 seems to fix. Not sure why it would be different as there is only every 1 retracted.

EDIT: oops no, still seems to crash after enough iterations.

Any reason you re-opened this?

I errorneously closed it, and then in an instance I reopened it.

But it runs now fine on my side:

$ ./tpl -v
Trealla Prolog (c) Infradig 2020-2023, v2.51.8-5-gbcb2
$ ./tpl
?- ['bench.p'].
   true.
?- time(test).
% Time elapsed 4.259s, 11000004 Inferences, 2.583 MLips
   true.
?- time(test).
% Time elapsed 4.168s, 11000004 Inferences, 2.639 MLips
   true.