summaryrefslogtreecommitdiff
path: root/compiler/GHC/Iface
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-04-03 12:18:57 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-04-30 01:56:56 -0400
commit10d15f1ec4bab4dd6152d87fc66e61658a705eb3 (patch)
treec25e1b33f62e13db7a3163f4e74330a52add80a2 /compiler/GHC/Iface
parentea717aa4248b2122e1f7550f30239b50ab560e4f (diff)
downloadhaskell-10d15f1ec4bab4dd6152d87fc66e61658a705eb3.tar.gz
Refactoring unit management code
Over the years the unit management code has been modified a lot to keep up with changes in Cabal (e.g. support for several library components in the same package), to integrate BackPack, etc. I found it very hard to understand as the terminology wasn't consistent, was referring to past concepts, etc. The terminology is now explained as clearly as I could in the Note "About Units" and the code is refactored to reflect it. ------------------- Many names were misleading: UnitId is not an Id but could be a virtual unit (an indefinite one instantiated on the fly), IndefUnitId constructor may contain a definite instantiated unit, etc. * Rename IndefUnitId into InstantiatedUnit * Rename IndefModule into InstantiatedModule * Rename UnitId type into Unit * Rename IndefiniteUnitId constructor into VirtUnit * Rename DefiniteUnitId constructor into RealUnit * Rename packageConfigId into mkUnit * Rename getPackageDetails into unsafeGetUnitInfo * Rename InstalledUnitId into UnitId Remove references to misleading ComponentId: a ComponentId is just an indefinite unit-id to be instantiated. * Rename ComponentId into IndefUnitId * Rename ComponentDetails into UnitPprInfo * Fix display of UnitPprInfo with empty version: this is now used for units dynamically generated by BackPack Generalize several types (Module, Unit, etc.) so that they can be used with different unit identifier types: UnitKey, UnitId, Unit, etc. * GenModule: Module, InstantiatedModule and InstalledModule are now instances of this type * Generalize DefUnitId, IndefUnitId, Unit, InstantiatedUnit, PackageDatabase Replace BackPack fake "hole" UnitId by a proper HoleUnit constructor. Add basic support for UnitKey. They should be used more in the future to avoid mixing them up with UnitId as we do now. Add many comments. Update Haddock submodule
Diffstat (limited to 'compiler/GHC/Iface')
-rw-r--r--compiler/GHC/Iface/Binary.hs4
-rw-r--r--compiler/GHC/Iface/Load.hs28
-rw-r--r--compiler/GHC/Iface/Make.hs2
-rw-r--r--compiler/GHC/Iface/Recomp.hs14
-rw-r--r--compiler/GHC/Iface/Rename.hs2
-rw-r--r--compiler/GHC/Iface/Tidy/StaticPtrTable.hs4
6 files changed, 27 insertions, 27 deletions
diff --git a/compiler/GHC/Iface/Binary.hs b/compiler/GHC/Iface/Binary.hs
index 3e00e8694d..e954413940 100644
--- a/compiler/GHC/Iface/Binary.hs
+++ b/compiler/GHC/Iface/Binary.hs
@@ -325,7 +325,7 @@ getSymbolTable bh ncu = do
newSTArray_ :: forall s. (Int, Int) -> ST s (STArray s Int Name)
newSTArray_ = newArray_
-type OnDiskName = (UnitId, ModuleName, OccName)
+type OnDiskName = (Unit, ModuleName, OccName)
fromOnDiskName :: NameCache -> OnDiskName -> (NameCache, Name)
fromOnDiskName nc (pid, mod_name, occ) =
@@ -342,7 +342,7 @@ fromOnDiskName nc (pid, mod_name, occ) =
serialiseName :: BinHandle -> Name -> UniqFM (Int,Name) -> IO ()
serialiseName bh name _ = do
let mod = ASSERT2( isExternalName name, ppr name ) nameModule name
- put_ bh (moduleUnitId mod, moduleName mod, nameOccName name)
+ put_ bh (moduleUnit mod, moduleName mod, nameOccName name)
-- Note [Symbol table representation of names]
diff --git a/compiler/GHC/Iface/Load.hs b/compiler/GHC/Iface/Load.hs
index 0068441ee3..c35a426e07 100644
--- a/compiler/GHC/Iface/Load.hs
+++ b/compiler/GHC/Iface/Load.hs
@@ -619,7 +619,7 @@ is_external_sig dflags iface =
-- It's a signature iface...
mi_semantic_module iface /= mi_module iface &&
-- and it's not from the local package
- moduleUnitId (mi_module iface) /= thisPackage dflags
+ moduleUnit (mi_module iface) /= thisPackage dflags
-- | This is an improved version of 'findAndReadIface' which can also
-- handle the case when a user requests @p[A=<B>]:M@ but we only
@@ -641,14 +641,14 @@ computeInterface ::
computeInterface doc_str hi_boot_file mod0 = do
MASSERT( not (isHoleModule mod0) )
dflags <- getDynFlags
- case splitModuleInsts mod0 of
- (imod, Just indef) | not (unitIdIsDefinite (thisPackage dflags)) -> do
+ case getModuleInstantiation mod0 of
+ (imod, Just indef) | not (unitIsDefinite (thisPackage dflags)) -> do
r <- findAndReadIface doc_str imod mod0 hi_boot_file
case r of
Succeeded (iface0, path) -> do
hsc_env <- getTopEnv
r <- liftIO $
- rnModIface hsc_env (indefUnitIdInsts (indefModuleUnitId indef))
+ rnModIface hsc_env (instUnitInsts (moduleUnit indef))
Nothing iface0
case r of
Right x -> return (Succeeded (x, path))
@@ -672,9 +672,9 @@ moduleFreeHolesPrecise
moduleFreeHolesPrecise doc_str mod
| moduleIsDefinite mod = return (Succeeded emptyUniqDSet)
| otherwise =
- case splitModuleInsts mod of
+ case getModuleInstantiation mod of
(imod, Just indef) -> do
- let insts = indefUnitIdInsts (indefModuleUnitId indef)
+ let insts = instUnitInsts (moduleUnit indef)
traceIf (text "Considering whether to load" <+> ppr mod <+>
text "to compute precise free module holes")
(eps, hpt) <- getEpsAndHpt
@@ -726,13 +726,13 @@ wantHiBootFile dflags eps mod from
-- The boot-ness of the requested interface,
-- based on the dependencies in directly-imported modules
where
- this_package = thisPackage dflags == moduleUnitId mod
+ this_package = thisPackage dflags == moduleUnit mod
badSourceImport :: Module -> SDoc
badSourceImport mod
= hang (text "You cannot {-# SOURCE #-} import a module from another package")
2 (text "but" <+> quotes (ppr mod) <+> ptext (sLit "is from package")
- <+> quotes (ppr (moduleUnitId mod)))
+ <+> quotes (ppr (moduleUnit mod)))
-----------------------------------------------------
-- Loading type/class/value decls
@@ -925,7 +925,7 @@ findAndReadIface doc_str mod wanted_mod_with_insts hi_boot_file
(ml_hi_file loc)
-- See Note [Home module load error]
- if installedModuleUnitId mod `installedUnitIdEq` thisPackage dflags &&
+ if moduleUnit mod `unitIdEq` thisPackage dflags &&
not (isOneShot (ghcMode dflags))
then return (Failed (homeModError mod loc))
else do r <- read_file file_path
@@ -935,7 +935,7 @@ findAndReadIface doc_str mod wanted_mod_with_insts hi_boot_file
traceIf (text "...not found")
dflags <- getDynFlags
return (Failed (cannotFindInterface dflags
- (installedModuleName mod) err))
+ (moduleName mod) err))
where read_file file_path = do
traceIf (text "readIFace" <+> text file_path)
-- Figure out what is recorded in mi_module. If this is
@@ -943,11 +943,11 @@ findAndReadIface doc_str mod wanted_mod_with_insts hi_boot_file
-- if it's indefinite, the inside will be uninstantiated!
dflags <- getDynFlags
let wanted_mod =
- case splitModuleInsts wanted_mod_with_insts of
+ case getModuleInstantiation wanted_mod_with_insts of
(_, Nothing) -> wanted_mod_with_insts
(_, Just indef_mod) ->
- indefModuleToModule dflags
- (generalizeIndefModule indef_mod)
+ instModuleToModule (pkgState dflags)
+ (uninstantiateInstantiatedModule indef_mod)
read_result <- readIface wanted_mod file_path
case read_result of
Failed err -> return (Failed (badIfaceFile file_path err))
@@ -1272,7 +1272,7 @@ badIfaceFile file err
hiModuleNameMismatchWarn :: DynFlags -> Module -> Module -> MsgDoc
hiModuleNameMismatchWarn dflags requested_mod read_mod
- | moduleUnitId requested_mod == moduleUnitId read_mod =
+ | moduleUnit requested_mod == moduleUnit read_mod =
sep [text "Interface file contains module" <+> quotes (ppr read_mod) <> comma,
text "but we were expecting module" <+> quotes (ppr requested_mod),
sep [text "Probable cause: the source code which generated interface file",
diff --git a/compiler/GHC/Iface/Make.hs b/compiler/GHC/Iface/Make.hs
index 6ffce05405..0b0c46019f 100644
--- a/compiler/GHC/Iface/Make.hs
+++ b/compiler/GHC/Iface/Make.hs
@@ -153,7 +153,7 @@ mkIfaceTc hsc_env safe_mode mod_details
let pluginModules =
map lpModule (cachedPlugins (hsc_dflags hsc_env))
deps <- mkDependencies
- (thisInstalledUnitId (hsc_dflags hsc_env))
+ (thisUnitId (hsc_dflags hsc_env))
(map mi_module pluginModules) tc_result
let hpc_info = emptyHpcInfo other_hpc_info
used_th <- readIORef tc_splice_used
diff --git a/compiler/GHC/Iface/Recomp.hs b/compiler/GHC/Iface/Recomp.hs
index 430f7b4207..bec782ff48 100644
--- a/compiler/GHC/Iface/Recomp.hs
+++ b/compiler/GHC/Iface/Recomp.hs
@@ -209,10 +209,10 @@ checkVersions hsc_env mod_summary iface
= do { traceHiDiffs (text "Considering whether compilation is required for" <+>
ppr (mi_module iface) <> colon)
- -- readIface will have verified that the InstalledUnitId matches,
+ -- readIface will have verified that the UnitId matches,
-- but we ALSO must make sure the instantiation matches up. See
-- test case bkpcabal04!
- ; if moduleUnitId (mi_module iface) /= thisPackage (hsc_dflags hsc_env)
+ ; if moduleUnit (mi_module iface) /= thisPackage (hsc_dflags hsc_env)
then return (RecompBecause "-this-unit-id changed", Nothing) else do {
; recomp <- checkFlagHash hsc_env iface
; if recompileRequired recomp then return (recomp, Nothing) else do {
@@ -332,7 +332,7 @@ checkHsig mod_summary iface = do
dflags <- getDynFlags
let outer_mod = ms_mod mod_summary
inner_mod = canonicalizeHomeModule dflags (moduleName outer_mod)
- MASSERT( moduleUnitId outer_mod == thisPackage dflags )
+ MASSERT( moduleUnit outer_mod == thisPackage dflags )
case inner_mod == mi_semantic_module iface of
True -> up_to_date (text "implementing module unchanged")
False -> return (RecompBecause "implementing module changed")
@@ -405,7 +405,7 @@ checkMergedSignatures mod_summary iface = do
new_merged = case Map.lookup (ms_mod_name mod_summary)
(requirementContext (pkgState dflags)) of
Nothing -> []
- Just r -> sort $ map (indefModuleToModule dflags) r
+ Just r -> sort $ map (instModuleToModule (pkgState dflags)) r
if old_merged == new_merged
then up_to_date (text "signatures to merge in unchanged" $$ ppr new_merged)
else return (RecompBecause "signatures to merge in changed")
@@ -463,7 +463,7 @@ checkDependencies hsc_env summary iface
else
return UpToDate
| otherwise
- -> if toInstalledUnitId pkg `notElem` (map fst prev_dep_pkgs)
+ -> if toUnitId pkg `notElem` (map fst prev_dep_pkgs)
then do traceHiDiffs $
text "imported module " <> quotes (ppr mod) <>
text " is from package " <> quotes (ppr pkg) <>
@@ -471,7 +471,7 @@ checkDependencies hsc_env summary iface
return (RecompBecause reason)
else
return UpToDate
- where pkg = moduleUnitId mod
+ where pkg = moduleUnit mod
_otherwise -> return (RecompBecause reason)
old_deps = Set.fromList $ map fst $ filter (not . snd) prev_dep_mods
@@ -561,7 +561,7 @@ getFromModIface doc_msg mod getter
-- | Given the usage information extracted from the old
-- M.hi file for the module being compiled, figure out
-- whether M needs to be recompiled.
-checkModUsage :: UnitId -> Usage -> IfG RecompileRequired
+checkModUsage :: Unit -> Usage -> IfG RecompileRequired
checkModUsage _this_pkg UsagePackageModule{
usg_mod = mod,
usg_mod_hash = old_mod_hash }
diff --git a/compiler/GHC/Iface/Rename.hs b/compiler/GHC/Iface/Rename.hs
index dbe847b5f4..29c0b3e593 100644
--- a/compiler/GHC/Iface/Rename.hs
+++ b/compiler/GHC/Iface/Rename.hs
@@ -211,7 +211,7 @@ data ShIfEnv = ShIfEnv {
-- The semantic module that we are renaming to
sh_if_semantic_module :: Module,
-- Cached hole substitution, e.g.
- -- @sh_if_hole_subst == listToUFM . unitIdInsts . moduleUnitId . sh_if_module@
+ -- @sh_if_hole_subst == listToUFM . unitIdInsts . moduleUnit . sh_if_module@
sh_if_hole_subst :: ShHoleSubst,
-- An optional name substitution to be applied when renaming
-- the names in the interface. If this is 'Nothing', then
diff --git a/compiler/GHC/Iface/Tidy/StaticPtrTable.hs b/compiler/GHC/Iface/Tidy/StaticPtrTable.hs
index 09125a4b53..453f859233 100644
--- a/compiler/GHC/Iface/Tidy/StaticPtrTable.hs
+++ b/compiler/GHC/Iface/Tidy/StaticPtrTable.hs
@@ -211,7 +211,7 @@ sptCreateStaticBinds hsc_env this_mod binds
info <- mkConApp staticPtrInfoDataCon <$>
(++[srcLoc]) <$>
mapM (mkStringExprFSWith (lift . lookupIdHscEnv))
- [ unitIdFS $ moduleUnitId this_mod
+ [ unitFS $ moduleUnit this_mod
, moduleNameFS $ moduleName this_mod
]
@@ -227,7 +227,7 @@ sptCreateStaticBinds hsc_env this_mod binds
mkStaticPtrFingerprint :: Int -> Fingerprint
mkStaticPtrFingerprint n = fingerprintString $ intercalate ":"
- [ unitIdString $ moduleUnitId this_mod
+ [ unitString $ moduleUnit this_mod
, moduleNameString $ moduleName this_mod
, show n
]