[Git][ghc/ghc][wip/romes/graph-compact-easy] Restore parts of API necessary for ghcide case study

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Fri Dec 13 15:20:23 UTC 2024



Rodrigo Mesquita pushed to branch wip/romes/graph-compact-easy at Glasgow Haskell Compiler / GHC


Commits:
d6a62da7 by Rodrigo Mesquita at 2024-12-13T15:20:03+00:00
Restore parts of API necessary for ghcide case study

- - - - -


3 changed files:

- compiler/GHC/Unit/Home/Graph.hs
- compiler/GHC/Unit/Home/PackageTable.hs
- docs/users_guide/9.14.1-notes.rst


Changes:

=====================================
compiler/GHC/Unit/Home/Graph.hs
=====================================
@@ -55,7 +55,7 @@ module GHC.Unit.Home.Graph
   , pprHomeUnitEnv
 
   -- * Auxiliary internal structure
-  , UnitEnvGraph
+  , UnitEnvGraph(..)
   , unitEnv_lookup_maybe
   , unitEnv_foldWithKey
   , unitEnv_singleton


=====================================
compiler/GHC/Unit/Home/PackageTable.hs
=====================================
@@ -81,11 +81,13 @@ module GHC.Unit.Home.PackageTable
     --
     -- | These provide access to the internals of the HomePackageTable to
     -- facilitate existing workflows that used the previous API. For instance,
-    -- if you were listing out all elements, you can keep doing so by reading
-    -- the internal IO ref and then listing the moduleenv contents out.
+    -- if you were listing out all elements or merging, you can keep doing so by reading
+    -- the internal IO ref and then using the moduleenv contents directly.
     --
-    -- In GHC itself these should be avoided.
+    -- In GHC itself these should be avoided, and other uses should justify why
+    -- it is not sufficient to go through the intended insert-only API.
   , hptInternalTableRef
+  , hptInternalTableFromRef
 
     -- * Legacy API
     --
@@ -117,6 +119,7 @@ import GHC.Unit.Module.ModDetails
 import GHC.Unit.Module.ModIface
 import GHC.Utils.Outputable
 import GHC.Builtin.Names (gHC_PRIM)
+import GHC.Utils.Misc (lastMaybe)
 
 -- | Helps us find information about modules in the home package
 data HomePackageTable = HPT {
@@ -210,6 +213,12 @@ addHomeModInfoToHpt hmi hpt = addToHpt hpt (moduleName (mi_module (hm_iface hmi)
 -- After deprecation cycle, move `addToHpt` to a `where` clause inside `addHomeModInfoToHpt`.
 addToHpt :: HomePackageTable -> ModuleName -> HomeModInfo -> IO HomePackageTable
 addToHpt HPT{table=hptr, hasHoles} mn hmi = do
+  -- ROMES:TODO: We could assert that we only overwrite with SrcFile infos:
+  -- Something like:
+  -- addToUDFM_C $ combineModules a b
+  -- x            | HsSrcFile <- mi_hsc_src (hm_iface a) = a
+  -- x            | otherwise = error "tried to overwrite with something other than SrcFile?"
+
   atomicModifyIORef' hptr (\hpt -> (addToUDFM hpt mn hmi, ()))
   -- If the key already existed in the map, this insertion is overwriting
   -- the HMI of a previously loaded module (likely in rehydration).
@@ -478,3 +487,15 @@ concatHpt f HPT{table} = do
 -- Use with care.
 hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
 hptInternalTableRef = table
+
+-- | Construct a HomePackageTable from the IORef.
+-- Use with care, only if you can really justify going around the intended insert-only API.
+hptInternalTableFromRef :: IORef (DModuleNameEnv HomeModInfo) -> IO HomePackageTable
+hptInternalTableFromRef ref = do
+  table {- use this to compute the other fields -} <- readIORef ref
+  return HPT {
+    table = ref,
+    hasHoles = any (isHoleModule . mi_semantic_module . hm_iface) table, -- going to be removed altogether soon
+    lastLoadedKey = lastMaybe (map fst $ udfmToList table) -- this probably as well...
+  }
+


=====================================
docs/users_guide/9.14.1-notes.rst
=====================================
@@ -47,6 +47,8 @@ Cmm
 ``ghc`` library
 ~~~~~~~~~~~~~~~
 
+Changes to the HPT and HUG interface:
+
 - `addToHpt` and `addListToHPT` were moved from `GHC.Unit.Home.ModInfo` to `GHC.Unit.Home.PackageTable` and deprecated in favour of `addHomeModInfoToHpt` and `addHomeModInfosToHpt`.
 - `UnitEnvGraph` and operations `unitEnv_lookup_maybe`, `unitEnv_foldWithKey, `unitEnv_singleton`, `unitEnv_adjust`, `unitEnv_insert`, `unitEnv_new` were moved from `GHC.Unit.Env` to `GHC.Unit.Home.Graph`.
 - The HomePackageTable (HPT) is now exported from `GHC.Unit.Home.PackageTable`,
@@ -56,6 +58,8 @@ Cmm
 - `mkHomeUnitEnv` was moved to `GHC.Unit.Home.PackageTable`, and now takes two
   extra explicit arguments. To restore previous behaviour, pass `emptyUnitState`
   and `Nothing` as the first two arguments additionally.
+- `hugElts` was removed in favour of using `allUnits` to get all units in the
+  HUG (the typical use case), or `traverse` or `unitEnv_foldWithKey` in other cases.
 
 ``ghc-heap`` library
 ~~~~~~~~~~~~~~~~~~~~



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d6a62da7b6e358994515813c1c4a817491003476

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d6a62da7b6e358994515813c1c4a817491003476
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241213/ff29193c/attachment-0001.html>


More information about the ghc-commits mailing list