trealla-prolog / trealla

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

Module visibility for attributes incorrect? #555

Closed guregu closed 1 week ago

guregu commented 1 week ago

Found an issue where copy_term/3 + clpz leads to an odd error. It looks like it's trying to call phrase/3 in the context of the funny module instead of clpz (which imports dcgs).

% funny.pl
:- module(funny, [test/0]).

:- use_module(library(iso_ext)). % for scryer
:- use_module(library(clpz)).

% if this is uncommented, it works:
% :- use_module(library(dcgs)).

test :-
    X in 1 .. 2,
    copy_term(X, X, Attrs),
    write(Attrs).
$ ./tpl -f funny -g 'test,halt'
   throw(error(existence_error(procedure,phrase/3),phrase/3)).
$ scryer-prolog -f funny -g 'test,halt'
[clpz:(_642047 in 1..2)]   

End of the trace:

[0:funny:1195:f53:fp115:cp0:sp656:hp735:tp168] EXIT '$redo_trail'('<$blob>'(0x600003df0c80))
[0:funny:1196:f53:fp115:cp0:sp656:hp735:tp168] CALL maplist(call,[phrase(do_queue,[queue(_387,_388,_389,_390)],_324)])
[0:funny:1197:f115:fp116:cp0:sp658:hp791:tp168] EXIT maplist(funny:call,[phrase(do_queue,[queue(_387,_388,_389,_390)],_324)])
[0:funny:1198:f115:fp116:cp0:sp658:hp791:tp168] CALL maplist_([phrase(do_queue,[queue(_387,_388,_389,_390)],_324)],funny:call)
[0:funny:1199:f116:fp117:cp0:sp661:hp791:tp168] EXIT maplist_([phrase(do_queue,[queue(_387,_388,_389,_390)],_324)],funny:call)
[0:funny:1200:f116:fp117:cp0:sp661:hp791:tp168] CALL call(funny:call,phrase(do_queue,[queue(_387,_388,_389,_390)],_324)),maplist_([],funny:call)
[0:funny:1201:f116:fp117:cp0:sp661:hp791:tp168] CALL call(funny:call,phrase(do_queue,[queue(_387,_388,_389,_390)],_324))
[0:funny:1202:f116:fp117:cp0:sp661:hp803:tp168] EXIT call(funny:call,phrase(do_queue,[queue(_387,_388,_389,_390)],_324))
[0:funny:1203:f116:fp117:cp0:sp661:hp803:tp168] CALL phrase(do_queue,[queue(_387,_388,_389,_390)],_324)
   throw(error(existence_error(procedure,phrase/3),phrase/3)).
[0:funny:1204:f116:fp117:cp0:sp661:hp830:tp168] FAIL phrase(do_queue,[queue(_387,_388,_389,_390)],_324)
guregu commented 1 week ago

Thanks! Sorry for ruining the optimization :-)

infradig commented 1 week ago

Hardly worth it or I would have found a way to make it work.

On Tue, 25 June 2024, 01:30 guregu, @.***> wrote:

Thanks! Sorry for ruining the optimization :-)

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