[GHC] #14259: Worker/Wrapper for sum return

GHC ghc-devs at haskell.org
Wed Sep 20 19:26:16 UTC 2017


#14259: Worker/Wrapper for sum return
-------------------------------------+-------------------------------------
           Reporter:  jheek          |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.2.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 GHC version 8.2 introduces Unboxed Sum types. It would be great if the
 worker/wrapper transformation could make use of this new functionality.

 For clarification I would expect a function like this:

 {{{#!haskell
 maybeEven :: Int -> Maybe Int
 maybeEven n = case even n of
   True  -> Just n
   False -> Nothing
 }}}

 to be transformed into (the core equivalent) of

 {{{#!haskell
 maybeEven :: Int -> Maybe Int
 MaybeEven (I# n#) = case workerMaybeEven n# of
   (# | x #)    -> Just x
   (# (# #) | #) -> Nothing

 workerMaybeEven :: Int# -> (# (# #) | Int #)
 {-# NOINLINE workerMaybeEven #-}
 workerMaybeEven n# = case even (I# n#) of
   True  -> (# | I# n# #)
   False -> (# (# #) | #)
 }}}

 Currently the core output for the maybeEven worker is:

 {{{#!haskell
 Main.$wmaybeEven :: Int# -> Maybe Int
 Main.$wmaybeEven
   = \ (ww_s4WH :: Int#) ->
       case remInt# ww_s4WH 2# of {
         __DEFAULT -> GHC.Base.Nothing @ Int;
         0# -> GHC.Base.Just @ Int (GHC.Types.I# ww_s4WH)
       }
 }}}

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


More information about the ghc-tickets mailing list