Where's the case? or The difference between simpl and prep

The -ddump-simpl output below doesn't contain a case corresponding to the
seq in sum', but the -ddump-prep does. Isn't the output from simpl the
input to prep? If so, where does the case reappear from? If not, how are
simpl and prep related?
It seems to have something to do with "Str=DmdType SS" but I don't
understand. This seems to come from the IdInfo on the Id which is the
binder "Test.sum'" but [1] says that this information is optional so it
seems strange that such crucial information would be encoded there.
Thanks,
Tom
[1] http://www.haskell.org/ghc/docs/7.6.2/html/libraries/ghc-7.6.2/IdInfo.html#t:IdInfo
% cat Test.hs
module Test where
sum' :: [Integer] -> Integer -> Integer
sum' [] n = n
sum' (x:xs) n = n `seq` sum' xs (n + x)
% ghc -fforce-recomp -ddump-simpl -O2 Test.hs
[1 of 1] Compiling Test ( Test.hs, Test.o )
==================== Tidy Core ====================
Result size = 14
Rec {
Test.sum' [Occ=LoopBreaker]

Re: Where's the case? or The difference between simpl and prep

Check out
http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/HscMain
and the notes at the top of
http://darcs.haskell.org/ghc/compiler/coreSyn/CorePrep.lhs
Beyond that I'm happy to help
Simon
| -----Original Message-----
| From: haskell-cafe-bounces <at> haskell.org [mailto:haskell-cafe-
| bounces <at> haskell.org] On Behalf Of Tom Ellis
| Sent: 14 March 2013 20:05
| To: Haskell Cafe
| Subject: [Haskell-cafe] Where's the case? or The difference between simpl and
| prep
|
| The -ddump-simpl output below doesn't contain a case corresponding to the
| seq in sum', but the -ddump-prep does. Isn't the output from simpl the
| input to prep? If so, where does the case reappear from? If not, how are
| simpl and prep related?
|
| It seems to have something to do with "Str=DmdType SS" but I don't
| understand. This seems to come from the IdInfo on the Id which is the
| binder "Test.sum'" but [1] says that this information is optional so it
| seems strange that such crucial information would be encoded there.
|
| Thanks,
|
| Tom

Re: Where's the case? or The difference between simpl and prep

On Thu, Mar 14, 2013 at 10:43:14PM +0000, Simon Peyton-Jones wrote:
> | -----Original Message-----
> | From: Tom Ellis
> | The -ddump-simpl output below doesn't contain a case corresponding to the
> | seq in sum', but the -ddump-prep does. Isn't the output from simpl the
> | input to prep? If so, where does the case reappear from? If not, how are
> | simpl and prep related?
> |
> | It seems to have something to do with "Str=DmdType SS" but I don't
> | understand. This seems to come from the IdInfo on the Id which is the
> | binder "Test.sum'" but [1] says that this information is optional so it
> | seems strange that such crucial information would be encoded there.
>
> Check out
> http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/HscMain
> and the notes at the top of
> http://darcs.haskell.org/ghc/compiler/coreSyn/CorePrep.lhs
Thanks Simon. That's lovely code and easy to read.
I see that the decision between let and case is made based on the
idDemandInfo which specifies whether a value is wanted strictly or not.
I presume that the explicit case is removed in the Simpl phase because it is
easier for optimisations to work on the Demand value than explicit case
statements.
Tom