Computing the final representation type of a TyCon (Was: Unpack primitive types by default in data)
Johan Tibell
johan.tibell at gmail.com
Thu Nov 29 19:13:06 CET 2012
Hi,
I've created an initial implementation that seems to work. I'd
appreciate it if someone could review the code (it's short!) to tell
me if it's sane, can be improved, etc:
https://github.com/tibbe/ghc/commit/6b44024173eae3029b7b43f7cc9fc7d9d801c367
On Thu, Nov 29, 2012 at 12:27 AM, Johan Tibell <johan.tibell at gmail.com> wrote:
> I've decided to try to implement the proposal included in the end of
> this message. To do so I need to write a function
>
> hasPointerSizedRepr :: TyCon -> Bool
>
> This function would check that that the TyCon is either
>
> * a newtype, which representation type has a pointer-sized representation, or
> * an algebraic data type, with one field that has a pointer-sized
> representation.
>
> I'm kinda lost in all the data types that GHC defines to represent
> types. I've gotten no further than
>
> hasPointerSizedRepr :: TyCon -> Bool
> hasPointerSizedRepr tc@(AlgTyCon {}) = case algTcRhs tc of
> DataTyCon{ data_cons = [data_con] }
> -> ...
> NewTyCon { data_con = [data_con] }
> -> ...
> _ -> False
> hasPointerSizedRepr _ = False
>
> I could use some pointers (no pun intended!) at this point. The
> function ought to return True for all the following types:
>
> data A = A Int#
> newtype B = B A
> data C = C !B
> data D = D !C
> data E = E !()
> data F = F !D
>
> One part that confuses me is figuring out the representation type of a
> data constructor after unpacking. For example, the function should not
> return true if called on G in this example:
>
> data G = G !H
> data H = H {-# UNPACK #-} !I
> data I = I !Int !Int
>
> because if we unpacked H into G's constructor it would take up two
> words, due to I being unpacked.
>
> Does DataCon contain the unpacked representation of the data
> constructor or only the before-optimizations representation?
More information about the Glasgow-haskell-users
mailing list