|
Re: [GHC] #876: stack overflow on 'length . filter odd $ [0 .. 999999999]': msg#00178lang.haskell.glasgow.bugs
#876: stack overflow on 'length . filter odd $ [0 .. 999999999]' ------------------------------+--------------------------------------------- Reporter: ariep@xxxxxxxxx | 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 simonpj@microsoft**20060508142726 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 Glasgow-haskell-bugs@xxxxxxxxxxx http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: [GHC] #879: Merge GHCi.debugger patches, GHC |
|---|---|
| Next by Date: | Re: weird data corruption, Frederik Eaton |
| Previous by Thread: | Re: [GHC] #876: stack overflow on 'length . filter odd $ [0 .. 999999999]', GHC |
| Next by Thread: | Re: [GHC] #876: stack overflow on 'length . filter odd $ [0 .. 999999999]', GHC |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |