On 19-Dec-1997, Simon L Peyton Jones <[EMAIL PROTECTED]> wrote:
> 
> I thought you might find the following bug I've just
> found in GHC entertaining.
> 
> In the strictness analyser we need to compare abstract values
> so that the fixpoint finder knows when to stop.  In the
> middle of this code was the following:
> 
>       sameVal :: AbsVal -> AbsVal -> Bool
> 
>       ...equations for sameVal...
> 
>       sameVal (AbsApproxFun str1 v1) (AbsApproxFun str2 v2) 
>               = str1 == str2 && sameVal v1 v1
> 
>       ...more equations...
> 
> That "sameVal v1 v1" should of course be "sameVal v1 v2".
... 
> this bug has gone un-noticed for I dread to think how long!
> 
> It showed up in a nofib test -- sing ho for regression tests.

This bug could have been caught by a very simple static analysis that
is very popular in the logic programming community: singleton variable
warnings.  In the code above, the variable `v2' occurs only once.
Singleton variables such as this are often bugs.  For cases where the
programmer really does want a singleton variable, the warning can be
suppressed by using a different naming convention (in Prolog, it
would be `_v2'; since Haskell doesn't allow leading underscores,
I suppose you could use `v2_').

So, sing ho for regression tests, but sing louder for static analysis ;-)

-- 
Fergus Henderson <[EMAIL PROTECTED]>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]         |     -- the last words of T. S. Garp.



Reply via email to