[GHC] #9214: UNPACK support for sum types

#9214: UNPACK support for sum types ------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- Currently the pragma only supports single-constructor types. So in the following example it will simply be ignored: {{{ data A = A1 Char | A2 {-# UNPACK #-} !B data B = B1 Int | B2 Bool }}} However the problem seems to be easily solvable by denormalizing the type {{{A}}} to something like the following during unpacking: {{{ data A = A1 Char | A2_1 Int | -- from B1 A2_2 Bool -- from B2 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9214 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9214: UNPACK support for sum types -------------------------------------+------------------------------------ Reporter: mojojojo | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 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 schyler): Smells fishy to me. Would create a pwr(N,2) number of denormalizations. Would be better to calculate the largest size of the fully unpacked type like a C compiler would for unions. o/t The behaviour of the trac for n^2 notation is really annoying! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9214#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9214: UNPACK support for sum types -------------------------------------+------------------------------------ Reporter: mojojojo | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 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 tibbe): It's even more complicated than just allocating the max needed by any of the unpacked sum type's constructor. The GC needs to know what the fields are in any given constructor to be able to GC correctly. I don't think this will be hard (that's why we haven't done it already). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9214#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9214: UNPACK support for sum types -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomie): * failure: None/Unknown => Runtime performance bug -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9214#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9214: UNPACK support for sum types -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: osa1 Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1540 Wiki Page: UnpackedSumTypes | Phab:D1559 -------------------------------------+------------------------------------- Changes (by thomie): * owner: => osa1 * differential: => Phab:D1540 Phab:D1559 * wikipage: => UnpackedSumTypes -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9214#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9214: UNPACK support for sum types -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: osa1 Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1540 Wiki Page: UnpackedSumTypes | Phab:D1559 -------------------------------------+------------------------------------- Comment (by dfeuer): I'm just popping in to +1 this. Currently, `Data.IntMap` defines {{{#!hs data IntMap a = Bin ... !(IntMap a) !(IntMap a) | Tip ... | Nil }}} Logically, it *should* be {{{#!hs data IntMap a = IM !(IntMap1) | Nil data IntMap1 a = Bin ... !(IntMap1) !(IntMap1) | Tip ... }}} which would enforce the invariant that no `Nil`s can occur within a tree. But that has an extra indirection, which seems likely unacceptable. If we could `UNPACK` the `IntMap1` into the `IntMap`, we'd get the current performance with much nicer type guarantees. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9214#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9214: UNPACK support for sum types -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: osa1 Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1540 Wiki Page: UnpackedSumTypes | Phab:D1559 -------------------------------------+------------------------------------- Comment (by dfeuer): One special case is a GADT with one constructor that takes one argument without any class context. For instance {{{#!hs data Foo a = This a | That a a data Bar a b where Bar :: !(Foo a) -> Bar a a data Baz where Baz :: !(Foo a) -> Baz }}} It would be great to be able to unpack `Foo` into `Bar` and `Baz`. Matching on the `Bar` or `Baz` constructor would force its contents to WHNF and reveal the evidence/open the existential. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9214#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9214: UNPACK support for sum types -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: osa1 Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1540 Wiki Page: UnpackedSumTypes | Phab:D1559 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * cc: RyanGlScott (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9214#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9214: UNPACK support for sum types -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: osa1 Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1540 Wiki Page: UnpackedSumTypes | Phab:D1559 Phab:D2259 -------------------------------------+------------------------------------- Changes (by michalt): * cc: michalt (added) * differential: Phab:D1540 Phab:D1559 => Phab:D1540 Phab:D1559 Phab:D2259 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9214#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9214: UNPACK support for sum types
-------------------------------------+-------------------------------------
Reporter: mojojojo | Owner: osa1
Type: feature request | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime | Unknown/Multiple
performance bug | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D1540
Wiki Page: UnpackedSumTypes | Phab:D1559 Phab:D2259
-------------------------------------+-------------------------------------
Changes (by thomie):
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"714bebff44076061d0a719c4eda2cfd213b7ac3d"]:
{{{
Author: Ömer Sinan Ağacan
participants (1)
-
GHC