Skip to content

Commit

Permalink
Merge pull request composewell#408 from SanchayanMaity/hlint_cleanup_1
Browse files Browse the repository at this point in the history
Hlint cleanup for Data, FileSystem and Memory directory
  • Loading branch information
harendra-kumar authored Feb 17, 2020
2 parents 61eb4eb + bbfffe8 commit 9034b2d
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 51 deletions.
3 changes: 0 additions & 3 deletions src/Streamly/Data/Unfold.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

#include "inline.hs"

Expand Down
12 changes: 4 additions & 8 deletions src/Streamly/FileSystem/FD.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE UnboxedTuples #-}

#include "inline.hs"

Expand Down Expand Up @@ -204,7 +200,7 @@ stderr = Handle FD.stderr
-- the same absolute path name and neither has been renamed, for example.
--
openFile :: FilePath -> IOMode -> IO Handle
openFile path mode = fmap (Handle . fst) $ FD.openFile path mode True
openFile path mode = Handle . fst <$> FD.openFile path mode True

-------------------------------------------------------------------------------
-- Array IO (Input)
Expand Down Expand Up @@ -241,7 +237,7 @@ readArrayUpto size (Handle fd) = do
{-# INLINABLE writeArray #-}
writeArray :: Storable a => Handle -> Array a -> IO ()
writeArray _ arr | A.length arr == 0 = return ()
writeArray (Handle fd) arr = withForeignPtr (aStart arr) $ \p -> do
writeArray (Handle fd) arr = withForeignPtr (aStart arr) $ \p ->
-- RawIO.writeAll fd (castPtr p) aLen
RawIO.write fd (castPtr p) aLen
{-
Expand Down Expand Up @@ -349,7 +345,7 @@ read = AS.concat . readArrays
-- @since 0.7.0
{-# INLINE writeArrays #-}
writeArrays :: (MonadIO m, Storable a) => Handle -> SerialT m (Array a) -> m ()
writeArrays h m = S.mapM_ (liftIO . writeArray h) m
writeArrays h = S.mapM_ (liftIO . writeArray h)

-- | Write a stream of arrays to a handle after coalescing them in chunks of
-- specified size. The chunk size is only a maximum and the actual writes could
Expand All @@ -369,7 +365,7 @@ writeArraysPackedUpto n h xs = writeArrays h $ AS.compact n xs
-- @since 0.7.0
{-# INLINE writev #-}
writev :: MonadIO m => Handle -> SerialT m (Array RawIO.IOVec) -> m ()
writev h m = S.mapM_ (liftIO . writeIOVec h) m
writev h = S.mapM_ (liftIO . writeIOVec h)

-- XXX this is incomplete
-- | Write a stream of arrays to a handle after grouping them in 'IOVec' arrays
Expand Down
3 changes: 0 additions & 3 deletions src/Streamly/FileSystem/FDIO.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE UnboxedTuples #-}

#include "inline.hs"

Expand Down
4 changes: 0 additions & 4 deletions src/Streamly/FileSystem/Handle.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE UnboxedTuples #-}

#include "inline.hs"

Expand Down
2 changes: 0 additions & 2 deletions src/Streamly/Internal/Mutable/Prim/Var.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE ScopedTypeVariables #-}

Expand Down
11 changes: 3 additions & 8 deletions src/Streamly/Internal/Network/Inet/TCP.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE UnboxedTuples #-}

#include "inline.hs"

Expand Down Expand Up @@ -359,13 +355,12 @@ writeChunks addr port = Fold step initial extract
where
initial = do
skt <- liftIO (connect addr port)
fld <- FL.initialize (SK.writeChunks skt)
`MC.onException` (liftIO $ Net.close skt)
fld <- FL.initialize (SK.writeChunks skt) `MC.onException` liftIO (Net.close skt)
return (fld, skt)
step (fld, skt) x = do
r <- FL.runStep fld x `MC.onException` (liftIO $ Net.close skt)
r <- FL.runStep fld x `MC.onException` liftIO (Net.close skt)
return (r, skt)
extract ((Fold _ initial1 extract1), skt) = do
extract (Fold _ initial1 extract1, skt) = do
liftIO $ Net.close skt
initial1 >>= extract1

Expand Down
15 changes: 4 additions & 11 deletions src/Streamly/Internal/Network/Socket.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE UnboxedTuples #-}

#include "inline.hs"

Expand Down Expand Up @@ -78,11 +75,10 @@ import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
import Foreign.Ptr (minusPtr, plusPtr, Ptr, castPtr)
import Foreign.Storable (Storable(..))
import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
import Network.Socket (sendBuf, recvBuf)
import Network.Socket
(Socket, SocketOption(..), Family(..), SockAddr(..),
ProtocolNumber, withSocketsDo, SocketType(..), socket, bind,
setSocketOption)
setSocketOption, sendBuf, recvBuf)
#if MIN_VERSION_network(3,1,0)
import Network.Socket (withFdSocket)
#else
Expand Down Expand Up @@ -160,9 +156,7 @@ listenTuples :: MonadIO m
=> Unfold m (Int, SockSpec, SockAddr) (Socket, SockAddr)
listenTuples = Unfold step inject
where
inject (listenQLen, spec, addr) = do
listener <- liftIO $ initListener listenQLen spec addr
return listener
inject (listenQLen, spec, addr) = liftIO $ initListener listenQLen spec addr

step listener = do
r <- liftIO $ Net.accept listener
Expand Down Expand Up @@ -208,8 +202,7 @@ recvConnectionTuplesWith tcpListenQ spec addr = S.unfoldrM step Nothing
-- /Internal/
{-# INLINE connections #-}
connections :: MonadAsync m => Int -> SockSpec -> SockAddr -> SerialT m Socket
connections tcpListenQ spec addr = fmap fst $
recvConnectionTuplesWith tcpListenQ spec addr
connections tcpListenQ spec addr = fst <$> recvConnectionTuplesWith tcpListenQ spec addr

-------------------------------------------------------------------------------
-- Array IO (Input)
Expand Down Expand Up @@ -416,7 +409,7 @@ read = UF.supplyFirst readWithBufferOf A.defaultChunkSize
{-# INLINE fromChunks #-}
fromChunks :: (MonadIO m, Storable a)
=> Socket -> SerialT m (Array a) -> m ()
fromChunks h m = S.mapM_ (liftIO . writeChunk h) m
fromChunks h = S.mapM_ (liftIO . writeChunk h)

-- | Write a stream of arrays to a socket. Each array in the stream is written
-- to the socket as a separate IO request.
Expand Down
4 changes: 0 additions & 4 deletions src/Streamly/Memory/Array.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE ScopedTypeVariables #-}

#include "inline.hs"
Expand Down
8 changes: 2 additions & 6 deletions src/Streamly/Memory/Malloc.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE FlexibleContexts #-}

#include "inline.hs"
Expand Down Expand Up @@ -40,8 +36,8 @@ import qualified GHC.ForeignPtr as GHC
{-# INLINE mallocForeignPtrAlignedBytes #-}
mallocForeignPtrAlignedBytes :: Int -> Int -> IO (GHC.ForeignPtr a)
#ifdef USE_GHC_MALLOC
mallocForeignPtrAlignedBytes size alignment = do
GHC.mallocPlainForeignPtrAlignedBytes size alignment
mallocForeignPtrAlignedBytes =
GHC.mallocPlainForeignPtrAlignedBytes
#else
mallocForeignPtrAlignedBytes size _alignment = do
p <- mallocBytes size
Expand Down
4 changes: 2 additions & 2 deletions src/Streamly/Memory/Ring.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ new count = do
let size = count * sizeOf (undefined :: a)
fptr <- mallocPlainForeignPtrAlignedBytes size (alignment (undefined :: a))
let p = unsafeForeignPtrToPtr fptr
return $ (Ring
return (Ring
{ ringStart = fptr
, ringBound = p `plusPtr` size
}, p)
Expand Down Expand Up @@ -105,7 +105,7 @@ unsafeEqArrayN :: Ring a -> Ptr a -> A.Array a -> Int -> Bool
unsafeEqArrayN Ring{..} rh A.Array{..} n =
let !res = A.unsafeInlineIO $ do
let rs = unsafeForeignPtrToPtr ringStart
let as = unsafeForeignPtrToPtr aStart
as = unsafeForeignPtrToPtr aStart
assert (aBound `minusPtr` as >= ringBound `minusPtr` rs) (return ())
let len = ringBound `minusPtr` rh
r1 <- A.memcmp (castPtr rh) (castPtr as) (min len n)
Expand Down

0 comments on commit 9034b2d

Please sign in to comment.