Join-point refactoring
authorSimon Peyton Jones <simonpj@microsoft.com>
Thu, 27 Apr 2017 16:04:14 +0000 (17:04 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Tue, 2 May 2017 08:00:14 +0000 (09:00 +0100)
commit71037b61597d8e80ba5acebc8ad2295e5266dc07
treeb86d5fc170ffa18ab43842dffa099c7ac3557834
parentc46a600f320b25e0ac73107acdb12a33d7fbd9c3
Join-point refactoring

This commit has a raft of refactorings that improve the treatment
of join points.  I wasn't aiming so much as to gain performance as
to make the code simpler.

The two big things are these:

* Make mkDupableCont work for SimplBind as well.  This is simpler than
  I thought and quite neat.  (Luke had aready done StrictArg.)  That's
  a win in its own right. But also now /all/ continuations can be made
  dup-able

* Now that all continuations can be made dup-able, I could simplify
  mkDupableCont to return just one SimplCont, instead of two.
  That really is a worthwhile simlification!  Much easier to think
  about.

Plus a bunch of smaller things:

* Remove the join-arity that had been added to seIdSubst.
  It can be done more simply by putting it in DoneEx, which
  is the only constructor that actually needs it, and now we
  don't need the unsavoury isJoinIdInEnv_maybe.

* Re-order the handling of join points in Simplify, so that we don't need
  the horrible resultTypeOfDupableCont

* Add field names for StrictBind, StrictArg; and use them

* Define simplMonad.newJoinId, and use it

* Rename the seFloats field of SimplEnv to seLetFloats

Binary sizes seem to go up slightly, but allocations generally
improve, sometimes significantly.  I don't believe the runtime numbers
are reliable enough to draw any conclusions about

--------------------------------------------------------------------------------
        Program           Size    Allocs   Runtime   Elapsed  TotalMem
--------------------------------------------------------------------------------
          event          +1.1%    -12.0%     -0.2%     -0.2%     -8.7%
         fulsom          +1.9%    -11.8%    -10.0%    -10.0%     +5.3%
     last-piece          +2.3%     -1.2%     -1.2%     -1.2%     +0.0%
           mate          +0.9%     -1.4%     -0.6%     -0.7%     +0.0%
     multiplier          +1.5%     -8.3%      0.17      0.17     +0.0%
         parser          +2.0%     +1.0%      0.04      0.04     +0.0%
        parstof          +1.5%     +0.7%      0.01      0.01     +0.0%
          sched          +1.3%     -6.1%      0.03      0.03     +0.0%
         simple          +1.8%     +1.0%     +9.7%     +9.6%     +0.0%
--------------------------------------------------------------------------------
            Min          +0.5%    -12.0%    -10.0%    -10.0%     -8.7%
            Max          +3.0%     +1.0%    +14.2%    +14.2%    +50.0%
 Geometric Mean          +1.4%     -0.4%     +0.3%     +0.4%     +0.5%

There's also a tests/perf/compiler improvement of 20% allocation in
T6048.  I think it's because we now generate smaller code.
compiler/simplCore/SimplEnv.hs
compiler/simplCore/SimplMonad.hs
compiler/simplCore/SimplUtils.hs
compiler/simplCore/Simplify.hs
testsuite/tests/perf/compiler/all.T
testsuite/tests/simplCore/should_compile/T12603.stdout
testsuite/tests/simplCore/should_compile/T3234.stderr