trealla-prolog / trealla

A compact, efficient Prolog interpreter written in plain-old C.
MIT License
270 stars 13 forks source link

consult/1 fails intermittently #604

Open dnmfarrell opened 1 week ago

dnmfarrell commented 1 week ago
?- consult("iam/arn.pl").
   throw(error(existence_error(source_sink,[i,a,m,/,a,r,n,'.',p,l]),load_files/2)).
   throw(error(resource_error(memory),load_files/2)).
?- consult("iam/arn.pl").
Warning: overwriting 'arn'/2
...
   true.
$  tpl -v
Trealla Prolog (c) Infradig 2020-2024, v2.57.1

edit: The same behavior occurs with reconsult/1.

$ uname -roi
5.15.0-122-generic x86_64 GNU/Linux
infradig commented 1 week ago

What if you use single-quotes instead of double?

On Mon, 7 Oct 2024, 22:51 David Farrell, @.***> wrote:

?- consult("iam/arn.pl"). throw(error(existence_error(source_sink,[i,a,m,/,a,r,n,'.',p,l]),load_files/2)). throw(error(resource_error(memory),load_files/2)). ?- consult("iam/arn.pl"). Warning: overwriting 'arn'/2 ... true.

$ tpl -v Trealla Prolog (c) Infradig 2020-2024, v2.57.1

— Reply to this email directly, view it on GitHub https://github.com/trealla-prolog/trealla/issues/604, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNKSETTZA2I7RITRSOS653Z2J7T5AVCNFSM6AAAAABPP3PKW2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGU3TAMZVGIYTCOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

dnmfarrell commented 1 week ago

What if you use single-quotes instead of double?

Same behavior:

?- consult('iam/arn.pl').
   throw(error(existence_error(source_sink,'iam/arn.pl'),load_files/2)).
   throw(error(resource_error(memory),load_files/2)).
pmoura commented 1 week ago

Do you have any initialization/1 directives in the file that you're trying to consult?

dnmfarrell commented 1 week ago

Do you have any initialization/1 directives in the file that you're trying to consult?

I don't think so, but it does load a few libraries (no ~/.tplrc). Here's the gist of my (wip) code.

dnmfarrell commented 1 week ago

FWIW, the behavior does seem to be specific to iam/arn.pl. I cannot reproduce the issue with another local file:

% anybuta.pl
anybuta --> nota, any.
nota    --> call(eos).
nota    --> [C], { dif(C, a) }.
any     --> [].
any     --> [_], any.

eos([],[]).
flexoron commented 1 week ago

I get the error (sometimes)

?- consult("./arn.pl").
   true.

?- reconsult("./arn.pl").
Warning: overwriting 'arn'/2
Warning: overwriting 'partition'/2
Warning: overwriting 'service'/2
Warning: overwriting 's3'/2
Warning: overwriting 'bucket'/2
Warning: overwriting 'object'/2
Warning: overwriting 'object_init'/2
Warning: overwriting 'object_leng'/2
Warning: overwriting 'object_chrs'/2
Warning: overwriting 'object_char'/2
Warning: overwriting 'object_over'/2
Warning: overwriting 'prefix_ok'/2
Warning: overwriting 'suffix_ok'/2
Warning: overwriting 'take'/3
Warning: overwriting 'take_'/3
Warning: overwriting 'bucket_init'/2
Warning: overwriting 'bucket_name'/2
Warning: overwriting 'bucket_midl'/2
Warning: overwriting 'midl_perio'/2
Warning: overwriting 'char_alnum'/2
Warning: overwriting 'char_hypen'/2
Warning: overwriting 'char_perio'/2
Warning: overwriting 'char_anyof'/2
Warning: overwriting 'alnum'/2
Warning: overwriting 'hpnum'/2
Warning: overwriting 'hypdot'/2
Warning: overwriting 'run_tests'/0
Warning: overwriting 'test_bucket'/0
Warning: overwriting 'test_failing_cases'/1
Warning: overwriting 'test_fail'/1
Warning: overwriting 'test_passing_cases'/1
Warning: overwriting 'test_pass'/1
Warning: overwriting 'test_case'/4
Warning: overwriting 'popit'/2
   true.

?- reconsult("./arn.pl"). % Sometimes you've to call reconsult several times
   throw(error(existence_error(source_sink,['.',/,a,r,n,'.',p,l]),load_files/2)).
   throw(error(resource_error(memory),load_files/2)).
