22{-# LANGUAGE CPP #-}
33{-# LANGUAGE DerivingVia #-}
44{-# LANGUAGE FlexibleInstances #-}
5- {-# LANGUAGE GeneralisedNewtypeDeriving #-}
65{-# LANGUAGE MultiParamTypeClasses #-}
76{-# LANGUAGE MultiWayIf #-}
87{-# LANGUAGE NamedFieldPuns #-}
8+ {-# LANGUAGE PatternSynonyms #-}
99{-# LANGUAGE RecordWildCards #-}
1010{-# LANGUAGE StandaloneDeriving #-}
1111{-# LANGUAGE TypeFamilies #-}
@@ -23,10 +23,14 @@ module System.IO.BlockIO (
2323
2424 -- * Performing I\/O
2525 submitIO ,
26- IOOp (IOOpRead , IOOpWrite ),
2726 IOResult (IOResult , IOError ),
2827 ByteCount , Errno (.. ),
2928
29+ -- ** IOOps
30+ IOOp (IOOpRead , IOOpWrite ),
31+ pattern V_IOOp , pattern MV_IOOp ,
32+ unzipIOOp , zipIOOp ,
33+ unzipIOOpMutable , zipIOOpMutable ,
3034 ) where
3135
3236import Data.Bit
@@ -218,11 +222,9 @@ data IOOp s = IOOpRead !Fd !FileOffset !(MutableByteArray s) !Int !ByteCount
218222 | IOOpWrite ! Fd ! FileOffset ! (MutableByteArray s ) ! Int ! ByteCount
219223
220224-- Pseudo-representation used for the Unbox instance (via IsoUnbox).
221- type UReprIOOp s = (Bit , Int , Int64 ,
222- VU. DoNotUnboxStrict (MutableByteArray s ),
223- Int , Word )
225+ #define UReprIOOp(s) (Bit, Int, Int64, VU.DoNotUnboxStrict (MutableByteArray s), Int, Word)
224226
225- instance VU. IsoUnbox (IOOp s ) ( UReprIOOp s ) where
227+ instance VU. IsoUnbox (IOOp s ) UReprIOOp ( s ) where
226228 {-# INLINE toURepr #-}
227229 toURepr (IOOpRead (Fd ! fd) ! off ! buf ! bufOff ! cnt) =
228230 (Bit True , fromIntegral fd, fromIntegral off,
@@ -239,12 +241,62 @@ instance VU.IsoUnbox (IOOp s) (UReprIOOp s) where
239241 IOOpWrite (Fd (fromIntegral fd)) (fromIntegral off)
240242 buf (fromIntegral bufOff) (fromIntegral cnt)
241243
242- newtype instance VUM. MVector s1 (IOOp s2 ) = MV_IOOp (VU. MVector s1 ( UReprIOOp s2 ))
243- newtype instance VU. Vector (IOOp s2 ) = V_IOOp (VU. Vector ( UReprIOOp s2 ))
244- deriving via (IOOp s `VU. As ` UReprIOOp s ) instance VGM. MVector VUM. MVector (IOOp s )
245- deriving via (IOOp s `VU. As ` UReprIOOp s ) instance VG. Vector VU. Vector (IOOp s )
244+ newtype instance VUM. MVector s1 (IOOp s2 ) = MV_IOOp (VU. MVector s1 UReprIOOp ( s2 ))
245+ newtype instance VU. Vector (IOOp s2 ) = V_IOOp (VU. Vector UReprIOOp ( s2 ))
246+ deriving via (IOOp s `VU. As ` UReprIOOp ( s ) ) instance VGM. MVector VUM. MVector (IOOp s )
247+ deriving via (IOOp s `VU. As ` UReprIOOp ( s ) ) instance VG. Vector VU. Vector (IOOp s )
246248instance VU. Unbox (IOOp s )
247249
250+ {-# INLINE unzipIOOp #-}
251+ -- | \( O(1) \) Unzip an unboxed vector of 'IOOp's into its components.
252+ unzipIOOp ::
253+ VU. Vector (IOOp s )
254+ -> ( VU. Vector Bit
255+ , VU. Vector Int
256+ , VU. Vector Int64
257+ , VU. Vector (VU. DoNotUnboxStrict (MutableByteArray s ))
258+ , VU. Vector Int
259+ , VU. Vector Word
260+ )
261+ unzipIOOp (V_IOOp v) = VU. unzip6 v
262+
263+ {-# INLINE zipIOOp #-}
264+ -- | \( O(1) \) Zip an unboxed vector of 'IOOp's from its components.
265+ zipIOOp ::
266+ VU. Vector Bit
267+ -> VU. Vector Int
268+ -> VU. Vector Int64
269+ -> VU. Vector (VU. DoNotUnboxStrict (MutableByteArray s ))
270+ -> VU. Vector Int
271+ -> VU. Vector Word
272+ -> VU. Vector (IOOp s )
273+ zipIOOp a b c d e f = V_IOOp (VU. zip6 a b c d e f)
274+
275+ {-# INLINE unzipIOOpMutable #-}
276+ -- | \( O(1) \) Unzip an unboxed, mutable vector of 'IOOp's into its components.
277+ unzipIOOpMutable ::
278+ VUM. MVector s1 (IOOp s2 )
279+ -> ( VUM. MVector s1 Bit
280+ , VUM. MVector s1 Int
281+ , VUM. MVector s1 Int64
282+ , VUM. MVector s1 (VU. DoNotUnboxStrict (MutableByteArray s2 ))
283+ , VUM. MVector s1 Int
284+ , VUM. MVector s1 Word
285+ )
286+ unzipIOOpMutable (MV_IOOp v) = VUM. unzip6 v
287+
288+ {-# INLINE zipIOOpMutable #-}
289+ -- | \( O(1) \) Zip an unboxed, mutable vector of 'IOOp's from its components.
290+ zipIOOpMutable ::
291+ VUM. MVector s1 Bit
292+ -> VUM. MVector s1 Int
293+ -> VUM. MVector s1 Int64
294+ -> VUM. MVector s1 (VU. DoNotUnboxStrict (MutableByteArray s2 ))
295+ -> VUM. MVector s1 Int
296+ -> VUM. MVector s1 Word
297+ -> VUM. MVector s1 (IOOp s2 )
298+ zipIOOpMutable a b c d e f = MV_IOOp (VUM. zip6 a b c d e f)
299+
248300-- | Submit a batch of I\/O operations, and wait for them all to complete.
249301-- The sequence of results matches up with the sequence of operations.
250302-- Any I\/O errors are reported in the result list, not as IO exceptions.
0 commit comments