summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBodigrim <andrew.lelechenko@gmail.com>2023-01-23 20:56:10 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-01-28 17:16:11 -0500
commit2b62739d7e6cc65f444029f252578f2dddb95ce3 (patch)
tree4df4fd28ce0e7b05d991fad8922cee4bceacc5fd /utils
parent6ea2aa0293aedea2f873b7b5d9cff5e7b9e2f188 (diff)
downloadhaskell-2b62739d7e6cc65f444029f252578f2dddb95ce3.tar.gz
Assorted changes to avoid Data.List.{head,tail}
Diffstat (limited to 'utils')
-rw-r--r--utils/check-exact/ExactPrint.hs9
-rw-r--r--utils/check-exact/Main.hs7
-rw-r--r--utils/check-exact/Preprocess.hs4
-rw-r--r--utils/check-exact/Transform.hs2
-rw-r--r--utils/check-exact/Utils.hs4
5 files changed, 14 insertions, 12 deletions
diff --git a/utils/check-exact/ExactPrint.hs b/utils/check-exact/ExactPrint.hs
index be7bb54c0d..a569b803d4 100644
--- a/utils/check-exact/ExactPrint.hs
+++ b/utils/check-exact/ExactPrint.hs
@@ -3696,12 +3696,13 @@ exactVanillaDeclHead :: (Monad m, Monoid w)
exactVanillaDeclHead thing tvs@(HsQTvs { hsq_explicit = tyvars }) fixity context = do
let
exact_tyvars (varl:varsr)
- | fixity == Infix && length varsr > 1 = do
+ | hvarsr : tvarsr@(_ : _) <- varsr
+ , fixity == Infix = do
varl' <- markAnnotated varl
thing' <- markAnnotated thing
- hvarsr <- markAnnotated (head varsr)
- tvarsr <- markAnnotated (tail varsr)
- return (thing', varl':hvarsr:tvarsr)
+ hvarsr' <- markAnnotated hvarsr
+ tvarsr' <- markAnnotated tvarsr
+ return (thing', varl':hvarsr':tvarsr')
| fixity == Infix = do
varl' <- markAnnotated varl
thing' <- markAnnotated thing
diff --git a/utils/check-exact/Main.hs b/utils/check-exact/Main.hs
index c4eedde74a..74525dd5f9 100644
--- a/utils/check-exact/Main.hs
+++ b/utils/check-exact/Main.hs
@@ -577,11 +577,11 @@ changeWhereIn3b :: Changer
changeWhereIn3b _libdir (L l p) = do
let decls0 = hsmodDecls p
(decls,_,w) = runTransform (balanceCommentsList decls0)
- (de0:_:de1:d2:_) = decls
+ (de0:tdecls@(_:de1:d2:_)) = decls
de0' = setEntryDP de0 (DifferentLine 2 0)
de1' = setEntryDP de1 (DifferentLine 2 0)
d2' = setEntryDP d2 (DifferentLine 2 0)
- decls' = d2':de1':de0':(tail decls)
+ decls' = d2':de1':de0':tdecls
debugM $ unlines w
debugM $ "changeWhereIn3b:de1':" ++ showAst de1'
let p2 = p { hsmodDecls = decls'}
@@ -799,8 +799,9 @@ rmDecl5 _libdir lp = do
go :: HsExpr GhcPs -> Transform (HsExpr GhcPs)
go (HsLet a tkLet lb tkIn expr) = do
decs <- hsDeclsValBinds lb
+ let hdecs : _ = decs
let dec = last decs
- _ <- transferEntryDP (head decs) dec
+ _ <- transferEntryDP hdecs dec
lb' <- replaceDeclsValbinds WithoutWhere lb [dec]
return (HsLet a tkLet lb' tkIn expr)
go x = return x
diff --git a/utils/check-exact/Preprocess.hs b/utils/check-exact/Preprocess.hs
index 756dc18984..55d84763f5 100644
--- a/utils/check-exact/Preprocess.hs
+++ b/utils/check-exact/Preprocess.hs
@@ -192,7 +192,7 @@ stripPreprocessorDirectives :: GHC.StringBuffer -> GHC.StringBuffer
stripPreprocessorDirectives buf = buf'
where
srcByLine = lines $ sbufToString buf
- noDirectivesLines = map (\line -> if line /= [] && head line == '#' then "" else line) srcByLine
+ noDirectivesLines = map (\line -> case line of '#' : _ -> ""; _ -> line) srcByLine
buf' = GHC.stringToStringBuffer $ unlines noDirectivesLines
-- ---------------------------------------------------------------------
@@ -259,7 +259,7 @@ fingerprintStrings ss = GHC.fingerprintFingerprints $ map GHC.fingerprintString
getPreprocessorAsComments :: FilePath -> IO [(GHC.Located GHC.Token, String)]
getPreprocessorAsComments srcFile = do
fcontents <- readFileGhc srcFile
- let directives = filter (\(_lineNum,line) -> line /= [] && head line == '#')
+ let directives = filter (\(_lineNum,line) -> case line of '#' : _ -> True; _ -> False)
$ zip [1..] (lines fcontents)
let mkTok (lineNum,line) = (GHC.L l (GHC.ITlineComment line (makeBufSpan l)),line)
diff --git a/utils/check-exact/Transform.hs b/utils/check-exact/Transform.hs
index 3e3ebdcb39..45f3612a76 100644
--- a/utils/check-exact/Transform.hs
+++ b/utils/check-exact/Transform.hs
@@ -322,7 +322,7 @@ setEntryDP (L (SrcSpanAnn (EpAnn (Anchor r _) an cs) l) a) dp
l) a
where
cs'' = setPriorComments cs (L (Anchor (anchor ca) (MovedAnchor dp)) c:cs')
- lc = head $ reverse $ (L ca c:cs')
+ lc = last $ (L ca c:cs')
delta = tweakDelta $ ss2delta (ss2pos $ anchor $ getLoc lc) r
line = getDeltaLine delta
col = deltaColumn delta
diff --git a/utils/check-exact/Utils.hs b/utils/check-exact/Utils.hs
index b60c989bcf..14a05a2337 100644
--- a/utils/check-exact/Utils.hs
+++ b/utils/check-exact/Utils.hs
@@ -458,8 +458,8 @@ glast info [] = error $ "glast " ++ info ++ " []"
glast _info h = last h
gtail :: String -> [a] -> [a]
-gtail info [] = error $ "gtail " ++ info ++ " []"
-gtail _info h = tail h
+gtail info [] = error $ "gtail " ++ info ++ " []"
+gtail _info (_:t) = t
gfromJust :: String -> Maybe a -> a
gfromJust _info (Just h) = h