#876: stack overflow on 'length . filter odd $ [0 .. 999999999]'
------------------------------+---------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 6.6
Component: Compiler | Version: 6.5
Severity: normal | Resolution:
Keywords: | Os: Linux
Difficulty: Unknown | Architecture: x86
------------------------------+---------------------------------------------
Comment (by igloo):
I've confirmed that the patch Simon M indicates is indeed the problem, and
I've copied it below for reference.
It makes sense to me that the above behaviour is seen: length is now a
good
consumer, but it generates 1+(1+(1+(1+... as it is consuming, and this
causes a stack overflow. I don't think we can fix this while staying with
fold/build fusion, so it looks to me like the patch should be reverted and
the whole problem looked at post-6.6.
Do you agree, Simon PJ?
Thanks
Ian
{{{
[Make length a good consumer
[EMAIL PROTECTED]
Make length into a good consumer. Fixes Trac bug #707.
(Before length simply didn't use foldr.)
] {
hunk ./GHC/List.lhs 114
-length :: [a] -> Int
-length l = len l 0#
- where
- len :: [a] -> Int# -> Int
- len [] a# = I# a#
- len (_:xs) a# = len xs (a# +# 1#)
+length :: [a] -> Int
+length l = lenAcc 0# l
+
+{-# RULES
+"length" [~1] forall xs. length xs = foldr incL (I# 0#) xs
+"lenAcc" [1] forall n#. foldr incL (I# n#) = lenAcc n#
+ #-}
+
+incL :: a -> Int -> Int -- Internal
+{-# NOINLINE [0] incL #-}
+incL x n = n `plusInt` oneInt
+
+lenAcc :: Int# -> [a] -> Int -- Internal
+lenAcc a# [] = I# a#
+lenAcc a# (_:xs) = lenAcc (a# +# 1#) xs
}
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/876>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs