Skip to content

Commit 9982e14

Browse files
authored
Merge pull request #720 from IntersectMBO/recursion-ninja/hlint-no-return
Updating HLint to require using 'pure' instead of 'return'
2 parents 4711ca0 + 126ea82 commit 9982e14

File tree

84 files changed

+481
-476
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+481
-476
lines changed

.hlint.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
#
7777
# Will suggest replacing "wibbleMany [myvar]" with "wibbleOne myvar"
7878
# - error: {lhs: "wibbleMany [x]", rhs: wibbleOne x}
79+
- error:
80+
{ note: Prefer pure to reduce Monad constraint
81+
, lhs: return x
82+
, rhs: pure x
83+
}
84+
7985
- error:
8086
name: "Use mkPrimVector"
8187
lhs: "Data.Vector.Primitive.Vector"

bench/macro/lsm-tree-bench-bloomfilter.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ benchmarks = do
113113
hashcost
114114
0
115115

116-
return ()
116+
pure ()
117117

118118
type Alloc = Int
119119

@@ -160,7 +160,7 @@ benchmark name description action n (subtractTime, subtractAlloc) expectedAlloc
160160
(truncate allocPerKey :: Int)
161161

162162
putStrLn ""
163-
return (timeNet, allocNet)
163+
pure (timeNet, allocNet)
164164

