diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-08-05 11:32:17 +0200 |
---|---|---|
committer | Sylvain Henry <sylvain@haskus.fr> | 2020-08-13 09:49:56 -0400 |
commit | ffc0d578ea22de02a68c64c094602701e65d8895 (patch) | |
tree | 168171a5fb54632f5f4fdd1130a31ed730248e73 /compiler/GHC/Unit/Info.hs | |
parent | cf97889a38edc3314a7b61e6e0b6e6d0f434c8a2 (diff) | |
download | haskell-ffc0d578ea22de02a68c64c094602701e65d8895.tar.gz |
Add HomeUnit type
Since Backpack the "home unit" is much more involved than what it was
before (just an identifier obtained with `-this-unit-id`). Now it is
used in conjunction with `-component-id` and `-instantiated-with` to
configure module instantiations and to detect if we are type-checking an
indefinite unit or compiling a definite one.
This patch introduces a new HomeUnit datatype which is much easier to
understand. Moreover to make GHC support several packages in the same
instances, we will need to handle several HomeUnits so having a
dedicated (documented) type is helpful.
Finally in #14335 we will also need to handle the case where we have no
HomeUnit at all because we are only loading existing interfaces for
plugins which live in a different space compared to units used to
produce target code. Several functions will have to be refactored to
accept "Maybe HomeUnit" parameters instead of implicitly querying the
HomeUnit fields in DynFlags. Having a dedicated type will make this
easier.
Bump haddock submodule
Diffstat (limited to 'compiler/GHC/Unit/Info.hs')
-rw-r--r-- | compiler/GHC/Unit/Info.hs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/compiler/GHC/Unit/Info.hs b/compiler/GHC/Unit/Info.hs index 002fb1b6a9..839344804c 100644 --- a/compiler/GHC/Unit/Info.hs +++ b/compiler/GHC/Unit/Info.hs @@ -46,12 +46,6 @@ import GHC.Unit.Ppr -- Units] in "GHC.Unit" type GenUnitInfo unit = GenericUnitInfo (Indefinite unit) PackageId PackageName unit ModuleName (GenModule (GenUnit unit)) --- | A unit key in the database -newtype UnitKey = UnitKey FastString - -unitKeyFS :: UnitKey -> FastString -unitKeyFS (UnitKey fs) = fs - -- | Information about an installed unit (units are identified by their database -- UnitKey) type UnitKeyInfo = GenUnitInfo UnitKey @@ -76,21 +70,21 @@ mkUnitKeyInfo = mapGenericUnitInfo mkModuleName' = mkModuleNameFS . mkFastStringByteString mkIndefUnitKey' cid = Indefinite (mkUnitKey' cid) Nothing mkVirtUnitKey' i = case i of - DbInstUnitId cid insts -> mkGenVirtUnit unitKeyFS (mkIndefUnitKey' cid) (fmap (bimap mkModuleName' mkModule') insts) + DbInstUnitId cid insts -> mkVirtUnit (mkIndefUnitKey' cid) (fmap (bimap mkModuleName' mkModule') insts) DbUnitId uid -> RealUnit (Definite (mkUnitKey' uid)) mkModule' m = case m of DbModule uid n -> mkModule (mkVirtUnitKey' uid) (mkModuleName' n) DbModuleVar n -> mkHoleModule (mkModuleName' n) -- | Map over the unit parameter -mapUnitInfo :: (u -> v) -> (v -> FastString) -> GenUnitInfo u -> GenUnitInfo v -mapUnitInfo f gunitFS = mapGenericUnitInfo +mapUnitInfo :: IsUnitId v => (u -> v) -> GenUnitInfo u -> GenUnitInfo v +mapUnitInfo f = mapGenericUnitInfo f -- unit identifier (fmap f) -- indefinite unit identifier id -- package identifier id -- package name id -- module name - (fmap (mapGenUnit f gunitFS)) -- instantiating modules + (fmap (mapGenUnit f)) -- instantiating modules -- TODO: there's no need for these to be FastString, as we don't need the uniq -- feature, but ghc doesn't currently have convenient support for any |