diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-08-20 16:55:59 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-08-26 04:50:58 -0400 |
commit | 0b17fa185aec793861364afd9a05aa4219fbc019 (patch) | |
tree | bb668be1d2b290fccfeb2beb982994b553789bb3 /compiler/GHC/Unit/State.hs | |
parent | b7d98cb2606997e05ad6406929dae3aba746fbb9 (diff) | |
download | haskell-0b17fa185aec793861364afd9a05aa4219fbc019.tar.gz |
Refactor UnitId pretty-printing
When we pretty-print a UnitId for the user, we try to map it back to its
origin package name, version and component to print
"package-version:component" instead of some hash.
The UnitId type doesn't carry these information, so we have to look into
a UnitState to find them. This is why the Outputable instance of
UnitId used `sdocWithDynFlags` in order to access the `unitState` field
of DynFlags.
This is wrong for several reasons:
1. The DynFlags are accessed when the message is printed, not when it is
generated. So we could imagine that the unitState may have changed
in-between. Especially if we want to allow unit unloading.
2. We want GHC to support several independent sessions at once, hence
several UnitState. The current approach supposes there is a unique
UnitState as a UnitId doesn't indicate which UnitState to use.
See the Note [Pretty-printing UnitId] in GHC.Unit for the new approach
implemented by this patch.
One step closer to remove `sdocDynFlags` field from `SDocContext`
(#10143).
Fix #18124.
Also fix some Backpack code to use SDoc instead of String.
Diffstat (limited to 'compiler/GHC/Unit/State.hs')
-rw-r--r-- | compiler/GHC/Unit/State.hs | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/compiler/GHC/Unit/State.hs b/compiler/GHC/Unit/State.hs index f35437be11..ec8cafe170 100644 --- a/compiler/GHC/Unit/State.hs +++ b/compiler/GHC/Unit/State.hs @@ -68,10 +68,9 @@ module GHC.Unit.State ( pprUnitIdForUser, pprUnitInfoForUser, pprModuleMap, + pprWithUnitState, -- * Utils - mkIndefUnitId, - updateIndefUnitId, unwireUnit ) where @@ -2128,15 +2127,6 @@ pprUnitInfoForUser info = ppr (mkUnitPprInfo unitIdFS info) lookupUnitPprInfo :: UnitState -> UnitId -> Maybe UnitPprInfo lookupUnitPprInfo state uid = fmap (mkUnitPprInfo unitIdFS) (lookupUnitId state uid) --- | Create a IndefUnitId. -mkIndefUnitId :: UnitState -> UnitId -> IndefUnitId -mkIndefUnitId state uid = Indefinite uid $! lookupUnitPprInfo state uid - --- | Update component ID details from the database -updateIndefUnitId :: UnitState -> IndefUnitId -> IndefUnitId -updateIndefUnitId pkgstate uid = mkIndefUnitId pkgstate (indefUnit uid) - - -- ----------------------------------------------------------------------------- -- Displaying packages @@ -2270,3 +2260,8 @@ instModuleToModule :: UnitState -> InstantiatedModule -> Module instModuleToModule pkgstate (Module iuid mod_name) = mkModule (instUnitToUnit pkgstate iuid) mod_name +-- | Print unit-ids with UnitInfo found in the given UnitState +pprWithUnitState :: UnitState -> SDoc -> SDoc +pprWithUnitState state = updSDocContext (\ctx -> ctx + { sdocUnitIdForUser = \fs -> pprUnitIdForUser state (UnitId fs) + }) |