summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorBartosz Nitka <niteria@gmail.com>2017-05-31 10:47:03 -0700
committerBartosz Nitka <niteria@gmail.com>2017-07-18 05:27:01 -0700
commitb8fec6950ad99cbf11cd22698b8d5ab35afb828f (patch)
treeda026b84ac5cfbf34c910d526fda9e106298cccb /ghc
parent935acb6f0de36822b46f8444199dbc37de784af4 (diff)
downloadhaskell-b8fec6950ad99cbf11cd22698b8d5ab35afb828f.tar.gz
Make module membership on ModuleGraph faster
When loading/reloading with a large number of modules (>5000) the cost of linear lookups becomes significant. The changes here made `:reload` go from 6s to 1s on my test case. The bottlenecks were `needsLinker` in `DriverPipeline` and `getModLoop` in `GhcMake`. Test Plan: ./validate Reviewers: simonmar, austin, bgamari Subscribers: thomie, rwbarton Differential Revision: https://phabricator.haskell.org/D3703
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI.hs23
-rw-r--r--ghc/GHCi/UI/Tags.hs2
2 files changed, 14 insertions, 11 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index d58724037f..8012d741e0 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -1403,7 +1403,7 @@ changeDirectory "" = do
Right dir -> changeDirectory dir
changeDirectory dir = do
graph <- GHC.getModuleGraph
- when (not (null graph)) $
+ when (not (null $ GHC.mgModSummaries graph)) $
liftIO $ putStrLn "Warning: changing directory causes all loaded modules to be unloaded,\nbecause the search path has changed."
GHC.setTargets []
_ <- GHC.load LoadAllTargets
@@ -1463,7 +1463,8 @@ chooseEditFile =
do let hasFailed x = fmap not $ GHC.isLoaded $ GHC.ms_mod_name x
graph <- GHC.getModuleGraph
- failed_graph <- filterM hasFailed graph
+ failed_graph <-
+ GHC.mkModuleGraph <$> filterM hasFailed (GHC.mgModSummaries graph)
let order g = flattenSCCs $ GHC.topSortModuleGraph True g Nothing
pick xs = case xs of
x : _ -> GHC.ml_hs_file (GHC.ms_location x)
@@ -1689,7 +1690,8 @@ doLoadAndCollectInfo retain_context howmuch = do
doLoad retain_context howmuch >>= \case
Succeeded | doCollectInfo -> do
- loaded <- getModuleGraph >>= filterM GHC.isLoaded . map GHC.ms_mod_name
+ mod_summaries <- GHC.mgModSummaries <$> getModuleGraph
+ loaded <- filterM GHC.isLoaded $ map GHC.ms_mod_name mod_summaries
v <- mod_infos <$> getGHCiState
!newInfos <- collectInfo v loaded
modifyGHCiState (\st -> st { mod_infos = newInfos })
@@ -1734,8 +1736,9 @@ setContextAfterLoad keep_ctxt ms = do
targets <- GHC.getTargets
case [ m | Just m <- map (findTarget ms) targets ] of
[] ->
- let graph' = flattenSCCs (GHC.topSortModuleGraph True ms Nothing) in
- load_this (last graph')
+ let graph = GHC.mkModuleGraph ms
+ graph' = flattenSCCs (GHC.topSortModuleGraph True graph Nothing)
+ in load_this (last graph')
(m:_) ->
load_this m
where
@@ -2813,7 +2816,7 @@ showModules = do
getLoadedModules :: GHC.GhcMonad m => m [GHC.ModSummary]
getLoadedModules = do
graph <- GHC.getModuleGraph
- filterM (GHC.isLoaded . GHC.ms_mod_name) graph
+ filterM (GHC.isLoaded . GHC.ms_mod_name) (GHC.mgModSummaries graph)
showBindings :: GHCi ()
showBindings = do
@@ -3050,7 +3053,7 @@ completeHomeModule = wrapIdentCompleter listHomeModules
listHomeModules :: String -> GHCi [String]
listHomeModules w = do
g <- GHC.getModuleGraph
- let home_mods = map GHC.ms_mod_name g
+ let home_mods = map GHC.ms_mod_name (GHC.mgModSummaries g)
dflags <- getDynFlags
return $ sort $ filter (w `isPrefixOf`)
$ map (showPpr dflags) home_mods
@@ -3492,10 +3495,10 @@ list2 _other =
listModuleLine :: Module -> Int -> InputT GHCi ()
listModuleLine modl line = do
graph <- GHC.getModuleGraph
- let this = filter ((== modl) . GHC.ms_mod) graph
+ let this = GHC.mgLookupModule graph modl
case this of
- [] -> panic "listModuleLine"
- summ:_ -> do
+ Nothing -> panic "listModuleLine"
+ Just summ -> do
let filename = expectJust "listModuleLine" (ml_hs_file (GHC.ms_location summ))
loc = mkRealSrcLoc (mkFastString (filename)) line 0
listAround (realSrcLocSpan loc) False
diff --git a/ghc/GHCi/UI/Tags.hs b/ghc/GHCi/UI/Tags.hs
index c23db57f81..d8af7f8718 100644
--- a/ghc/GHCi/UI/Tags.hs
+++ b/ghc/GHCi/UI/Tags.hs
@@ -72,7 +72,7 @@ ghciCreateTagsFile kind file = do
createTagsFile :: TagsKind -> FilePath -> GHCi ()
createTagsFile tagskind tagsFile = do
graph <- GHC.getModuleGraph
- mtags <- mapM listModuleTags (map GHC.ms_mod graph)
+ mtags <- mapM listModuleTags (map GHC.ms_mod $ GHC.mgModSummaries graph)
either_res <- liftIO $ collateAndWriteTags tagskind tagsFile $ concat mtags
case either_res of
Left e -> liftIO $ hPutStrLn stderr $ ioeGetErrorString e