diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-05-05 13:48:19 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-05-19 23:33:02 -0400 |
commit | 38faeea1a94072ffd9f459d9fe570f06bc1da84a (patch) | |
tree | 00df888e529aa208e40589fe3f73790906324b8b /compiler/GHC/HsToCore/Usage.hs | |
parent | c8564c639a9889d4d19c68f4b96c092f670b092c (diff) | |
download | haskell-38faeea1a94072ffd9f459d9fe570f06bc1da84a.tar.gz |
Remove transitive information about modules and packages from interface files
This commit modifies interface files so that *only* direct information
about modules and packages is stored in the interface file.
* Only direct module and direct package dependencies are stored in the
interface files.
* Trusted packages are now stored separately as they need to be checked
transitively.
* hs-boot files below the compiled module in the home module are stored
so that eps_is_boot can be calculated in one-shot mode without loading
all interface files in the home package.
* The transitive closure of signatures is stored separately
This is important for two reasons
* Less recompilation is needed, as motivated by #16885, a lot of
redundant compilation was triggered when adding new imports deep in the
module tree as all the parent interface files had to be redundantly
updated.
* Checking an interface file is cheaper because you don't have to
perform a transitive traversal to check the dependencies are up-to-date.
In the code, places where we would have used the transitive closure, we
instead compute the necessary transitive closure. The closure is not
computed very often, was already happening in checkDependencies, and
was already happening in getLinkDeps.
Fixes #16885
-------------------------
Metric Decrease:
MultiLayerModules
T13701
T13719
-------------------------
Diffstat (limited to 'compiler/GHC/HsToCore/Usage.hs')
-rw-r--r-- | compiler/GHC/HsToCore/Usage.hs | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/compiler/GHC/HsToCore/Usage.hs b/compiler/GHC/HsToCore/Usage.hs index 139ec05167..0da8f59070 100644 --- a/compiler/GHC/HsToCore/Usage.hs +++ b/compiler/GHC/HsToCore/Usage.hs @@ -38,11 +38,12 @@ import GHC.Unit.Module.Deps import GHC.Data.Maybe import Control.Monad (filterM) -import Data.List (sort, sortBy, nub) +import Data.List (sortBy, sort, nub) import Data.IORef import Data.Map (Map) import qualified Data.Map as Map import qualified Data.Set as Set + import System.Directory import System.FilePath @@ -80,8 +81,7 @@ mkDependencies iuid pluginModules let (dep_plgins, ms) = unzip [ (moduleName mn, mn) | mn <- pluginModules ] plugin_dep_pkgs = filter (/= iuid) (map (toUnitId . moduleUnit) ms) th_used <- readIORef th_var - let dep_mods = modDepsElts (delFromUFM (imp_dep_mods imports) - (moduleName mod)) + let direct_mods = modDepsElts (delFromUFM (imp_direct_dep_mods imports) (moduleName mod)) -- M.hi-boot can be in the imp_dep_mods, but we must remove -- it before recording the modules on which this one depends! -- (We want to retain M.hi-boot in imp_dep_mods so that @@ -93,19 +93,28 @@ mkDependencies iuid pluginModules -- We must also remove self-references from imp_orphs. See -- Note [Module self-dependency] - raw_pkgs = foldr Set.insert (imp_dep_pkgs imports) plugin_dep_pkgs + direct_pkgs_0 = foldr Set.insert (imp_dep_direct_pkgs imports) plugin_dep_pkgs - pkgs | th_used = Set.insert thUnitId raw_pkgs - | otherwise = raw_pkgs + direct_pkgs + | th_used = Set.insert thUnitId direct_pkgs_0 + | otherwise = direct_pkgs_0 -- Set the packages required to be Safe according to Safe Haskell. -- See Note [Tracking Trust Transitively] in GHC.Rename.Names - sorted_pkgs = sort (Set.toList pkgs) + sorted_direct_pkgs = sort (Set.toList direct_pkgs) trust_pkgs = imp_trust_pkgs imports - dep_pkgs' = map (\x -> (x, x `Set.member` trust_pkgs)) sorted_pkgs - - return Deps { dep_mods = dep_mods, - dep_pkgs = dep_pkgs', + -- If there's a non-boot import, then it shadows the boot import + -- coming from the dependencies + source_mods = + modDepsElts $ (imp_boot_mods imports) + + sig_mods = filter (/= (moduleName mod)) $ imp_sig_mods imports + + return Deps { dep_direct_mods = direct_mods, + dep_direct_pkgs = sorted_direct_pkgs, + dep_sig_mods = sort sig_mods, + dep_trusted_pkgs = sort (Set.toList trust_pkgs), + dep_boot_mods = sort source_mods, dep_orphs = dep_orphs, dep_plgins = dep_plgins, dep_finsts = sortBy stableModuleCmp (imp_finsts imports) } @@ -235,7 +244,7 @@ mkPluginUsage hsc_env pluginModule pNm = moduleName $ mi_module pluginModule pPkg = moduleUnit $ mi_module pluginModule deps = map gwib_mod $ - dep_mods $ mi_deps pluginModule + dep_direct_mods $ mi_deps pluginModule -- Lookup object file for a plugin dependency, -- from the same package as the plugin. |