Control validity-checking of type synonym applications more carefully
authorRyan Scott <ryan.gl.scott@gmail.com>
Thu, 10 Jan 2019 21:55:51 +0000 (16:55 -0500)
committerRyan Scott <ryan.gl.scott@gmail.com>
Tue, 15 Jan 2019 21:09:27 +0000 (16:09 -0500)
commit9dc56b61ae10cb26ec8b2bc132ae6c9b620707a8
tree51690d72af413c0deb9cf17f3a4e10e44db1411c
parente63518f5d6a93be111f9108c0990a1162f88d615
Control validity-checking of type synonym applications more carefully

Trac #16059 shows that when validity checking applications of type
synonyms, GHC sometimes wasn't checking the expanded type enough.
We must be careful, however, since checking both the expanded type as
well as the arguments to the type synonym can lead to exponential
blowup (see https://ghc.haskell.org/trac/ghc/ticket/16059#comment:4).
Nor can we omit checking either the expanded type or the argument for
correctness reasons.

The solution here is to introduce a new `ExpandMode` data type that
is plumbed through all of the type-validity-checking functions in
`TcValidity`. `ExpandMode` dictates whether we only check the
expanded type (`Expand`), only check the arguments (`NoExpand), or
both (`Both`). Importantly, if we check `Both` in the function for
validity checking type synonym applications, then we switch to
`NoExpand` when checking the arguments so as to avoid exponential
blowup. See `Note [Correctness and performance of type synonym validity
checking]` for the full story.
14 files changed:
compiler/typecheck/TcValidity.hs
testsuite/tests/safeHaskell/unsafeLibs/Dep05.hs
testsuite/tests/safeHaskell/unsafeLibs/Dep05.stderr
testsuite/tests/typecheck/should_fail/T16059a.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T16059a.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T16059b.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T16059c.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T16059c.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T16059d.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T16059d.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T16059e.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T16059e.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T9858a.stderr
testsuite/tests/typecheck/should_fail/all.T