[Hugs-bugs] coredump on innocent code
Hello. $ cat bug.hs main = print (let (x,(q,_)) = (1,divMod x x) in q) $ runhugs bug.hs Illegal instruction (core dumped) $ md5 hugs98-Mar2005-patched.tar.gz MD5 (hugs98-Mar2005-patched.tar.gz) = f72c378251f0d488fff9871583d26843 $ uname -a NetBSD droog 2.0.2_STABLE NetBSD 2.0.2_STABLE (sdf) #0: Sun Jun 12 15:36:54 UTC 2005 root@vinland:/var/netbsd/arch/alpha/compile/sdf alpha $ cat workaround1.hs main = print (let x = 1 (q,_) = divMod x x in q) $ runhugs workaround1.hs 1 $ cat workaround2.hs main = print (let (x,(q,_)) = (1,dm x x) in q) dm a b = (div a b,mod a b) $ runhugs workaround2.hs 1 $ Thank you for making hugs freely and libre available. fool at sdf-eu.org
On Thu, Sep 08, 2005 at 04:00:47PM +0000, fool@sdf-eu.org wrote:
$ cat bug.hs main = print (let (x,(q,_)) = (1,divMod x x) in q) $ runhugs bug.hs Illegal instruction (core dumped)
Not entirely innocent: demand for x also causes evaluation of the second pair, which depends on x: an infinite loop. The correct version is main = print (let (x,~(q,_)) = (1,divMod x x) in q) Unfortunately, it's a known bug that some infinite loops cause Hugs to overrun the C stack, crashing the program. (This is caught under Windows, but not Unix.)
On Thu, Sep 08, 2005 at 04:00:47PM +0000, fool@sdf-eu.org wrote:
$ cat bug.hs main = print (let (x,(q,_)) = (1,divMod x x) in q) $ runhugs bug.hs Illegal instruction (core dumped)
Not entirely innocent: demand for x also causes evaluation of the second pair, which depends on x: an infinite loop. The correct version is
main = print (let (x,~(q,_)) = (1,divMod x x) in q)
This is a valuable clue. I previously thought that rewriting let <a> = <b> <c> = <d> in <e> as let (<a>,<c>) = (<b>,<d>) in <e> is harmless, but section 3.12 of the Report says different. I still don't understand why main = print (let (x,(q,_)) = (1,divMod x x) in q) and main = print (let (x,(q,_)) = (1,divmod x x) in q) divmod x y = (div x y,mod x y) behave differently. Please give me another clue. Thank you.
On Sat, Sep 10, 2005 at 03:18:16PM -0000, fool@sdf-eu.org wrote:
I previously thought that rewriting
let <a> = <b> <c> = <d> in <e>
as
let (<a>,<c>) = (<b>,<d>) in <e>
is harmless, but section 3.12 of the Report says different.
Yes, you'd have to write it as let (~<a>,~<c>) = (<b>,<d>) in <e>
I still don't understand why
main = print (let (x,(q,_)) = (1,divMod x x) in q)
and
main = print (let (x,(q,_)) = (1,divmod x x) in q) divmod x y = (div x y,mod x y)
behave differently.
In both cases, to for x is to ask for the rhs to be reduced to the form (<a>,(<b>,<c>)). In the former case this can't be done without knowing the value of x; in the latter it can.
participants (2)
-
fool@sdf-eu.org -
Ross Paterson