summaryrefslogtreecommitdiff
path: root/compiler/GHC/Unit
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-08-09 11:29:45 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-08-13 07:54:32 -0400
commitc367b39e5236b86b4923d826ab0395b33211d30a (patch)
tree658e595a18356bcda04f3f72b168eb86bc51bf99 /compiler/GHC/Unit
parent7ad813a480c9ed383fe1fea11a57f90d4f6f9b71 (diff)
downloadhaskell-c367b39e5236b86b4923d826ab0395b33211d30a.tar.gz
Refactoring module dependencies
* Make mkDependencies pure * Use Sets instead of sorted lists Notable perf changes: MultiLayerModules(normal) ghc/alloc 4130851520.0 2981473072.0 -27.8% T13719(normal) ghc/alloc 4313296052.0 4151647512.0 -3.7% Metric Decrease: MultiLayerModules T13719
Diffstat (limited to 'compiler/GHC/Unit')
-rw-r--r--compiler/GHC/Unit/Module/Deps.hs21
-rw-r--r--compiler/GHC/Unit/Module/ModGuts.hs4
-rw-r--r--compiler/GHC/Unit/Types.hs3
3 files changed, 22 insertions, 6 deletions
diff --git a/compiler/GHC/Unit/Module/Deps.hs b/compiler/GHC/Unit/Module/Deps.hs
index 9832383d8a..ebdd4b351f 100644
--- a/compiler/GHC/Unit/Module/Deps.hs
+++ b/compiler/GHC/Unit/Module/Deps.hs
@@ -16,6 +16,9 @@ import GHC.Unit.Module
import GHC.Utils.Fingerprint
import GHC.Utils.Binary
+import Data.Set (Set)
+import qualified Data.Set as Set
+
-- | Dependency information about ALL modules and packages below this one
-- in the import hierarchy. This is the serialisable version of `ImportAvails`.
--
@@ -25,10 +28,10 @@ import GHC.Utils.Binary
--
-- See Note [Transitive Information in Dependencies]
data Dependencies = Deps
- { dep_direct_mods :: [ModuleNameWithIsBoot]
+ { dep_direct_mods :: Set ModuleNameWithIsBoot
-- ^ All home-package modules which are directly imported by this one.
- , dep_direct_pkgs :: [UnitId]
+ , dep_direct_pkgs :: Set UnitId
-- ^ All packages directly imported by this module
-- I.e. packages to which this module's direct imports belong.
--
@@ -38,12 +41,12 @@ data Dependencies = Deps
-- ^ Transitive closure of hsig files in the home package
- , dep_trusted_pkgs :: [UnitId]
+ , dep_trusted_pkgs :: Set UnitId
-- Packages which we are required to trust
-- when the module is imported as a safe import
-- (Safe Haskell). See Note [Tracking Trust Transitively] in GHC.Rename.Names
- , dep_boot_mods :: [ModuleNameWithIsBoot]
+ , dep_boot_mods :: Set ModuleNameWithIsBoot
-- ^ All modules which have boot files below this one, and whether we
-- should use the boot file or not.
-- This information is only used to populate the eps_is_boot field.
@@ -96,7 +99,15 @@ instance Binary Dependencies where
dep_finsts = fis })
noDependencies :: Dependencies
-noDependencies = Deps [] [] [] [] [] [] []
+noDependencies = Deps
+ { dep_direct_mods = Set.empty
+ , dep_direct_pkgs = Set.empty
+ , dep_sig_mods = []
+ , dep_boot_mods = Set.empty
+ , dep_trusted_pkgs = Set.empty
+ , dep_orphs = []
+ , dep_finsts = []
+ }
-- | Records modules for which changes may force recompilation of this module
-- See wiki: https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler/recompilation-avoidance
diff --git a/compiler/GHC/Unit/Module/ModGuts.hs b/compiler/GHC/Unit/Module/ModGuts.hs
index e799ebf2a1..1558e5944a 100644
--- a/compiler/GHC/Unit/Module/ModGuts.hs
+++ b/compiler/GHC/Unit/Module/ModGuts.hs
@@ -36,6 +36,8 @@ import GHC.Types.SourceFile ( HscSource(..), hscSourceToIsBoot )
import GHC.Types.SrcLoc
import GHC.Types.CostCentre
+import Data.Set (Set)
+
-- | A ModGuts is carried through the compiler, accumulating stuff as it goes
-- There is only one ModGuts at any time, the one for the module
@@ -135,7 +137,7 @@ data CgGuts
cg_ccs :: [CostCentre], -- List of cost centres used in bindings and rules
cg_foreign :: !ForeignStubs, -- ^ Foreign export stubs
cg_foreign_files :: ![(ForeignSrcLang, FilePath)],
- cg_dep_pkgs :: ![UnitId], -- ^ Dependent packages, used to
+ cg_dep_pkgs :: !(Set UnitId), -- ^ Dependent packages, used to
-- generate #includes for C code gen
cg_hpc_info :: !HpcInfo, -- ^ Program coverage tick box information
cg_modBreaks :: !(Maybe ModBreaks), -- ^ Module breakpoints
diff --git a/compiler/GHC/Unit/Types.hs b/compiler/GHC/Unit/Types.hs
index 5dca26a90f..890e92b008 100644
--- a/compiler/GHC/Unit/Types.hs
+++ b/compiler/GHC/Unit/Types.hs
@@ -660,6 +660,9 @@ data GenWithIsBoot mod = GWIB
} deriving ( Eq, Ord, Show
, Functor, Foldable, Traversable
)
+ -- the Ord instance must ensure that we first sort by Module and then by
+ -- IsBootInterface: this is assumed to perform filtering of non-boot modules,
+ -- e.g. in GHC.Driver.Env.hptModulesBelow
type ModuleNameWithIsBoot = GenWithIsBoot ModuleName