[commit: ghc] master: Another major constraint-solver refactoring (1eec1f2)

git at git.haskell.org git at git.haskell.org
Fri Nov 25 11:30:42 UTC 2016


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

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

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

commit 1eec1f21268af907f59b5d5c071a9a25de7369c7
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Tue Oct 25 17:41:45 2016 +0100

    Another major constraint-solver refactoring
    
    This patch takes further my refactoring of the constraint
    solver, which I've been doing over the last couple of months
    in consultation with Richard.
    
    It fixes a number of tricky bugs that made the constraint
    solver actually go into a loop, including
    
      Trac #12526
      Trac #12444
      Trac #12538
    
    The main changes are these
    
    * Flatten unification variables (fmvs/fuvs) appear on the LHS
      of a tvar/tyvar equality; thus
               fmv ~ alpha
      and not
               alpha ~ fmv
    
      See Note [Put flatten unification variables on the left]
      in TcUnify.  This is implemented by TcUnify.swapOverTyVars.
    
    * Don't reduce a "loopy" CFunEqCan where the fsk appears on
      the LHS:
          F t1 .. tn ~ fsk
      where 'fsk' is free in t1..tn.
      See Note [FunEq occurs-check principle] in TcInteract
    
      This neatly stops some infinite loops that people reported;
      and it allows us to delete some crufty code in reduce_top_fun_eq.
      And it appears to be no loss whatsoever.
    
      As well as fixing loops, ContextStack2 and T5837 both terminate
      when they didn't before.
    
    * Previously we generated "derived shadow" constraints from
      Wanteds, but we could (and sometimes did; Trac #xxxx) repeatedly
      generate a derived shadow from the same Wanted.
    
      A big change in this patch is to have two kinds of Wanteds:
         [WD] behaves like a pair of a Wanted and a Derived
         [W]  behaves like a Wanted only
      See CtFlavour and ShadowInfo in TcRnTypes, and the ctev_nosh
      field of a Wanted.
    
      This turned out to be a lot simpler.  A [WD] gets split into a
      [W] and a [D] in TcSMonad.maybeEmitShaodow.
    
      See TcSMonad Note [The improvement story and derived shadows]
    
    * Rather than have a separate inert_model in the InertCans, I've
      put the derived equalities back into inert_eqs.  We weren't
      gaining anything from a separate field.
    
    * Previously we had a mode for the constraint solver in which it
      would more aggressively solve Derived constraints; it was used
      for simplifying the context of a 'deriving' clause, or a 'default'
      delcaration, for example.
    
      But the complexity wasn't worth it; now I just make proper Wanted
      constraints.  See TcMType.cloneWC
    
    * Don't generate injectivity improvement for Givens; see
      Note [No FunEq improvement for Givens] in TcInteract
    
    * solveSimpleWanteds leaves the insolubles in-place rather than
      returning them.  Simpler.
    
    I also did lots of work on comments, including fixing Trac #12821.


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

1eec1f21268af907f59b5d5c071a9a25de7369c7
 compiler/iface/ToIface.hs                          |    2 +
 compiler/typecheck/TcCanonical.hs                  |    2 +-
 compiler/typecheck/TcErrors.hs                     |   21 +-
 compiler/typecheck/TcExpr.hs                       |    1 +
 compiler/typecheck/TcFlatten.hs                    |  307 +++---
 compiler/typecheck/TcInteract.hs                   |  777 ++++++++------
 compiler/typecheck/TcMType.hs                      |   25 +-
 compiler/typecheck/TcRnTypes.hs                    |  264 +++--
 compiler/typecheck/TcRules.hs                      |   21 +-
 compiler/typecheck/TcSMonad.hs                     | 1134 +++++++++-----------
 compiler/typecheck/TcSimplify.hs                   |  146 +--
 compiler/typecheck/TcType.hs                       |   18 +
 compiler/typecheck/TcUnify.hs                      |   45 +-
 .../tests/indexed-types/should_compile/T10226.hs   |   57 +
 .../tests/indexed-types/should_compile/T10634.hs   |   15 +
 .../tests/indexed-types/should_compile/T12526.hs   |   69 ++
 .../tests/indexed-types/should_compile/T12538.hs   |   40 +
 .../indexed-types/should_compile/T12538.stderr     |   13 +
 .../indexed-types/should_compile/T3017.stderr      |    2 +-
 .../tests/indexed-types/should_compile/T4338.hs    |   35 +-
 testsuite/tests/indexed-types/should_compile/all.T |    2 +
 .../tests/indexed-types/should_fail/T2544.stderr   |   24 +-
 .../tests/indexed-types/should_fail/T2627b.stderr  |    4 +-
 .../tests/indexed-types/should_fail/T3330c.stderr  |    6 +-
 .../tests/indexed-types/should_fail/T4179.stderr   |    6 +-
 .../tests/indexed-types/should_fail/T6123.stderr   |    6 +-
 testsuite/tests/indexed-types/should_fail/T7786.hs |   16 +-
 .../tests/indexed-types/should_fail/T7786.stderr   |   43 +-
 .../tests/indexed-types/should_fail/T8227.stderr   |   13 +-
 .../partial-sigs/should_compile/T10403.stderr      |   15 -
 testsuite/tests/perf/compiler/T5837.hs             |   29 +-
 testsuite/tests/perf/compiler/T5837.stderr         |   91 --
 testsuite/tests/perf/compiler/all.T                |    7 +-
 testsuite/tests/polykinds/T12444.hs                |   65 ++
 testsuite/tests/polykinds/T12444.stderr            |   16 +
 testsuite/tests/polykinds/T9222.stderr             |    6 +-
 testsuite/tests/polykinds/all.T                    |    1 +
 .../tests/typecheck/should_compile/Improvement.hs  |   12 +-
 testsuite/tests/typecheck/should_compile/T6018.hs  |   32 +
 .../tests/typecheck/should_compile/T6018.stderr    |    8 +-
 .../tests/typecheck/should_fail/ContextStack2.hs   |    2 +
 .../typecheck/should_fail/ContextStack2.stderr     |   13 -
 testsuite/tests/typecheck/should_fail/Makefile     |    5 +
 testsuite/tests/typecheck/should_fail/T5691.stderr |   10 +-
 testsuite/tests/typecheck/should_fail/T5853.stderr |   28 +-
 testsuite/tests/typecheck/should_fail/T8450.stderr |   10 +-
 testsuite/tests/typecheck/should_fail/T9260.stderr |   11 +-
 testsuite/tests/typecheck/should_fail/all.T        |    2 +-
 48 files changed, 1875 insertions(+), 1602 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 1eec1f21268af907f59b5d5c071a9a25de7369c7


More information about the ghc-commits mailing list