Skip to content

Unit refactoring

Sylvain Henry requested to merge hsyl20/ghc:hsyl20-unitid into master

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 of Unit (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 and WiredInUnitId = UnitId (we use UnitId directly now). This is preliminary work before we can give the wiring map the type Map UnitId UnitKey.

  • Remove the use for a Backpack specific UnitInfoMap datatype. Its two fields have been unpacked into UnitState. InstalledPackageIndex is now renamed into UnitInfoMap.

  • GHC.Unit.Subst has been merged into GHC.Unit.State. Less SOURCE imports: good.

Edited by Sylvain Henry

Merge request reports