Filter instance visibility based on set of visible orphans, fixes #2182.
authorEdward Z. Yang <ezyang@cs.stanford.edu>
Tue, 18 Nov 2014 05:23:52 +0000 (21:23 -0800)
committerEdward Z. Yang <ezyang@cs.stanford.edu>
Sun, 30 Nov 2014 07:16:31 +0000 (23:16 -0800)
commit4c834fdddf4d44d12039da4d6a2c63a660975b95
tree58c18fc03de10b2832ca62655dbba4cd833cec95
parent46c53d5ce5a1d00f29ffea0c3741d972e4beab97
Filter instance visibility based on set of visible orphans, fixes #2182.

Summary:
Amazingly, the fix for this very old bug is quite simple: when type-checking,
maintain a set of "visible orphan modules" based on the orphans list of
modules which we explicitly imported.  When we import an instance and it
is an orphan, we check if it is in the visible modules set, and if not,
ignore it.  A little bit of refactoring for when orphan-hood is calculated
happens so that we always know if an instance is an orphan or not.

For GHCi, we preinitialize the visible modules set based on the list of
interactive imports which are active.

Future work: Cache the visible orphan modules set for GHCi, rather than
recomputing it every type-checking round.  (But it's tricky what to do when you
/remove/ a module: you need a data structure a little more complicated than
just a set of modules.)

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Test Plan: new tests and validate

Reviewers: simonpj, austin

Subscribers: thomie, carter

Differential Revision: https://phabricator.haskell.org/D488

GHC Trac Issues: #2182
34 files changed:
compiler/basicTypes/Module.lhs
compiler/iface/IfaceSyn.lhs
compiler/iface/MkIface.lhs
compiler/iface/TcIface.lhs
compiler/main/HscTypes.lhs
compiler/typecheck/FunDeps.lhs
compiler/typecheck/Inst.lhs
compiler/typecheck/TcEnv.lhs
compiler/typecheck/TcPluginM.hs
compiler/typecheck/TcRnDriver.lhs
compiler/typecheck/TcRnMonad.lhs
compiler/typecheck/TcRnTypes.lhs
compiler/typecheck/TcSMonad.lhs
compiler/types/InstEnv.lhs
compiler/vectorise/Vectorise/Env.hs
compiler/vectorise/Vectorise/Monad.hs
testsuite/tests/driver/Makefile
testsuite/tests/driver/T2182.hs [new file with mode: 0644]
testsuite/tests/driver/T2182.stderr [new file with mode: 0644]
testsuite/tests/driver/T2182_A.hs [new file with mode: 0644]
testsuite/tests/driver/all.T
testsuite/tests/ghci.debugger/scripts/break006.stderr
testsuite/tests/ghci.debugger/scripts/print019.stderr
testsuite/tests/ghci/scripts/T2182ghci.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/T2182ghci.stderr [new file with mode: 0644]
testsuite/tests/ghci/scripts/T2182ghci.stdout [new file with mode: 0644]
testsuite/tests/ghci/scripts/T2182ghci2.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/T2182ghci2.stderr [new file with mode: 0644]
testsuite/tests/ghci/scripts/T2182ghci2.stdout [new file with mode: 0644]
testsuite/tests/ghci/scripts/T2182ghci_A.hs [new file with mode: 0644]
testsuite/tests/ghci/scripts/T2182ghci_B.hs [new file with mode: 0644]
testsuite/tests/ghci/scripts/T2182ghci_C.hs [new file with mode: 0644]
testsuite/tests/ghci/scripts/all.T
testsuite/tests/typecheck/should_fail/T5095.stderr