Subject: Re: Optimisation bug

From: Jan Wielemaker <[email-masked]>
Date: Thu, 9 Nov 2000 16:27:51 +0100

> I think that i found a bug in prolog optimization code.
> 
> I write prolog program, then start pl -O -g 'consult(my_file)' and ooops,
> got segv 11 segmentation fault. Then i began to play with my code, and the
> result are this fragments:
> 
> d(_) :-
>         a(_,W,_),
> 	b(_,_),
> 	c(_-_M/_),
> 	_ is W - M,
> 	f(M).
> 					        
> [leo@raven ~/test-pl]$ pl -O -g 'consult(test)'
> ERROR: (/home/leo/test-pl/test.pl:1):
> iso_message/3: Caught signal 11 (segv)
> ERROR: Failed to load test

Leo,

You found a bug, but it isn't too bad.  What happens in non-optimised
code is that arithmetic is compiled to calls to foreign predicates
evaluating arithmetic expressions.  In optimised mode, arithmetic is
compiled to actions on an arithmetic stack-engine.  This avoids creating
(garbage) terms and pushes the resolutions of the proper functions to
the compiler.

However, it also allows for compile time error checking.  So if the
compiler detects an argument to an arithmetic function is always
unbound, it will throw an exception.  This works fine of the argument
is a singleton, but there was an error if the variable is used multiple
times, but the first time is as argument to an arithetic function.  It
then passes an illegal term used by the compiler to flag variables to
the exception handling code.

Please find a modified pl-comp.c on the CVS server, restoring proper
Prolog data before raising the exception.
	
	Regards --- Jan