summaryrefslogtreecommitdiff
path: root/compiler/GHC/Unit/Module
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-09-22 18:28:35 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-22 19:20:44 -0400
commit806e49ae36a058dbe4494055a6b936dd153c6194 (patch)
tree982c304986bf925187aae36997d4602e3419c8e9 /compiler/GHC/Unit/Module
parent6fd7da745a518a93f6685171701a27283cfe2d4e (diff)
downloadhaskell-806e49ae36a058dbe4494055a6b936dd153c6194.tar.gz
Refactor package imports
Use an (Raw)PkgQual datatype instead of `Maybe FastString` to represent package imports. Factorize the code that renames RawPkgQual into PkgQual in function `rnPkgQual`. Renaming consists in checking if the FastString is the magic "this" keyword, the home-unit unit-id or something else. Bump haddock submodule
Diffstat (limited to 'compiler/GHC/Unit/Module')
-rw-r--r--compiler/GHC/Unit/Module/ModSummary.hs29
1 files changed, 16 insertions, 13 deletions
diff --git a/compiler/GHC/Unit/Module/ModSummary.hs b/compiler/GHC/Unit/Module/ModSummary.hs
index 20d61ad4f8..0f29c5a477 100644
--- a/compiler/GHC/Unit/Module/ModSummary.hs
+++ b/compiler/GHC/Unit/Module/ModSummary.hs
@@ -37,9 +37,9 @@ import GHC.Unit.Module
import GHC.Types.SourceFile ( HscSource(..), hscSourceString )
import GHC.Types.SrcLoc
import GHC.Types.Target
+import GHC.Types.PkgQual
import GHC.Data.Maybe
-import GHC.Data.FastString
import GHC.Data.StringBuffer ( StringBuffer )
import GHC.Utils.Fingerprint
@@ -88,9 +88,9 @@ data ModSummary
-- See Note [When source is considered modified] and #9243
ms_hie_date :: Maybe UTCTime,
-- ^ Timestamp of hie file, if we have one
- ms_srcimps :: [(Maybe FastString, Located ModuleName)],
+ ms_srcimps :: [(PkgQual, Located ModuleName)], -- FIXME: source imports are never from an external package, why do we allow PkgQual?
-- ^ Source imports of the module
- ms_textual_imps :: [(Maybe FastString, Located ModuleName)],
+ ms_textual_imps :: [(PkgQual, Located ModuleName)],
-- ^ Non-source imports of the module from the module *text*
ms_ghc_prim_import :: !Bool,
-- ^ Whether the special module GHC.Prim was imported explicitliy
@@ -116,19 +116,22 @@ ms_mod_name :: ModSummary -> ModuleName
ms_mod_name = moduleName . ms_mod
-- | Textual imports, plus plugin imports but not SOURCE imports.
-ms_imps :: ModSummary -> [(Maybe FastString, Located ModuleName)]
+ms_imps :: ModSummary -> [(PkgQual, Located ModuleName)]
ms_imps ms = ms_textual_imps ms ++ ms_plugin_imps ms
-- | Plugin imports
-ms_plugin_imps :: ModSummary -> [(Maybe FastString, Located ModuleName)]
-ms_plugin_imps ms = map ((Nothing,) . noLoc) (pluginModNames (ms_hspp_opts ms))
-
-home_imps :: [(Maybe FastString, Located ModuleName)] -> [Located ModuleName]
-home_imps imps = [ lmodname | (mb_pkg, lmodname) <- imps,
- isLocal mb_pkg ]
- where isLocal Nothing = True
- isLocal (Just pkg) | pkg == fsLit "this" = True -- "this" is special
- isLocal _ = False
+ms_plugin_imps :: ModSummary -> [(PkgQual, Located ModuleName)]
+ms_plugin_imps ms = map ((NoPkgQual,) . noLoc) (pluginModNames (ms_hspp_opts ms))
+
+-- | All of the (possibly) home module imports from the given list that is to
+-- say, each of these module names could be a home import if an appropriately
+-- named file existed. (This is in contrast to package qualified imports, which
+-- are guaranteed not to be home imports.)
+home_imps :: [(PkgQual, Located ModuleName)] -> [Located ModuleName]
+home_imps imps = fmap snd (filter (maybe_home . fst) imps)
+ where maybe_home NoPkgQual = True
+ maybe_home (ThisPkg _) = True
+ maybe_home (OtherPkg _) = False
-- | Like 'ms_home_imps', but for SOURCE imports.
ms_home_srcimps :: ModSummary -> [Located ModuleName]