Major Overhaul of Pattern Match Checking (Fixes #595)
authorGeorge Karachalias <george.karachalias@gmail.com>
Thu, 3 Dec 2015 11:57:19 +0000 (12:57 +0100)
committerGeorge Karachalias <george.karachalias@gmail.com>
Thu, 3 Dec 2015 11:57:19 +0000 (12:57 +0100)
commit8a506104d5b5b71d5640afc69c992e0af40f2213
tree7c2c35faab5a2a7e41d74da227d77156d383d370
parentd25f3c076e6c47bc7c8d0d27e724a3ad2b7d7399
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.
87 files changed:
compiler/basicTypes/UniqSupply.hs
compiler/deSugar/Check.hs
compiler/deSugar/DsBinds.hs
compiler/deSugar/DsExpr.hs
compiler/deSugar/DsGRHSs.hs
compiler/deSugar/DsMonad.hs
compiler/deSugar/Match.hs
compiler/deSugar/Match.hs-boot
compiler/deSugar/PmExpr.hs [new file with mode: 0644]
compiler/deSugar/TmOracle.hs [new file with mode: 0644]
compiler/ghc.cabal.in
compiler/ghc.mk
compiler/hsSyn/HsLit.hs
compiler/hsSyn/HsPat.hs
compiler/prelude/TysWiredIn.hs-boot
compiler/typecheck/TcMType.hs
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcSMonad.hs
compiler/typecheck/TcSimplify.hs
compiler/typecheck/TcType.hs
compiler/types/Type.hs
compiler/utils/Bag.hs
compiler/utils/MonadUtils.hs
testsuite/tests/deSugar/should_compile/T2395.stderr
testsuite/tests/deSugar/should_compile/T5117.stderr
testsuite/tests/deSugar/should_compile/all.T
testsuite/tests/deSugar/should_compile/ds002.stderr
testsuite/tests/deSugar/should_compile/ds003.stderr
testsuite/tests/deSugar/should_compile/ds019.stderr
testsuite/tests/deSugar/should_compile/ds020.stderr
testsuite/tests/deSugar/should_compile/ds022.hs
testsuite/tests/deSugar/should_compile/ds022.stderr
testsuite/tests/deSugar/should_compile/ds043.stderr
testsuite/tests/deSugar/should_compile/ds051.stderr
testsuite/tests/deSugar/should_compile/ds056.stderr
testsuite/tests/deSugar/should_compile/ds058.stderr
testsuite/tests/deSugar/should_compile/ds060.hs [deleted file]
testsuite/tests/driver/werror.stderr
testsuite/tests/gadt/Gadt17_help.hs
testsuite/tests/gadt/T7294.stderr
testsuite/tests/ghci/scripts/Defer02.stderr
testsuite/tests/pmcheck/Makefile [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/Makefile [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T2006.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T2006.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T2204.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T2204.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T3078.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T3078.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T322.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T322.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T366.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T366.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T3927.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T3927.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T3927a.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T3927a.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T3927b.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T3927b.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T4139.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T4139.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T6124.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T6124.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T7669.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T7669.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T8970.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T8970.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T9951.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T9951.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T9951b.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/T9951b.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/all.T [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc001.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc001.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc002.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc002.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc003.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc003.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc004.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc004.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc005.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc005.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc006.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc006.stderr [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc007.hs [new file with mode: 0644]
testsuite/tests/pmcheck/should_compile/pmc007.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_compile/T5490.stderr [new file with mode: 0644]