on master help sign in
Relax version constraints for primitive to >= 0.6.2.0

Add Internal.Data.Prim.Array.Types Use Internal.Data.Prim.Array.Types if primitive version is < 0.6.4.0 Modify Internal.Data.Prim.Array accordingly

commit0cccb7fc792a1d57bea058092f8e373e39850db8 authoradithyaov <adi.obilisetty@gmail.com> dateThu 6 Feb 2020, 17:00 (7 years ago) parente14ad7b
3 files changed+13−36
src/Streamly/Internal/Data/Prim/Array.hs+1−2 src/Streamly/Internal/Data/Prim/Array/Types.hs+9−32 streamly.cabal+3−2
src/Streamly/Internal/Data/Prim/Array.hs+1−2
@@ -61,8 +61,7 @@ import Control.Monad.IO.Class (liftIO, MonadIO)
6161import GHC.IO (unsafePerformIO)
6262import Data.Primitive.Types (Prim(..))
6363
64−import Data.Primitive.PrimArray
65−
64+import Streamly.Internal.Data.Prim.Array.Types
6665import Streamly.Internal.Data.Unfold.Types (Unfold(..))
6766import Streamly.Internal.Data.Fold.Types (Fold(..))
6867import Streamly.Internal.Data.Stream.StreamK.Type (IsStream)
src/Streamly/Internal/Data/Prim/Array/Types.hs+9−32
@@ -6,13 +6,12 @@
66{-# LANGUAGE TypeFamilies #-}
77{-# LANGUAGE UnboxedTuples #-}
88
9−
109-- |
11−-- Module : Data.Primitive.PrimArray
10+-- Module : Streamly.Internal.Data.Prim.Array.Types
1211-- Copyright : (c) Roman Leshchinskiy 2009-2012
1312-- License : BSD-style
1413--
15−-- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au>
14+-- Maintainer : streamly@composewell.com
1615-- Portability : non-portable
1716--
1817-- Arrays of unboxed primitive types. The function provided by this module
@@ -25,16 +24,14 @@
2524-- terms of elements, not bytes.
2625--
2726-- @since 0.6.4.0
28−module Data.Primitive.PrimArray
27+module Streamly.Internal.Data.Prim.Array.Types
2928 ( -- * Types
3029 PrimArray(..)
3130 , MutablePrimArray(..)
3231 -- * Allocation
3332 , newPrimArray
3433 , resizeMutablePrimArray
35−#if __GLASGOW_HASKELL__ >= 710
3634 , shrinkMutablePrimArray
37−#endif
3835 -- * Element Access
3936 , readPrimArray
4037 , writePrimArray
@@ -45,10 +42,8 @@ module Data.Primitive.PrimArray
4542 -- * Block Operations
4643 , copyPrimArray
4744 , copyMutablePrimArray
48−#if __GLASGOW_HASKELL__ >= 708
4945 , copyPrimArrayToPtr
5046 , copyMutablePrimArrayToPtr
51−#endif
5247 , setPrimArray
5348 -- * Information
5449 , sameMutablePrimArray
@@ -94,11 +89,12 @@ module Data.Primitive.PrimArray
9489 ) where
9590
9691import GHC.Exts
97−import GHC.Base ( Int(..) )
98−import Data.Primitive.Internal.Compat (isTrue#)
92+
9993import Data.Primitive.Types
10094import Data.Primitive.ByteArray (ByteArray(..))
95+#if !MIN_VERSION_base(4,11,0)
10196import Data.Monoid (Monoid(..),(<>))
97+#endif
10298import Control.Applicative
10399import Control.Monad.Primitive
104100import Control.Monad.ST
@@ -106,12 +102,10 @@ import qualified Data.List as L
106102import qualified Data.Primitive.ByteArray as PB
107103import qualified Data.Primitive.Types as PT
108104
109−#if MIN_VERSION_base(4,7,0)
110−import GHC.Exts (IsList(..))
105+#if MIN_VERSION_base(4,9,0) && !MIN_VERSION_base(4,11,0)
106+import Data.Semigroup (Semigroup)
111107#endif
112−
113108#if MIN_VERSION_base(4,9,0)
114−import Data.Semigroup (Semigroup)
115109import qualified Data.Semigroup as SG
116110#endif
117111
@@ -134,12 +128,7 @@ data MutablePrimArray s a = MutablePrimArray (MutableByteArray# s)
134128sameByteArray :: ByteArray# -> ByteArray# -> Bool
135129sameByteArray ba1 ba2 =
136130 case reallyUnsafePtrEquality# (unsafeCoerce# ba1 :: ()) (unsafeCoerce# ba2 :: ()) of
137−#if __GLASGOW_HASKELL__ >= 708
138131 r -> isTrue# r
139−#else
140− 1# -> True
141− _ -> False
142−#endif
143132
144133-- | @since 0.6.4.0
145134instance (Eq a, Prim a) => Eq (PrimArray a) where
@@ -174,14 +163,12 @@ instance (Ord a, Prim a) => Ord (PrimArray a) where
174163 | otherwise = compare sz1 sz2
175164 {-# INLINE compare #-}
176165
177−#if MIN_VERSION_base(4,7,0)
178166-- | @since 0.6.4.0
179167instance Prim a => IsList (PrimArray a) where
180168 type Item (PrimArray a) = a
181169 fromList = primArrayFromList
182170 fromListN = primArrayFromListN
183171 toList = primArrayToList
184−#endif
185172
186173-- | @since 0.6.4.0
187174instance (Show a, Prim a) => Show (PrimArray a) where
@@ -271,20 +258,13 @@ resizeMutablePrimArray :: forall m a. (PrimMonad m, Prim a)
271258 -> Int -- ^ new size
272259 -> m (MutablePrimArray (PrimState m) a)
273260{-# INLINE resizeMutablePrimArray #-}
274−#if __GLASGOW_HASKELL__ >= 710
275261resizeMutablePrimArray (MutablePrimArray arr#) (I# n#)
276262 = primitive (\s# -> case resizeMutableByteArray# arr# (n# *# sizeOf# (undefined :: a)) s# of
277263 (# 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
284264
285265-- Although it is possible to shim resizeMutableByteArray for old GHCs, this
286266-- is not the case with shrinkMutablePrimArray.
287−#if __GLASGOW_HASKELL__ >= 710
267+
288268-- | Shrink a mutable primitive array. The new size is given in elements.
289269-- It must be smaller than the old size. The array will be resized in place.
290270-- 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)
295275{-# INLINE shrinkMutablePrimArray #-}
296276shrinkMutablePrimArray (MutablePrimArray arr#) (I# n#)
297277 = primitive_ (shrinkMutableByteArray# arr# (n# *# sizeOf# (undefined :: a)))
298−#endif
299278
300279readPrimArray :: (Prim a, PrimMonad m) => MutablePrimArray (PrimState m) a -> Int -> m a
301280{-# INLINE readPrimArray #-}
@@ -353,7 +332,6 @@ copyPrimArray (MutablePrimArray dst#) (I# doff#) (PrimArray src#) (I# soff#) (I#
353332 (n# *# (sizeOf# (undefined :: a)))
354333 )
355334
356−#if __GLASGOW_HASKELL__ >= 708
357335-- | Copy a slice of an immutable primitive array to an address.
358336-- The offset and length are given in elements of type @a@.
359337-- This function assumes that the 'Prim' instance of @a@
@@ -389,7 +367,6 @@ copyMutablePrimArrayToPtr (Ptr addr#) (MutablePrimArray mba#) (I# soff#) (I# n#)
389367 let s'# = copyMutableByteArrayToAddr# mba# (soff# *# siz#) addr# (n# *# siz#) s#
390368 in (# s'#, () #))
391369 where siz# = sizeOf# (undefined :: a)
392−#endif
393370
394371-- | Fill a slice of a mutable primitive array with a value.
395372setPrimArray
streamly.cabal+3−2
@@ -306,6 +306,7 @@ library
306306 , Streamly.Internal.Data.Time.Clock
307307 , Streamly.Internal.Data.SVar
308308 , Streamly.Internal.Data.Array
309+ , Streamly.Internal.Data.Prim.Array.Types
309310 , Streamly.Internal.Data.Prim.Array
310311 , Streamly.Internal.Data.SmallArray
311312 , Streamly.Internal.Memory.Array.Types
@@ -370,7 +371,7 @@ library
370371 , transformers >= 0.4 && < 0.6
371372
372373 , heaps >= 0.3 && < 0.4
373− , primitive >= 0.6.4.0 && < 0.8
374+ , primitive >= 0.6.2.0 && < 0.8
374375
375376 -- concurrency
376377 , atomic-primops >= 0.8 && < 0.9
@@ -707,7 +708,7 @@ benchmark prim-array
707708 if impl(ghc < 8.0)
708709 build-depends:
709710 transformers >= 0.4 && < 0.6
710−
711+
711712benchmark small-array
712713 import: bench-options
713714 type: exitcode-stdio-1.0