on master help sign in
Fix bug in ArrayOps.hs

Remove DATA_PRIM_ARRAY Add DATA_ARRAY_PRIM & DATA_ARRAY_PRIM_PINNED Reduce the use of #else in CPP

commit73df67ee931323bfa5a2c236ef21316411588e61 authoradithyaov <adithya@composewell.com> dateWed 11 Nov 2020, 19:17 (6 years ago) parentaced270
2 files changed+21−11
benchmark/Streamly/Benchmark/Data/Array.hs+2 benchmark/Streamly/Benchmark/Data/ArrayOps.hs+19−11
benchmark/Streamly/Benchmark/Data/Array.hs+2
@@ -44,7 +44,9 @@ benchIO name src f = bench name $ nfIO $
4444-- Drain a source that generates an array in the IO monad
4545{-# INLINE benchIOSrc #-}
4646benchIOSrc ::
47+#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
4748 NFData a =>
49+#endif
4850#ifdef MEMORY_ARRAY
4951 Storable a =>
5052#endif
benchmark/Streamly/Benchmark/Data/ArrayOps.hs+19−11
@@ -12,7 +12,8 @@
1212-- CPP:
1313-- MEMORY_ARRAY
1414-- DATA_ARRAY
15−-- DATA_PRIM_ARRAY
15+-- DATA_ARRAY_PRIM
16+-- DATA_ARRAY_PRIM_PINNED
1617-- DATA_SMALLARRAY
1718
1819module Streamly.Benchmark.Data.ArrayOps where
@@ -23,7 +24,7 @@ import Prelude (Bool, Int, Maybe(..), ($), (+), (.), (==), (>), undefined)
2324import qualified Prelude as P
2425import qualified Streamly.Prelude as S
2526
26−#ifndef DATA_PRIM_ARRAY
27+#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
2728#ifdef DEVBUILD
2829import qualified Data.Foldable as F
2930#endif
@@ -37,10 +38,13 @@ import qualified GHC.Exts as GHC
3738import qualified Streamly.Data.Array.Storable.Foreign as A
3839import qualified Streamly.Internal.Data.Array.Storable.Foreign as A
3940type Stream = A.Array
40−#elif defined(DATA_PRIM_ARRAY)
41−import qualified Streamly.Internal.Data.Prim.Array as A
42−type Stream = A.PrimArray
43−#else
41+#elif defined(DATA_ARRAY_PRIM)
42+import qualified Streamly.Internal.Data.Array.Prim as A
43+type Stream = A.Array
44+#elif defined(DATA_ARRAY_PRIM_PINNED)
45+import qualified Streamly.Internal.Data.Array.Prim.Pinned as A
46+type Stream = A.Array
47+#elif defined(DATA_ARRAY)
4448import qualified Streamly.Internal.Data.Array as A
4549type Stream = A.Array
4650#endif
@@ -57,7 +61,8 @@ type Stream = A.Array
5761-- CPP Common to:
5862-- MEMORY_ARRAY
5963-- DATA_ARRAY
60−-- DATA_PRIM_ARRAY
64+-- DATA_ARRAY_PRIM
65+-- DATA_ARRAY_PRIM_PINNED
6166-- DATA_SMALLARRAY
6267-------------------------------------------------------------------------------
6368
@@ -92,7 +97,8 @@ sourceIntFromToFromList value n = P.return $ A.fromListN value $ [n..n + value]
9297-- CPP Common to:
9398-- MEMORY_ARRAY
9499-- DATA_ARRAY
95−-- DATA_PRIM_ARRAY
100+-- DATA_ARRAY_PRIM
101+-- DATA_ARRAY_PRIM_PINNED
96102-------------------------------------------------------------------------------
97103
98104-- CPP:
@@ -126,7 +132,8 @@ sourceIsString value n = GHC.fromString (P.replicate (n + value) 'a')
126132-- CPP Common to:
127133-- MEMORY_ARRAY
128134-- DATA_ARRAY
129−-- DATA_PRIM_ARRAY
135+-- DATA_ARRAY_PRIM
136+-- DATA_ARRAY_PRIM_PINNED
130137-- DATA_SMALLARRAY
131138-------------------------------------------------------------------------------
132139
@@ -193,7 +200,7 @@ pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
193200-------------------------------------------------------------------------------
194201
195202-- CPP:
196−#ifndef DATA_PRIM_ARRAY
203+#if !defined(DATA_ARRAY_PRIM) && !defined(DATA_ARRAY_PRIM_PINNED)
197204{-# INLINE readInstance #-}
198205readInstance :: P.String -> Stream Int
199206readInstance str =
@@ -221,7 +228,8 @@ foldableSum = P.sum
221228-- CPP Common to:
222229-- MEMORY_ARRAY
223230-- DATA_ARRAY
224−-- DATA_PRIM_ARRAY
231+-- DATA_ARRAY_PRIM
232+-- DATA_ARRAY_PRIM_PINNED
225233-- DATA_SMALLARRAY
226234-------------------------------------------------------------------------------
227235