Unboxing through unboxed sums

In the topic One Billion Row challenge in Hs, @sgraf mentioned

unboxed sums and GHC’s current inability to unbox through those

Would @sgraf, or anyone, be able to explain what it means to be unable to unbox through an unboxed sum?

1 Like

In the context of that thread, I rather meant that we should be able to at least discard absent unboxed sums, such as in a function like

f :: (# Int | Bool #) -> Int -> Int
f _ x = x
{-# NOINLINE f #-}

For any type other than those unboxed sums, we’d make the following worker/wrapper split:

$wf :: Int -> Int
$wf x = x
{-# NOINLINE $wf #-}

f _ x = $wf x

And the code I reviewed did not do this for unboxed sums for some reason.

But more generally, unboxing through an unboxed sum is rather like unboxing through a boxed sum, and for that we have this issue tracking the Demand Analysis side (i.e., unboxing arguments) and this issue tracking unboxing through arbitrary sum results.

So it’s not actually that it hasn’t been reported, contrary to what I said… It should not be terribly complicated technically, either (there were many small changes to Demand Analysis over the years that mean it might be more easily possible now), but I’m more or less convinced that we need to solve both arg and result unboxing issues in one go, otherwise we are likely to suffer from reboxing.

Unfortunately, I currently don’t want to take on a bigger project because I can’t afford to be distracted from my dissertation that is due soon™. But perhaps I won’t be able to stop myself to at least try; a PoC is often done in a few days of work.