I'll give that a try. The main use of the stg types in the stg-to-cmm pass is to call idPrimRep (which call typePrimRep) to figure out which register type we need to use. I guess as long as I rewrite the stg types so they give me the typePrimRep I want in the end I should be fine.

On Thu, Sep 10, 2015 at 2:37 AM, Simon Peyton Jones <simonpj@microsoft.com> wrote:

The problem is that stg is too strongly typed

 

It’s not really typed, or at least only in a very half-hearted way.  To be concrete I think you can just use Any for any Pointer arg.   All STG needs to know, really, is which things are pointers.  Detailed type info like “are you a Char or a Bool” is strictly jam; indeed never used I think.  (I could be wrong but I’m pretty sure I’m not wrong in a fundamental way.

 

SImon

 

From: Johan Tibell [mailto:johan.tibell@gmail.com]
Sent: 09 September 2015 23:22
To: Simon Peyton Jones; Simon Marlow; ghc-devs@haskell.org
Subject: Converting unboxed sum types in StgCmm

 

Hi!

 

The original idea for implementing the backend part of the unboxed sums proposal was to convert from the core representation to the actual data representation (i.e. a tag followed by some pointer and non-pointer fields) in the unarise stg-to-stg pass.

 

I have now realized that this won't work. The problem is that stg is too strongly typed. When we "desugar" sum types we need to convert functions receiving a value e.g. from

 

    f :: (# Bool | Char #) -> ...

 

to

 

    f :: NonPointer {-# tag#-} -> Pointer {-# Bool or Char #-} -> ...

 

Since stg is still typed with normal Haskell types (e.g. Bool, Char, etc), this is not possible, as we cannot represent an argument which has two different types.

 

It seems to me that we will have to do the conversion in the stg-to-cmm pass, which is quite a bit more involved. For example, StgCmmEnv.idToReg function will have to change from

 

    idToReg :: DynFlags -> NonVoid Id -> LocalReg

 

to

 

    idToReg :: DynFlags -> NonVoid Id -> [LocalReg]

 

to accommodate the fact that we might need more than one register to store a binder.

 

Any ideas for a better solution?

 

-- Johan