Skip to content

Boxity: DataCon wrappers have no boxity signature

Example

data D = D !Int

f :: Bool -> Int -> D
f x y = D (go x)
  where
    go False = y
    go True  = go False
{-# NOINLINE f #-}

Core after DmdAnal:

f [InlPrag=NOINLINE] :: Bool -> Int -> D
[LclIdX,
 Arity=2,
 Str=<1L><SL>,
 Cpr=1,
 Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
         WorkFree=True, Expandable=True, Guidance=IF_ARGS [0 0] 52 0}]
f = \ (x_auC [Dmd=1L] :: Bool) (y_auD [Dmd=SL] :: Int) ->
      join {
        $j_svX [Dmd=SCS(!P(L))] :: Int %1 -> D
        [LclId[JoinId(1)(Nothing)], Arity=1, Str=<SL>, Cpr=1]
        $j_svX (arg_svW [Dmd=SL, OS=OneShot] :: Int) = Lib.$WD arg_svW } in
      joinrec {
        go_svV [Occ=LoopBreaker, Dmd=SCS(!P(L))] :: Bool -> D
        [LclId[JoinId(1)(Nothing)],
         Arity=1,
         Str=<1L> {auD->SL svX->SCS(!P(L))},
         Cpr=1,
         Unf=Unf{Src=<vanilla>, TopLvl=False, Value=True, ConLike=True,
                 WorkFree=True, Expandable=True, Guidance=IF_ARGS [34] 28 0}]
        go_svV (ds_dvL [Dmd=1L] :: Bool)
          = case ds_dvL of {
              False -> jump $j_svX y_auD;
              True -> jump go_svV GHC.Types.False
            }; } in
      jump go_svV x_auC

So today, we won't unbox y, which is bogus, because the DataCon wrapper will unbox it anyway (if inlined).

Note that CPR will fire on f, because it handles DataCon wrappers by lookin at the unfolding, see Note [CPR for DataCon wrappers]. Let's do the same for demand analysis.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information