?- 
flexoron commented 1 week ago
$ cat bbb.pl
% arn:partition:service:region:account-id:resource-type/resource-id
:- use_module(library(clpz)).
:- use_module(library(charsio)).
:- use_module(library(debug)).
:- use_module(library(error)).
:- use_module(library(lists)).

bbb         --> "bbb".

popit([_|As],As).
%bucket_leng       --> [L], { L #=< 63 }.
%alnum_            --> [C], { char_type(C, decimal_digit); char_type(C, lower)}.
?- consult("./bbb.pl").
   true.
?- reconsult("./bbb.pl").
Warning: overwriting 'bbb'/2
Warning: overwriting 'popit'/2
   true.
?- reconsult("./bbb.pl").
Warning: overwriting 'bbb'/2
Warning: overwriting 'popit'/2
   true.
?- reconsult("./bbb.pl").
Warning: overwriting 'bbb'/2
Warning: overwriting 'popit'/2
   true.
?- reconsult("./bbb.pl").
Warning: overwriting 'bbb'/2
Warning: overwriting 'popit'/2
   true.
?- reconsult("./bbb.pl").
Warning: overwriting 'bbb'/2
Warning: overwriting 'popit'/2
   true.
?- reconsult("./bbb.pl").
Warning: overwriting 'bbb'/2
Warning: overwriting 'popit'/2
   true.
?- reconsult("./bbb.pl").
   throw(error(existence_error(source_sink,['.',/,b,b,b,'.',p,l]),load_files/2)).
   throw(error(resource_error(memory),load_files/2)).
?- halt.

Note: I don't see this error with b.pl and b --> "b". or bb.pl and bb --> "bb".

flexoron commented 1 week ago
$ cat bbb.pl 
bbb         --> "bbb".
p([_|_],_). % Looks like it has to do with this p/2. With p/1 p([_|_]), I don't get the error.
infradig commented 1 week ago

Ok with...

$ cat bbbb.pl
bbb         --> "bbb".
p([_|_],_). % Looks like it has to do with this p/2. With p/1 p([_|_]), I don't get the error

i get:

$ valgrind tpl
==657973== Memcheck, a memory error detector
==657973== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==657973== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==657973== Command: tpl
==657973== 
?- consult('bbbb.pl').
   true.
?- reconsult('bbbb.pl').
Warning: overwriting 'bbb'/2
Warning: overwriting 'p'/2
   true.
?- reconsult('bbbb.pl').
==657973== Invalid write of size 8
==657973==    at 0x2076F8: list_push_back (in /home/andrew/trealla/tpl)
==657973==    by 0x20C2BE: unload_realfile (in /home/andrew/trealla/tpl)
==657973==    by 0x20D317: unload_file (in /home/andrew/trealla/tpl)
==657973==    by 0x1BB187: do_consult (in /home/andrew/trealla/tpl)
==657973==    by 0x1C2A6D: bif_load_files_2 (in /home/andrew/trealla/tpl)
==657973==    by 0x2371E2: start (in /home/andrew/trealla/tpl)
==657973==    by 0x21DD14: run (in /home/andrew/trealla/tpl)
==657973==    by 0x22E807: pl_eval (in /home/andrew/trealla/tpl)
==657973==    by 0x1190D1: main (in /home/andrew/trealla/tpl)
==657973==  Address 0x5528728 is 8 bytes inside a block of size 472 free'd
==657973==    at 0x484988F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==657973==    by 0x20CC2F: assertz_to_db (in /home/andrew/trealla/tpl)
==657973==    by 0x216638: process_term (in /home/andrew/trealla/tpl)
==657973==    by 0x21B41E: tokenize (in /home/andrew/trealla/tpl)
==657973==    by 0x20D4E1: load_fp (in /home/andrew/trealla/tpl)
==657973==    by 0x20DE5C: load_file (in /home/andrew/trealla/tpl)
==657973==    by 0x1BB1A0: do_consult (in /home/andrew/trealla/tpl)
==657973==    by 0x1C2A6D: bif_load_files_2 (in /home/andrew/trealla/tpl)
==657973==    by 0x2371E2: start (in /home/andrew/trealla/tpl)
==657973==    by 0x21DD14: run (in /home/andrew/trealla/tpl)
==657973==    by 0x22E807: pl_eval (in /home/andrew/trealla/tpl)
==657973==    by 0x1190D1: main (in /home/andrew/trealla/tpl)
==657973==  Block was alloc'd at
==657973==    at 0x484D953: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==657973==    by 0x20A716: assert_begin (in /home/andrew/trealla/tpl)
==657973==    by 0x20CA23: assertz_to_db (in /home/andrew/trealla/tpl)
==657973==    by 0x216638: process_term (in /home/andrew/trealla/tpl)
==657973==    by 0x21B41E: tokenize (in /home/andrew/trealla/tpl)
==657973==    by 0x20D4E1: load_fp (in /home/andrew/trealla/tpl)
==657973==    by 0x20DE5C: load_file (in /home/andrew/trealla/tpl)
==657973==    by 0x1BB1A0: do_consult (in /home/andrew/trealla/tpl)
==657973==    by 0x1C2A6D: bif_load_files_2 (in /home/andrew/trealla/tpl)
==657973==    by 0x2371E2: start (in /home/andrew/trealla/tpl)
==657973==    by 0x21DD14: run (in /home/andrew/trealla/tpl)
==657973==    by 0x22E807: pl_eval (in /home/andrew/trealla/tpl)
==657973== 
Warning: overwriting 'bbb'/2
Warning: overwriting 'p'/2
   true.
?- 

And I get the same error with your p/1.

flexoron commented 1 week ago
$ cat bbbb.pl
bbb         --> "bbb".
x.
y.

v2.57.4

$ tpl
?- consult("./bbbb.pl").
   true.
?- listing.
bbb(A,B) :-
   A=[b,b,b|B].
x.
y.
   true.

?- reconsult("./bbbb.pl").
Warning: overwriting 'bbb'/2  % just bbb/2 ? 
   true.
?- listing.
x.
x.
y.
y.
   true.

?- reconsult("./bbbb.pl").
Warning: overwriting 'x'/0 % easygoing, step by step
   true.
?- listing.
y.
y.
y.
   true.

?- reconsult("./bbbb.pl").
Warning: overwriting 'y'/0 % 
   true.
?- listing.
   true.  % empty?

?- x,y.   % no
   true
;  true.

?-
infradig commented 1 week ago

Yeah, i noticed listing is acting up.

On Tue, Oct 8, 2024 at 8:49 AM flexoron @.***> wrote:

$ cat bbbb.pl bbb --> "bbb". x. y.

v2.57.4

$ tpl ?- consult("./bbbb.pl"). true. ?- listing. bbb(A,B) :- A=[b,b,b|B]. x. y. true.

?- reconsult("./bbbb.pl"). Warning: overwriting 'bbb'/2 % just bbb/2 ? true. ?- listing. x. x. y. y. true.

?- reconsult("./bbbb.pl"). Warning: overwriting 'x'/0 % easygoing, step by step true. ?- listing. y. y. y. true.

?- reconsult("./bbbb.pl"). Warning: overwriting 'y'/0 % true. ?- listing. true. % empty?

?- x,y. % no true ; true.

?-

— Reply to this email directly, view it on GitHub https://github.com/trealla-prolog/trealla/issues/604#issuecomment-2398060059, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNKSEVV2ERZJO53NHMR6V3Z2MFYPAVCNFSM6AAAAABPP3PKW2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJYGA3DAMBVHE . You are receiving this because you commented.Message ID: @.***>

infradig commented 1 week ago

A couple of things actually...

$ cat x.pl
f.
$ tpl
?- consult('x.pl').
   true.
?- listing.
f.
   true.
?- f.
   true.
?- deconsult('x.pl').
   true.
?- listing.
   true.
?- f.
   throw(error(existence_error(procedure,f/0),f/0)).
?- consult('x.pl').
Warning: overwriting 'f'/0
   true.
?- listing.
   true.
?- f.
   true.
?- 

The overwriting warning as well as actual listing noshow.

infradig commented 1 week ago

It seems deconsult/1 has gone out of fashion everywhere, I should probably remove it. Perhaps reconsult/1 & consult/1 as well.

Although [filename] is just a disguised consult/reconsult & shows the same problem of course.

flexoron commented 1 week ago
$ cat x.pl
f.

$ tpl
?- "x" = '.'(x,[]).
   true.
?- "x".
   throw(error(type_error(callable,[x]),x/0)).
?- '.'(x,[]).
   true.
?- x =.. F,call(F).
Warning: overwriting 'f'/0
   F = "x".
?- 
$ scryer-prolog -f
?- .(x,[]).
   true.
?- [x].
   true.
?- x =.. F,call(F).
   error(type_error(callable,"x"),call/1). % twilight sky
?- "x".
   true.
?-