listArray loop counter Int is boxed
I previously prepared !16 (merged) to make listArray
and newListArray
good consumers of the input list. While this did improve things when there is fusion, the change unfortunately caused the loop counter to remain boxed when there is no fusion. I did not check the core for such a case at that time.
The loop in the core looks like
joinrec {
go1_s1RN [Occ=LoopBreaker, Dmd=SCS(C1(C1(L)))]
:: [Int]
-> Int -- !BOXED!
-> GHC.Prim.State# GHC.Prim.RealWorld
-> (# GHC.Prim.State# GHC.Prim.RealWorld, IOUArray Int Int #)
[LclId[JoinId(3)], Arity=3, Str=<1L><MP(L)><L>, Unf=OtherCon []]
go1_s1RN (ds1_a1ND :: [Int])
(eta1_X2 :: Int)
(eta2_B1 [OS=OneShot] :: GHC.Prim.State# GHC.Prim.RealWorld)
= case ds1_a1ND of {
[] -> jump $w$j1_s1RV eta2_B1;
: y_a1NG ys_a1NH ->
case eta1_X2 of { GHC.Types.I# x_a1OC ->
case n1_s1QH of { GHC.Types.I# y1_a1OF ->
case GHC.Prim.==# x_a1OC y1_a1OF of {
__DEFAULT ->
case y_a1NG of { GHC.Types.I# e#_a1OX ->
case GHC.Prim.writeIntArray#
@GHC.Prim.RealWorld ipv1_a1KG x_a1OC e#_a1OX eta2_B1
of s2#_a1OZ
{ __DEFAULT ->
jump go1_s1RN
ys_a1NH (GHC.Types.I# (GHC.Prim.+# x_a1OC 1#)) s2#_a1OZ
}
};
1# -> jump $w$j1_s1RV eta2_B1
}
}
}
}; }
As you can see if you generate core on https://play.haskell.org/saved/tIod2GmZ
Luckily the fix seems simple. With
- foldr f (const (return ())) es 0
+ foldr f (\ !_ -> return ()) es 0
the Int is unboxed as we would want.
I will prepare an MR.