compiling-to-categories / concat

Compiling to Categories
http://conal.net/papers/compiling-to-categories
BSD 3-Clause "New" or "Revised" License
436 stars 50 forks source link

Reboxing failures #8

Open conal opened 7 years ago

conal commented 7 years ago

The reboxing scheme described in section 10.1 of Compiling to categories sometimes fails. Collect examples here, and mull over improved schemes.

conal commented 7 years ago

This example comes from compiling toEnum @Bool:

lam Case of boxer: bare unboxed var
  case n_ahgh of _ [Occ=Dead] { I# x_ahgk ->
  case x_ahgk of _ [Occ=Dead] {
    __DEFAULT -> $fEnumBool1;
    0# -> False;
    1# -> True
  }
  }
jcmartin commented 7 years ago

The issue arises from unlifted literal alternatives. Haskell does not have lifted literal alternatives except for Integer.

https://github.com/ghc/ghc/blob/master/compiler/coreSyn/CoreSyn.hs

Given that is the case, a reasonable solution would seem to be to convert the unlifted variables into lifted Integer and then convert each alternative to a literal Integer alternative. For many cases, this is trivial because the internal representation is also an Integer. For the case of Double and Float, they are represented as Rational, so it will be necessary to convert the Rational (two Integer) to a single Integer (probably using some bit shifting and or-ing them together).

conal commented 7 years ago

I fixed case-of-Int# in 6af4d1a6aaa1117964e78710c011ce711d4ae6b8, with some improvements over the next few commits.