[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: --min-bips omits necessary library
From: |
Daniel Diaz |
Subject: |
Re: --min-bips omits necessary library |
Date: |
Thu, 13 Jul 2023 11:35:51 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 |
Hi Jasper,
First the solution ! Add the following directive:
:- ensure_linked((=)/2).
When compiling a meta-predicate (here \+), the compiler does not know
the final goal that will be called (it will be known at run-time). If it
is not "statically" referenced (like q is in p:-q.), it will not be
linked with --min-bips. The directive explicitly asks for the link of a
given predicate. This is needed if a meta-predicate can call a predicate
which is not elsewhere statically referenced.
Here, for =/2 it is because it is inlined.
This case seems obvious for several reasons: it is the well-known
negation \+, its goal is known, its goal is the most obvious predicate:
unification.
I admit, the compiler could be optimized for meta-predicates and, in
this case, detect the called goal is =/2 and so force its link (or
better it could also inline it). But this is more difficult with complex
goals (\+ (a,b ; c)). And, in any case, we can have variables (\+ X).
The directive is unavoidable.
A solution to mimic the optimization: put the meta-called goal inside a
sub-predicate.
main :-
\+ sub_goal,
write(hello), nl.
sub_goal :-
[1,_,3] = [_,2,4].
:- initialization(main).
Btw: you can now report a problem/bug by opening an issue at
https://github.com/didoudiaz/gprolog/issues.
Daniel
Le 10/07/2023 à 12:44, Jasper Taylor a écrit :
The following produces an error when built with --min-bips but not
otherwise...
cat hello.pl
main :-
\+ [1,_,3] = [_,2,4],
write(hello), nl.
:- initialization(main).
jaspert@barbie:~/Build/Test$ gplc --no-top-level hello.pl
jaspert@barbie:~/Build/Test$ ./hello
hello
jaspert@barbie:~/Build/Test$ gplc -v --no-top-level --min-bips hello.pl
Prolog compiler (GNU Prolog) 1.6.0
Copyright (C) 1999-2023 Daniel Diaz
GNU Prolog comes with ABSOLUTELY NO WARRANTY.
This is free software; see the source or the file
named COPYING for copying conditions.
Path used: /usr/local/gprolog-1.6.0
*** Compiling
--- file: hello.pl
pl2wam -o /tmp/gplcwgQv0b.wam hello.pl
wam2ma -o /tmp/gplcSmwRQd.ma /tmp/gplcwgQv0b.wam
delete /tmp/gplcwgQv0b.wam
ma2asm -o /tmp/gplcetcdHf.s /tmp/gplcSmwRQd.ma
delete /tmp/gplcSmwRQd.ma
as -o /tmp/gplcAzSyxh.o /tmp/gplcetcdHf.s
delete /tmp/gplcetcdHf.s
*** Linking
gcc -fno-strict-aliasing -fcommon -o hello /tmp/gplcAzSyxh.o
/usr/local/gprolog-1.6.0/lib/libbips_pl.a
/usr/local/gprolog-1.6.0/lib/libengine_pl.a
/usr/local/gprolog-1.6.0/lib/liblinedit.a -lm
delete /tmp/gplcAzSyxh.o
jaspert@barbie:~/Build/Test$ ./hello
system_error(cannot_catch_throw(error(existence_error(procedure,(=)/2),(\+)/1)))
hello
Regards
Jasper