[commit: ghc] wip/nfs-locking: Use Extra library (693a66c)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:04:00 UTC 2017


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

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/693a66cafe77e0ea2449e9f7b4bc51145c97ab38/ghc

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

commit 693a66cafe77e0ea2449e9f7b4bc51145c97ab38
Author: Moritz Angermann <moritz.angermann at gmail.com>
Date:   Sat Jan 9 17:04:58 2016 +0800

    Use Extra library
    
    - replaces `wordsWhen` with `wordsBy`
    - replaces `replace` with `replace`
    Fixes #130


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

693a66cafe77e0ea2449e9f7b4bc51145c97ab38
 src/Base.hs                 | 23 ++---------------------
 src/Oracles/LookupInPath.hs |  3 ++-
 src/Rules/Data.hs           |  1 +
 src/Rules/Libffi.hs         |  1 +
 4 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/src/Base.hs b/src/Base.hs
index 925c427..fb33907 100644
--- a/src/Base.hs
+++ b/src/Base.hs
@@ -22,9 +22,9 @@ module Base (
     putColoured, putOracle, putBuild, putSuccess, putError, renderBox,
 
     -- * Miscellaneous utilities
-    bimap, minusOrd, intersectOrd, replaceEq, replace, quote, chunksOfSize,
+    bimap, minusOrd, intersectOrd, replaceEq, quote, chunksOfSize,
     replaceSeparators, decodeModule, encodeModule, unifyPath, (-/-),
-    versionToInt, removeFileIfExists, removeDirectoryIfExists, wordsWhen
+    versionToInt, removeFileIfExists, removeDirectoryIfExists
     ) where
 
 import Control.Applicative
@@ -90,25 +90,6 @@ replaceSeparators = replaceWhen isPathSeparator
 replaceWhen :: (a -> Bool) -> a -> [a] -> [a]
 replaceWhen p to = map (\from -> if p from then to else from)
 
--- | Find all occurrences of substring 'from' and replace them to 'to' in a
--- given string. Not very efficient, but simple and fast enough for our purposes
-replace :: Eq a => [a] -> [a] -> [a] -> [a]
-replace from to = go
-  where
-    skipFrom = drop $ length from
-    go [] = []
-    go s @ (x : xs)
-        | from `isPrefixOf` s = to ++ go (skipFrom s)
-        | otherwise           = x  :  go xs
-
--- | Split a list into chunks in places where the predicate @p@ holds.
--- See: http://stackoverflow.com/a/4981265
-wordsWhen :: Eq a => (a -> Bool) -> [a] -> [[a]]
-wordsWhen p list =
-    case dropWhile p list of
-        [] -> []
-        l  -> w : wordsWhen p rest where (w, rest) = break p l
-
 -- | @chunksOfSize size strings@ splits a given list of strings into chunks not
 -- exceeding the given @size at .
 chunksOfSize :: Int -> [String] -> [[String]]
diff --git a/src/Oracles/LookupInPath.hs b/src/Oracles/LookupInPath.hs
index c2a05e2..2532cb9 100644
--- a/src/Oracles/LookupInPath.hs
+++ b/src/Oracles/LookupInPath.hs
@@ -4,6 +4,7 @@ module Oracles.LookupInPath (
     ) where
 
 import Base
+import Extra (wordsBy)
 
 newtype LookupInPath = LookupInPath String
     deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
@@ -22,7 +23,7 @@ lookupInPath c
 lookupInPathOracle :: Rules ()
 lookupInPathOracle = do
     o <- newCache $ \c -> do
-        envPaths <- wordsWhen (== ':') <$> getEnvWithDefault "" "PATH"
+        envPaths <- wordsBy (== ':') <$> getEnvWithDefault "" "PATH"
         let candidates = map (-/- c) envPaths
         -- this will crash if we do not find any valid candidate.
         fullCommand <- head <$> filterM doesFileExist candidates
diff --git a/src/Rules/Data.hs b/src/Rules/Data.hs
index de4f8c0..b2c5878 100644
--- a/src/Rules/Data.hs
+++ b/src/Rules/Data.hs
@@ -2,6 +2,7 @@ module Rules.Data (buildPackageData) where
 
 import Base
 import Expression
+import Extra (replace)
 import GHC
 import Oracles
 import Predicates (registerPackage)
diff --git a/src/Rules/Libffi.hs b/src/Rules/Libffi.hs
index 9d77814..31f249b 100644
--- a/src/Rules/Libffi.hs
+++ b/src/Rules/Libffi.hs
@@ -2,6 +2,7 @@ module Rules.Libffi (libffiRules, libffiDependencies) where
 
 import Base
 import Expression
+import Extra (replace)
 import GHC
 import Oracles
 import Rules.Actions



More information about the ghc-commits mailing list