[commit: ghc] master: Clean up findPartiallyCompletedCycles (e90f611)

git at git.haskell.org git at git.haskell.org
Wed Feb 8 02:41:39 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/e90f611d2c4d4cfea80400b4dce30e9659ae0655/ghc

>---------------------------------------------------------------

commit e90f611d2c4d4cfea80400b4dce30e9659ae0655
Author: David Feuer <david.feuer at gmail.com>
Date:   Tue Feb 7 21:38:34 2017 -0500

    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


>---------------------------------------------------------------

e90f611d2c4d4cfea80400b4dce30e9659ae0655
 compiler/main/GhcMake.hs | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs
index 77b9581..b518518 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]
 
 
 -- ---------------------------------------------------------------------------



More information about the ghc-commits mailing list