165165
-- | (numEntries, sizeFactor, (BloomSize numBits numHashFuncs))
166166
type BloomFilterSizeInfo = (Integer, Integer, BloomSize)
@@ -233,7 +233,7 @@ elemManyEnv filterSizes rng0 =
233233
let k :: Word256
234234
(!k, !rng') = uniform rng
235235
Bloom.insert mb (serialiseKey k)
236-
return rng'
236+
pure rng'
237237
)
238238
rng0
239239
(zip [0 .. totalNumEntries filterSizes - 1]

bench/macro/lsm-tree-bench-lookups.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ benchmark name description action n (subtractTime, subtractAlloc) = do
267267
printStat "Alloc net per key: " allocPerKey "bytes"
268268

269269
putStrLn ""
270-
return (timeNet, allocNet)
270+
pure (timeNet, allocNet)
271271

272272
-- | (numEntries, sizeFactor)
273273
type RunSizeInfo = (Int, Int)

bench/macro/lsm-tree-bench-wp8.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ makeKey seed =
122122
case v of
123123
P.MutablePrimArray mba -> do
124124
_ <- P.resizeMutableByteArray (P.MutableByteArray mba) 34
125-
return v
125+
pure v
126126

127127
of (P.PrimArray ba :: P.PrimArray Word64) ->
128128
byteArrayToSBS (P.ByteArray ba)
@@ -262,7 +262,7 @@ timed action = do
262262
printf "Running time: %.03f sec\n" t
263263
printf "/proc/self/io after vs. before: %s\n" (ppShow p)
264264
printf "RTSStats after vs. before: %s\n" (ppShow s)
265-
return (x, t, s, p)
265+
pure (x, t, s, p)
266266

267267
timed_ :: IO () -> IO (Double, RTSStatsDiff Triple, ProcIODiff)
268268
timed_ action = do
@@ -479,7 +479,7 @@ doDryRun' gopts opts = do
479479
let (batch1, batch2) = toOperations lookups inserts
480480
_ <- evaluate $ force (batch1, batch2)
481481

482-
return g'
482+
pure g'
483483

484484
when (check opts) $ do
485485
duplicates <- readIORef duplicateRef
@@ -589,7 +589,7 @@ doRun gopts opts = do
589589
checkvar <- newIORef $ pureReference
590590
(initialSize gopts) (batchSize opts)
591591
(batchCount opts) (seed opts)
592-
let fcheck | not (check opts) = \_ _ -> return ()
592+
let fcheck | not (check opts) = \_ _ -> pure ()
593593
| otherwise = \b y -> do
594594
(x:xs) <- readIORef checkvar
595595
unless (x == y) $
@@ -642,7 +642,7 @@ sequentialIteration h output !initialSize !batchSize !tbl !b !g =
642642
_ <- timeLatency tref $ LSM.updates tbl is
643643

644644
-- continue to the next batch
645-
return g'
645+
pure g'
646646

647647

648648
sequentialIterations :: LatencyHandle
@@ -674,7 +674,7 @@ sequentialIterationLO output !initialSize !batchSize !tbl !b !g = do
674674
output b (V.zip ls (fmap (fmap (const ())) results))
675675

676676
-- continue to the next batch
677-
return g'
677+
pure g'
678678

679679
sequentialIterationsLO :: (Int -> LookupResults -> IO ())
680680
-> Int -> Int -> Int -> Word64
@@ -780,7 +780,7 @@ pipelinedIteration h output !initialSize !batchSize
780780
!delta' = Map.fromList (V.toList is)
781781
putMVar syncTblOut (tbl_n2, delta')
782782

783-
return tbl_n2
783+
pure tbl_n2
784784
where
785785
applyUpdates :: Map K (LSM.Update V a)
786786
-> V.Vector (K, LSM.LookupResult V b)
@@ -839,7 +839,7 @@ pipelinedIterations h output !initialSize !batchSize !batchCount !seed tbl_0 = d
839839
-- If run with +RTS -N2 then we'll put each thread on a separate core.
840840
withAsyncOn 0 threadA $ \ta ->
841841
withAsyncOn 1 threadB $ \tb ->
842-
waitBoth ta tb >> return ()
842+
waitBoth ta tb >> pure ()
843843

844844
-------------------------------------------------------------------------------
845845
-- Testing
@@ -1020,7 +1020,7 @@ main = do
10201020
forFoldM_ :: Monad m => s -> [a] -> (a -> s -> m s) -> m s
10211021
forFoldM_ !s0 xs0 f = go s0 xs0
10221022
where
1023-
go !s [] = return s
1023+
go !s [] = pure s
10241024
go !s (x:xs) = do
10251025
!s' <- f x s
10261026
go s' xs

bench/macro/rocksdb-bench-wp8.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ timed action = do
156156
x <- action
157157
t2 <- Clock.getTime Clock.Monotonic
158158
let !t = fromIntegral (Clock.toNanoSecs (Clock.diffTimeSpec t2 t1)) * 1e-9
159-
return (x, t)
159+
pure (x, t)
160160

161161
timed_ :: IO () -> IO Double
162162
timed_ action = do
163163
t1 <- Clock.getTime Clock.Monotonic
164164
action
165165
t2 <- Clock.getTime Clock.Monotonic
166-
return $! fromIntegral (Clock.toNanoSecs (Clock.diffTimeSpec t2 t1)) * 1e-9
166+
pure $! fromIntegral (Clock.toNanoSecs (Clock.diffTimeSpec t2 t1)) * 1e-9
167167

168168
-------------------------------------------------------------------------------
169169
-- setup
@@ -270,7 +270,7 @@ doDryRun' gopts opts = do
270270
let k = makeKey k'
271271
evaluate k >> evaluate (makeValue k)
272272

273-
return nextG
273+
pure nextG
274274

275275
when (check opts) $ do
276276
duplicates <- readIORef duplicateRef
@@ -376,7 +376,7 @@ doRun' gopts opts =
376376

377377
RocksDB.write db wopts batch
378378

379-
return nextG
379+
pure nextG
380380
where
381381
initGen = MCG.make
382382
(fromIntegral $ initialSize gopts + batchSize opts * batchCount opts)
@@ -409,7 +409,7 @@ main = do
409409
-------------------------------------------------------------------------------
410410

411411
forFoldM_ :: Monad m => s -> [a] -> (a -> s -> m s) -> m s
412-
forFoldM_ !s [] _ = return s
412+
forFoldM_ !s [] _ = pure s
413413
forFoldM_ !s (x:xs) f = do
414414
!s' <- f x s
415415
forFoldM_ s' xs f

bench/micro/Bench/Database/LSMTree/Internal/Index.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ benchmarks = bgroup "Bench.Database.LSMTree.Internal.Index" $
3737
= bgroup (indexTypeName ++ " index") $
3838
[
3939
-- Search
40-
env (return $ searchIndex indexType 10000) $ \ index ->
41-
env (return $ searchKeys 1000) $ \ keys ->
40+
env (pure $ searchIndex indexType 10000) $ \ index ->
41+
env (pure $ searchKeys 1000) $ \ keys ->
4242
bench "Search" $
4343
searchBenchmarkable index keys,
4444

4545
-- Incremental construction
46-
env (return $ incrementalConstructionAppends 10000) $ \ appends ->
46+
env (pure $ incrementalConstructionAppends 10000) $ \ appends ->
4747
bench "Incremental construction" $
4848
incrementalConstructionBenchmarkable indexType appends
4949
]

blockio/src-sim/System/FS/BlockIO/Sim.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ simTryLockFile hfs path lockmode =
8282
mkLockFileHandle
8383
ExclusiveLock | n == 0 -> do writeCount h (-1)
8484
mkLockFileHandle
85-
_ -> return Nothing
85+
_ -> pure Nothing
8686
where
8787
mkLockFileHandle = do
8888
-- A lock file handle keeps open the file in read mode, such that a locked
8989
-- file contributes to the number of open file handles. The mock FS allows
9090
-- multiple readers and up to one writer to open the file concurrently.
9191
h <- API.hOpen hfs path ReadMode
92-
return (Just (LockFileHandle { hUnlock = hUnlock h }))
92+
pure (Just (LockFileHandle { hUnlock = hUnlock h }))
9393

9494
hUnlock h0 =
9595
API.withFile hfs path (ReadWriteMode AllowExisting) $ \h -> do
@@ -112,7 +112,7 @@ simTryLockFile hfs path lockmode =
112112
writeCount h n = do
113113
API.hSeek hfs h AbsoluteSeek 0
114114
_ <- API.hPutAllStrict hfs h (BS.pack (show n))
115-
return ()
115+
pure ()
116116

117117
countCorrupt =
118118
FsError {

blockio/src/System/FS/BlockIO/API.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ rethrowFsErrorIO hfs fp action = do
321321
res <- try action
322322
case res of
323323
Left err -> handleError err
324-
Right a -> return a
324+
Right a -> pure a
325325
where
326326
handleError :: HasCallStack => IOError -> IO a
327327
handleError ioErr =

bloomfilter/src/Data/BloomFilter/Blocked.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ unfold bloomsize f k =
162162
where
163163
loop :: b -> ST s ()
164164
loop !j = case f j of
165-
Nothing -> return ()
165+
Nothing -> pure ()
166166
Just (a, j') -> insert mb a >> loop j'
167167

168168
-- | Create a Bloom filter, populating it from a sequence of values.
@@ -241,7 +241,7 @@ insertMany bloom key n =
241241
prepareProbes (i+1) (i_w+1)
242242

243243
| n > 0 = insertProbe 0 0 i_w
244-
| otherwise = return ()
244+
| otherwise = pure ()
245245

246246
-- Read from the read end of the buffer and do the inserts.
247247
insertProbe :: Int -> Int -> Int -> ST s ()
@@ -275,4 +275,4 @@ insertMany bloom key n =
275275
i_w
276276

277277
-- When the buffer is empty, we're done.
278-
| otherwise = return ()
278+
| otherwise = pure ()

bloomfilter/src/Data/BloomFilter/Blocked/BitArray.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ new :: NumBlocks -> ST s (MBitArray s)
9797
new (NumBlocks numBlocks) = do
9898
mba@(MutableByteArray mba#) <- newAlignedPinnedByteArray numBytes 64
9999
setByteArray mba 0 numBytes (0 :: Word8)
100-
return (MBitArray (MutablePrimArray mba#))
100+
pure (MBitArray (MutablePrimArray mba#))
101101
where
102102
!numBytes = numBlocks * 64
103103

@@ -126,7 +126,7 @@ unsafeSet :: MBitArray s -> BlockIx -> BitIx -> ST s ()
126126
unsafeSet (MBitArray arr) blockIx blockBitIx = do
127127
#ifdef NO_IGNORE_ASSERTS
128128
sz <- getSizeofMutablePrimArray arr
129-
assert (wordIx >= 0 && wordIx < sz) $ return ()
129+
assert (wordIx >= 0 && wordIx < sz) $ pure ()
130130
#endif
131131
w <- readPrimArray arr wordIx
132132
writePrimArray arr wordIx (unsafeSetBit w wordBitIx)
@@ -146,7 +146,7 @@ prefetchSet (MBitArray (MutablePrimArray mba#)) (BlockIx blockIx) = do
146146

147147
#ifdef NO_IGNORE_ASSERTS
148148
sz <- getSizeofMutableByteArray (MutableByteArray mba#)
149-
assert (let i = I# i# in i >= 0 && i < sz-63) $ return ()
149+
assert (let i = I# i# in i >= 0 && i < sz-63) $ pure ()
150150
#endif
151151

152152
-- In prefetchMutableByteArray0, the 0 refers to a "non temporal" load,

0 commit comments

Comments
 (0)