Unit refactoring
The aim of this patch is to work towards fixing #14335. To do that I did quite a lot of refactoring to avoid passing DynFlags to every function (#17957). I've also added some documentation (especially about Backpack, #17525).
Main outcome: we don't need a DynFlags anymore to initialize units. mkUnitState
takes an UnitConfig
argument instead. It will be used to fix #14335 by initializing a second UnitState
for plugins (UnitState
contains loaded units, the wiring map, etc.).
Refactorings:
-
Remove some useless type aliases (
LinkerUnitId
,PreloadUnitId
) -
Several renamings to use "Unit" instead of "Package". The terminology changed over time and now package databases contain "units" (there can be several units compiled from a single Cabal package: one per-component, one for each option set, one per instantiation, etc.). We should try to be consistent internally and use "units": that's what this renaming does. Maybe one day we'll fix the UI too (e.g. replace
-package-id
with-unit-id
, we already have-this-unit-id
and ghc-pkg already has-unit-id
...) but it's not done in this patch. -
Use
UnitId
in the backend instead ofUnit
(which is only useful for Backpack: module holes and type-checking on-the-fly instantiated units) -
Refactor the wiring map (mapping wired-in unit ids to real unit keys in the db) to avoid having both
WiredUnitId = DefUnitId
andWiredInUnitId = UnitId
(we useUnitId
directly now). This is preliminary work before we can give the wiring map the typeMap UnitId UnitKey
. -
Remove the use for a Backpack specific
UnitInfoMap
datatype. Its two fields have been unpacked intoUnitState
.InstalledPackageIndex
is now renamed intoUnitInfoMap
. -
GHC.Unit.Subst
has been merged intoGHC.Unit.State
. Less SOURCE imports: good.