[commit: ghc] master: Cure exponential behaviour in the simplifier (a1b753e)

git at git.haskell.org git at git.haskell.org
Fri Apr 28 11:04:27 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/a1b753e8b1475659440f524b3e66dfbea31c5787/ghc

>---------------------------------------------------------------

commit a1b753e8b1475659440f524b3e66dfbea31c5787
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Wed Apr 26 17:31:36 2017 +0100

    Cure exponential behaviour in the simplifier
    
    This patch nails a Bad Bug exposed in Trac #13379. Roughly,
    a deeply-nested application like
       f (f (f ....) ) )
    could make the simplifier go exponential -- without producing
    an exponential-sized result!
    
    The reason was that we
      - simplified a (big) function argument
      - then decided to inline the function
      - then preInilneUnconditionally the argument
      - and then re-simplified the big argument
    
    And if the "big argument" itself had a similar structure
    things could get very bad.
    
    Once I'd understood, it was easy to fix:
    
    * See Note Note [Avoiding exponential behaviour] for an overview
    
    * The key change is that Simplify.simplLam now as a case for
      (isSimplified dup). This is what removes the perf bug.
    
    * But I also made simplCast more parsimonious about simplifying,
      avoiding doing so when the coercion is Refl
    
    * And similarly I now try to avoid simplifying arguments
      where possible before applying rules.
      See Note [Trying rewrite rules]
    
    The latter two points tackle common cases, and in those cases make the
    simplifier take fewer iterations.


>---------------------------------------------------------------

a1b753e8b1475659440f524b3e66dfbea31c5787
 compiler/simplCore/SimplUtils.hs                   |  35 +-
 compiler/simplCore/Simplify.hs                     | 175 +++++++---
 testsuite/tests/perf/compiler/T13379.hs            | 372 +++++++++++++++++++++
 testsuite/tests/perf/compiler/T4007.stdout         |   2 +-
 testsuite/tests/perf/compiler/all.T                |  16 +-
 .../tests/simplCore/should_compile/T3234.stderr    |  20 +-
 6 files changed, 549 insertions(+), 71 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc a1b753e8b1475659440f524b3e66dfbea31c5787


More information about the ghc-commits mailing list