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

#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

#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: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: osa1 (added) Comment: Note that osa1 had some work in the direction. See Phab:D2436. I should also mention Phab:D2424, which is also a bit of unboxed sums work that is in limbo. osa1, perhaps you would care to say a few words about the status of these? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Changes (by bgamari): * keywords: => UnboxedSums * related: => #12364 Comment: Also relevant is #12364. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

osa1, perhaps you would care to say a few words about the status of
#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 osa1): these? Sure. CPR and worker/wrapper are easy to implement and I even have patches for these. (all of which should be up on phabricator) Demand analysis on the other hand is not that easy to extend (conceptually) and implement. We had some work on this too but we couldn't finish it (after several weeks of work) and these days I unfortunately don't have time & energy to work on this ;-( -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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: | -------------------------------------+------------------------------------- Changes (by maoe): * cc: maoe (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#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: | -------------------------------------+------------------------------------- Changes (by simonpj): * cc: sgraf (added) Comment: Sebastian is working in this territory. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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, | CPRAnalysis, DemandAnalysis 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: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: UnboxedSums => UnboxedSums, CPRAnalysis, DemandAnalysis -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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, | CPRAnalysis, DemandAnalysis 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): Is there a merge request or differential with Sebastian's work? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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, | CPRAnalysis, DemandAnalysis 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 sgraf): Not yet, but it's high on my todo list. See https://phabricator.haskell.org/D4244#126311 for the last attempt; I'll prepare a wiki page with a proper motivation for why I think it's best to split off CPR analysis and then reimplement the nested CPR idea on top. Actually, the CPRing sums idea is rather orthogonal, so I can probably cook that up first... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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, | CPRAnalysis, DemandAnalysis 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 sgraf): Replying to [comment:9 sgraf]:
Actually, the CPRing sums idea is rather orthogonal, so I can probably cook that up first...
Nope, I realised that a useful CPR for sums needs CPR of depth > 1, so I'll pursue the nested CPR idea and all that comes with it first. The wiki page for why splitting off CPR is a good thing is wiki:NestedCPR/SplitOffCPR. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14259#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC