Rewrite CorePrep and improve eta expansion
authorsimonpj@microsoft.com <unknown>
Tue, 13 Jan 2009 16:49:53 +0000 (16:49 +0000)
committersimonpj@microsoft.com <unknown>
Tue, 13 Jan 2009 16:49:53 +0000 (16:49 +0000)
commit62eeda5aed31173b234b2965ccf4bd6979ffd9a4
treeeebec9862e2c7d4918300286a5a75a79a55edc4e
parenta17d329568660592dad5c7668fb09f31ab77cd69
Rewrite CorePrep and improve eta expansion

This patch does two main things

a) Rewrite most of CorePrep to be much easier to understand (I hope!).
   The invariants established by CorePrep are now written out, and
   the code is more perspicuous.  It is surpringly hard to get right,
   and the old code had become quite incomprehensible.

b) Rewrite the eta-expander so that it does a bit of simplifying
   on-the-fly, and thereby guarantees to maintain the CorePrep
   invariants.  This make it much easier to use from CorePrep, and
   is a generally good thing anyway.

A couple of pieces of re-structuring:

*  I moved the eta-expander and arity analysis stuff into a new
   module coreSyn/CoreArity.

   Max will find that the type CoreArity.EtaInfo looks strangely
   familiar.

*  I moved a bunch of comments from Simplify to OccurAnal; that's
   why it looks as though there's a lot of lines changed in those
   modules.

On the way I fixed various things

  - Function arguments are eta expanded
       f (map g)  ===>  let s = \x. map g x in f s

  - Trac #2368

The result is a modest performance gain, I think mainly due
to the first of these changes:

--------------------------------------------------------------------------------
        Program           Size    Allocs   Runtime   Elapsed
--------------------------------------------------------------------------------
            Min          -1.0%    -17.4%    -19.1%    -46.4%
            Max          +0.3%     +0.5%     +5.4%    +53.8%
 Geometric Mean          -0.1%     -0.3%     -7.0%    -10.2%
13 files changed:
compiler/coreSyn/CoreArity.lhs [new file with mode: 0644]
compiler/coreSyn/CorePrep.lhs
compiler/coreSyn/CoreSubst.lhs
compiler/coreSyn/CoreTidy.lhs
compiler/coreSyn/CoreUtils.lhs
compiler/ghc.cabal.in
compiler/main/TidyPgm.lhs
compiler/simplCore/OccurAnal.lhs
compiler/simplCore/SimplUtils.lhs
compiler/simplCore/Simplify.lhs
compiler/stgSyn/CoreToStg.lhs
compiler/stranal/DmdAnal.lhs
compiler/stranal/WorkWrap.lhs