From 47b10b39146d46a937cd0b086720638f9751005d Mon Sep 17 00:00:00 2001 From: Harendra Kumar Date: Fri, 24 Nov 2023 08:06:55 +0530 Subject: [PATCH] Rename MutableByteArray to MutByteArray --- .../Streamly/Benchmark/Data/Serialize.hs | 6 +- core/src/Streamly/Data/Serialize.hs | 2 +- core/src/Streamly/Internal/Data/Array/Type.hs | 4 +- .../Streamly/Internal/Data/IORef/Unboxed.hs | 4 +- .../Streamly/Internal/Data/MutArray/Type.hs | 16 ++-- core/src/Streamly/Internal/Data/Serialize.hs | 16 ++-- .../Internal/Data/Serialize/TH/RecHeader.hs | 6 +- .../Streamly/Internal/Data/Serialize/Type.hs | 14 ++-- core/src/Streamly/Internal/Data/Unbox.hs | 80 ++++++++++--------- core/src/Streamly/Internal/Unicode/Stream.hs | 8 +- test/Streamly/Test/Data/Serialize.hs | 6 +- test/Streamly/Test/Data/Unbox.hs | 4 +- 12 files changed, 86 insertions(+), 80 deletions(-) diff --git a/benchmark/Streamly/Benchmark/Data/Serialize.hs b/benchmark/Streamly/Benchmark/Data/Serialize.hs index 0601f064c..a0340f98f 100644 --- a/benchmark/Streamly/Benchmark/Data/Serialize.hs +++ b/benchmark/Streamly/Benchmark/Data/Serialize.hs @@ -326,7 +326,7 @@ benchSink name times f = bench name (nfIO (randomRIO (times, times) >>= f)) {- {-# INLINE pokeWithSize #-} -pokeWithSize :: SERIALIZE_CLASS a => MutableByteArray -> a -> IO () +pokeWithSize :: SERIALIZE_CLASS a => MutByteArray -> a -> IO () pokeWithSize arr val = do let n = getSize val n `seq` SERIALIZE_OP 0 arr val >> return () @@ -340,7 +340,7 @@ pokeTimesWithSize val times = do -} {-# INLINE poke #-} -poke :: SERIALIZE_CLASS a => MutableByteArray -> a -> IO () +poke :: SERIALIZE_CLASS a => MutByteArray -> a -> IO () poke arr val = SERIALIZE_OP 0 arr val >> return () {-# INLINE pokeTimes #-} @@ -363,7 +363,7 @@ encodeTimes val times = loop times encode val {-# INLINE peek #-} peek :: forall a. (NFData a, SERIALIZE_CLASS a) => - (a, Int) -> MutableByteArray -> IO () + (a, Int) -> MutByteArray -> IO () #ifdef USE_UNBOX peek (_val, _) arr = do (val1 :: a) <- DESERIALIZE_OP 0 arr diff --git a/core/src/Streamly/Data/Serialize.hs b/core/src/Streamly/Data/Serialize.hs index 43bb3ac57..90a7e4826 100644 --- a/core/src/Streamly/Data/Serialize.hs +++ b/core/src/Streamly/Data/Serialize.hs @@ -42,7 +42,7 @@ module Streamly.Data.Serialize ( -- * MutableByteArray - MutableByteArray + MutByteArray -- , isPinned -- , pin -- , unpin diff --git a/core/src/Streamly/Internal/Data/Array/Type.hs b/core/src/Streamly/Internal/Data/Array/Type.hs index 9aca60176..a7345f6a7 100644 --- a/core/src/Streamly/Internal/Data/Array/Type.hs +++ b/core/src/Streamly/Internal/Data/Array/Type.hs @@ -107,7 +107,7 @@ import GHC.Exts (IsList, IsString(..), Addr#) import GHC.IO (unsafePerformIO) import GHC.Ptr (Ptr(..)) -import Streamly.Internal.Data.MutArray.Type (MutArray(..), MutableByteArray) +import Streamly.Internal.Data.MutArray.Type (MutArray(..), MutByteArray) import Streamly.Internal.Data.Fold.Type (Fold(..)) import Streamly.Internal.Data.Stream.Type (Stream) import Streamly.Internal.Data.Unbox (Unbox(..)) @@ -164,7 +164,7 @@ data Array a = #endif -- All offsets are in terms of bytes from the start of arraycontents Array - { arrContents :: {-# UNPACK #-} !MutableByteArray + { arrContents :: {-# UNPACK #-} !MutByteArray , arrStart :: {-# UNPACK #-} !Int -- offset , arrEnd :: {-# UNPACK #-} !Int -- offset + len } diff --git a/core/src/Streamly/Internal/Data/IORef/Unboxed.hs b/core/src/Streamly/Internal/Data/IORef/Unboxed.hs index a9dcf42c3..968ff26f2 100644 --- a/core/src/Streamly/Internal/Data/IORef/Unboxed.hs +++ b/core/src/Streamly/Internal/Data/IORef/Unboxed.hs @@ -41,7 +41,7 @@ where import Data.Proxy (Proxy(..)) import Control.Monad.IO.Class (MonadIO(..)) import Streamly.Internal.Data.Unbox - ( MutableByteArray(..) + ( MutByteArray(..) , Unbox(..) , newBytes , sizeOf @@ -50,7 +50,7 @@ import Streamly.Internal.Data.Unbox import qualified Streamly.Internal.Data.Stream.Type as D -- | An 'IORef' holds a single 'Unbox'-able value. -newtype IORef a = IORef MutableByteArray +newtype IORef a = IORef MutByteArray -- | Create a new 'IORef'. -- diff --git a/core/src/Streamly/Internal/Data/MutArray/Type.hs b/core/src/Streamly/Internal/Data/MutArray/Type.hs index e95b68cdc..dd109e5e3 100644 --- a/core/src/Streamly/Internal/Data/MutArray/Type.hs +++ b/core/src/Streamly/Internal/Data/MutArray/Type.hs @@ -31,6 +31,7 @@ module Streamly.Internal.Data.MutArray.Type -- * Type -- $arrayNotes MutArray (..) + , MutByteArray , MutableByteArray , pin , unpin @@ -239,7 +240,8 @@ import Data.Word (Word8) import Foreign.C.Types (CSize(..), CInt(..)) import Foreign.Ptr (plusPtr, minusPtr, nullPtr) import Streamly.Internal.Data.Unbox - ( MutableByteArray(..) + ( MutByteArray(..) + , MutableByteArray , Unbox(..) , PinnedState(..) , getMutableByteArray# @@ -343,7 +345,7 @@ data MutArray a = -- The array is a range into arrContents. arrContents may be a superset of -- the slice represented by the array. All offsets are in bytes. MutArray - { arrContents :: {-# UNPACK #-} !MutableByteArray + { arrContents :: {-# UNPACK #-} !MutByteArray , arrStart :: {-# UNPACK #-} !Int -- ^ index into arrContents , arrEnd :: {-# UNPACK #-} !Int -- ^ index into arrContents -- Represents the first invalid index of @@ -405,7 +407,7 @@ isPinned MutArray{..} = Unboxed.isPinned arrContents -- /Pre-release/ {-# INLINE newArrayWith #-} newArrayWith :: forall m a. (MonadIO m, Unbox a) - => (Int -> Int -> m MutableByteArray) -> Int -> Int -> m (MutArray a) + => (Int -> Int -> m MutByteArray) -> Int -> Int -> m (MutArray a) newArrayWith alloc alignSize count = do let size = max (count * SIZE_OF(a)) 0 contents <- alloc size alignSize @@ -602,7 +604,7 @@ modify MutArray{..} f = liftIO $ swapArrayByteIndices :: forall a. Unbox a => Proxy a - -> MutableByteArray + -> MutByteArray -> Int -> Int -> IO () @@ -744,8 +746,8 @@ reallocExplicit elemSize newCapacityInBytes MutArray{..} = do if Unboxed.isPinned arrContents then Unboxed.pinnedNewBytes newCapMaxInBytes else Unboxed.newBytes newCapMaxInBytes - let !(MutableByteArray mbarrFrom#) = arrContents - !(MutableByteArray mbarrTo#) = contents + let !(MutByteArray mbarrFrom#) = arrContents + !(MutByteArray mbarrTo#) = contents -- Copy old data let oldStart = arrStart @@ -1455,7 +1457,7 @@ flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state) ------------------------------------------------------------------------------- data ArrayUnsafe a = ArrayUnsafe - {-# UNPACK #-} !MutableByteArray -- contents + {-# UNPACK #-} !MutByteArray -- contents {-# UNPACK #-} !Int -- index 1 {-# UNPACK #-} !Int -- index 2 diff --git a/core/src/Streamly/Internal/Data/Serialize.hs b/core/src/Streamly/Internal/Data/Serialize.hs index 901d6a2e5..4dcf9bc30 100644 --- a/core/src/Streamly/Internal/Data/Serialize.hs +++ b/core/src/Streamly/Internal/Data/Serialize.hs @@ -206,15 +206,15 @@ instance Serialize LiftedInteger where liftInteger :: Integer -> LiftedInteger liftInteger (IS x) = LIS (I# x) liftInteger (IP x) = - LIP (Array (MutableByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x))) + LIP (Array (MutByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x))) liftInteger (IN x) = - LIN (Array (MutableByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x))) + LIN (Array (MutByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x))) {-# INLINE unliftInteger #-} unliftInteger :: LiftedInteger -> Integer unliftInteger (LIS (I# x)) = IS x -unliftInteger (LIP (Array (MutableByteArray x) _ _)) = IP (unsafeCoerce# x) -unliftInteger (LIN (Array (MutableByteArray x) _ _)) = IN (unsafeCoerce# x) +unliftInteger (LIP (Array (MutByteArray x) _ _)) = IP (unsafeCoerce# x) +unliftInteger (LIN (Array (MutByteArray x) _ _)) = IN (unsafeCoerce# x) #else @@ -222,16 +222,16 @@ unliftInteger (LIN (Array (MutableByteArray x) _ _)) = IN (unsafeCoerce# x) liftInteger :: Integer -> LiftedInteger liftInteger (S# x) = LIS (I# x) liftInteger (Jp# (BN# x)) = - LIP (Array (MutableByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x))) + LIP (Array (MutByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x))) liftInteger (Jn# (BN# x)) = - LIN (Array (MutableByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x))) + LIN (Array (MutByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x))) {-# INLINE unliftInteger #-} unliftInteger :: LiftedInteger -> Integer unliftInteger (LIS (I# x)) = S# x -unliftInteger (LIP (Array (MutableByteArray x) _ _)) = +unliftInteger (LIP (Array (MutByteArray x) _ _)) = Jp# (BN# (unsafeCoerce# x)) -unliftInteger (LIN (Array (MutableByteArray x) _ _)) = +unliftInteger (LIN (Array (MutByteArray x) _ _)) = Jn# (BN# (unsafeCoerce# x)) #endif diff --git a/core/src/Streamly/Internal/Data/Serialize/TH/RecHeader.hs b/core/src/Streamly/Internal/Data/Serialize/TH/RecHeader.hs index dab9ff4a3..f41fa4625 100644 --- a/core/src/Streamly/Internal/Data/Serialize/TH/RecHeader.hs +++ b/core/src/Streamly/Internal/Data/Serialize/TH/RecHeader.hs @@ -27,7 +27,7 @@ import Data.Maybe (fromJust) import Language.Haskell.TH import Streamly.Internal.Data.Serialize.Type (Serialize(..)) import Data.Foldable (foldlM) -import Streamly.Internal.Data.Unbox (MutableByteArray) +import Streamly.Internal.Data.Unbox (MutByteArray) import Data.Proxy (Proxy(..)) import qualified Streamly.Internal.Data.Unbox as Unbox @@ -225,7 +225,7 @@ headerValue (SimpleDataCon _ fields) = -- its type. We encode the size as 'Word32' hence there is a 4 bytes increase -- in size. {-# INLINE serializeWithSize #-} -serializeWithSize :: Serialize a => Int -> MutableByteArray -> a -> IO Int +serializeWithSize :: Serialize a => Int -> MutByteArray -> a -> IO Int serializeWithSize off arr val = do off1 <- serialize (off + 4) arr val Unbox.pokeByteIndex off arr (int_w32 (off1 - off - 4) :: Word32) @@ -263,7 +263,7 @@ mkRecSerializeExpr initialOffset (con@(SimpleDataCon cname fields)) = do {-# INLINE deserializeWithSize #-} deserializeWithSize :: - Serialize a => Int -> MutableByteArray -> Int -> IO (Int, a) + Serialize a => Int -> MutByteArray -> Int -> IO (Int, a) deserializeWithSize off arr endOff = deserialize (off + 4) arr endOff conUpdateFuncDec :: Name -> [Field] -> Q [Dec] diff --git a/core/src/Streamly/Internal/Data/Serialize/Type.hs b/core/src/Streamly/Internal/Data/Serialize/Type.hs index 3f12da75d..5dfb44ee9 100644 --- a/core/src/Streamly/Internal/Data/Serialize/Type.hs +++ b/core/src/Streamly/Internal/Data/Serialize/Type.hs @@ -28,7 +28,7 @@ import Control.Exception (assert) import Data.List (foldl') import Data.Proxy (Proxy (..)) import Streamly.Internal.Data.Unbox - ( MutableByteArray(..) + ( MutByteArray(..) , PinnedState(..) , Unbox ) @@ -144,7 +144,7 @@ class Serialize a where -- byte-offset and the deserialized value. -- -- Throws an exception if the operation would exceed the supplied arrayLen. - deserialize :: Int -> MutableByteArray -> Int -> IO (Int, a) + deserialize :: Int -> MutByteArray -> Int -> IO (Int, a) -- | @serialize byte-offset array value@ writes the serialized -- representation of the @value@ in the array at the given byte-offset. @@ -153,7 +153,7 @@ class Serialize a where -- This is an unsafe operation, the programmer must ensure that the array -- has enough space available to serialize the value as determined by the -- @size@ operation. - serialize :: Int -> MutableByteArray -> a -> IO Int + serialize :: Int -> MutByteArray -> a -> IO Int -------------------------------------------------------------------------------- -- Instances @@ -165,7 +165,7 @@ class Serialize a where -- #ifdef DEBUG {-# INLINE checkBounds #-} -checkBounds :: String -> Int -> MutableByteArray -> IO () +checkBounds :: String -> Int -> MutByteArray -> IO () checkBounds _label _off _arr = do sz <- sizeOfMutableByteArray _arr if (_off > sz) @@ -196,7 +196,7 @@ checkBounds _label _off _arr = do -- serialized value with a size header. -- {-# INLINE deserializeUnsafe #-} -deserializeUnsafe :: forall a. Unbox a => Int -> MutableByteArray -> Int -> IO (Int, a) +deserializeUnsafe :: forall a. Unbox a => Int -> MutByteArray -> Int -> IO (Int, a) deserializeUnsafe off arr sz = let next = off + Unbox.sizeOf (Proxy :: Proxy a) in do @@ -209,7 +209,7 @@ deserializeUnsafe off arr sz = ++ " max valid offset = " ++ show (sz - 1) {-# INLINE serializeUnsafe #-} -serializeUnsafe :: forall a. Unbox a => Int -> MutableByteArray -> a -> IO Int +serializeUnsafe :: forall a. Unbox a => Int -> MutByteArray -> a -> IO Int serializeUnsafe off arr val = let next = off + Unbox.sizeOf (Proxy :: Proxy a) in do @@ -227,7 +227,7 @@ instance Serialize _type where \ ; deserialize off arr end = deserializeUnsafe off arr end :: IO (Int, _type) \ ; {-# INLINE serialize #-} \ ; serialize = \ - serializeUnsafe :: Int -> MutableByteArray -> _type -> IO Int + serializeUnsafe :: Int -> MutByteArray -> _type -> IO Int DERIVE_SERIALIZE_FROM_UNBOX(()) DERIVE_SERIALIZE_FROM_UNBOX(Bool) diff --git a/core/src/Streamly/Internal/Data/Unbox.hs b/core/src/Streamly/Internal/Data/Unbox.hs index 29beb3dae..76a4b987b 100644 --- a/core/src/Streamly/Internal/Data/Unbox.hs +++ b/core/src/Streamly/Internal/Data/Unbox.hs @@ -13,8 +13,9 @@ -- module Streamly.Internal.Data.Unbox ( - -- ** MutableByteArray - MutableByteArray(..) + -- ** MutByteArray + MutByteArray(..) + , MutableByteArray , getMutableByteArray# , sizeOfMutableByteArray , nil @@ -100,23 +101,26 @@ data PinnedState -- | A lifted mutable byte array type wrapping @MutableByteArray# RealWorld@. -- This is a low level array used to back high level unboxed arrays and -- serialized data. -data MutableByteArray = MutableByteArray (MutableByteArray# RealWorld) +data MutByteArray = MutByteArray (MutableByteArray# RealWorld) + +{-# DEPRECATED MutableByteArray "Please use MutByteArray instead" #-} +type MutableByteArray = MutByteArray {-# INLINE getMutableByteArray# #-} -getMutableByteArray# :: MutableByteArray -> MutableByteArray# RealWorld -getMutableByteArray# (MutableByteArray mbarr) = mbarr +getMutableByteArray# :: MutByteArray -> MutableByteArray# RealWorld +getMutableByteArray# (MutByteArray mbarr) = mbarr -- | Return the size of the array in bytes. {-# INLINE sizeOfMutableByteArray #-} -sizeOfMutableByteArray :: MutableByteArray -> IO Int -sizeOfMutableByteArray (MutableByteArray arr) = +sizeOfMutableByteArray :: MutByteArray -> IO Int +sizeOfMutableByteArray (MutByteArray arr) = IO $ \s -> case getSizeofMutableByteArray# arr s of (# s1, i #) -> (# s1, I# i #) {-# INLINE touch #-} -touch :: MutableByteArray -> IO () -touch (MutableByteArray contents) = +touch :: MutByteArray -> IO () +touch (MutByteArray contents) = IO $ \s -> case touch# contents s of s' -> (# s', () #) -- XXX We can provide another API for "unsafe" FFI calls passing an unlifted @@ -131,7 +135,7 @@ touch (MutableByteArray contents) = -- guarantees that unsafe calls will be performed in the calling thread. Making -- it safe to pass heap-allocated objects to unsafe functions. --- | Use a @MutableByteArray@ as @Ptr a@. This is useful when we want to pass +-- | Use a @MutByteArray@ as @Ptr a@. This is useful when we want to pass -- an array as a pointer to some operating system call or to a "safe" FFI call. -- -- If the array is not pinned it is copied to pinned memory before passing it @@ -148,7 +152,7 @@ touch (MutableByteArray contents) = -- /Pre-release/ -- {-# INLINE asPtrUnsafe #-} -asPtrUnsafe :: MonadIO m => MutableByteArray -> (Ptr a -> m b) -> m b +asPtrUnsafe :: MonadIO m => MutByteArray -> (Ptr a -> m b) -> m b asPtrUnsafe arr f = do contents <- liftIO $ pin arr let !ptr = Ptr (byteArrayContents# @@ -162,41 +166,41 @@ asPtrUnsafe arr f = do -------------------------------------------------------------------------------- {-# NOINLINE nil #-} -nil :: MutableByteArray +nil :: MutByteArray nil = unsafePerformIO $ newBytes 0 {-# INLINE newBytes #-} -newBytes :: Int -> IO MutableByteArray +newBytes :: Int -> IO MutByteArray newBytes nbytes | nbytes < 0 = errorWithoutStackTrace "newBytes: size must be >= 0" newBytes (I# nbytes) = IO $ \s -> case newByteArray# nbytes s of (# s', mbarr# #) -> - let c = MutableByteArray mbarr# + let c = MutByteArray mbarr# in (# s', c #) {-# INLINE pinnedNewBytes #-} -pinnedNewBytes :: Int -> IO MutableByteArray +pinnedNewBytes :: Int -> IO MutByteArray pinnedNewBytes nbytes | nbytes < 0 = errorWithoutStackTrace "pinnedNewBytes: size must be >= 0" pinnedNewBytes (I# nbytes) = IO $ \s -> case newPinnedByteArray# nbytes s of (# s', mbarr# #) -> - let c = MutableByteArray mbarr# + let c = MutByteArray mbarr# in (# s', c #) {-# INLINE pinnedNewAlignedBytes #-} -pinnedNewAlignedBytes :: Int -> Int -> IO MutableByteArray +pinnedNewAlignedBytes :: Int -> Int -> IO MutByteArray pinnedNewAlignedBytes nbytes _align | nbytes < 0 = errorWithoutStackTrace "pinnedNewAlignedBytes: size must be >= 0" pinnedNewAlignedBytes (I# nbytes) (I# align) = IO $ \s -> case newAlignedPinnedByteArray# nbytes align s of (# s', mbarr# #) -> - let c = MutableByteArray mbarr# + let c = MutByteArray mbarr# in (# s', c #) {-# INLINE newBytesAs #-} -newBytesAs :: PinnedState -> Int -> IO MutableByteArray +newBytesAs :: PinnedState -> Int -> IO MutByteArray newBytesAs Unpinned = newBytes newBytesAs Pinned = pinnedNewBytes @@ -209,9 +213,9 @@ newBytesAs Pinned = pinnedNewBytes {-# INLINE putSliceUnsafe #-} putSliceUnsafe :: MonadIO m - => MutableByteArray + => MutByteArray -> Int - -> MutableByteArray + -> MutByteArray -> Int -> Int -> m () @@ -236,8 +240,8 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do ------------------------------------------------------------------------------- {-# INLINE isPinned #-} -isPinned :: MutableByteArray -> Bool -isPinned (MutableByteArray arr#) = +isPinned :: MutByteArray -> Bool +isPinned (MutByteArray arr#) = let pinnedInt = I# (isMutableByteArrayPinned# arr#) in pinnedInt /= 0 @@ -258,8 +262,8 @@ cloneMutableArrayWith# alloc# arr# s# = s3# -> (# s3#, arr1# #) {-# INLINE pin #-} -pin :: MutableByteArray -> IO MutableByteArray -pin arr@(MutableByteArray marr#) = +pin :: MutByteArray -> IO MutByteArray +pin arr@(MutByteArray marr#) = if isPinned arr then return arr else @@ -271,11 +275,11 @@ pin arr@(MutableByteArray marr#) = IO $ \s# -> case cloneMutableArrayWith# newPinnedByteArray# marr# s# of - (# s1#, marr1# #) -> (# s1#, MutableByteArray marr1# #) + (# s1#, marr1# #) -> (# s1#, MutByteArray marr1# #) {-# INLINE unpin #-} -unpin :: MutableByteArray -> IO MutableByteArray -unpin arr@(MutableByteArray marr#) = +unpin :: MutByteArray -> IO MutByteArray +unpin arr@(MutByteArray marr#) = if not (isPinned arr) then return arr else @@ -287,7 +291,7 @@ unpin arr@(MutableByteArray marr#) = IO $ \s# -> case cloneMutableArrayWith# newByteArray# marr# s# of - (# s1#, marr1# #) -> (# s1#, MutableByteArray marr1# #) + (# s1#, marr1# #) -> (# s1#, MutByteArray marr1# #) -------------------------------------------------------------------------------- -- The Unbox type class @@ -458,11 +462,11 @@ class Unbox a where -- -- IMPORTANT: The implementation of this interface may not check the bounds -- of the array, the caller must not assume that. - peekByteIndex :: Int -> MutableByteArray -> IO a + peekByteIndex :: Int -> MutByteArray -> IO a {-# INLINE peekByteIndex #-} default peekByteIndex :: (Generic a, PeekRep (Rep a)) => - Int -> MutableByteArray -> IO a + Int -> MutByteArray -> IO a peekByteIndex i arr = genericPeekByteIndex arr i -- | @pokeByteIndex byte-index array@ writes an element of type @a@ to the @@ -470,11 +474,11 @@ class Unbox a where -- -- IMPORTANT: The implementation of this interface may not check the bounds -- of the array, the caller must not assume that. - pokeByteIndex :: Int -> MutableByteArray -> a -> IO () + pokeByteIndex :: Int -> MutByteArray -> a -> IO () {-# INLINE pokeByteIndex #-} default pokeByteIndex :: (Generic a, PokeRep (Rep a)) => - Int -> MutableByteArray -> a -> IO () + Int -> MutByteArray -> a -> IO () pokeByteIndex i arr = genericPokeByteIndex arr i -- XXX Add asserts to check bounds @@ -482,11 +486,11 @@ class Unbox a where #define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray, _sizeOf) \ instance Unbox _type where { \ ; {-# INLINE peekByteIndex #-} \ -; peekByteIndex (I# n) (MutableByteArray mbarr) = IO $ \s -> \ +; peekByteIndex (I# n) (MutByteArray mbarr) = IO $ \s -> \ case _readArray mbarr n s of \ { (# s1, i #) -> (# s1, _constructor i #) } \ ; {-# INLINE pokeByteIndex #-} \ -; pokeByteIndex (I# n) (MutableByteArray mbarr) (_constructor val) = \ +; pokeByteIndex (I# n) (MutByteArray mbarr) (_constructor val) = \ IO $ \s -> (# _writeArray mbarr n val s, () #) \ ; {-# INLINE sizeOf #-} \ ; sizeOf _ = _sizeOf \ @@ -681,7 +685,7 @@ instance Unbox Bool where -- cheaper to just get the bound using the size of the array whenever needed? data BoundedPtr = BoundedPtr - MutableByteArray -- byte array + MutByteArray -- byte array Int -- current pos Int -- position after end @@ -966,7 +970,7 @@ genericPokeObj a ptr = void $ genericPokeObject a ptr {-# INLINE genericPokeByteIndex #-} genericPokeByteIndex :: (Generic a, PokeRep (Rep a)) => - MutableByteArray -> Int -> a -> IO () + MutByteArray -> Int -> a -> IO () genericPokeByteIndex arr index x = do -- XXX Should we use unsafe poke? #ifdef DEBUG @@ -1072,7 +1076,7 @@ genericPeekBoundedPtr = runPeeker genericPeeker {-# INLINE genericPeekByteIndex #-} genericPeekByteIndex :: (Generic a, PeekRep (Rep a)) => - MutableByteArray -> Int -> IO a + MutByteArray -> Int -> IO a genericPeekByteIndex arr index = do -- XXX Should we use unsafe peek? #ifdef DEBUG diff --git a/core/src/Streamly/Internal/Unicode/Stream.hs b/core/src/Streamly/Internal/Unicode/Stream.hs index 63c3d8a0e..9920e4637 100644 --- a/core/src/Streamly/Internal/Unicode/Stream.hs +++ b/core/src/Streamly/Internal/Unicode/Stream.hs @@ -109,7 +109,7 @@ import GHC.IO.Encoding.Failure (isSurrogate) import GHC.Ptr (Ptr (..), plusPtr) import System.IO.Unsafe (unsafePerformIO) import Streamly.Internal.Data.Array.Type (Array(..)) -import Streamly.Internal.Data.MutArray.Type (MutableByteArray) +import Streamly.Internal.Data.MutArray.Type (MutByteArray) import Streamly.Internal.Data.Fold (Fold) import Streamly.Internal.Data.Parser (Parser) import Streamly.Internal.Data.Stream (Stream) @@ -685,9 +685,9 @@ decodeUtf8Lax = decodeUtf8 #endif data FlattenState s = OuterLoop s !(Maybe (DecodeState, CodePoint)) - | InnerLoopDecodeInit s MutableByteArray !Int !Int - | InnerLoopDecodeFirst s MutableByteArray !Int !Int Word8 - | InnerLoopDecoding s MutableByteArray !Int !Int + | InnerLoopDecodeInit s MutByteArray !Int !Int + | InnerLoopDecodeFirst s MutByteArray !Int !Int Word8 + | InnerLoopDecoding s MutByteArray !Int !Int !DecodeState !CodePoint | YAndC !Char (FlattenState s) -- These constructors can be -- encoded in the UTF8DecodeState diff --git a/test/Streamly/Test/Data/Serialize.hs b/test/Streamly/Test/Data/Serialize.hs index 9f07ab3bb..96ae6a466 100644 --- a/test/Streamly/Test/Data/Serialize.hs +++ b/test/Streamly/Test/Data/Serialize.hs @@ -22,7 +22,7 @@ module Streamly.Test.Data.Serialize (main) where -------------------------------------------------------------------------------- import System.Random (randomRIO) -import Streamly.Internal.Data.Serialize (MutableByteArray, newBytes) +import Streamly.Internal.Data.Serialize (MutByteArray, newBytes) import GHC.Generics (Generic) import Streamly.Data.Serialize (Serialize) import Streamly.Test.Data.Serialize.TH (genDatatype) @@ -158,7 +158,7 @@ testCompatibility v0 v1 = do poke :: forall a. Serialize.Serialize a => a - -> IO (MutableByteArray, Int, Int) + -> IO (MutByteArray, Int, Int) poke val = do let sz = Serialize.size 0 val @@ -177,7 +177,7 @@ poke val = do peekAndVerify :: forall a. (Eq a, Show a, Serialize.Serialize a) - => (MutableByteArray, Int, Int) + => (MutByteArray, Int, Int) -> a -> IO () peekAndVerify (arr, serStartOff, serEndOff) val = do diff --git a/test/Streamly/Test/Data/Unbox.hs b/test/Streamly/Test/Data/Unbox.hs index ec811fe17..7f1e87ecc 100644 --- a/test/Streamly/Test/Data/Unbox.hs +++ b/test/Streamly/Test/Data/Unbox.hs @@ -72,7 +72,7 @@ import Test.Hspec as H peekByteIndexWithNextOff :: forall a. Unbox a => Int - -> MutableByteArray + -> MutByteArray -> IO (Int, a) peekByteIndexWithNextOff i arr = do val <- peekByteIndex i arr @@ -81,7 +81,7 @@ peekByteIndexWithNextOff i arr = do pokeByteIndexWithNextOff :: forall a. Unbox a => Int - -> MutableByteArray + -> MutByteArray -> a -> IO Int pokeByteIndexWithNextOff i arr val = do