
#13422: INLINE CONLIKE sometimes fails to inline -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #7206 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Here's the reason. We get {{{ let xs = case n of I# n1 -> cheapBuild blah in ...(foldr k z xs)...(foldr k2 z2 xs)... }}} So the `cheapBuild` is hidden behind that `case n` and the `foldr/cheapBuild` rule does not fire. The problem comes from {{{ instance Enum Int where ... enumFromTo (I# x) (I# y) = eftInt x y }}} So `[1..n]` desugars into `(case n of I# n' -> eftInt 1# n')`. This doesn't hurt normal foldr/build because if we see {{{ foldr k z (case n of I# n' -> build blah) }}} we know that `foldr` is strict and so float the case outwards. This doesn't happen with the `cheapBuild` stuff since the producer and consumer are further apart. But the solution is, I think, easy: move the evaluation of n into `eftInt`. So we have {{{ instance Enum Int where ... enumFromTo x y = eftInt x y }}} Now `eftInt` takes boxed `Ints` but it can evaluate them just fine. I've pushed a patch to `wip/cheap-build`, and it works just fine. '''However''': * It needs a serious note (steal the text above) * Other uses of `cheapBuild` need similar treatment. So the commit needs work. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13422#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler