diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-08-06 18:35:06 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-11-20 05:35:42 -0500 |
commit | bdeea37efc76bc22a0d2e17f66dbf2ae8ad556fc (patch) | |
tree | ed1e62d7f2d34e4c77ff650828de872fb8daeb7a /compiler/GHC/Unit | |
parent | 3d6b78dbd19f9061387c60e553638f9c26839d50 (diff) | |
download | haskell-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')
-rw-r--r-- | compiler/GHC/Unit/Finder.hs | 30 | ||||
-rw-r--r-- | compiler/GHC/Unit/Home.hs | 13 |
2 files changed, 30 insertions, 13 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 diff --git a/compiler/GHC/Unit/Home.hs b/compiler/GHC/Unit/Home.hs index 02b60e64c9..c72d21e537 100644 --- a/compiler/GHC/Unit/Home.hs +++ b/compiler/GHC/Unit/Home.hs @@ -18,6 +18,7 @@ module GHC.Unit.Home , isHomeUnitInstanceOf , isHomeModule , isHomeInstalledModule + , notHomeUnitId , notHomeModule , notHomeModuleMaybe , notHomeInstalledModule @@ -142,6 +143,11 @@ isHomeUnit hu u = u == homeUnitAsUnit hu isHomeUnitId :: GenHomeUnit u -> UnitId -> Bool isHomeUnitId hu uid = uid == homeUnitId hu +-- | Test if the unit-id is not the home unit-id +notHomeUnitId :: Maybe (GenHomeUnit u) -> UnitId -> Bool +notHomeUnitId Nothing _ = True +notHomeUnitId (Just hu) uid = not (isHomeUnitId hu uid) + -- | Test if the home unit is an instance of the given unit-id isHomeUnitInstanceOf :: HomeUnit -> UnitId -> Bool isHomeUnitInstanceOf hu u = homeUnitInstanceOf hu == u @@ -204,8 +210,9 @@ homeModuleNameInstantiation hu mod_name = -- the instantiating module of @r:A@ in @p[A=q[]:B]@ is @r:A@. -- the instantiating module of @p:A@ in @p@ is @p:A@. -- the instantiating module of @r:A@ in @p@ is @r:A@. -homeModuleInstantiation :: HomeUnit -> Module -> Module -homeModuleInstantiation hu mod - | isHomeModule hu mod = homeModuleNameInstantiation hu (moduleName mod) +homeModuleInstantiation :: Maybe HomeUnit -> Module -> Module +homeModuleInstantiation mhu mod + | Just hu <- mhu + , isHomeModule hu mod = homeModuleNameInstantiation hu (moduleName mod) | otherwise = mod |