[GHC] #7994: Make foldl into a good consumer

GHC ghc-devs at haskell.org
Fri Jan 17 15:45:32 UTC 2014


#7994: Make foldl into a good consumer
-------------------------------------+------------------------------------
        Reporter:  simonpj           |            Owner:
            Type:  bug               |           Status:  new
        Priority:  normal            |        Milestone:
       Component:  Compiler          |          Version:  7.6.3
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------

Comment (by nomeata):

 Yesterday it looked as if this has magically improved, but at least with
 the example from the ticket, put into self-contained as follows:

 {{{#!haskell
 module Foo( foo ) where
 import Data.Complex

 import Prelude hiding (sum, foldl)

 foldl k z xs = foldr (\v fn z -> fn (k z v)) id xs z
 {-# INLINE foldl #-}

 sum                     =  foldl (+) 0
 {-# INLINE sum #-}

 foo x = sum [f n | n <- [1 .. x]]

 f :: Int -> Complex Double
 {-# NOINLINE f #-}
 f n = mkPolar 1 ((2*pi)/fromIntegral n) ^ n
 }}}

 I still get bad code:

 {{{
 Foo.$wfoo :: GHC.Prim.Int# -> Data.Complex.Complex GHC.Types.Double
 [GblId,
  Arity=1,
  Str=DmdType <L,U>,
  Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=1, Value=True,
          ConLike=True, WorkFree=True, Expandable=True,
          Guidance=IF_ARGS [0] 225 0}]
 Foo.$wfoo =
   \ (ww_s1nN :: GHC.Prim.Int#) ->
     case GHC.Prim.tagToEnum# @ GHC.Types.Bool (GHC.Prim.># 1 ww_s1nN)
     of _ [Occ=Dead] {
       GHC.Types.False ->
         letrec {
           go_a1k0 [Occ=LoopBreaker]
             :: GHC.Prim.Int#
                -> Data.Complex.Complex GHC.Types.Double
                -> Data.Complex.Complex GHC.Types.Double
           [LclId, Arity=1, Str=DmdType <L,U>]
           go_a1k0 =
             \ (x_a1k1 :: GHC.Prim.Int#) ->
               let {
                 v_ayO [Dmd=<L,U(U(U),U(U))>]
                   :: Data.Complex.Complex GHC.Types.Double
                 [LclId, Str=DmdType]
                 v_ayO = Foo.f (GHC.Types.I# x_a1k1) } in
               let {
                 ds_dWw [Dmd=<L,C(U)>]
                   :: Data.Complex.Complex GHC.Types.Double
                      -> Data.Complex.Complex GHC.Types.Double
                 [LclId, Str=DmdType]
                 ds_dWw =
                   case GHC.Prim.tagToEnum#
                          @ GHC.Types.Bool (GHC.Prim.==# x_a1k1 ww_s1nN)
                   of _ [Occ=Dead] {
                     GHC.Types.False -> go_a1k0 (GHC.Prim.+# x_a1k1 1);
                     GHC.Types.True ->
                       GHC.Base.id @ (Data.Complex.Complex
 GHC.Types.Double)
                   } } in
               \ (z_ayQ :: Data.Complex.Complex GHC.Types.Double) ->
                 ds_dWw (Data.Complex.$fFloatingComplex_$s$c+ z_ayQ v_ayO);
 } in
         go_a1k0 1 Foo.foo1;
       GHC.Types.True -> Foo.foo1
     }
 }}}

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


More information about the ghc-tickets mailing list