summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Feuer <david.feuer@gmail.com>2017-02-07 21:38:34 -0500
committerDavid Feuer <David.Feuer@gmail.com>2017-02-07 21:38:35 -0500
commite90f611d2c4d4cfea80400b4dce30e9659ae0655 (patch)
tree143e09a186b95cc71461000c7ef615f9f54a56a8
parentd5e9b7f5b84440e0e81515773c8fa31cbaebfd57 (diff)
downloadhaskell-e90f611d2c4d4cfea80400b4dce30e9659ae0655.tar.gz
Clean up findPartiallyCompletedCycles
Rewrite `findPartiallyCompletedCycles` to use a list comprehension rather than pattern matching on a list. Make it use `Data.Set` rather than fussing with lists. Reviewers: austin, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D3102
-rw-r--r--compiler/main/GhcMake.hs29
1 files changed, 12 insertions, 17 deletions
diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs
index 77b9581a2e..b518518b1f 100644
--- a/compiler/main/GhcMake.hs
+++ b/compiler/main/GhcMake.hs
@@ -414,7 +414,7 @@ load' how_much mHscMessage mod_graph = do
= findPartiallyCompletedCycles modsDone_names
mg2_with_srcimps
let mods_to_keep
- = filter ((`notElem` mods_to_zap_names).ms_mod)
+ = filter ((`Set.notMember` mods_to_zap_names).ms_mod)
modsDone
hsc_env1 <- getSession
@@ -575,23 +575,18 @@ pruneHomePackageTable hpt summ (stable_obj, stable_bco)
--
-- | Return (names of) all those in modsDone who are part of a cycle as defined
-- by theGraph.
-findPartiallyCompletedCycles :: [Module] -> [SCC ModSummary] -> [Module]
+findPartiallyCompletedCycles :: [Module] -> [SCC ModSummary] -> Set.Set Module
findPartiallyCompletedCycles modsDone theGraph
- = chew theGraph
- where
- chew [] = []
- chew ((AcyclicSCC _):rest) = chew rest -- acyclic? not interesting.
- chew ((CyclicSCC vs):rest)
- = let names_in_this_cycle = nub (map ms_mod vs)
- mods_in_this_cycle
- = nub ([done | done <- modsDone,
- done `elem` names_in_this_cycle])
- chewed_rest = chew rest
- in
- if notNull mods_in_this_cycle
- && length mods_in_this_cycle < length names_in_this_cycle
- then mods_in_this_cycle ++ chewed_rest
- else chewed_rest
+ = Set.unions
+ [mods_in_this_cycle
+ | CyclicSCC vs <- theGraph -- Acyclic? Not interesting.
+ , let names_in_this_cycle = Set.fromList (map ms_mod vs)
+ mods_in_this_cycle =
+ Set.intersection (Set.fromList modsDone) names_in_this_cycle
+ -- If size mods_in_this_cycle == size names_in_this_cycle,
+ -- then this cycle has already been completed and we're not
+ -- interested.
+ , Set.size mods_in_this_cycle < Set.size names_in_this_cycle]
-- ---------------------------------------------------------------------------