
#14259: Worker/Wrapper for sum return -------------------------------------+------------------------------------- Reporter: jheek | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: UnboxedSums Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #12364 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by andrewthad): Even only having CPR analysis (and not demand analysis) working with `UnboxedSums` is rather useful to me. I have some libraries where several functions look like this: {{{ data MyExceptionType = ... -- many constructors foo :: Int -> Int -> IO (Either MyExceptionType Int) }}} Crucially, `foo` is to large to inline, and I expect that the user is going to case on the result immediately (directly or by using something than inlines like `either`). If Phab:D2436 is correct, I'd be happy to rebase it and stick it behind a flag (maybe `-fcpr-small-sums`) that would cause this to happen for types with three or fewer data constructors (so `MyExceptionType` above doesn't get worker-wrappered). Hopefully, I could get this core: {{{ foo :: Int -> Int -> IO (Either MyExceptionType Int) fooInner :: Int# -> Int# -> State# RealWorld -> (# State# RealWorld, (# MyExceptionType | Int# #) #) }}} Since this does not reduce allocations in general, it has to be behind a flag. I don't know what a good name would be. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler