[project @ 2004-04-27 12:47:13 by simonpj]
authorsimonpj <unknown>
Tue, 27 Apr 2004 12:47:18 +0000 (12:47 +0000)
committersimonpj <unknown>
Tue, 27 Apr 2004 12:47:18 +0000 (12:47 +0000)
commit74e0bdb67ea643c0586e40893bdafcbe651267ba
tree848f06e32bc962bc8299480cb218a22523cfad48
parent8685fce563b3d30c937ebaad1f4342966df44808
[project @ 2004-04-27 12:47:13 by simonpj]
----------------------------------------
     1. Make primOpIsCheap do something sensible
     2. Make the state hack work better
     ----------------------------------------

1.  In March 2001, we changed primOpIsCheap to
primOpIsCheap op = False
thereby making *no* primops seem cheap.  But this killed eta
expansion on case (x ==# y) of True -> \s -> ...
which is bad.  In particular a loop like
  doLoop n = loop 0
    where
      loop i | i == n    = return ()
             | otherwise = bar i >> loop (i+1)
allocated a closure every time round because it didn't eta expand.

The problem that made us set primOpIsCheap to False was
let x = a +# b *# c in x +# x
where we don't want to inline x. But primopIsCheap doesn't control
that (it's exprIsDupable that does) so the problem doesn't occur
even if primOpIsCheap sometimes says 'True'.  I think that perhaps
something changed since March 2001.

2.  Consider this
case x of
  True  -> \(s:RealWorld) -> e
  False -> foo
where foo has arity 1.  If we are using the "state hack" we want to
eta expand here.  This commit fixes arityType in the Var case (for foo)
to take account of foo's type.

Also add -fno-state-hack to the static flags, to allow the state hack to
be switched off.
ghc/compiler/basicTypes/Id.lhs
ghc/compiler/coreSyn/CoreUtils.lhs
ghc/compiler/main/CmdLineOpts.lhs
ghc/compiler/prelude/PrimOp.lhs