summaryrefslogtreecommitdiff
path: root/compiler/GHC/Unit/Finder.hs
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-08-06 18:35:06 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-20 05:35:42 -0500
commitbdeea37efc76bc22a0d2e17f66dbf2ae8ad556fc (patch)
treeed1e62d7f2d34e4c77ff650828de872fb8daeb7a /compiler/GHC/Unit/Finder.hs
parent3d6b78dbd19f9061387c60e553638f9c26839d50 (diff)
downloadhaskell-bdeea37efc76bc22a0d2e17f66dbf2ae8ad556fc.tar.gz
More support for optional home-unit
This is a preliminary refactoring for #14335 (supporting plugins in cross-compilers). In many places the home-unit must be optional because there won't be one available in the plugin environment (we won't be compiling anything in this environment). Hence we replace "HomeUnit" with "Maybe HomeUnit" in a few places and we avoid the use of "hsc_home_unit" (which is partial) in some few others.
Diffstat (limited to 'compiler/GHC/Unit/Finder.hs')
-rw-r--r--compiler/GHC/Unit/Finder.hs30
1 files changed, 20 insertions, 10 deletions
diff --git a/compiler/GHC/Unit/Finder.hs b/compiler/GHC/Unit/Finder.hs
index cc16cd0dad..d4de80947b 100644
--- a/compiler/GHC/Unit/Finder.hs
+++ b/compiler/GHC/Unit/Finder.hs
@@ -134,18 +134,24 @@ findImportedModule
:: FinderCache
-> FinderOpts
-> UnitState
- -> HomeUnit
+ -> Maybe HomeUnit
-> ModuleName
-> PkgQual
-> IO FindResult
-findImportedModule fc fopts units home_unit mod_name mb_pkg =
+findImportedModule fc fopts units mhome_unit mod_name mb_pkg =
case mb_pkg of
NoPkgQual -> unqual_import
ThisPkg _ -> home_import
OtherPkg _ -> pkg_import
where
- home_import = findHomeModule fc fopts home_unit mod_name
+ home_import
+ | Just home_unit <- mhome_unit
+ = findHomeModule fc fopts home_unit mod_name
+ | otherwise
+ = pure $ NoPackage (panic "findImportedModule: no home-unit")
+
pkg_import = findExposedPackageModule fc fopts units mod_name mb_pkg
+
unqual_import = home_import
`orIfNotFound`
findExposedPackageModule fc fopts units mod_name NoPkgQual
@@ -154,11 +160,13 @@ findImportedModule fc fopts units home_unit mod_name mb_pkg =
-- plugin. This consults the same set of exposed packages as
-- 'findImportedModule', unless @-hide-all-plugin-packages@ or
-- @-plugin-package@ are specified.
-findPluginModule :: FinderCache -> FinderOpts -> UnitState -> HomeUnit -> ModuleName -> IO FindResult
-findPluginModule fc fopts units home_unit mod_name =
+findPluginModule :: FinderCache -> FinderOpts -> UnitState -> Maybe HomeUnit -> ModuleName -> IO FindResult
+findPluginModule fc fopts units (Just home_unit) mod_name =
findHomeModule fc fopts home_unit mod_name
`orIfNotFound`
findExposedPluginPackageModule fc fopts units mod_name
+findPluginModule fc fopts units Nothing mod_name =
+ findExposedPluginPackageModule fc fopts units 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
@@ -166,11 +174,13 @@ findPluginModule fc fopts units home_unit mod_name =
-- reading the interface for a module mentioned by another interface,
-- for example (a "system import").
-findExactModule :: FinderCache -> FinderOpts -> UnitState -> HomeUnit -> InstalledModule -> IO InstalledFindResult
-findExactModule fc fopts unit_state home_unit mod = do
- if isHomeInstalledModule home_unit mod
- then findInstalledHomeModule fc fopts home_unit (moduleName mod)
- else findPackageModule fc unit_state fopts mod
+findExactModule :: FinderCache -> FinderOpts -> UnitState -> Maybe HomeUnit -> InstalledModule -> IO InstalledFindResult
+findExactModule fc fopts unit_state mhome_unit mod = do
+ case mhome_unit of
+ Just home_unit
+ | isHomeInstalledModule home_unit mod
+ -> findInstalledHomeModule fc fopts home_unit (moduleName mod)
+ _ -> findPackageModule fc unit_state fopts mod
-- -----------------------------------------------------------------------------
-- Helpers