on master help sign in
Fix hlint issues in benchmarks
a067d53Harendra Kumar
.hlint.ignore+1
@@ -31,6 +31,7 @@ benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs
31benchmark/Streamly/Benchmark/Data/Unfold.hs
31benchmark/Streamly/Benchmark/Data/Unfold.hs
32benchmark/Streamly/Benchmark/FileSystem/Handle.hs
32benchmark/Streamly/Benchmark/FileSystem/Handle.hs
33benchmark/Streamly/Benchmark/Prelude/Async.hs
33benchmark/Streamly/Benchmark/Prelude/Async.hs
34+benchmark/Streamly/Benchmark/Prelude/Concurrent.hs
34benchmark/Streamly/Benchmark/Prelude/Merge.hs
35benchmark/Streamly/Benchmark/Prelude/Merge.hs
35benchmark/Streamly/Benchmark/Prelude/Parallel.hs
36benchmark/Streamly/Benchmark/Prelude/Parallel.hs
36benchmark/Streamly/Benchmark/Prelude/Rate.hs
37benchmark/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)
269{-# INLINE unzipWithFstM #-}
269{-# INLINE unzipWithFstM #-}
270unzipWithFstM :: Monad m => Stream m Int -> m (Int, Int)
270unzipWithFstM :: Monad m => Stream m Int -> m (Int, Int)
271unzipWithFstM = do
271unzipWithFstM = do
272− let f = \a -> return (a + 1, a)
272+ let f a = return (a + 1, a)
273 Stream.fold (FL.unzipWithFstM f FL.sum FL.length)
273 Stream.fold (FL.unzipWithFstM f FL.sum FL.length)
274
274
275{-# INLINE unzipWithMinM #-}
275{-# INLINE unzipWithMinM #-}
276unzipWithMinM :: Monad m => Stream m Int -> m (Int, Int)
276unzipWithMinM :: Monad m => Stream m Int -> m (Int, Int)
277unzipWithMinM = do
277unzipWithMinM = do
278− let f = \a -> return (a + 1, a)
278+ let f a = return (a + 1, a)
279 Stream.fold (FL.unzipWithMinM f FL.sum FL.length)
279 Stream.fold (FL.unzipWithMinM f FL.sum FL.length)
280
280
281-------------------------------------------------------------------------------
281-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/Data/Serialize.hs+9−12
@@ -1,4 +1,5 @@
1{-# LANGUAGE TemplateHaskell #-}
1{-# LANGUAGE TemplateHaskell #-}
2+{- HLINT ignore -}
2
3
3#undef FUSION_CHECK
4#undef FUSION_CHECK
4#ifdef FUSION_CHECK
5#ifdef FUSION_CHECK
@@ -18,6 +19,7 @@ module Main (main) where
18-------------------------------------------------------------------------------
19-------------------------------------------------------------------------------
19
20
20import Control.DeepSeq (NFData(..), deepseq)
21import Control.DeepSeq (NFData(..), deepseq)
22+import Control.Monad (when, void)
21import GHC.Generics (Generic)
23import GHC.Generics (Generic)
22import System.Random (randomRIO)
24import System.Random (randomRIO)
23#ifndef USE_UNBOX
25#ifndef USE_UNBOX
@@ -264,13 +266,13 @@ $(deriveSerialize [d|instance Serialize a => Serialize (BinTree a)|])
264instance NFData a => NFData (BinTree a) where
266instance NFData a => NFData (BinTree a) where
265 {-# INLINE rnf #-}
267 {-# INLINE rnf #-}
266 rnf (Leaf a) = rnf a `seq` ()
268 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
268
270
269instance Arbitrary a => Arbitrary (BinTree a) where
271instance Arbitrary a => Arbitrary (BinTree a) where
270 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
272 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
271
273
272mkBinTree :: (Arbitrary a) => Int -> IO (BinTree a)
274mkBinTree :: (Arbitrary a) => Int -> IO (BinTree a)
273−mkBinTree = go (generate $ arbitrary)
275+mkBinTree = go (generate arbitrary)
274
276
275 where
277 where
276
278
@@ -295,16 +297,14 @@ getSize = addSizeTo 0
295-- Common helpers
297-- Common helpers
296-------------------------------------------------------------------------------
298-------------------------------------------------------------------------------
297
299
300+{- HLINT ignore "Eta reduce" -}
298-- Parts of "f" that are dependent on val will not be optimized out.
301-- Parts of "f" that are dependent on val will not be optimized out.
299{-# INLINE loop #-}
302{-# INLINE loop #-}
300loop :: Int -> (a -> IO b) -> a -> IO ()
303loop :: Int -> (a -> IO b) -> a -> IO ()
301loop count f val = go count val
304loop count f val = go count val
302 where
305 where
303
306
304− go n x = do
305− if n > 0
306− then f x >> go (n-1) x
307+ go n x = when (n > 0) $ f x >> go (n-1) x
307− else return ()
308
308
309-- The first arg of "f" is the environment which is not threaded around in the
309-- The first arg of "f" is the environment which is not threaded around in the
310-- loop.
310-- loop.
@@ -313,10 +313,7 @@ loopWith :: Int -> (e -> a -> IO b) -> e -> a -> IO ()
313loopWith count f e val = go count val
313loopWith count f e val = go count val
314 where
314 where
315
315
316− go n x = do
317− if n > 0
318− then f e x >> go (n-1) x
316+ go n x = when (n > 0) $ f e x >> go (n-1) x
319− else return ()
320
317
321benchSink :: NFData b => String -> Int -> (Int -> IO b) -> Benchmark
318benchSink :: NFData b => String -> Int -> (Int -> IO b) -> Benchmark
322benchSink name times f = bench name (nfIO (randomRIO (times, times) >>= f))
319benchSink name times f = bench name (nfIO (randomRIO (times, times) >>= f))
@@ -342,7 +339,7 @@ pokeTimesWithSize val times = do
342
339
343{-# INLINE poke #-}
340{-# INLINE poke #-}
344poke :: SERIALIZE_CLASS a => MutByteArray -> a -> IO ()
341poke :: 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)
346
343
347{-# INLINE pokeTimes #-}
344{-# INLINE pokeTimes #-}
348pokeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
345pokeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
@@ -356,7 +353,7 @@ encode :: SERIALIZE_CLASS a => a -> IO ()
356encode val = do
353encode val = do
357 let n = getSize val
354 let n = getSize val
358 arr <- MBA.new n
355 arr <- MBA.new n
359− SERIALIZE_OP 0 arr val >> return ()
356+ void (SERIALIZE_OP 0 arr val)
360
357
361{-# INLINE encodeTimes #-}
358{-# INLINE encodeTimes #-}
362encodeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
359encodeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
benchmark/Streamly/Benchmark/Data/Serialize/TH.hs+3−3
@@ -18,7 +18,7 @@ import Control.DeepSeq (NFData(..))
18genLargeRecord :: String -> Int -> Q [Dec]
18genLargeRecord :: String -> Int -> Q [Dec]
19genLargeRecord tyName numFields =
19genLargeRecord tyName numFields =
20 sequence
20 sequence
21− ([ dataD
21+ [ dataD
22 (pure [])
22 (pure [])
23 (mkName tyName)
23 (mkName tyName)
24 []
24 []
@@ -28,7 +28,7 @@ genLargeRecord tyName numFields =
28 , mkValueSigDec
28 , mkValueSigDec
29 , mkValueDec
29 , mkValueDec
30 , nfDataInstance tyName
30 , nfDataInstance tyName
31− ])
31+ ]
32
32
33 where
33 where
34
34
@@ -64,7 +64,7 @@ genLargeRecord tyName numFields =
64 (foldl
64 (foldl
65 (\b a -> [|$(b) $(a)|])
65 (\b a -> [|$(b) $(a)|])
66 (conE (mkName tyName))
66 (conE (mkName tyName))
67− (const (conE '()) <$> [0 .. (numFields - 1)])))
67+ (conE '() <$ [0 .. (numFields - 1)])))
68 []
68 []
69 ]
69 ]
70 mkCon nm = recC (mkName nm) (mkField <$> [0 .. (numFields - 1)])
70 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
132foldableAny value n =
132foldableAny value n =
133 Prelude.any (> (value + 1)) (sourceUnfoldr value n :: Stream Identity Int)
133 Prelude.any (> (value + 1)) (sourceUnfoldr value n :: Stream Identity Int)
134
134
135+{- HLINT ignore "Use all"-}
135{-# INLINE foldableAnd #-}
136{-# INLINE foldableAnd #-}
136foldableAnd :: Int -> Int -> Bool
137foldableAnd :: Int -> Int -> Bool
137foldableAnd value n =
138foldableAnd value n =
138 Prelude.and $ fmap
139 Prelude.and $ fmap
139 (<= (value + 1)) (sourceUnfoldr value n :: Stream Identity Int)
140 (<= (value + 1)) (sourceUnfoldr value n :: Stream Identity Int)
140
141
142+{- HLINT ignore "Use any"-}
141{-# INLINE foldableOr #-}
143{-# INLINE foldableOr #-}
142foldableOr :: Int -> Int -> Bool
144foldableOr :: Int -> Int -> Bool
143foldableOr value n =
145foldableOr value n =
benchmark/Streamly/Benchmark/Data/Stream/StreamKAlt.hs+1−1
@@ -452,4 +452,4 @@ o_1_space =
452 ]
452 ]
453
453
454main :: IO ()
454main :: 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]
120{-# INLINE fromFoldableM #-}
120{-# INLINE fromFoldableM #-}
121fromFoldableM :: Monad m => Int -> Int -> Stream m Int
121fromFoldableM :: Monad m => Int -> Int -> Stream m Int
122fromFoldableM streamLen n =
122fromFoldableM 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]
124
124
125{-
125{-
126{-# INLINABLE concatMapFoldableWith #-}
126{-# INLINABLE concatMapFoldableWith #-}