#1216: indexing 2d arrays is slow and leaky. why?
----------------------+-----------------------------------------------------
Reporter: claus | Owner: simonpj
Type: bug | Status: new
Priority: normal | Milestone: 6.8.3
Component: Compiler | Version: 6.6
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: Unknown
Os: Unknown |
----------------------+-----------------------------------------------------
Comment (by simonpj):
A Friday afternoon, so I thought I'd look at this. The problem is that
`GHC.Arr.$windex1`, which is called from the inner loop has this inlining:
{{{
$windex1 :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int# ->
GHC.Base.Int
{- Arity: 3 Strictness: LLL
Unfolding: (\ ww :: GHC.Prim.Int# ww1 :: GHC.Prim.Int# ww2 ::
GHC.Prim.Int# ->
case @ GHC.Base.Int GHC.Prim.<=# ww ww2 of wild {
GHC.Base.False
-> GHC.Arr.indexError2
(GHC.Base.I# ww, GHC.Base.I# ww1)
(GHC.Base.I# ww2)
GHC.Arr.lvl3
GHC.Base.True
-> case @ GHC.Base.Int GHC.Prim.<=# ww2 ww1 of wild1 {
GHC.Base.False
-> GHC.Arr.indexError2
(GHC.Base.I# ww, GHC.Base.I# ww1)
(GHC.Base.I# ww2)
GHC.Arr.lvl3
GHC.Base.True -> GHC.Base.I# (GHC.Prim.-# ww2 ww)
} }) -}
}}}
Note the allocation of the `I#` box! Why? Becuase `GHC.Arr.indexError`
is not marked as a bottoming function. Why not? Because it looks like
this:
{{{
[Arity 1
Str: DmdType L]
GHC.Arr.indexError =
\ (@ a_aRh) (@ b_aRi) ($dShow_aRD [ALWAYS Just L] :: GHC.Show.Show
a_aRh) ->
let {
shows1_X1Am [ALWAYS Just L] :: a_aRh -> GHC.Show.ShowS
[Str: DmdType {aRD->U(C(S)AA)}]
shows1_X1Am = GHC.Show.shows @ a_aRh $dShow_aRD } in
let {
shows2_X1Ap [ALWAYS Just L] :: a_aRh -> GHC.Show.ShowS
[Str: DmdType {aRD->U(C(S)AA)}]
shows2_X1Ap = GHC.Show.shows @ a_aRh $dShow_aRD } in
\ (rng_ah3 [ALWAYS Just L] :: (a_aRh, a_aRh))
(i_ah5 [ALWAYS Just L] :: a_aRh)
(tp_ah7 [ALWAYS Just S] :: GHC.Base.String) ->
GHC.Err.error @ b_aRi (...stuff...)
}}}
Note the stupid arity and that the strictness analyser is not spotting the
bottom result.
I'll think about how to fix this stupidity.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1216#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs