on master help sign in
Relax version constraints for primitive to >= 0.6.2.0
0cccb7fadithyaov
src/Streamly/Internal/Data/Prim/Array.hs+1−2
@@ -61,8 +61,7 @@ import Control.Monad.IO.Class (liftIO, MonadIO)
61import GHC.IO (unsafePerformIO)
61import GHC.IO (unsafePerformIO)
62import Data.Primitive.Types (Prim(..))
62import Data.Primitive.Types (Prim(..))
63
63
64−import Data.Primitive.PrimArray
64+import Streamly.Internal.Data.Prim.Array.Types
65−
66import Streamly.Internal.Data.Unfold.Types (Unfold(..))
65import Streamly.Internal.Data.Unfold.Types (Unfold(..))
67import Streamly.Internal.Data.Fold.Types (Fold(..))
66import Streamly.Internal.Data.Fold.Types (Fold(..))
68import Streamly.Internal.Data.Stream.StreamK.Type (IsStream)
67import Streamly.Internal.Data.Stream.StreamK.Type (IsStream)
src/Streamly/Internal/Data/Prim/Array/Types.hs+9−32
@@ -6,13 +6,12 @@
6{-# LANGUAGE TypeFamilies #-}
6{-# LANGUAGE TypeFamilies #-}
7{-# LANGUAGE UnboxedTuples #-}
7{-# LANGUAGE UnboxedTuples #-}
8
8
9−
10-- |
9-- |
11−-- Module : Data.Primitive.PrimArray
10+-- Module : Streamly.Internal.Data.Prim.Array.Types
12-- Copyright : (c) Roman Leshchinskiy 2009-2012
11-- Copyright : (c) Roman Leshchinskiy 2009-2012
13-- License : BSD-style
12-- License : BSD-style
14--
13--
15−-- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au>
14+-- Maintainer : streamly@composewell.com
16-- Portability : non-portable
15-- Portability : non-portable
17--
16--
18-- Arrays of unboxed primitive types. The function provided by this module
17-- Arrays of unboxed primitive types. The function provided by this module
@@ -25,16 +24,14 @@
25-- terms of elements, not bytes.
24-- terms of elements, not bytes.
26--
25--
27-- @since 0.6.4.0
26-- @since 0.6.4.0
28−module Data.Primitive.PrimArray
27+module Streamly.Internal.Data.Prim.Array.Types
29 ( -- * Types
28 ( -- * Types
30 PrimArray(..)
29 PrimArray(..)
31 , MutablePrimArray(..)
30 , MutablePrimArray(..)
32 -- * Allocation
31 -- * Allocation
33 , newPrimArray
32 , newPrimArray
34 , resizeMutablePrimArray
33 , resizeMutablePrimArray
35−#if __GLASGOW_HASKELL__ >= 710
36 , shrinkMutablePrimArray
34 , shrinkMutablePrimArray
37−#endif
38 -- * Element Access
35 -- * Element Access
39 , readPrimArray
36 , readPrimArray
40 , writePrimArray
37 , writePrimArray
@@ -45,10 +42,8 @@ module Data.Primitive.PrimArray
45 -- * Block Operations
42 -- * Block Operations
46 , copyPrimArray
43 , copyPrimArray
47 , copyMutablePrimArray
44 , copyMutablePrimArray
48−#if __GLASGOW_HASKELL__ >= 708
49 , copyPrimArrayToPtr
45 , copyPrimArrayToPtr
50 , copyMutablePrimArrayToPtr
46 , copyMutablePrimArrayToPtr
51−#endif
52 , setPrimArray
47 , setPrimArray
53 -- * Information
48 -- * Information
54 , sameMutablePrimArray
49 , sameMutablePrimArray
@@ -94,11 +89,12 @@ module Data.Primitive.PrimArray
94 ) where
89 ) where
95
90
96import GHC.Exts
91import GHC.Exts
97−import GHC.Base ( Int(..) )
92+
98−import Data.Primitive.Internal.Compat (isTrue#)
99import Data.Primitive.Types
93import Data.Primitive.Types
100import Data.Primitive.ByteArray (ByteArray(..))
94import Data.Primitive.ByteArray (ByteArray(..))
95+#if !MIN_VERSION_base(4,11,0)
101import Data.Monoid (Monoid(..),(<>))
96import Data.Monoid (Monoid(..),(<>))
97+#endif
102import Control.Applicative
98import Control.Applicative
103import Control.Monad.Primitive
99import Control.Monad.Primitive
104import Control.Monad.ST
100import Control.Monad.ST
@@ -106,12 +102,10 @@ import qualified Data.List as L
106import qualified Data.Primitive.ByteArray as PB
102import qualified Data.Primitive.ByteArray as PB
107import qualified Data.Primitive.Types as PT
103import qualified Data.Primitive.Types as PT
108
104
109−#if MIN_VERSION_base(4,7,0)
105+#if MIN_VERSION_base(4,9,0) && !MIN_VERSION_base(4,11,0)
110−import GHC.Exts (IsList(..))
106+import Data.Semigroup (Semigroup)
111#endif
107#endif
112−
113#if MIN_VERSION_base(4,9,0)
108#if MIN_VERSION_base(4,9,0)
114−import Data.Semigroup (Semigroup)
115import qualified Data.Semigroup as SG
109import qualified Data.Semigroup as SG
116#endif
110#endif
117
111
@@ -134,12 +128,7 @@ data MutablePrimArray s a = MutablePrimArray (MutableByteArray# s)
134sameByteArray :: ByteArray# -> ByteArray# -> Bool
128sameByteArray :: ByteArray# -> ByteArray# -> Bool
135sameByteArray ba1 ba2 =
129sameByteArray ba1 ba2 =
136 case reallyUnsafePtrEquality# (unsafeCoerce# ba1 :: ()) (unsafeCoerce# ba2 :: ()) of
130 case reallyUnsafePtrEquality# (unsafeCoerce# ba1 :: ()) (unsafeCoerce# ba2 :: ()) of
137−#if __GLASGOW_HASKELL__ >= 708
138 r -> isTrue# r
131 r -> isTrue# r
139−#else
140− 1# -> True
141− _ -> False
142−#endif
143
132
144-- | @since 0.6.4.0
133-- | @since 0.6.4.0
145instance (Eq a, Prim a) => Eq (PrimArray a) where
134instance (Eq a, Prim a) => Eq (PrimArray a) where
@@ -174,14 +163,12 @@ instance (Ord a, Prim a) => Ord (PrimArray a) where
174 | otherwise = compare sz1 sz2
163 | otherwise = compare sz1 sz2
175 {-# INLINE compare #-}
164 {-# INLINE compare #-}
176
165
177−#if MIN_VERSION_base(4,7,0)
178-- | @since 0.6.4.0
166-- | @since 0.6.4.0
179instance Prim a => IsList (PrimArray a) where
167instance Prim a => IsList (PrimArray a) where
180 type Item (PrimArray a) = a
168 type Item (PrimArray a) = a
181 fromList = primArrayFromList
169 fromList = primArrayFromList
182 fromListN = primArrayFromListN
170 fromListN = primArrayFromListN
183 toList = primArrayToList
171 toList = primArrayToList
184−#endif
185
172
186-- | @since 0.6.4.0
173-- | @since 0.6.4.0
187instance (Show a, Prim a) => Show (PrimArray a) where
174instance (Show a, Prim a) => Show (PrimArray a) where
@@ -271,20 +258,13 @@ resizeMutablePrimArray :: forall m a. (PrimMonad m, Prim a)
271 -> Int -- ^ new size
258 -> Int -- ^ new size
272 -> m (MutablePrimArray (PrimState m) a)
259 -> m (MutablePrimArray (PrimState m) a)
273{-# INLINE resizeMutablePrimArray #-}
260{-# INLINE resizeMutablePrimArray #-}
274−#if __GLASGOW_HASKELL__ >= 710
275resizeMutablePrimArray (MutablePrimArray arr#) (I# n#)
261resizeMutablePrimArray (MutablePrimArray arr#) (I# n#)
276 = primitive (\s# -> case resizeMutableByteArray# arr# (n# *# sizeOf# (undefined :: a)) s# of
262 = primitive (\s# -> case resizeMutableByteArray# arr# (n# *# sizeOf# (undefined :: a)) s# of
277 (# s'#, arr'# #) -> (# s'#, MutablePrimArray arr'# #))
263 (# s'#, arr'# #) -> (# s'#, MutablePrimArray arr'# #))
278−#else
279−resizeMutablePrimArray arr n
280− = do arr' <- newPrimArray n
281− copyMutablePrimArray arr' 0 arr 0 (min (sizeofMutablePrimArray arr) n)
282− return arr'
283−#endif
284
264
285-- Although it is possible to shim resizeMutableByteArray for old GHCs, this
265-- Although it is possible to shim resizeMutableByteArray for old GHCs, this
286-- is not the case with shrinkMutablePrimArray.
266-- is not the case with shrinkMutablePrimArray.
287−#if __GLASGOW_HASKELL__ >= 710
267+
288-- | Shrink a mutable primitive array. The new size is given in elements.
268-- | Shrink a mutable primitive array. The new size is given in elements.
289-- It must be smaller than the old size. The array will be resized in place.
269-- It must be smaller than the old size. The array will be resized in place.
290-- This function is only available when compiling with GHC 7.10 or newer.
270-- This function is only available when compiling with GHC 7.10 or newer.
@@ -295,7 +275,6 @@ shrinkMutablePrimArray :: forall m a. (PrimMonad m, Prim a)
295{-# INLINE shrinkMutablePrimArray #-}
275{-# INLINE shrinkMutablePrimArray #-}
296shrinkMutablePrimArray (MutablePrimArray arr#) (I# n#)
276shrinkMutablePrimArray (MutablePrimArray arr#) (I# n#)
297 = primitive_ (shrinkMutableByteArray# arr# (n# *# sizeOf# (undefined :: a)))
277 = primitive_ (shrinkMutableByteArray# arr# (n# *# sizeOf# (undefined :: a)))
298−#endif
299
278
300readPrimArray :: (Prim a, PrimMonad m) => MutablePrimArray (PrimState m) a -> Int -> m a
279readPrimArray :: (Prim a, PrimMonad m) => MutablePrimArray (PrimState m) a -> Int -> m a
301{-# INLINE readPrimArray #-}
280{-# INLINE readPrimArray #-}
@@ -353,7 +332,6 @@ copyPrimArray (MutablePrimArray dst#) (I# doff#) (PrimArray src#) (I# soff#) (I#
353 (n# *# (sizeOf# (undefined :: a)))
332 (n# *# (sizeOf# (undefined :: a)))
354 )
333 )
355
334
356−#if __GLASGOW_HASKELL__ >= 708
357-- | Copy a slice of an immutable primitive array to an address.
335-- | Copy a slice of an immutable primitive array to an address.
358-- The offset and length are given in elements of type @a@.
336-- The offset and length are given in elements of type @a@.
359-- This function assumes that the 'Prim' instance of @a@
337-- This function assumes that the 'Prim' instance of @a@
@@ -389,7 +367,6 @@ copyMutablePrimArrayToPtr (Ptr addr#) (MutablePrimArray mba#) (I# soff#) (I# n#)
389 let s'# = copyMutableByteArrayToAddr# mba# (soff# *# siz#) addr# (n# *# siz#) s#
367 let s'# = copyMutableByteArrayToAddr# mba# (soff# *# siz#) addr# (n# *# siz#) s#
390 in (# s'#, () #))
368 in (# s'#, () #))
391 where siz# = sizeOf# (undefined :: a)
369 where siz# = sizeOf# (undefined :: a)
392−#endif
393
370
394-- | Fill a slice of a mutable primitive array with a value.
371-- | Fill a slice of a mutable primitive array with a value.
395setPrimArray
372setPrimArray
streamly.cabal+3−2
@@ -306,6 +306,7 @@ library
306 , Streamly.Internal.Data.Time.Clock
306 , Streamly.Internal.Data.Time.Clock
307 , Streamly.Internal.Data.SVar
307 , Streamly.Internal.Data.SVar
308 , Streamly.Internal.Data.Array
308 , Streamly.Internal.Data.Array
309+ , Streamly.Internal.Data.Prim.Array.Types
309 , Streamly.Internal.Data.Prim.Array
310 , Streamly.Internal.Data.Prim.Array
310 , Streamly.Internal.Data.SmallArray
311 , Streamly.Internal.Data.SmallArray
311 , Streamly.Internal.Memory.Array.Types
312 , Streamly.Internal.Memory.Array.Types
@@ -370,7 +371,7 @@ library
370 , transformers >= 0.4 && < 0.6
371 , transformers >= 0.4 && < 0.6
371
372
372 , heaps >= 0.3 && < 0.4
373 , heaps >= 0.3 && < 0.4
373− , primitive >= 0.6.4.0 && < 0.8
374+ , primitive >= 0.6.2.0 && < 0.8
374
375
375 -- concurrency
376 -- concurrency
376 , atomic-primops >= 0.8 && < 0.9
377 , atomic-primops >= 0.8 && < 0.9
@@ -707,7 +708,7 @@ benchmark prim-array
707 if impl(ghc < 8.0)
708 if impl(ghc < 8.0)
708 build-depends:
709 build-depends:
709 transformers >= 0.4 && < 0.6
710 transformers >= 0.4 && < 0.6
710−
711+
711benchmark small-array
712benchmark small-array
712 import: bench-options
713 import: bench-options
713 type: exitcode-stdio-1.0
714 type: exitcode-stdio-1.0