Johan Tibell | 29 Nov 09:27 2012
Picon

Computing the final representation type of a TyCon (Was: Unpack primitive types by default in data)

Hi all,

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 <at> (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
(Continue reading)

Johan Tibell | 29 Nov 19:13 2012
Picon

Re: Computing the final representation type of a TyCon (Was: Unpack primitive types by default in data)

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 <at> (AlgTyCon {}) = case algTcRhs tc of
>                                              DataTyCon{ data_cons = [data_con] }
>                                                          -> ...
>                                              NewTyCon { data_con = [data_con] }
>                                                          -> ...
>                                              _           -> False
(Continue reading)

Simon Peyton-Jones | 6 Dec 15:06 2012
Picon

RE: Computing the final representation type of a TyCon (Was: Unpack primitive types by default in data)

Johan

Yes broadly that looks like the right kind of thing.

I think it'd be better to look more like "can_unbox". So first check for a product tycon (ie one data
constructor), then deal with newtypes, and *then* do something different, namely check whether the
(single) data con has zero or one fields, and recurse.

Since it's all flag-controlled you could push and I can subsequently edit

Simoin

| -----Original Message-----
| From: glasgow-haskell-users-bounces <at> haskell.org [mailto:glasgow-haskell-
| users-bounces <at> haskell.org] On Behalf Of Johan Tibell
| Sent: 29 November 2012 18:13
| To: glasgow-haskell-users
| Subject: Re: Computing the final representation type of a TyCon (Was:
| Unpack primitive types by default in data)
| 
| 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/6b44024173eae3029b7b43f7cc9fc7d9d801
| c367
| 
| On Thu, Nov 29, 2012 at 12:27 AM, Johan Tibell <johan.tibell <at> gmail.com>
(Continue reading)

Johan Tibell | 7 Dec 06:33 2012
Picon

Re: Computing the final representation type of a TyCon (Was: Unpack primitive types by default in data)

On Thu, Dec 6, 2012 at 6:06 AM, Simon Peyton-Jones
<simonpj <at> microsoft.com> wrote:
> Johan
>
> Yes broadly that looks like the right kind of thing.
>
> I think it'd be better to look more like "can_unbox". So first check for a product tycon (ie one data
constructor), then deal with newtypes, and *then* do something different, namely check whether the
(single) data con has zero or one fields, and recurse.
>
> Since it's all flag-controlled you could push and I can subsequently edit

I did some cleaning to the best of my ability and pushed the result as

    http://hackage.haskell.org/trac/ghc/changeset/566920c77bce252d807e9a7cc3da862e5817d340

Feel free to edit to your hearts content.

I also added a should_compile to the test suite.

Cheers,
Johan

Gmane