on master help sign in
Fix hlint issues in benchmarks
commita067d5363218e9f9ef532ac27525e8db1cf9c393 authorHarendra Kumar <harendra@composewell.com> dateMon 18 Dec 2023, 23:14 (3 years ago) parentce86302
7 files changed+19−19
.hlint.ignore+1 benchmark/Streamly/Benchmark/Data/Fold.hs+2−2 benchmark/Streamly/Benchmark/Data/Serialize.hs+9−12 benchmark/Streamly/Benchmark/Data/Serialize/TH.hs+3−3 benchmark/Streamly/Benchmark/Data/Stream/Eliminate.hs+2 benchmark/Streamly/Benchmark/Data/Stream/StreamKAlt.hs+1−1 benchmark/Streamly/Benchmark/Data/Stream/ToStreamK.hs+1−1
.hlint.ignore+1
@@ -31,6 +31,7 @@ benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs
3131benchmark/Streamly/Benchmark/Data/Unfold.hs
3232benchmark/Streamly/Benchmark/FileSystem/Handle.hs
3333benchmark/Streamly/Benchmark/Prelude/Async.hs
34+benchmark/Streamly/Benchmark/Prelude/Concurrent.hs
3435benchmark/Streamly/Benchmark/Prelude/Merge.hs
3536benchmark/Streamly/Benchmark/Prelude/Parallel.hs
3637benchmark/Streamly/Benchmark/Prelude/Rate.hs
benchmark/Streamly/Benchmark/Data/Fold.hs+2−2
@@ -269,13 +269,13 @@ unzip = Stream.fold $ FL.lmap (\a -> (a, a)) (FL.unzip FL.sum FL.length)
269269{-# INLINE unzipWithFstM #-}
270270unzipWithFstM :: Monad m => Stream m Int -> m (Int, Int)
271271unzipWithFstM = do
272− let f = \a -> return (a + 1, a)
272+ let f a = return (a + 1, a)
273273 Stream.fold (FL.unzipWithFstM f FL.sum FL.length)
274274
275275{-# INLINE unzipWithMinM #-}
276276unzipWithMinM :: Monad m => Stream m Int -> m (Int, Int)
277277unzipWithMinM = do
278− let f = \a -> return (a + 1, a)
278+ let f a = return (a + 1, a)
279279 Stream.fold (FL.unzipWithMinM f FL.sum FL.length)
280280
281281-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/Data/Serialize.hs+9−12
@@ -1,4 +1,5 @@
11{-# LANGUAGE TemplateHaskell #-}
2+{- HLINT ignore -}
23
34#undef FUSION_CHECK
45#ifdef FUSION_CHECK
@@ -18,6 +19,7 @@ module Main (main) where
1819-------------------------------------------------------------------------------
1920
2021import Control.DeepSeq (NFData(..), deepseq)
22+import Control.Monad (when, void)
2123import GHC.Generics (Generic)
2224import System.Random (randomRIO)
2325#ifndef USE_UNBOX
@@ -264,13 +266,13 @@ $(deriveSerialize [d|instance Serialize a => Serialize (BinTree a)|])
264266instance NFData a => NFData (BinTree a) where
265267 {-# INLINE rnf #-}
266268 rnf (Leaf a) = rnf a `seq` ()
267− rnf (Tree l r) = rnf l `seq` rnf r `seq` ()
269+ rnf (Tree l r) = rnf l `seq` rnf r
268270
269271instance Arbitrary a => Arbitrary (BinTree a) where
270272 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
271273
272274mkBinTree :: (Arbitrary a) => Int -> IO (BinTree a)
273−mkBinTree = go (generate $ arbitrary)
275+mkBinTree = go (generate arbitrary)
274276
275277 where
276278
@@ -295,16 +297,14 @@ getSize = addSizeTo 0
295297-- Common helpers
296298-------------------------------------------------------------------------------
297299
300+{- HLINT ignore "Eta reduce" -}
298301-- Parts of "f" that are dependent on val will not be optimized out.
299302{-# INLINE loop #-}
300303loop :: Int -> (a -> IO b) -> a -> IO ()
301304loop count f val = go count val
302305 where
303306
304− go n x = do
305− if n > 0
306− then f x >> go (n-1) x
307− else return ()
307+ go n x = when (n > 0) $ f x >> go (n-1) x
308308
309309-- The first arg of "f" is the environment which is not threaded around in the
310310-- loop.
@@ -313,10 +313,7 @@ loopWith :: Int -> (e -> a -> IO b) -> e -> a -> IO ()
313313loopWith count f e val = go count val
314314 where
315315
316− go n x = do
317− if n > 0
318− then f e x >> go (n-1) x
319− else return ()
316+ go n x = when (n > 0) $ f e x >> go (n-1) x
320317
321318benchSink :: NFData b => String -> Int -> (Int -> IO b) -> Benchmark
322319benchSink name times f = bench name (nfIO (randomRIO (times, times) >>= f))
@@ -342,7 +339,7 @@ pokeTimesWithSize val times = do
342339
343340{-# INLINE poke #-}
344341poke :: SERIALIZE_CLASS a => MutByteArray -> a -> IO ()
345−poke arr val = SERIALIZE_OP 0 arr val >> return ()
342+poke arr val = void (SERIALIZE_OP 0 arr val)
346343
347344{-# INLINE pokeTimes #-}
348345pokeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
@@ -356,7 +353,7 @@ encode :: SERIALIZE_CLASS a => a -> IO ()
356353encode val = do
357354 let n = getSize val
358355 arr <- MBA.new n
359− SERIALIZE_OP 0 arr val >> return ()
356+ void (SERIALIZE_OP 0 arr val)
360357
361358{-# INLINE encodeTimes #-}
362359encodeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
benchmark/Streamly/Benchmark/Data/Serialize/TH.hs+3−3
@@ -18,7 +18,7 @@ import Control.DeepSeq (NFData(..))
1818genLargeRecord :: String -> Int -> Q [Dec]
1919genLargeRecord tyName numFields =
2020 sequence
21− ([ dataD
21+ [ dataD
2222 (pure [])
2323 (mkName tyName)
2424 []
@@ -28,7 +28,7 @@ genLargeRecord tyName numFields =
2828 , mkValueSigDec
2929 , mkValueDec
3030 , nfDataInstance tyName
31− ])
31+ ]
3232
3333 where
3434
@@ -64,7 +64,7 @@ genLargeRecord tyName numFields =
6464 (foldl
6565 (\b a -> [|$(b) $(a)|])
6666 (conE (mkName tyName))
67− (const (conE '()) <$> [0 .. (numFields - 1)])))
67+ (conE '() <$ [0 .. (numFields - 1)])))
6868 []
6969 ]
7070 mkCon nm = recC (mkName nm) (mkField <$> [0 .. (numFields - 1)])
benchmark/Streamly/Benchmark/Data/Stream/Eliminate.hs+2
@@ -132,12 +132,14 @@ foldableAny :: Int -> Int -> Bool
132132foldableAny value n =
133133 Prelude.any (> (value + 1)) (sourceUnfoldr value n :: Stream Identity Int)
134134
135+{- HLINT ignore "Use all"-}
135136{-# INLINE foldableAnd #-}
136137foldableAnd :: Int -> Int -> Bool
137138foldableAnd value n =
138139 Prelude.and $ fmap
139140 (<= (value + 1)) (sourceUnfoldr value n :: Stream Identity Int)
140141
142+{- HLINT ignore "Use any"-}
141143{-# INLINE foldableOr #-}
142144foldableOr :: Int -> Int -> Bool
143145foldableOr value n =
benchmark/Streamly/Benchmark/Data/Stream/StreamKAlt.hs+1−1
@@ -452,4 +452,4 @@ o_1_space =
452452 ]
453453
454454main :: IO ()
455−main = defaultMain $ concat [o_1_space]
455+main = defaultMain [o_1_space]
benchmark/Streamly/Benchmark/Data/Stream/ToStreamK.hs+1−1
@@ -120,7 +120,7 @@ fromFoldable streamLen n = S.fromFoldable [n..n+streamLen]
120120{-# INLINE fromFoldableM #-}
121121fromFoldableM :: Monad m => Int -> Int -> Stream m Int
122122fromFoldableM streamLen n =
123− Prelude.foldr S.consM S.nil (Prelude.fmap return [n..n+streamLen])
123+ Prelude.foldr (S.consM . return) S.nil [n .. n + streamLen]
124124
125125{-
126126{-# INLINABLE concatMapFoldableWith #-}