From 0b17fa185aec793861364afd9a05aa4219fbc019 Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Thu, 20 Aug 2020 16:55:59 +0200 Subject: 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. --- compiler/GHC/Driver/Finder.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'compiler/GHC/Driver/Finder.hs') diff --git a/compiler/GHC/Driver/Finder.hs b/compiler/GHC/Driver/Finder.hs index 0b9ad24371..c598e36791 100644 --- a/compiler/GHC/Driver/Finder.hs +++ b/compiler/GHC/Driver/Finder.hs @@ -620,11 +620,12 @@ findObjectLinkable mod obj_fn obj_time = return (LM obj_time mod [DotO obj_fn]) -- Error messages cannotFindModule :: DynFlags -> ModuleName -> FindResult -> SDoc -cannotFindModule flags mod res = +cannotFindModule dflags mod res = pprWithUnitState unit_state $ cantFindErr (sLit cannotFindMsg) (sLit "Ambiguous module name") - flags mod res + dflags mod res where + unit_state = unitState dflags cannotFindMsg = case res of NotFound { fr_mods_hidden = hidden_mods -- cgit v1.2.1