#4978: Continuation passing style loop doesn't compile into a loop
---------------------------------+------------------------------------------
Reporter: tibbe | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 7.2.1
Component: Compiler | Version: 7.0.1
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Comment(by simonmar):
Here's my example boiled down as much as I can.
{{{
module Fac (fac) where
newtype Par a = Par {
runCont :: (a -> Trace) -> Trace
}
instance Monad Par where
return a = Par $ \c -> c a
m >>= k = Par $ \c -> runCont m (\a -> runCont (k a) c)
data Sched = Sched
type Trace = Sched -> IO ()
fac :: Int -> Par Int
fac n = if n <= 1 then return 1
else do x <- fac (n-1)
return (x * n)
}}}
which yields this for `fac` with today's HEAD:
{{{
a2_rnD :: (GHC.Types.Int -> ParFib.Trace) -> ParFib.Trace
[GblId, Arity=1, Caf=NoCafRefs, Str=DmdType C(S)]
a2_rnD = \ (c_agZ :: GHC.Types.Int -> ParFib.Trace) -> c_agZ a1_rnC
Rec {
ParFib.$wfac [Occ=LoopBreaker]
:: GHC.Prim.Int# -> (GHC.Types.Int -> ParFib.Trace) -> ParFib.Trace
[GblId, Arity=1, Caf=NoCafRefs, Str=DmdType L]
ParFib.$wfac =
\ (ww_snb :: GHC.Prim.Int#) ->
case GHC.Prim.<=# ww_snb 1 of _ {
GHC.Types.False ->
let {
a3_sno :: (GHC.Types.Int -> ParFib.Trace) -> ParFib.Trace
[LclId, Str=DmdType]
a3_sno = ParFib.$wfac (GHC.Prim.-# ww_snb 1) } in
\ (c_ah2 :: GHC.Types.Int -> ParFib.Trace) ->
a3_sno
(\ (a4_ah3 :: GHC.Types.Int) ->
c_ah2
(case a4_ah3 of _ { GHC.Types.I# x_ams ->
GHC.Types.I# (GHC.Prim.*# x_ams ww_snb)
}));
GHC.Types.True -> a2_rnD
}
end Rec }
}}}
It looks like the arity analyser should infer an arity of at least 2
(ultimately we want 3) for `fac`, but it has inferred only 1. The `case`
should look cheap, and the `let` is for the recursive call.
I have tried eta-expanding `return` and `>>=`, to no avail. (that might
still be necessary to get to arity 3, I'm not sure).
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4978#comment:11>
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