New handling of overlapping inst in Safe Haskell
authorDavid Terei <code@davidterei.com>
Mon, 11 May 2015 23:05:37 +0000 (16:05 -0700)
committerDavid Terei <code@davidterei.com>
Tue, 12 May 2015 01:21:11 +0000 (18:21 -0700)
commit4fffbc34c024231c3c9fac7a2134896cc09c7fb7
treea4b775d9f04997c2834303b2249dcae5ac42c642
parenteecef1733d5de342383665943b955bc1c96472f4
New handling of overlapping inst in Safe Haskell

We do much better now due to the newish per-instance flags. Rather than
mark any module that uses `-XOverlappingInstances`,
`-XIncoherentInstances` or the new `OVERLAP*` pragmas as unsafe, we
regard them all as safe and defer the check until an overlap occurs.

An type-class method call that involves overlapping instances is
considered _unsafe_ when:

1) The most specific instance, Ix, is from a module marked `-XSafe`
2) Ix is an orphan instance or a MPTC
3) At least one instance that Ix overlaps, Iy, is:
   a) from a different module than Ix
   AND
   b) Iy is not marked `OVERLAPPABLE`

This check is only enforced in modules compiled with `-XSafe` or
`-XTrustworthy`.

This fixes Safe Haskell to work with the latest overlapping instance
pragmas, and also brings consistent behavior. Previously, Safe Inferred
modules behaved differently than `-XSafe` modules.
72 files changed:
compiler/main/DynFlags.hs
compiler/main/HscMain.hs
compiler/typecheck/Inst.hs
compiler/typecheck/TcErrors.hs
compiler/typecheck/TcForeign.hs
compiler/typecheck/TcInstDcls.hs
compiler/typecheck/TcInteract.hs
compiler/typecheck/TcRnMonad.hs
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcSMonad.hs
compiler/typecheck/TcSimplify.hs
compiler/typecheck/TcSplice.hs
compiler/types/InstEnv.hs
testsuite/tests/safeHaskell/ghci/P13_A.hs
testsuite/tests/safeHaskell/ghci/p13.stderr
testsuite/tests/safeHaskell/overlapping/Makefile [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap1.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap1.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap10.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap10.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap10_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap10_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap11.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap11.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap11_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap11_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap1_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap1_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap2.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap2.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap2_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap2_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap3.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap3.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap3_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap3_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap4.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap4.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap4_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap4_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap5.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap5.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap5_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap5_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap6.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap6.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap6_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap6_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap7.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap7.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap7_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap7_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap8.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap8.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap8_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap9.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap9.stderr [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap9_A.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/SH_Overlap9_B.hs [new file with mode: 0644]
testsuite/tests/safeHaskell/overlapping/all.T [new file with mode: 0644]
testsuite/tests/safeHaskell/safeInfered/SafeInfered05.hs
testsuite/tests/safeHaskell/safeInfered/SafeInfered05.stderr
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered08.stderr
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered08_A.hs
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered13.stderr
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered14.stderr
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered15.stderr
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered16.stderr
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered17.stderr
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered18.stderr
testsuite/tests/safeHaskell/safeInfered/UnsafeInfered19.stderr
testsuite/tests/safeHaskell/safeInfered/all.T