on master help sign in
Move SmallArray to dev flag (#1783)
6e77cdbRanjeet Ranjan
.github/workflows/regression-check.yml−2
@@ -24,9 +24,7 @@ jobs:
24 Data.Parser
24 Data.Parser
25 Data.Parser.ParserD
25 Data.Parser.ParserD
26 Data.Parser.ParserK
26 Data.Parser.ParserK
27− Data.SmallArray
28 Data.Stream.StreamD
27 Data.Stream.StreamD
29− Data.Stream.StreamDK
30 Data.Stream.StreamK:6
28 Data.Stream.StreamK:6
31 Data.Unfold
29 Data.Unfold
32 Data.Stream
30 Data.Stream
benchmark/NanoBenchmarks.hs+23−17
@@ -6,27 +6,27 @@
6{-# LANGUAGE FlexibleContexts #-}
6{-# LANGUAGE FlexibleContexts #-}
7{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE ScopedTypeVariables #-}
8
8
9+import Data.Char (ord)
9import Streamly.Internal.Data.Stream (Stream)
10import Streamly.Internal.Data.Stream (Stream)
10−import Streamly.Internal.Data.SVar (MonadAsync)
11+import System.IO (hSeek, SeekMode(..), openFile, IOMode(..))
11
12
12import qualified Streamly.Data.Array.Unboxed as A
13import qualified Streamly.Data.Array.Unboxed as A
13−import qualified Streamly.FileSystem.Handle as FH
14import qualified Streamly.Internal.FileSystem.Handle as IFH
14import qualified Streamly.Internal.FileSystem.Handle as IFH
15import qualified Streamly.Data.Fold as FL
15import qualified Streamly.Data.Fold as FL
16+import qualified Streamly.Internal.Data.Stream as S
16import qualified Streamly.Internal.Data.Stream.IsStream as Internal
17import qualified Streamly.Internal.Data.Stream.IsStream as Internal
17−import qualified Streamly.Prelude as S
18−import qualified Streamly.Internal.Data.Stream.StreamK as K
19
18
20−import Data.Char (ord)
21import Gauge
19import Gauge
22−import System.IO (hSeek, SeekMode(..), openFile, IOMode(..))
23import System.Random
20import System.Random
24
21
25maxValue :: Int
22maxValue :: Int
26maxValue = 100000
23maxValue = 100000
27
24
25+drain :: Monad m => S.Stream m a -> m ()
26+drain = S.fold FL.drain
27+
28{-# INLINE sourceUnfoldrM #-}
28{-# INLINE sourceUnfoldrM #-}
29−sourceUnfoldrM :: MonadAsync m => Stream m Int
29+sourceUnfoldrM :: Monad m => Stream m Int
30sourceUnfoldrM = S.unfoldrM step 0
30sourceUnfoldrM = S.unfoldrM step 0
31 where
31 where
32 step cnt =
32 step cnt =
@@ -35,7 +35,7 @@ sourceUnfoldrM = S.unfoldrM step 0
35 else return (Just (cnt, cnt + 1))
35 else return (Just (cnt, cnt + 1))
36
36
37{-# INLINE sourceUnfoldrMN #-}
37{-# INLINE sourceUnfoldrMN #-}
38−sourceUnfoldrMN :: MonadAsync m => Int -> Stream m Int
38+sourceUnfoldrMN :: Monad m => Int -> Stream m Int
39sourceUnfoldrMN n = S.unfoldrM step n
39sourceUnfoldrMN n = S.unfoldrM step n
40 where
40 where
41 step cnt =
41 step cnt =
@@ -64,7 +64,7 @@ takeAllDropOne = S.drop 1 . S.take maxValue
64
64
65{-# INLINE takeDrop #-}
65{-# INLINE takeDrop #-}
66takeDrop :: Monad m => Stream m Int -> m ()
66takeDrop :: Monad m => Stream m Int -> m ()
67−takeDrop = S.drain .
67+takeDrop = drain .
68 takeAllDropOne . takeAllDropOne . takeAllDropOne . takeAllDropOne
68 takeAllDropOne . takeAllDropOne . takeAllDropOne . takeAllDropOne
69
69
70-------------------------------------------------------------------------------
70-------------------------------------------------------------------------------
@@ -79,7 +79,7 @@ dropWhileFalse = S.dropWhile (> maxValue)
79
79
80{-# INLINE dropWhileFalseX4 #-}
80{-# INLINE dropWhileFalseX4 #-}
81dropWhileFalseX4 :: Monad m => Stream m Int -> m ()
81dropWhileFalseX4 :: Monad m => Stream m Int -> m ()
82−dropWhileFalseX4 = S.drain
82+dropWhileFalseX4 = drain
83 . dropWhileFalse . dropWhileFalse . dropWhileFalse . dropWhileFalse
83 . dropWhileFalse . dropWhileFalse . dropWhileFalse . dropWhileFalse
84
84
85-------------------------------------------------------------------------------
85-------------------------------------------------------------------------------
@@ -88,7 +88,7 @@ dropWhileFalseX4 = S.drain
88
88
89{-# INLINE iterateSource #-}
89{-# INLINE iterateSource #-}
90iterateSource
90iterateSource
91− :: MonadAsync m
91+ :: Monad m
92 => (Stream m Int -> Stream m Int) -> Int -> Int -> Stream m Int
92 => (Stream m Int -> Stream m Int) -> Int -> Int -> Stream m Int
93iterateSource g i n = f i (sourceUnfoldrMN n)
93iterateSource g i n = f i (sourceUnfoldrMN n)
94 where
94 where
@@ -100,20 +100,26 @@ iterateSource g i n = f i (sourceUnfoldrMN n)
100main :: IO ()
100main :: IO ()
101main = do
101main = do
102 defaultMain [bench "unfoldr" $ nfIO $
102 defaultMain [bench "unfoldr" $ nfIO $
103− randomRIO (1,1) >>= \n -> S.drain (sourceUnfoldr n)]
103+ randomRIO (1,1) >>= \n -> drain (sourceUnfoldr n)]
104 defaultMain [bench "take-drop" $ nfIO $ takeDrop sourceUnfoldrM]
104 defaultMain [bench "take-drop" $ nfIO $ takeDrop sourceUnfoldrM]
105 defaultMain [bench "dropWhileFalseX4" $
105 defaultMain [bench "dropWhileFalseX4" $
106 nfIO $ dropWhileFalseX4 sourceUnfoldrM]
106 nfIO $ dropWhileFalseX4 sourceUnfoldrM]
107 defaultMain [bench "iterate-mapM" $
107 defaultMain [bench "iterate-mapM" $
108− nfIO $ S.drain $ iterateSource (S.mapM return) 100000 10]
108+ nfIO $ drain $ iterateSource (S.mapM return) 100000 10]
109
109
110 inText <- openFile "benchmark/text-processing/gutenberg-500.txt" ReadMode
110 inText <- openFile "benchmark/text-processing/gutenberg-500.txt" ReadMode
111 defaultMain [mkBenchText "splitOn abc...xyz" inText $ do
111 defaultMain [mkBenchText "splitOn abc...xyz" inText $ do
112+ S.fold FL.length
112− (S.length $ Internal.splitOnSeq (A.fromList $ map (fromIntegral . ord)
113+ (Internal.splitOnSeq
114+ (A.fromList
113− "abcdefghijklmnopqrstuvwxyz") FL.drain
115+ $ map (fromIntegral . ord) "abcdefghijklmnopqrstuvwxyz"
116+ )
117+ FL.drain
114− $ IFH.getBytes inText) >>= print
118+ $ IFH.getBytes inText
119+ )
120+ >>= print
115 ]
121 ]
116 where
122 where
117
123
118 mkBenchText name h action =
124 mkBenchText name h action =
119− bench name $ perRunEnv (hSeek h AbsoluteSeek 0) (\_ -> action)
125+ env (hSeek h AbsoluteSeek 0) (\_ -> bench name $ nfIO action)
benchmark/bench-runner/Main.hs−1
@@ -74,7 +74,6 @@ rtsOpts exeName benchName0 = unwords [general, exeSpecific, benchSpecific]
74 | "Data.Parser.ParserK/o-n-heap.someAlt" == benchName = "-K4M -M128M"
74 | "Data.Parser.ParserK/o-n-heap.someAlt" == benchName = "-K4M -M128M"
75 | "Data.Parser.ParserK/o-n-heap.sequence" == benchName = "-M64M"
75 | "Data.Parser.ParserK/o-n-heap.sequence" == benchName = "-M64M"
76 | "Data.Parser.ParserK/o-n-heap.sequenceA" == benchName = "-M64M"
76 | "Data.Parser.ParserK/o-n-heap.sequenceA" == benchName = "-M64M"
77− | "Data.SmallArray.o-1-sp" `isPrefixOf` benchName = "-K128K"
78 | "Data.Array" `isPrefixOf` benchName
77 | "Data.Array" `isPrefixOf` benchName
79 && "/o-1-space.generation.read" `isSuffixOf` benchName = "-M32M"
78 && "/o-1-space.generation.read" `isSuffixOf` benchName = "-M32M"
80 | "Data.Array" `isPrefixOf` benchName
79 | "Data.Array" `isPrefixOf` benchName
benchmark/streamly-benchmarks.cabal+4−6
@@ -450,10 +450,8 @@ benchmark Data.Stream.StreamDK
450 type: exitcode-stdio-1.0
450 type: exitcode-stdio-1.0
451 hs-source-dirs: Streamly/Benchmark/Data/Stream
451 hs-source-dirs: Streamly/Benchmark/Data/Stream
452 main-is: StreamDK.hs
452 main-is: StreamDK.hs
453− if impl(ghcjs)
453+ if !flag(dev) || impl(ghcjs)
454 buildable: False
454 buildable: False
455− else
456− buildable: True
457
455
458executable nano-bench
456executable nano-bench
459 import: bench-options
457 import: bench-options
@@ -516,10 +514,10 @@ benchmark Data.SmallArray
516 import: bench-options
514 import: bench-options
517 type: exitcode-stdio-1.0
515 type: exitcode-stdio-1.0
518 main-is: Streamly/Benchmark/Data/Array/SmallArray.hs
516 main-is: Streamly/Benchmark/Data/Array/SmallArray.hs
519− if flag(use-streamly-core)
517+ if flag(dev) && !flag(use-streamly-core)
520− buildable: False
521− else
522 buildable: True
518 buildable: True
519+ else
520+ buildable: False
523
521
524benchmark Data.Array.Unboxed
522benchmark Data.Array.Unboxed
525 import: bench-options
523 import: bench-options
core/src/Streamly/Internal/Data/Array/Stream/Fold/Foreign.hs+12
@@ -98,7 +98,11 @@ newtype ArrayFold m a b = ArrayFold (ParserD.Parser m (Array a) b)
98--
98--
99-- /Pre-release/
99-- /Pre-release/
100{-# INLINE fromFold #-}
100{-# INLINE fromFold #-}
101+#ifdef DEVBUILD
102+fromFold :: forall m a b. (MonadIO m) =>
103+#else
101fromFold :: forall m a b. (MonadIO m, Unboxed a) =>
104fromFold :: forall m a b. (MonadIO m, Unboxed a) =>
105+#endif
102 Fold.Fold m a b -> ArrayFold m a b
106 Fold.Fold m a b -> ArrayFold m a b
103fromFold (Fold.Fold fstep finitial fextract) =
107fromFold (Fold.Fold fstep finitial fextract) =
104 ArrayFold (ParserD.Parser step initial (fmap (Done 0) . fextract))
108 ArrayFold (ParserD.Parser step initial (fmap (Done 0) . fextract))
@@ -136,7 +140,11 @@ fromFold (Fold.Fold fstep finitial fextract) =
136--
140--
137-- /Pre-release/
141-- /Pre-release/
138{-# INLINE fromParserD #-}
142{-# INLINE fromParserD #-}
143+#ifdef DEVBUILD
144+fromParserD :: forall m a b. (MonadIO m) =>
145+#else
139fromParserD :: forall m a b. (MonadIO m, Unboxed a) =>
146fromParserD :: forall m a b. (MonadIO m, Unboxed a) =>
147+#endif
140 ParserD.Parser m a b -> ArrayFold m a b
148 ParserD.Parser m a b -> ArrayFold m a b
141fromParserD (ParserD.Parser step1 initial1 extract1) =
149fromParserD (ParserD.Parser step1 initial1 extract1) =
142 ArrayFold (ParserD.Parser step initial1 extract1)
150 ArrayFold (ParserD.Parser step initial1 extract1)
@@ -178,7 +186,11 @@ fromParserD (ParserD.Parser step1 initial1 extract1) =
178--
186--
179-- /Pre-release/
187-- /Pre-release/
180{-# INLINE fromParser #-}
188{-# INLINE fromParser #-}
189+#ifdef DEVBUILD
190+fromParser :: forall m a b. (MonadThrow m, MonadIO m) =>
191+#else
181fromParser :: forall m a b. (MonadThrow m, MonadIO m, Unboxed a) =>
192fromParser :: forall m a b. (MonadThrow m, MonadIO m, Unboxed a) =>
193+#endif
182 Parser.Parser m a b -> ArrayFold m a b
194 Parser.Parser m a b -> ArrayFold m a b
183fromParser = fromParserD . ParserD.fromParserK
195fromParser = fromParserD . ParserD.fromParserK
184
196
core/src/Streamly/Internal/Data/Array/Unboxed/Mut/Type.hs−3
@@ -253,9 +253,6 @@ import Streamly.Internal.Data.Unfold.Type (Unfold(..))
253import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
253import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
254import System.IO.Unsafe (unsafePerformIO)
254import System.IO.Unsafe (unsafePerformIO)
255
255
256−#ifdef DEVBUILD
257−import qualified Data.Foldable as F
258−#endif
259import qualified Streamly.Internal.Data.Fold.Type as FL
256import qualified Streamly.Internal.Data.Fold.Type as FL
260import qualified Streamly.Internal.Data.Producer as Producer
257import qualified Streamly.Internal.Data.Producer as Producer
261import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
258import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
core/src/Streamly/Internal/Data/Array/Unboxed/Type.hs+5−12
@@ -107,10 +107,6 @@ import Streamly.Internal.System.IO (unsafeInlineIO, defaultChunkSize)
107import Data.Semigroup (Semigroup(..))
107import Data.Semigroup (Semigroup(..))
108#endif
108#endif
109
109
110−#ifdef DEVBUILD
111−import qualified Data.Foldable as F
112−#endif
113−
114--
110--
115-- $setup
111-- $setup
116-- >>> :m
112-- >>> :m
@@ -563,9 +559,9 @@ instance (Unboxed a, Ord a) => Ord (Array a) where
563-- Definitions using the Unboxed constraint from the Array type. These are to
559-- Definitions using the Unboxed constraint from the Array type. These are to
564-- make the Foldable instance possible though it is much slower (7x slower).
560-- make the Foldable instance possible though it is much slower (7x slower).
565--
561--
566−{-# INLINE_NORMAL toStreamD_ #-}
562+{-# INLINE_NORMAL _toStreamD_ #-}
567−toStreamD_ :: forall m a. MonadIO m => Int -> Array a -> D.Stream m a
563+_toStreamD_ :: forall m a. MonadIO m => Int -> Array a -> D.Stream m a
568−toStreamD_ size Array{..} = D.Stream step arrStart
564+_toStreamD_ size Array{..} = D.Stream step arrStart
569
565
570 where
566 where
571
567
@@ -573,25 +569,22 @@ toStreamD_ size Array{..} = D.Stream step arrStart
573 step _ p | p == arrEnd = return D.Stop
569 step _ p | p == arrEnd = return D.Stop
574 step _ p = liftIO $ do
570 step _ p = liftIO $ do
575 x <- peekWith arrContents p
571 x <- peekWith arrContents p
576− return $ D.Yield x (p `plusPtr` size)
572+ return $ D.Yield x (p + size)
577
573
578{-
574{-
579−
580XXX Why isn't Unboxed implicit? This does not compile unless I use the Unboxed
575XXX Why isn't Unboxed implicit? This does not compile unless I use the Unboxed
581contraint.
576contraint.
582−
583{-# INLINE_NORMAL _foldr #-}
577{-# INLINE_NORMAL _foldr #-}
584_foldr :: forall a b. (a -> b -> b) -> b -> Array a -> b
578_foldr :: forall a b. (a -> b -> b) -> b -> Array a -> b
585_foldr f z arr =
579_foldr f z arr =
586 let !n = SIZE_OF(a)
580 let !n = SIZE_OF(a)
587 in unsafePerformIO $ D.foldr f z $ toStreamD_ n arr
581 in unsafePerformIO $ D.foldr f z $ toStreamD_ n arr
588−
589-- | Note that the 'Foldable' instance is 7x slower than the direct
582-- | Note that the 'Foldable' instance is 7x slower than the direct
590-- operations.
583-- operations.
591instance Foldable Array where
584instance Foldable Array where
592 foldr = _foldr
585 foldr = _foldr
593−
594-}
586-}
587+
595#endif
588#endif
596
589
597-------------------------------------------------------------------------------
590-------------------------------------------------------------------------------
core/streamly-core.cabal+5−2
@@ -265,7 +265,6 @@ library
265 , Streamly.Internal.Data.Fold.Type
265 , Streamly.Internal.Data.Fold.Type
266 , Streamly.Internal.Data.Stream.StreamD.Step
266 , Streamly.Internal.Data.Stream.StreamD.Step
267 , Streamly.Internal.Data.Stream.StreamD.Type
267 , Streamly.Internal.Data.Stream.StreamD.Type
268− , Streamly.Internal.Data.Stream.StreamDK.Type
269 , Streamly.Internal.Data.Unfold.Type
268 , Streamly.Internal.Data.Unfold.Type
270 , Streamly.Internal.Data.Producer.Type
269 , Streamly.Internal.Data.Producer.Type
271 , Streamly.Internal.Data.Producer
270 , Streamly.Internal.Data.Producer
@@ -293,7 +292,6 @@ library
293 , Streamly.Internal.Data.Stream.StreamD.Exception
292 , Streamly.Internal.Data.Stream.StreamD.Exception
294 , Streamly.Internal.Data.Stream.StreamD.Lift
293 , Streamly.Internal.Data.Stream.StreamD.Lift
295 , Streamly.Internal.Data.Stream.StreamD
294 , Streamly.Internal.Data.Stream.StreamD
296− , Streamly.Internal.Data.Stream.StreamDK
297 , Streamly.Internal.Data.Stream.Common
295 , Streamly.Internal.Data.Stream.Common
298
296
299 , Streamly.Internal.Data.Parser.ParserD.Tee
297 , Streamly.Internal.Data.Parser.ParserD.Tee
@@ -346,6 +344,11 @@ library
346 , Streamly.Data.Array.Unboxed
344 , Streamly.Data.Array.Unboxed
347 , Streamly.Data.Unfold
345 , Streamly.Data.Unfold
348
346
347+ if flag(dev)
348+ exposed-modules:
349+ Streamly.Internal.Data.Stream.StreamDK
350+ , Streamly.Internal.Data.Stream.StreamDK.Type
351+
349 build-depends:
352 build-depends:
350 -- Core libraries shipped with ghc, the min and max
353 -- Core libraries shipped with ghc, the min and max
351 -- constraints of these libraries should match with
354 -- constraints of these libraries should match with
streamly.cabal+10−10
@@ -430,10 +430,6 @@ library
430
430
431 Streamly.Internal.Data.IsMap.HashMap
431 Streamly.Internal.Data.IsMap.HashMap
432
432
433− -- XXX To be removed or put under dev flag
434− , Streamly.Internal.Data.SmallArray.Type
435− , Streamly.Internal.Data.SmallArray
436−
437 -- streamly-concurrent
433 -- streamly-concurrent
438 , Streamly.Internal.Data.Atomics
434 , Streamly.Internal.Data.Atomics
439 , Streamly.Internal.Data.SVar.Worker
435 , Streamly.Internal.Data.SVar.Worker
@@ -551,7 +547,6 @@ library
551 , Streamly.Internal.Data.Fold.Type
547 , Streamly.Internal.Data.Fold.Type
552 , Streamly.Internal.Data.Stream.StreamD.Step
548 , Streamly.Internal.Data.Stream.StreamD.Step
553 , Streamly.Internal.Data.Stream.StreamD.Type
549 , Streamly.Internal.Data.Stream.StreamD.Type
554− , Streamly.Internal.Data.Stream.StreamDK.Type
555 , Streamly.Internal.Data.Unfold.Type
550 , Streamly.Internal.Data.Unfold.Type
556 , Streamly.Internal.Data.Producer.Type
551 , Streamly.Internal.Data.Producer.Type
557 , Streamly.Internal.Data.Producer
552 , Streamly.Internal.Data.Producer
@@ -580,7 +575,6 @@ library
580 , Streamly.Internal.Data.Stream.StreamD.Exception
575 , Streamly.Internal.Data.Stream.StreamD.Exception
581 , Streamly.Internal.Data.Stream.StreamD.Lift
576 , Streamly.Internal.Data.Stream.StreamD.Lift
582 , Streamly.Internal.Data.Stream.StreamD
577 , Streamly.Internal.Data.Stream.StreamD
583− , Streamly.Internal.Data.Stream.StreamDK
584 , Streamly.Internal.Data.Stream.Common
578 , Streamly.Internal.Data.Stream.Common
585 , Streamly.Internal.Data.Parser.ParserD.Tee
579 , Streamly.Internal.Data.Parser.ParserD.Tee
586 , Streamly.Internal.Data.Parser.ParserD
580 , Streamly.Internal.Data.Parser.ParserD
@@ -632,8 +626,12 @@ library
632 , Streamly.Data.Array.Unboxed
626 , Streamly.Data.Array.Unboxed
633
627
634 other-modules:
628 other-modules:
635− Streamly.Data.Array
629+ Streamly.Data.Array
630+
631+ if flag(dev)
632+ exposed-modules: Streamly.Data.SmallArray
636− , Streamly.Data.SmallArray
633+ , Streamly.Internal.Data.SmallArray
634+ , Streamly.Internal.Data.SmallArray.Type
637
635
638 if os(windows)
636 if os(windows)
639 exposed-modules: Streamly.Internal.FileSystem.Event.Windows
637 exposed-modules: Streamly.Internal.FileSystem.Event.Windows
@@ -675,18 +673,20 @@ library
675
673
676 -- XXX to be removed
674 -- XXX to be removed
677 , transformers-base >= 0.4 && < 0.5
675 , transformers-base >= 0.4 && < 0.5
678− , primitive >= 0.5.4 && < 0.8
679 , heaps >= 0.3 && < 0.5
676 , heaps >= 0.3 && < 0.5
680
677
681 -- concurrency
678 -- concurrency
682 , atomic-primops >= 0.8 && < 0.9
679 , atomic-primops >= 0.8 && < 0.9
683 , lockfree-queue >= 0.2.3 && < 0.3
680 , lockfree-queue >= 0.2.3 && < 0.3
684−
681+
685 , unicode-data >= 0.1 && < 0.4
682 , unicode-data >= 0.1 && < 0.4
686
683
687 -- Network
684 -- Network
688 , network >= 2.6 && < 3.2
685 , network >= 2.6 && < 3.2
689
686
687+ if flag(dev)
688+ build-depends: primitive >= 0.5.4 && < 0.8
689+
690 if os(windows)
690 if os(windows)
691 build-depends: Win32 >= 2.6 && < 2.13
691 build-depends: Win32 >= 2.6 && < 2.13
692
692
test/streamly-tests.cabal+1−1
@@ -290,7 +290,7 @@ test-suite Data.SmallArray
290 type: exitcode-stdio-1.0
290 type: exitcode-stdio-1.0
291 main-is: Streamly/Test/Data/SmallArray.hs
291 main-is: Streamly/Test/Data/SmallArray.hs
292 ghc-options: -main-is Streamly.Test.Data.SmallArray.main
292 ghc-options: -main-is Streamly.Test.Data.SmallArray.main
293− if flag(use-streamly-core)
293+ if !flag(dev) || flag(use-streamly-core)
294 buildable: False
294 buildable: False
295
295
296test-suite Data.Unfold
296test-suite Data.Unfold