diff options
author | Edward Z. Yang <ezyang@cs.stanford.edu> | 2015-12-18 18:29:52 -0800 |
---|---|---|
committer | Edward Z. Yang <ezyang@cs.stanford.edu> | 2015-12-22 14:23:16 -0800 |
commit | 1faf1fcaebb2871f8085b01d0c6d19eec11dc808 (patch) | |
tree | ff61505ef4e115f5b13933b5e05a574d507629f5 /compiler/main/Finder.hs | |
parent | 998739df630cbee7d006329a76786239e3e2c0be (diff) | |
download | haskell-1faf1fcaebb2871f8085b01d0c6d19eec11dc808.tar.gz |
Implement -hide-all-plugin-packages and -plugin-package(-id), fixing #11244
Summary:
The basic idea is that we have a new set of "exposed modules"
which are /only/ used for plugins, i.e. -fplugin Foo and
--frontend Foo. You can interact with this namespace
using the flags -plugin-package-id and -plugin-package.
By default, this namespace contains all modules in the
user namespace (as before), but you can toggle that using
-hide-all-plugin-packages.
There is one nasty hack: GhcMake respects -fplugin in
GHC_OPTIONS to make local plugins work correctly. It also
bails out of you have an import of a module which doesn't
exist locally or in the package database. The upshot is
that we need to be sure to check in the plugin modules
too, so we don't give a spurious failure when a plugin
is in the plugin namespace but not the main namespace.
A better way to fix this would be to distinguish between
plugin and normal dependencies in ModSummary.
I cheated a little and tweaked a few existing plugins
tests to exercise the new code paths.
TODO: Documentation
Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Test Plan: validate
Reviewers: bgamari, austin, simonpj, duncan
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1661
GHC Trac Issues: #11244
Diffstat (limited to 'compiler/main/Finder.hs')
-rw-r--r-- | compiler/main/Finder.hs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/compiler/main/Finder.hs b/compiler/main/Finder.hs index c6bbd7583f..dddc09a6eb 100644 --- a/compiler/main/Finder.hs +++ b/compiler/main/Finder.hs @@ -10,6 +10,7 @@ module Finder ( flushFinderCaches, FindResult(..), findImportedModule, + findPluginModule, findExactModule, findHomeModule, findExposedPackageModule, @@ -89,7 +90,7 @@ lookupFinderCache ref key = do return $! lookupModuleEnv c key -- ----------------------------------------------------------------------------- --- The two external entry points +-- The three external entry points -- | Locate a module that was imported by the user. We have the -- module's name, and possibly a package name. Without a package @@ -112,6 +113,16 @@ findImportedModule hsc_env mod_name mb_pkg = `orIfNotFound` findExposedPackageModule hsc_env mod_name Nothing +-- | Locate a plugin module requested by the user, for a compiler +-- plugin. This consults the same set of exposed packages as +-- 'findImportedModule', unless @-hide-all-plugin-packages@ or +-- @-plugin-package@ are specified. +findPluginModule :: HscEnv -> ModuleName -> IO FindResult +findPluginModule hsc_env mod_name = + findHomeModule hsc_env mod_name + `orIfNotFound` + findExposedPluginPackageModule hsc_env mod_name + -- | Locate a specific 'Module'. The purpose of this function is to -- create a 'ModLocation' for a given 'Module', that is to find out -- where the files associated with this module live. It is used when @@ -160,7 +171,19 @@ homeSearchCache hsc_env mod_name do_this = do findExposedPackageModule :: HscEnv -> ModuleName -> Maybe FastString -> IO FindResult findExposedPackageModule hsc_env mod_name mb_pkg - = case lookupModuleWithSuggestions (hsc_dflags hsc_env) mod_name mb_pkg of + = findLookupResult hsc_env + $ lookupModuleWithSuggestions + (hsc_dflags hsc_env) mod_name mb_pkg + +findExposedPluginPackageModule :: HscEnv -> ModuleName + -> IO FindResult +findExposedPluginPackageModule hsc_env mod_name + = findLookupResult hsc_env + $ lookupPluginModuleWithSuggestions + (hsc_dflags hsc_env) mod_name Nothing + +findLookupResult :: HscEnv -> LookupResult -> IO FindResult +findLookupResult hsc_env r = case r of LookupFound m pkg_conf -> findPackageModule_ hsc_env m pkg_conf LookupMultiple rs -> |