Support for multiple signature files in scope.
authorEdward Z. Yang <ezyang@cs.stanford.edu>
Wed, 8 Oct 2014 03:54:54 +0000 (20:54 -0700)
committerEdward Z. Yang <ezyang@cs.stanford.edu>
Tue, 7 Apr 2015 18:55:49 +0000 (11:55 -0700)
commita7524eaed33324e2155c47d4a705bef1d70a2b5b
treed3bb67c7cdfc5a6afa663484efe7b15c87ce43f1
parenta058ad65e0936c1b7104ee976cbf80d97fd7232e
Support for multiple signature files in scope.

Summary:
A common pattern when programming with signatures is to combine multiple
signatures together (signature linking).  We achieve this by making it
not-an-error to have multiple, distinct interface files for the same module
name, as long as they have the same backing implementation.  When a user
imports a module name, they get ALL matching signatures dumped into their
scope.

On the way, I refactored the module finder code, which now distinguishes
between exact finds (when you had a 'Module') and regular finds (when
you had a 'ModuleName').  I also refactored the package finder code to
use a Monoid instance on LookupResult to collect together various results.

ToDo: At the moment, if a signature is declared in the local package,
it completely overrides any remote signatures.  Eventually, we'll want
to also pull in the remote signatures (or even override the local signature,
if the full implementation is available.)  There are bunch of ToDos in the
code for what to do once this is done.

ToDo: At the moment, whenever a module name lookup occurs in GHCi and we
would have seen a signature, we instead continue and return the Module
for the backing implementation.  This is correct for most cases, but there
might be some situations where we want something a little more fine-grained
(e.g. :browse should only list identifiers which are available through
the in-scope signatures, and not ALL of them.)

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

Reviewers: simonpj, hvr, austin

Subscribers: carter, thomie

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

GHC Trac Issues: #9252
39 files changed:
compiler/deSugar/DsMonad.hs
compiler/ghci/Linker.hs
compiler/iface/LoadIface.hs
compiler/iface/MkIface.hs
compiler/main/DriverMkDepend.hs
compiler/main/DynamicLoading.hs
compiler/main/Finder.hs
compiler/main/GHC.hs
compiler/main/GhcMake.hs
compiler/main/HscTypes.hs
compiler/main/Packages.hs
docs/users_guide/separate_compilation.xml
ghc/Main.hs
testsuite/.gitignore
testsuite/tests/cabal/sigcabal02/Main.hs [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/Makefile [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/Setup.hs [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/ShouldFail.hs [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/all.T [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/p/LICENSE [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/p/Map.hsig [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/p/P.hs [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/p/Set.hsig [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/p/p.cabal [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/q/LICENSE [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/q/Map.hsig [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/q/Q.hs [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/q/q.cabal [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/sigcabal02.stderr [new file with mode: 0644]
testsuite/tests/cabal/sigcabal02/sigcabal02.stdout [new file with mode: 0644]
testsuite/tests/driver/recomp014/Makefile
testsuite/tests/driver/recomp014/recomp014.stdout
testsuite/tests/driver/sigof01/Makefile
testsuite/tests/driver/sigof01/all.T
testsuite/tests/driver/sigof01/sigof01i.script [new file with mode: 0644]
testsuite/tests/driver/sigof01/sigof01i.stdout [new file with mode: 0644]
testsuite/tests/driver/sigof01/sigof01i2.script [new file with mode: 0644]
testsuite/tests/driver/sigof01/sigof01i2.stdout [new file with mode: 0644]
testsuite/tests/package/package09e.stderr