From jan@swi.psy.uva.nl  Thu Nov  9 16:27:50 2000
Received: from gollem.swi.psy.uva.nl (gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA07563;
	Thu, 9 Nov 2000 16:27:50 +0100 (MET)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id QAA29741;
	Thu, 9 Nov 2000 16:27:51 +0100
Date: Thu, 9 Nov 2000 16:27:51 +0100
Message-Id: <200011091527.QAA29741@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: Optimisation bug
To: leo@solvo.ru, prolog@swi.psy.uva.nl
In-Reply-To: leo@solvo.ru's message of Thu, 9 Nov 2000 15:29:46 +0300
Phone: +31 - 20 - 525 6121

> 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

