[commit: ghc] wip/gadtpm: Major Overhaul of Pattern Match Checking (Fixes #595) (5d13d6b)

git at git.haskell.org git at git.haskell.org
Wed Dec 2 22:55:32 UTC 2015


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

On branch  : wip/gadtpm
Link       : http://ghc.haskell.org/trac/ghc/changeset/5d13d6b41fd00f2cb279416b8baa957b218e3ec5/ghc

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

commit 5d13d6b41fd00f2cb279416b8baa957b218e3ec5
Author: George Karachalias <george.karachalias at gmail.com>
Date:   Wed Dec 2 23:43:28 2015 +0100

    Major Overhaul of Pattern Match Checking (Fixes #595)
    
    This patch adresses several problems concerned with exhaustiveness and
    redundancy checking of pattern matching. The list of improvements includes:
    
    * Making the check type-aware (handles GADTs, Type Families, DataKinds, etc.).
      This fixes #4139, #3927, #8970 and other related tickets.
    
    * Making the check laziness-aware. Cases that are overlapped but affect
      evaluation are issued now with "Patterns have inaccessible right hand side".
      Additionally, "Patterns are overlapped" is now replaced by "Patterns are
      redundant".
    
    * Improved messages for literals. This addresses tickets #5724, #2204, etc.
    
    * Improved reasoning concerning cases where simple and overloaded
      patterns are matched (See #322).
    
    * Substantially improved reasoning for pattern guards. Addresses #3078.
    
    * OverloadedLists extension does not break exhaustiveness checking anymore
      (addresses #9951). Note that in general this cannot be handled but if we know
      that an argument has type '[a]', we treat it as a list since, the instance of
      'IsList' gives the identity for both 'fromList' and 'toList'. If the type is
      not clear or is not the list type, then the check cannot do much still. I am
      a bit concerned about OverlappingInstances though, since one may override the
      '[a]' instance with e.g. an '[Int]' instance that is not the identity.
    
    * Improved reasoning for nested pattern matching (partial solution). Now we
      propagate type and (some) term constraints deeper when checking, so we can
      detect more inconsistencies. For example, this is needed for #4139.
    
    I am still not satisfied with several things but I would like to address at
    least the following before the next release:
        Term constraints are too many and not printed for non-exhaustive matches
    (with the exception of literals). This sometimes results in two identical (in
    appearance) uncovered warnings. Unless we actually show their difference, I
    would like to have a single warning.


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

5d13d6b41fd00f2cb279416b8baa957b218e3ec5
 compiler/basicTypes/UniqSupply.hs                  |   26 +-
 compiler/deSugar/Check.hs                          | 2017 +++++++++++++-------
 compiler/deSugar/DsBinds.hs                        |   10 +-
 compiler/deSugar/DsExpr.hs                         |   18 +-
 compiler/deSugar/DsGRHSs.hs                        |    2 +-
 compiler/deSugar/DsMonad.hs                        |   64 +-
 compiler/deSugar/Match.hs                          |  174 +-
 compiler/deSugar/Match.hs-boot                     |    1 +
 compiler/deSugar/PmExpr.hs                         |  377 ++++
 compiler/deSugar/TmOracle.hs                       |  455 +++++
 compiler/ghc.cabal.in                              |    2 +
 compiler/ghc.mk                                    |    1 +
 compiler/hsSyn/HsLit.hs                            |   22 +
 compiler/hsSyn/HsPat.hs                            |   41 +-
 compiler/prelude/TysWiredIn.hs-boot                |    2 +-
 compiler/typecheck/TcMType.hs                      |   15 +
 compiler/typecheck/TcRnTypes.hs                    |    5 +-
 compiler/typecheck/TcSMonad.hs                     |    1 -
 compiler/typecheck/TcSimplify.hs                   |   14 +
 compiler/typecheck/TcType.hs                       |   42 +
 compiler/types/Type.hs                             |   22 +-
 compiler/utils/Bag.hs                              |   26 +-
 compiler/utils/MonadUtils.hs                       |    6 +-
 .../tests/deSugar/should_compile/T2395.stderr      |    4 +-
 .../tests/deSugar/should_compile/T5117.stderr      |    2 +-
 testsuite/tests/deSugar/should_compile/all.T       |    1 -
 .../tests/deSugar/should_compile/ds002.stderr      |    4 +-
 .../tests/deSugar/should_compile/ds003.stderr      |    2 +-
 .../tests/deSugar/should_compile/ds019.stderr      |    2 +-
 .../tests/deSugar/should_compile/ds020.stderr      |    8 +-
 testsuite/tests/deSugar/should_compile/ds022.hs    |    2 +
 .../tests/deSugar/should_compile/ds022.stderr      |    4 +-
 .../tests/deSugar/should_compile/ds043.stderr      |    6 +-
 .../tests/deSugar/should_compile/ds051.stderr      |    6 +-
 .../tests/deSugar/should_compile/ds056.stderr      |    4 +-
 .../tests/deSugar/should_compile/ds058.stderr      |    6 +-
 testsuite/tests/deSugar/should_compile/ds060.hs    |   25 -
 testsuite/tests/driver/werror.stderr               |    4 +-
 testsuite/tests/gadt/Gadt17_help.hs                |    1 -
 testsuite/tests/gadt/T7294.stderr                  |    4 +
 testsuite/tests/ghci/scripts/Defer02.stderr        |    8 +
 testsuite/tests/{ado => pmcheck}/Makefile          |    0
 .../should_compile/Makefile                        |    0
 testsuite/tests/pmcheck/should_compile/T2006.hs    |   13 +
 .../tests/pmcheck/should_compile/T2006.stderr      |    0
 testsuite/tests/pmcheck/should_compile/T2204.hs    |    9 +
 .../tests/pmcheck/should_compile/T2204.stderr      |   14 +
 testsuite/tests/pmcheck/should_compile/T3078.hs    |   12 +
 .../tests/pmcheck/should_compile/T3078.stderr      |    0
 testsuite/tests/pmcheck/should_compile/T322.hs     |   29 +
 .../tests/pmcheck/should_compile/T322.stderr       |    0
 testsuite/tests/pmcheck/should_compile/T366.hs     |   10 +
 .../tests/pmcheck/should_compile/T366.stderr       |    0
 testsuite/tests/pmcheck/should_compile/T3927.hs    |   13 +
 .../tests/pmcheck/should_compile/T3927.stderr      |    0
 testsuite/tests/pmcheck/should_compile/T3927a.hs   |   15 +
 .../tests/pmcheck/should_compile/T3927a.stderr     |    0
 testsuite/tests/pmcheck/should_compile/T3927b.hs   |   75 +
 .../tests/pmcheck/should_compile/T3927b.stderr     |   39 +
 testsuite/tests/pmcheck/should_compile/T4139.hs    |   28 +
 .../tests/pmcheck/should_compile/T4139.stderr      |    0
 testsuite/tests/pmcheck/should_compile/T6124.hs    |   14 +
 .../tests/pmcheck/should_compile/T6124.stderr      |    0
 testsuite/tests/pmcheck/should_compile/T7669.hs    |    9 +
 .../tests/pmcheck/should_compile/T7669.stderr      |    0
 testsuite/tests/pmcheck/should_compile/T8970.hs    |   22 +
 .../tests/pmcheck/should_compile/T8970.stderr      |    0
 testsuite/tests/pmcheck/should_compile/T9951.hs    |   10 +
 .../tests/pmcheck/should_compile/T9951.stderr      |    0
 testsuite/tests/pmcheck/should_compile/T9951b.hs   |    7 +
 .../tests/pmcheck/should_compile/T9951b.stderr     |    9 +
 testsuite/tests/pmcheck/should_compile/all.T       |   35 +
 testsuite/tests/pmcheck/should_compile/pmc001.hs   |   22 +
 .../tests/pmcheck/should_compile/pmc001.stderr     |   17 +
 testsuite/tests/pmcheck/should_compile/pmc002.hs   |    7 +
 .../tests/pmcheck/should_compile/pmc002.stderr     |    0
 testsuite/tests/pmcheck/should_compile/pmc003.hs   |    9 +
 .../tests/pmcheck/should_compile/pmc003.stderr     |    3 +
 testsuite/tests/pmcheck/should_compile/pmc004.hs   |   16 +
 .../tests/pmcheck/should_compile/pmc004.stderr     |    3 +
 testsuite/tests/pmcheck/should_compile/pmc005.hs   |   12 +
 .../tests/pmcheck/should_compile/pmc005.stderr     |    7 +
 testsuite/tests/pmcheck/should_compile/pmc006.hs   |   22 +
 .../tests/pmcheck/should_compile/pmc006.stderr     |    0
 testsuite/tests/pmcheck/should_compile/pmc007.hs   |   20 +
 .../tests/pmcheck/should_compile/pmc007.stderr     |   24 +
 .../tests/typecheck/should_compile/T5490.stderr    |    8 +
 87 files changed, 3056 insertions(+), 913 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 5d13d6b41fd00f2cb279416b8baa957b218e3ec5


More information about the ghc-commits mailing list