From bdeea37efc76bc22a0d2e17f66dbf2ae8ad556fc Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Fri, 6 Aug 2021 18:35:06 +0200 Subject: 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. --- compiler/GHC/Unit/Finder.hs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'compiler/GHC/Unit/Finder.hs') 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 -- cgit v1.2.1