[Git][ghc/ghc][wip/T25693] 2 commits: hadrian: Drop uses of head/tail

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Fri Feb 7 21:16:55 UTC 2025



Ben Gamari pushed to branch wip/T25693 at Glasgow Haskell Compiler / GHC


Commits:
f47bcc22 by Ben Gamari at 2025-02-07T16:16:49-05:00
hadrian: Drop uses of head/tail

To silence warnings with GHC 9.10

- - - - -
30528c4a by Ben Gamari at 2025-02-07T16:16:49-05:00
hadrian: Disable x-data-list-nonempty-unzip warning

- - - - -


4 changed files:

- hadrian/src/Hadrian/Utilities.hs
- hadrian/src/Oracles/ModuleFiles.hs
- hadrian/src/Rules/Dependencies.hs
- hadrian/src/Settings/Parser.hs


Changes:

=====================================
hadrian/src/Hadrian/Utilities.hs
=====================================
@@ -149,7 +149,10 @@ as /c/foo, while it occasionally falls over on paths of the form C:\foo.
 --
 -- See Note [Absolute paths and MSYS].
 (-/-) :: FilePath -> FilePath -> FilePath
-_  -/- b | isAbsolute b && not (isAbsolute $ tail b) = b
+_  -/- b
+    | isAbsolute b
+    , _:b' <- b
+    , not (isAbsolute b') = b
 "" -/- b = b
 a  -/- b
     | last a == '/' = a ++       b
@@ -636,7 +639,8 @@ renderLibrary name lib synopsis = renderBox $
 -- | ipsum    |
 -- \----------/
 renderBox :: [String] -> String
-renderBox ls = tail $ concatMap ('\n' :) (boxTop : map renderLine ls ++ [boxBot])
+renderBox ls =
+    drop 1 $ concatMap ('\n' :) (boxTop : map renderLine ls ++ [boxBot])
   where
     -- Minimum total width of the box in characters
     minimumBoxWidth = 32


=====================================
hadrian/src/Oracles/ModuleFiles.hs
=====================================
@@ -169,10 +169,12 @@ moduleFilesOracle = void $ do
 
         let pairs = sort $ mainpairs ++ [ (encodeModule d f, f) | (fs, d) <- result, f <- fs ]
             multi = [ (m, f1, f2) | (m, f1):(n, f2):_ <- tails pairs, m == n ]
-        unless (null multi) $ do
-            let (m, f1, f2) = head multi
-            error $ "Module " ++ m ++ " has more than one source file: "
-                ++ f1 ++ " and " ++ f2 ++ "."
+
+        case multi of
+            [] -> return ()
+            (m, f1, f2) : _ ->
+              fail $ "Module " ++ m ++ " has more than one source file: "
+                  ++ f1 ++ " and " ++ f2 ++ "."
         return $ lookupAll modules pairs
 
     -- Optimisation: we discard Haskell files here, because they are never used


=====================================
hadrian/src/Rules/Dependencies.hs
=====================================
@@ -1,4 +1,5 @@
 {-# OPTIONS_GHC -Wno-deprecations #-}
+{-# OPTIONS_GHC -Wno-x-data-list-nonempty-unzip #-}
 
 module Rules.Dependencies (buildPackageDependencies) where
 


=====================================
hadrian/src/Settings/Parser.hs
=====================================
@@ -184,14 +184,11 @@ instance Match SettingsM where
 matchStringSettingsM :: String -> SettingsM ()
 matchStringSettingsM s = do
   ks <- State.get
-  if null ks
-    then throwError $ "expected " ++ show s ++ ", got nothing"
-    else go (head ks)
-
-  where go k
-          | k == s = State.modify tail
-          | otherwise = throwError $
-              "expected " ++ show s ++ ", got " ++ show k
+  case ks of
+    []            -> throwError $ "expected " ++ show s ++ ", got nothing"
+    k:_
+      | k == s    -> State.modify (drop 1)
+      | otherwise -> throwError $ "expected " ++ show s ++ ", got " ++ show k
 
 matchOneOfSettingsM :: [SettingsM a] -> SettingsM a
 matchOneOfSettingsM acts = StateT $ \k -> do



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/123db91417734ff5b6080cfa86b16fad60538766...30528c4a2b0cd8b0ece1f33c4328737010dfbc4a

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/123db91417734ff5b6080cfa86b16fad60538766...30528c4a2b0cd8b0ece1f33c4328737010dfbc4a
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20250207/0b94079e/attachment-0001.html>


More information about the ghc-commits mailing list