[GHC] #16329: Simplifier ticks exhausted when fusing list literals

GHC ghc-devs at haskell.org
Mon Feb 25 11:51:57 UTC 2019


#16329: Simplifier ticks exhausted when fusing list literals
-------------------------------------+-------------------------------------
        Reporter:  autotaker         |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.6.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #11707            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by autotaker):

 A workaround found.

 Adding `{-# INLINE [0] step #-}` avoids the code explosion problem,
 although I'm not sure why it works.

 I think desugaring `[1,2,..,10]` to `build (\c n -> c 1 (c 2 (...(c 10
 n))))` is the cause of the problem.
 Since `c` is duplicated, code inlininng often generates a very complicated
 program.

 How about desugaring an explicit list literal `[v1, v2, v3, ... ,vn]`
 using an indexing function? That is:
 {{{#!hs
 [v1, v2, ..., vn ] = map f [1..n ::Int]
   where
   f i = case i of
    1 -> v1
    2 -> v2
    ...
    n -> vn
 }}}

 Then it is fused to the following code:
 {{{#!hs
 build (\c n -> go 1#
   where
   go i#
   | i# == n# = n
   | otherwise =
     let-join j v = v `c` go (i# +# 1) in
     case i# of
       1# -> j v1
       2# -> j v2
       ...
       n# -> j vn)
 }}}
 In this version, inlining does not cause code explosion problems  because
 `c` occurs at once.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16329#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list