diff options
author | Edward Z. Yang <ezyang@cs.stanford.edu> | 2014-10-07 20:54:54 -0700 |
---|---|---|
committer | Edward Z. Yang <ezyang@cs.stanford.edu> | 2015-04-07 11:55:49 -0700 |
commit | a7524eaed33324e2155c47d4a705bef1d70a2b5b (patch) | |
tree | d3bb67c7cdfc5a6afa663484efe7b15c87ce43f1 /compiler/main/DynamicLoading.hs | |
parent | a058ad65e0936c1b7104ee976cbf80d97fd7232e (diff) | |
download | haskell-a7524eaed33324e2155c47d4a705bef1d70a2b5b.tar.gz |
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
Diffstat (limited to 'compiler/main/DynamicLoading.hs')
-rw-r--r-- | compiler/main/DynamicLoading.hs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/compiler/main/DynamicLoading.hs b/compiler/main/DynamicLoading.hs index 82081bf1a3..546cc6879c 100644 --- a/compiler/main/DynamicLoading.hs +++ b/compiler/main/DynamicLoading.hs @@ -203,7 +203,15 @@ lookupRdrNameInModuleForPlugins hsc_env mod_name rdr_name = do -- First find the package the module resides in by searching exposed packages and home modules found_module <- findImportedModule hsc_env mod_name Nothing case found_module of - Found _ mod -> do + FoundModule h -> check_mod (fr_mod h) + FoundSigs hs _backing -> check_mods (map fr_mod hs) -- (not tested) + err -> throwCmdLineErrorS dflags $ cannotFindModule dflags mod_name err + where + dflags = hsc_dflags hsc_env + meth = "lookupRdrNameInModule" + doc = ptext (sLit $ "contains a name used in an invocation of " ++ meth) + + check_mod mod = do -- Find the exports of the module (_, mb_iface) <- initTcInteractive hsc_env $ initIfaceTcRn $ @@ -221,10 +229,13 @@ lookupRdrNameInModuleForPlugins hsc_env mod_name rdr_name = do _ -> panic "lookupRdrNameInModule" Nothing -> throwCmdLineErrorS dflags $ hsep [ptext (sLit "Could not determine the exports of the module"), ppr mod_name] - err -> throwCmdLineErrorS dflags $ cannotFindModule dflags mod_name err - where - dflags = hsc_dflags hsc_env - doc = ptext (sLit "contains a name used in an invocation of lookupRdrNameInModule") + + check_mods [] = return Nothing + check_mods (m:ms) = do + r <- check_mod m + case r of + Nothing -> check_mods ms + Just _ -> return r wrongTyThingError :: Name -> TyThing -> SDoc wrongTyThingError name got_thing = hsep [ptext (sLit "The name"), ppr name, ptext (sLit "is not that of a value but rather a"), pprTyThingCategory got_thing] |