Warn about simplifiable class constraints
authorSimon Peyton Jones <simonpj@microsoft.com>
Thu, 21 Apr 2016 12:06:54 +0000 (13:06 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Fri, 22 Apr 2016 10:32:31 +0000 (11:32 +0100)
commit9421b0c77122d40bf72665ea9f90dca64a0a0ae2
treee6a76ff1e6f6dab8590086d7ef89fc54bb842a0b
parentedf54d72b5b8a6dd0deafa036dc16dcfc3fcb29f
Warn about simplifiable class constraints

Provoked by Trac #11948, this patch adds a new warning to GHC

  -Wsimplifiable-class-constraints

It warns if you write a class constraint in a type signature that
can be simplified by an existing instance declaration.  Almost always
this means you should simplify it right now; type inference is very
fragile without it, as #11948 shows.

I've put the warning as on-by-default, but I suppose that if there are
howls of protest we can move it out (as happened for -Wredundant-constraints.

It actually found an example of an over-complicated context in CmmNode.

Quite a few tests use these weird contexts to trigger something else,
so I had to suppress the warning in those.

The 'haskeline' library has a few occurrences of the warning (which
I think should be fixed), so I switched it off for that library in
warnings.mk.

The warning itself is done in TcValidity.check_class_pred.

HOWEVER, when type inference fails we get a type error; and the error
suppresses the (informative) warning.  So as things stand, the warning
only happens when it doesn't cause a problem.  Not sure what to do
about this, but this patch takes us forward, I think.
31 files changed:
compiler/basicTypes/BasicTypes.hs
compiler/cmm/CmmNode.hs
compiler/main/DynFlags.hs
compiler/typecheck/TcInteract.hs
compiler/typecheck/TcType.hs
compiler/typecheck/TcValidity.hs
compiler/types/InstEnv.hs
docs/users_guide/using-warnings.rst
mk/warnings.mk
testsuite/tests/dependent/should_compile/dynamic-paper.hs
testsuite/tests/ghci/scripts/ghci047.script
testsuite/tests/ghci/scripts/ghci047.stderr
testsuite/tests/indexed-types/should_compile/Gentle.hs
testsuite/tests/indexed-types/should_compile/NonLinearLHS.hs
testsuite/tests/indexed-types/should_compile/T11067.hs
testsuite/tests/indexed-types/should_compile/T5002.hs
testsuite/tests/partial-sigs/should_compile/SomethingShowable.stderr
testsuite/tests/polykinds/T6020a.hs
testsuite/tests/simplCore/should_compile/simpl014.hs
testsuite/tests/th/T3100.hs
testsuite/tests/typecheck/should_compile/GivenOverlapping.hs
testsuite/tests/typecheck/should_compile/T10195.hs
testsuite/tests/typecheck/should_compile/T3108.hs
testsuite/tests/typecheck/should_compile/T4361.hs
testsuite/tests/typecheck/should_compile/T6055.hs
testsuite/tests/typecheck/should_compile/T7541.hs
testsuite/tests/typecheck/should_compile/T7875.hs
testsuite/tests/typecheck/should_compile/tc229.hs
testsuite/tests/typecheck/should_fail/T11948.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T11948.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/all.T