[GHC] #15226: GHC doesn't know that seq# produces something in WHNF

GHC ghc-devs at haskell.org
Mon Jun 4 18:37:21 UTC 2018


#15226: GHC doesn't know that seq# produces something in WHNF
-------------------------------------+-------------------------------------
           Reporter:  dfeuer         |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:  8.6.1
          Component:  Compiler       |           Version:  8.4.3
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  Runtime
  Unknown/Multiple                   |  performance bug
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 {{{#!hs
 data Str a = Str !a
 bar :: Maybe a -> IO (Str (Maybe a))
 bar x = do
   x' <- evaluate x
   pure (Str x')
 }}}

 This compiles to

 {{{#!hs
 Test.bar1
   = \ (@ a_a3Ld)
       (x_a3Ah :: Maybe a_a3Ld)
       (s_i3Nz :: GHC.Prim.State# GHC.Prim.RealWorld) ->
       case GHC.Prim.seq#
              @ (Maybe a_a3Ld) @ GHC.Prim.RealWorld x_a3Ah s_i3Nz
       of
       { (# ipv_i3NC, ipv1_i3ND #) ->
       (# ipv_i3NC, Test.$WStr @ (Maybe a_a3Ld) ipv1_i3ND #)
       }
 }}}

 We suspend the application of `$WStr` to `ipv1_i3ND`, when all we actually
 need to do is apply `Str` directly. We could work around this in `base` by
 defining

 {{{#!hs
 evaluate x = IO $ \s ->
   case seq# x s of
     (# s', !x' #) -> (# s', x' #)
 }}}

 but that seems more than a little bit silly.

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


More information about the ghc-tickets mailing list