on master help sign in
Repurpose the streamk build flag

Fix review comments Fix review comments Rename stramk CI to no-fusion

commitca76876369e991c8c37793838926ac78884a1dba authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateThu 11 Aug 2022, 13:54 (4 years ago) parent9cce0eb
13 files changed+82−148
.github/workflows/haskell.yml+2−2 core/src/Streamly/Internal/Data/Stream/Common.hs+6−13 core/src/inline.hs+1−1 core/streamly-core.cabal−8 src/Streamly/Internal/Data/Stream/IsStream/Common.hs+14−19 src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+23−28 src/Streamly/Internal/Data/Stream/IsStream/Expand.hs+1−1 src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+10−16 src/Streamly/Internal/Data/Stream/IsStream/Lift.hs+3−8 src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+10−15 src/Streamly/Internal/Data/Stream/IsStream/Type.hs+11−28 src/inline.hs+1−1 streamly.cabal−8
.github/workflows/haskell.yml+2−2
@@ -132,13 +132,13 @@ jobs:
132132 cabal_project: cabal.project
133133 cabal_build_options: "--flag fusion-plugin"
134134 ignore_error: false
135− - name: 8.6.5-sdist-streamk-unoptimized
135+ - name: 8.6.5-sdist-no-fusion-unoptimized
136136 ghc_version: 8.6.5
137137 runner: ubuntu-latest
138138 build: cabal
139139 cabal_version: 3.6
140140 cabal_project: cabal.project
141− cabal_build_options: "--flag streamk --flag -opt"
141+ cabal_build_options: "--flag no-fusion --flag -opt"
142142 ignore_error: false
143143 - name: 8.6.5-sdist-debug-unoptimized
144144 ghc_version: 8.6.5
core/src/Streamly/Internal/Data/Stream/Common.hs+6−13
@@ -33,13 +33,6 @@ where
3333
3434import Streamly.Internal.Data.Fold.Type (Fold (..))
3535
36−#ifdef USE_STREAMK_ONLY
37−import qualified Streamly.Internal.Data.Stream.StreamK as S
38−import qualified Streamly.Internal.Data.Stream.StreamK.Type as S
39−#else
40−import qualified Streamly.Internal.Data.Stream.StreamD.Type as S
41−#endif
42−
4336import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
4437import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
4538
@@ -59,15 +52,15 @@ import Prelude hiding (foldr, repeat)
5952--
6053{-# INLINE_EARLY fromList #-}
6154fromList :: Monad m => [a] -> K.Stream m a
62−fromList = S.toStreamK . S.fromList
55+fromList = D.toStreamK . D.fromList
6356{-# RULES "fromList fallback to StreamK" [1]
64− forall a. S.toStreamK (S.fromList a) = K.fromFoldable a #-}
57+ forall a. D.toStreamK (D.fromList a) = K.fromFoldable a #-}
6558
6659-- | Convert a stream into a list in the underlying monad.
6760--
6861{-# INLINE toList #-}
6962toList :: Monad m => K.Stream m a -> m [a]
70−toList m = S.toList $ S.fromStreamK m
63+toList m = D.toList $ D.fromStreamK m
7164
7265------------------------------------------------------------------------------
7366-- Folds
@@ -75,7 +68,7 @@ toList m = S.toList $ S.fromStreamK m
7568
7669{-# INLINE foldrM #-}
7770foldrM :: Monad m => (a -> m b -> m b) -> m b -> K.Stream m a -> m b
78−foldrM step acc m = S.foldrM step acc $ S.fromStreamK m
71+foldrM step acc m = D.foldrM step acc $ D.fromStreamK m
7972
8073{-# INLINE foldr #-}
8174foldr :: Monad m => (a -> b -> b) -> b -> K.Stream m a -> m b
@@ -86,12 +79,12 @@ foldr f z = foldrM (\a b -> f a <$> b) (return z)
8679{-# INLINE foldl' #-}
8780foldl' ::
8881 Monad m => (b -> a -> b) -> b -> K.Stream m a -> m b
89−foldl' step begin m = S.foldl' step begin $ S.fromStreamK m
82+foldl' step begin m = D.foldl' step begin $ D.fromStreamK m
9083
9184
9285{-# INLINE fold #-}
9386fold :: Monad m => Fold m a b -> K.Stream m a -> m b
94−fold fld m = S.fold fld $ S.fromStreamK m
87+fold fld m = D.fold fld $ D.fromStreamK m
9588
9689------------------------------------------------------------------------------
9790-- Comparison
core/src/inline.hs+1−1
@@ -9,7 +9,7 @@
99--
1010-- {-# INLINE_EARLY unfoldr #-}
1111-- unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
12−-- unfoldr step seed = fromStreamS (S.unfoldr step seed)
12+-- unfoldr step seed = fromStreamD (S.unfoldr step seed)
1313-- {-# RULES "unfoldr fallback to StreamK" [1]
1414-- forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}```
1515--
core/streamly-core.cabal−8
@@ -57,11 +57,6 @@ flag no-fusion
5757 manual: True
5858 default: False
5959
60−flag streamk
61− description: Use CPS style streams when possible
62− manual: True
63− default: False
64−
6560flag use-c-malloc
6661 description: Use C malloc instead of GHC malloc
6762 manual: True
@@ -99,9 +94,6 @@ flag use-folds
9994common compile-options
10095 default-language: Haskell2010
10196
102− if flag(streamk)
103− cpp-options: -DUSE_STREAMK_ONLY
104−
10597 if flag(no-fusion)
10698 cpp-options: -DDISABLE_FUSION
10799
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+14−19
@@ -75,7 +75,7 @@ import Streamly.Internal.Data.Array.Unboxed.Type (Array)
7575import Streamly.Internal.Data.Fold.Type (Fold (..))
7676import Streamly.Internal.Data.Stream.IsStream.Combinators (maxYields)
7777import Streamly.Internal.Data.Stream.IsStream.Type
78− (IsStream(..), fromStreamD, toStreamD, fromStreamS, toStreamS)
78+ (IsStream(..), fromStreamD, toStreamD)
7979import Streamly.Internal.Data.Stream.Serial (SerialT)
8080import Streamly.Internal.Data.Time.Units (AbsTime, RelTime64, addToAbsTime64)
8181import Streamly.Internal.System.IO (defaultChunkSize)
@@ -87,11 +87,6 @@ import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
8787import qualified Streamly.Internal.Data.Stream.Parallel as Par
8888import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
8989import qualified Streamly.Internal.Data.Stream.StreamD as D
90−#ifdef USE_STREAMK_ONLY
91−import qualified Streamly.Internal.Data.Stream.StreamK as S
92−#else
93−import qualified Streamly.Internal.Data.Stream.StreamD as S
94−#endif
9590import qualified Streamly.Internal.Data.Stream as Stream
9691
9792import Prelude hiding (take, takeWhile, drop, reverse, concatMap, map, zipWith)
@@ -202,7 +197,7 @@ repeatM = K.repeatMWith IsStream.consM
202197{-# RULES "repeatM serial" repeatM = repeatMSerial #-}
203198{-# INLINE repeatMSerial #-}
204199repeatMSerial :: MonadAsync m => m a -> SerialT m a
205−repeatMSerial = fromStreamS . S.repeatM
200+repeatMSerial = fromStreamD . D.repeatM
206201
207202------------------------------------------------------------------------------
208203-- Generation - Time related
@@ -298,7 +293,7 @@ foldContinue f s = D.foldContinue f $ IsStream.toStreamD s
298293-- Same as 'fmap'.
299294--
300295-- @
301−-- > S.toList $ S.map (+1) $ S.fromList [1,2,3]
296+-- > D.toList $ D.map (+1) $ D.fromList [1,2,3]
302297-- [2,3,4]
303298-- @
304299--
@@ -397,7 +392,7 @@ smapM step initial stream =
397392-- @since 0.1.0
398393{-# INLINE take #-}
399394take :: (IsStream t, Monad m) => Int -> t m a -> t m a
400−take n m = fromStreamS $ S.take n $ toStreamS
395+take n m = fromStreamD $ D.take n $ toStreamD
401396 (maxYields (Just (fromIntegral n)) m)
402397
403398-- | End the stream as soon as the predicate fails on an element.
@@ -405,7 +400,7 @@ take n m = fromStreamS $ S.take n $ toStreamS
405400-- @since 0.1.0
406401{-# INLINE takeWhile #-}
407402takeWhile :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
408−takeWhile p m = fromStreamS $ S.takeWhile p $ toStreamS m
403+takeWhile p m = fromStreamD $ D.takeWhile p $ toStreamD m
409404
410405{-# INLINE takeEndBy #-}
411406takeEndBy :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
@@ -416,7 +411,7 @@ takeEndBy p m = fromStreamD $ D.takeEndBy p $ toStreamD m
416411-- @since 0.1.0
417412{-# INLINE drop #-}
418413drop :: (IsStream t, Monad m) => Int -> t m a -> t m a
419−drop n m = fromStreamS $ S.drop n $ toStreamS m
414+drop n m = fromStreamD $ D.drop n $ toStreamD m
420415
421416------------------------------------------------------------------------------
422417-- Searching
@@ -430,7 +425,7 @@ drop n m = fromStreamS $ S.drop n $ toStreamS m
430425-- @since 0.5.0
431426{-# INLINE findIndices #-}
432427findIndices :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m Int
433−findIndices p m = fromStreamS $ S.findIndices p (toStreamS m)
428+findIndices p m = fromStreamD $ D.findIndices p (toStreamD m)
434429
435430------------------------------------------------------------------------------
436431-- Transformation by Inserting
@@ -454,7 +449,7 @@ findIndices p m = fromStreamS $ S.findIndices p (toStreamS m)
454449-- @since 0.5.0
455450{-# INLINE intersperseM #-}
456451intersperseM :: (IsStream t, MonadAsync m) => m a -> t m a -> t m a
457−intersperseM m = fromStreamS . S.intersperseM m . toStreamS
452+intersperseM m = fromStreamD . D.intersperseM m . toStreamD
458453
459454-- | Intersperse a monadic action into the input stream after every @n@
460455-- seconds.
@@ -493,7 +488,7 @@ interjectSuffix n f xs = xs `parallelFst` repeatM timed
493488-- /Since: 0.1.1/
494489{-# INLINE reverse #-}
495490reverse :: (IsStream t, Monad m) => t m a -> t m a
496−reverse s = fromStreamS $ S.reverse $ toStreamS s
491+reverse s = fromStreamD $ D.reverse $ toStreamD s
497492
498493-- | Like 'reverse' but several times faster, requires a 'Storable' instance.
499494--
@@ -699,8 +694,8 @@ splitOnSeq patt f m =
699694{-# INLINE zipWithM #-}
700695zipWithM :: (IsStream t, Monad m) => (a -> b -> m c) -> t m a -> t m b -> t m c
701696zipWithM f m1 m2 =
702− IsStream.fromStreamS
703− $ S.zipWithM f (IsStream.toStreamS m1) (IsStream.toStreamS m2)
697+ IsStream.fromStreamD
698+ $ D.zipWithM f (IsStream.toStreamD m1) (IsStream.toStreamD m2)
704699
705700-- | Stream @a@ is evaluated first, followed by stream @b@, the resulting
706701-- elements @a@ and @b@ are then zipped using the supplied zip function and the
@@ -710,7 +705,7 @@ zipWithM f m1 m2 =
710705-- first, the element @a@ from previous evaluation of stream @a@ is discarded.
711706--
712707-- @
713−-- > S.toList $ S.zipWith (+) (S.fromList [1,2,3]) (S.fromList [4,5,6])
708+-- > D.toList $ D.zipWith (+) (D.fromList [1,2,3]) (D.fromList [4,5,6])
714709-- [5,7,9]
715710-- @
716711--
@@ -718,5 +713,5 @@ zipWithM f m1 m2 =
718713{-# INLINE zipWith #-}
719714zipWith :: (IsStream t, Monad m) => (a -> b -> c) -> t m a -> t m b -> t m c
720715zipWith f m1 m2 =
721− IsStream.fromStreamS
722− $ S.zipWith f (IsStream.toStreamS m1) (IsStream.toStreamS m2)
716+ IsStream.fromStreamD
717+ $ D.zipWith f (IsStream.toStreamD m1) (IsStream.toStreamD m2)
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+23−28
@@ -163,7 +163,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
163163 ( fold, foldBreak, foldContinue, drop, findIndices, reverse, splitOnSeq
164164 , take , takeWhile, mkParallel)
165165import Streamly.Internal.Data.Stream.IsStream.Type
166− (IsStream, toStreamS, fromStreamD, toStreamD)
166+ (IsStream, toStreamD, fromStreamD, toStreamD)
167167import Streamly.Internal.Data.Stream.Serial (SerialT)
168168import Streamly.Internal.Data.Unboxed (Unboxed)
169169
@@ -172,11 +172,6 @@ import qualified Streamly.Internal.Data.Fold as FL
172172import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
173173import qualified Streamly.Internal.Data.Stream.StreamD as D
174174import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
175−#ifdef USE_STREAMK_ONLY
176−import qualified Streamly.Internal.Data.Stream.StreamK as S
177−#else
178−import qualified Streamly.Internal.Data.Stream.StreamD as S
179−#endif
180175import qualified Streamly.Internal.Data.Stream as Stream
181176import qualified System.IO as IO
182177
@@ -240,7 +235,7 @@ uncons = fmap (fmap (fmap IsStream.fromStream)) . K.uncons . Stream.toStreamK
240235{-# INLINE foldr1 #-}
241236{-# DEPRECATED foldr1 "Use foldrM instead." #-}
242237foldr1 :: Monad m => (a -> a -> a) -> SerialT m a -> m (Maybe a)
243−foldr1 f m = S.foldr1 f (toStreamS m)
238+foldr1 f m = D.foldr1 f (toStreamD m)
244239
245240------------------------------------------------------------------------------
246241-- Left Folds
@@ -260,12 +255,12 @@ foldlS f z =
260255--
261256-- For example, to reverse a stream:
262257--
263−-- > S.toList $ S.foldlT (flip S.cons) S.nil $ (S.fromList [1..5] :: SerialT IO Int)
258+-- > D.toList $ D.foldlT (flip D.cons) D.nil $ (D.fromList [1..5] :: SerialT IO Int)
264259--
265260{-# INLINE foldlT #-}
266261foldlT :: (Monad m, IsStream t, Monad (s m), MonadTrans s)
267262 => (s m b -> a -> s m b) -> s m b -> t m a -> s m b
268−foldlT f z s = S.foldlT f z (toStreamS s)
263+foldlT f z s = D.foldlT f z (toStreamD s)
269264
270265-- | Strict left fold with an extraction function. Like the standard strict
271266-- left fold, but applies a user supplied extraction function (the third
@@ -320,7 +315,7 @@ foldxM = IsStream.foldlMx'
320315-- /Since: 0.8.0 (signature change)/
321316{-# INLINE foldlM' #-}
322317foldlM' :: Monad m => (b -> a -> m b) -> m b -> SerialT m a -> m b
323−foldlM' step begin = S.foldlM' step begin . IsStream.toStreamS
318+foldlM' step begin = D.foldlM' step begin . IsStream.toStreamD
324319
325320------------------------------------------------------------------------------
326321-- Running a sink
@@ -347,7 +342,7 @@ runSink = fold . toFold
347342-- @since 0.1.0
348343{-# INLINE mapM_ #-}
349344mapM_ :: Monad m => (a -> m b) -> SerialT m a -> m ()
350−mapM_ f = S.mapM_ f . IsStream.toStreamS
345+mapM_ f = D.mapM_ f . IsStream.toStreamD
351346
352347-- |
353348-- > drain = mapM_ (\_ -> return ())
@@ -422,7 +417,7 @@ runStream = drain
422417-- @since 0.1.1
423418{-# INLINE null #-}
424419null :: Monad m => SerialT m a -> m Bool
425−null = S.null . toStreamS
420+null = D.null . toStreamD
426421
427422-- | Extract the first element of the stream, if any.
428423--
@@ -432,7 +427,7 @@ null = S.null . toStreamS
432427-- @since 0.1.0
433428{-# INLINE head #-}
434429head :: Monad m => SerialT m a -> m (Maybe a)
435−head = S.head . toStreamS
430+head = D.head . toStreamD
436431
437432-- | Extract the first element of the stream, if any, otherwise use the
438433-- supplied default value. It can help avoid one branch in high performance
@@ -468,7 +463,7 @@ init m = fmap (fmap IsStream.fromStream) $ K.init $ Stream.toStreamK m
468463-- @since 0.1.1
469464{-# INLINE last #-}
470465last :: Monad m => SerialT m a -> m (Maybe a)
471−last m = S.last $ toStreamS m
466+last m = D.last $ toStreamD m
472467
473468-- | Determine whether an element is present in the stream.
474469--
@@ -477,7 +472,7 @@ last m = S.last $ toStreamS m
477472-- @since 0.1.0
478473{-# INLINE elem #-}
479474elem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
480−elem e m = S.elem e (toStreamS m)
475+elem e m = D.elem e (toStreamD m)
481476
482477-- | Determine whether an element is not present in the stream.
483478--
@@ -486,7 +481,7 @@ elem e m = S.elem e (toStreamS m)
486481-- @since 0.1.0
487482{-# INLINE notElem #-}
488483notElem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
489−notElem e m = S.notElem e (toStreamS m)
484+notElem e m = D.notElem e (toStreamD m)
490485
491486-- | Determine the length of the stream.
492487--
@@ -502,7 +497,7 @@ length = foldl' (\n _ -> n + 1) 0
502497-- @since 0.1.0
503498{-# INLINE all #-}
504499all :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
505−all p m = S.all p (toStreamS m)
500+all p m = D.all p (toStreamD m)
506501
507502-- | Determine whether any of the elements of a stream satisfy a predicate.
508503--
@@ -511,7 +506,7 @@ all p m = S.all p (toStreamS m)
511506-- @since 0.1.0
512507{-# INLINE any #-}
513508any :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
514−any p m = S.any p (toStreamS m)
509+any p m = D.any p (toStreamD m)
515510
516511-- | Determines if all elements of a boolean stream are True.
517512--
@@ -572,7 +567,7 @@ mconcat = Stream.foldr mappend mempty
572567-- @since 0.1.0
573568{-# INLINE minimum #-}
574569minimum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
575−minimum m = S.minimum (toStreamS m)
570+minimum m = D.minimum (toStreamD m)
576571
577572-- | Determine the minimum element in a stream using the supplied comparison
578573-- function.
@@ -582,7 +577,7 @@ minimum m = S.minimum (toStreamS m)
582577-- @since 0.6.0
583578{-# INLINE minimumBy #-}
584579minimumBy :: Monad m => (a -> a -> Ordering) -> SerialT m a -> m (Maybe a)
585−minimumBy cmp m = S.minimumBy cmp (toStreamS m)
580+minimumBy cmp m = D.minimumBy cmp (toStreamD m)
586581
587582-- |
588583-- @
@@ -595,7 +590,7 @@ minimumBy cmp m = S.minimumBy cmp (toStreamS m)
595590-- @since 0.1.0
596591{-# INLINE maximum #-}
597592maximum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
598−maximum m = S.maximum (toStreamS m)
593+maximum m = D.maximum (toStreamD m)
599594
600595-- | Determine the maximum element in a stream using the supplied comparison
601596-- function.
@@ -605,7 +600,7 @@ maximum m = S.maximum (toStreamS m)
605600-- @since 0.6.0
606601{-# INLINE maximumBy #-}
607602maximumBy :: Monad m => (a -> a -> Ordering) -> SerialT m a -> m (Maybe a)
608−maximumBy cmp m = S.maximumBy cmp (toStreamS m)
603+maximumBy cmp m = D.maximumBy cmp (toStreamD m)
609604
610605-- | Ensures that all the elements of the stream are identical and then returns
611606-- that unique element.
@@ -613,7 +608,7 @@ maximumBy cmp m = S.maximumBy cmp (toStreamS m)
613608-- @since 0.6.0
614609{-# INLINE the #-}
615610the :: (Eq a, Monad m) => SerialT m a -> m (Maybe a)
616−the m = S.the (toStreamS m)
611+the m = D.the (toStreamD m)
617612
618613------------------------------------------------------------------------------
619614-- Searching
@@ -624,7 +619,7 @@ the m = S.the (toStreamS m)
624619-- @since 0.6.0
625620{-# INLINE (!!) #-}
626621(!!) :: Monad m => SerialT m a -> Int -> m (Maybe a)
627−m !! i = toStreamS m S.!! i
622+m !! i = toStreamD m D.!! i
628623
629624-- | In a stream of (key-value) pairs @(a, b)@, return the value @b@ of the
630625-- first pair where the key equals the given value @a@.
@@ -635,7 +630,7 @@ m !! i = toStreamS m S.!! i
635630-- @since 0.5.0
636631{-# INLINE lookup #-}
637632lookup :: (Monad m, Eq a) => a -> SerialT m (a, b) -> m (Maybe b)
638−lookup a m = S.lookup a (toStreamS m)
633+lookup a m = D.lookup a (toStreamD m)
639634
640635-- | Like 'findM' but with a non-monadic predicate.
641636--
@@ -645,7 +640,7 @@ lookup a m = S.lookup a (toStreamS m)
645640-- @since 0.5.0
646641{-# INLINE find #-}
647642find :: Monad m => (a -> Bool) -> SerialT m a -> m (Maybe a)
648−find p m = S.find p (toStreamS m)
643+find p m = D.find p (toStreamD m)
649644
650645-- | Returns the first element that satisfies the given predicate.
651646--
@@ -654,7 +649,7 @@ find p m = S.find p (toStreamS m)
654649-- @since 0.6.0
655650{-# INLINE findM #-}
656651findM :: Monad m => (a -> m Bool) -> SerialT m a -> m (Maybe a)
657−findM p m = S.findM p (toStreamS m)
652+findM p m = D.findM p (toStreamD m)
658653
659654-- | Returns the first index that satisfies the given predicate.
660655--
@@ -712,7 +707,7 @@ toListRev = D.toListRev . toStreamD
712707
713708-- |
714709-- @
715−-- toHandle h = S.mapM_ $ hPutStrLn h
710+-- toHandle h = D.mapM_ $ hPutStrLn h
716711-- @
717712--
718713-- Write a stream of Strings to an IO Handle.
src/Streamly/Internal/Data/Stream/IsStream/Expand.hs+1−1
@@ -763,7 +763,7 @@ mergeMinBy _f _m1 _m2 = undefined
763763mergeFstBy :: -- (IsStream t, Monad m) =>
764764 (a -> a -> m Ordering) -> t m a -> t m a -> t m a
765765mergeFstBy _f _m1 _m2 = undefined
766− -- fromStreamS $ D.mergeFstBy f (toStreamD m1) (toStreamD m2)
766+ -- fromStreamD $ D.mergeFstBy f (toStreamD m1) (toStreamD m2)
767767
768768-- XXX we may want to use the name "merge" differently
769769-- | Same as @'mergeBy' 'compare'@.
src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+10−16
@@ -99,7 +99,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
9999 ( absTimesWith, concatM, relTimesWith, timesWith, fromPure, fromEffect
100100 , yield, yieldM, repeatM)
101101import Streamly.Internal.Data.Stream.IsStream.Type
102− (IsStream (..), fromSerial, consM, fromStreamD, fromStreamS)
102+ (IsStream (..), fromSerial, consM, fromStreamD)
103103import Streamly.Internal.Data.Stream.Serial (SerialT)
104104import Streamly.Internal.Data.Stream.WSerial (WSerialT)
105105import Streamly.Internal.Data.Stream.Zip (ZipSerialM)
@@ -112,12 +112,6 @@ import qualified Streamly.Internal.Data.Stream.Parallel as Par
112112import qualified Streamly.Internal.Data.Stream.Serial as Serial
113113import qualified Streamly.Internal.Data.Stream.StreamD.Generate as D
114114import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
115−#ifdef USE_STREAMK_ONLY
116−import qualified Streamly.Internal.Data.Stream.StreamK as S
117−import qualified Streamly.Internal.Data.Stream.StreamK.Type as S
118−#else
119−import qualified Streamly.Internal.Data.Stream.StreamD.Generate as S
120−#endif
121115import qualified Streamly.Internal.Data.Stream.Type as Stream
122116import qualified System.IO as IO
123117
@@ -187,9 +181,9 @@ unfold0 unf = unfold unf (error "unfold0: unexpected void evaluation")
187181-- @since 0.1.0
188182{-# INLINE_EARLY unfoldr #-}
189183unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
190−unfoldr step seed = fromStreamS (S.unfoldr step seed)
184+unfoldr step seed = fromStreamD (D.unfoldr step seed)
191185{-# RULES "unfoldr fallback to StreamK" [1]
192− forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}
186+ forall a b. D.toStreamK (D.unfoldr a b) = K.unfoldr a b #-}
193187
194188-- | Build a stream by unfolding a /monadic/ step function starting from a
195189-- seed. The step function returns the next element in the stream and the next
@@ -253,7 +247,7 @@ unfoldrMZipSerial f = fromSerial . Serial.unfoldrM f
253247-- @since 0.4.0
254248{-# INLINE_NORMAL repeat #-}
255249repeat :: (IsStream t, Monad m) => a -> t m a
256−repeat = fromStreamS . S.repeat
250+repeat = fromStreamD . D.repeat
257251
258252-- |
259253-- >>> replicate n = Stream.take n . Stream.repeat
@@ -263,7 +257,7 @@ repeat = fromStreamS . S.repeat
263257-- @since 0.6.0
264258{-# INLINE_NORMAL replicate #-}
265259replicate :: (IsStream t, Monad m) => Int -> a -> t m a
266−replicate n = fromStreamS . S.replicate n
260+replicate n = fromStreamD . D.replicate n
267261
268262-- |
269263-- >>> replicateM n = Stream.take n . Stream.repeatM
@@ -297,7 +291,7 @@ replicateM count =
297291{-# RULES "replicateM serial" replicateM = replicateMSerial #-}
298292{-# INLINE replicateMSerial #-}
299293replicateMSerial :: MonadAsync m => Int -> m a -> SerialT m a
300−replicateMSerial n = fromStreamS . S.replicateM n
294+replicateMSerial n = fromStreamD . D.replicateM n
301295
302296------------------------------------------------------------------------------
303297-- Time Enumeration
@@ -420,7 +414,7 @@ timeout = undefined
420414-- @since 0.6.0
421415{-# INLINE fromIndices #-}
422416fromIndices :: (IsStream t, Monad m) => (Int -> a) -> t m a
423−fromIndices = fromStreamS . S.fromIndices
417+fromIndices = fromStreamD . D.fromIndices
424418
425419--
426420-- |
@@ -441,7 +435,7 @@ fromIndicesM = fromStream . K.fromIndicesMWith (IsStream.toConsK (consM @t))
441435{-# RULES "fromIndicesM serial" fromIndicesM = fromIndicesMSerial #-}
442436{-# INLINE fromIndicesMSerial #-}
443437fromIndicesMSerial :: MonadAsync m => (Int -> m a) -> SerialT m a
444−fromIndicesMSerial = fromStreamS . S.fromIndicesM
438+fromIndicesMSerial = fromStreamD . D.fromIndicesM
445439
446440------------------------------------------------------------------------------
447441-- Iterating functions
@@ -460,7 +454,7 @@ fromIndicesMSerial = fromStreamS . S.fromIndicesM
460454-- @since 0.1.2
461455{-# INLINE_NORMAL iterate #-}
462456iterate :: (IsStream t, Monad m) => (a -> a) -> a -> t m a
463−iterate step = fromStreamS . S.iterate step
457+iterate step = fromStreamD . D.iterate step
464458
465459-- |
466460-- >>> iterateM f m = m >>= \a -> return a `Stream.consM` iterateM f (f a)
@@ -509,7 +503,7 @@ iterateM f = fromStream . K.iterateMWith (IsStream.toConsK (consM @t)) f
509503{-# RULES "iterateM serial" iterateM = iterateMSerial #-}
510504{-# INLINE iterateMSerial #-}
511505iterateMSerial :: MonadAsync m => (a -> m a) -> m a -> SerialT m a
512−iterateMSerial step = fromStreamS . S.iterateM step
506+iterateMSerial step = fromStreamD . D.iterateM step
513507
514508-- | We can define cyclic structures using @let@:
515509--
src/Streamly/Internal/Data/Stream/IsStream/Lift.hs+3−8
@@ -29,15 +29,10 @@ import Control.Monad.Trans.State.Strict (StateT)
2929import Control.Monad.Trans.Class (MonadTrans(..))
3030import Data.Functor.Identity (Identity (..))
3131import Streamly.Internal.Data.Stream.IsStream.Type
32− (IsStream(..), fromStreamS, toStreamS, fromStreamD, toStreamD)
32+ (IsStream(..), fromStreamD, toStreamD)
3333import Streamly.Internal.Data.Stream.Serial (SerialT)
3434
3535import qualified Streamly.Internal.Data.Stream.StreamD as D
36−#ifdef USE_STREAMK_ONLY
37−import qualified Streamly.Internal.Data.Stream.StreamK as S
38−#else
39−import qualified Streamly.Internal.Data.Stream.StreamD as S
40−#endif
4136
4237------------------------------------------------------------------------------
4338-- Generalize the underlying monad
@@ -50,7 +45,7 @@ import qualified Streamly.Internal.Data.Stream.StreamD as S
5045{-# INLINE hoist #-}
5146hoist :: (Monad m, Monad n)
5247 => (forall x. m x -> n x) -> SerialT m a -> SerialT n a
53−hoist f xs = fromStreamS $ S.hoist f (toStreamS xs)
48+hoist f xs = fromStreamD $ D.hoist f (toStreamD xs)
5449
5550-- | Generalize the inner monad of the stream from 'Identity' to any monad.
5651--
@@ -58,7 +53,7 @@ hoist f xs = fromStreamS $ S.hoist f (toStreamS xs)
5853--
5954{-# INLINE generally #-}
6055generally :: (IsStream t, Monad m) => t Identity a -> t m a
61−generally xs = fromStreamS $ S.hoist (return . runIdentity) (toStreamS xs)
56+generally xs = fromStreamD $ D.hoist (return . runIdentity) (toStreamD xs)
6257
6358------------------------------------------------------------------------------
6459-- Add and remove a monad transformer
src/Streamly/Internal/Data/Stream/IsStream/Transform.hs+10−15
@@ -247,7 +247,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
247247 )
248248import Streamly.Internal.Control.Concurrent (MonadAsync)
249249import Streamly.Internal.Data.Stream.IsStream.Type
250− (IsStream(..), fromStreamS, toStreamS, fromStreamD, toStreamD, toConsK)
250+ (IsStream(..), fromStreamD, toStreamD, toConsK)
251251import Streamly.Internal.Data.Stream.Serial (SerialT)
252252import Streamly.Internal.Data.SVar (Rate(..))
253253import Streamly.Internal.Data.Time.Units (TimeUnit64, AbsTime, RelTime64)
@@ -257,11 +257,6 @@ import qualified Streamly.Internal.Data.Stream.Parallel as Par
257257import qualified Streamly.Internal.Data.Stream.Serial as Serial
258258import qualified Streamly.Internal.Data.Stream.StreamD as D
259259import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
260−#ifdef USE_STREAMK_ONLY
261−import qualified Streamly.Internal.Data.Stream.StreamK as S
262−#else
263−import qualified Streamly.Internal.Data.Stream.StreamD as S
264−#endif
265260import qualified Prelude
266261
267262import Prelude hiding
@@ -359,7 +354,7 @@ foldrSShared f z xs =
359354{-# INLINE foldrT #-}
360355foldrT :: (IsStream t, Monad m, Monad (s m), MonadTrans s)
361356 => (a -> s m b -> s m b) -> s m b -> t m a -> s m b
362−foldrT f z s = S.foldrT f z (toStreamS s)
357+foldrT f z s = D.foldrT f z (toStreamD s)
363358
364359------------------------------------------------------------------------------
365360-- Transformation by Mapping
@@ -681,7 +676,7 @@ postscan fld = fromStreamD . D.postscanOnce fld . toStreamD
681676{-# DEPRECATED scanx "Please use scanl followed by map instead." #-}
682677{-# INLINE scanx #-}
683678scanx :: (IsStream t, Monad m) => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
684−scanx step begin done = fromStreamS . S.scanlx' step begin done . toStreamS
679+scanx step begin done = fromStreamD . D.scanlx' step begin done . toStreamD
685680
686681-- XXX this needs to be concurrent
687682-- XXX because of the use of D.cons for appending, scanlM' has quadratic
@@ -760,7 +755,7 @@ scanlM' step begin m = fromStreamD $ D.scanlM' step begin $ toStreamD m
760755-- @since 0.2.0
761756{-# INLINE scanl' #-}
762757scanl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> t m b
763−scanl' step z m = fromStreamS $ S.scanl' step z $ toStreamS m
758+scanl' step z m = fromStreamD $ D.scanl' step z $ toStreamD m
764759
765760-- | Like 'scanl'' but does not stream the initial value of the accumulator.
766761--
@@ -841,7 +836,7 @@ with f comb g = fmap snd . comb g . f
841836-- @since 0.1.0
842837{-# INLINE filter #-}
843838filter :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
844−filter p m = fromStreamS $ S.filter p $ toStreamS m
839+filter p m = fromStreamD $ D.filter p $ toStreamD m
845840
846841-- | Same as 'filter' but with a monadic predicate.
847842--
@@ -953,7 +948,7 @@ nubBy = undefined -- fromStreamD . D.nubBy . toStreamD
953948-- @since 0.6.0
954949{-# INLINE deleteBy #-}
955950deleteBy :: (IsStream t, Monad m) => (a -> a -> Bool) -> a -> t m a -> t m a
956−deleteBy cmp x m = fromStreamS $ S.deleteBy cmp x (toStreamS m)
951+deleteBy cmp x m = fromStreamD $ D.deleteBy cmp x (toStreamD m)
957952
958953------------------------------------------------------------------------------
959954-- Lossy Buffering
@@ -1082,7 +1077,7 @@ takeInterval d = fromStreamD . D.takeByTime d . toStreamD
10821077-- @since 0.1.0
10831078{-# INLINE dropWhile #-}
10841079dropWhile :: (IsStream t, Monad m) => (a -> Bool) -> t m a -> t m a
1085−dropWhile p m = fromStreamS $ S.dropWhile p $ toStreamS m
1080+dropWhile p m = fromStreamD $ D.dropWhile p $ toStreamD m
10861081
10871082-- | Same as 'dropWhile' but with a monadic predicate.
10881083--
@@ -1171,7 +1166,7 @@ dropWhileAround = undefined -- fromStreamD $ D.dropWhileAround n $ toStreamD m
11711166{-# INLINE insertBy #-}
11721167insertBy ::
11731168 (IsStream t, Monad m) => (a -> a -> Ordering) -> a -> t m a -> t m a
1174−insertBy cmp x m = fromStreamS $ S.insertBy cmp x (toStreamS m)
1169+insertBy cmp x m = fromStreamD $ D.insertBy cmp x (toStreamD m)
11751170
11761171-- | Insert a pure value between successive elements of a stream.
11771172--
@@ -1181,7 +1176,7 @@ insertBy cmp x m = fromStreamS $ S.insertBy cmp x (toStreamS m)
11811176-- @since 0.7.0
11821177{-# INLINE intersperse #-}
11831178intersperse :: (IsStream t, MonadAsync m) => a -> t m a -> t m a
1184−intersperse a = fromStreamS . S.intersperse a . toStreamS
1179+intersperse a = fromStreamD . D.intersperse a . toStreamD
11851180
11861181-- | Insert a side effect before consuming an element of a stream except the
11871182-- first one.
@@ -1503,7 +1498,7 @@ rollingMap2 f m = fromStreamD $ D.rollingMap2 f $ toStreamD m
15031498-- @since 0.3.0
15041499{-# INLINE mapMaybe #-}
15051500mapMaybe :: (IsStream t, Monad m) => (a -> Maybe b) -> t m a -> t m b
1506−mapMaybe f m = fromStreamS $ S.mapMaybe f $ toStreamS m
1501+mapMaybe f m = fromStreamD $ D.mapMaybe f $ toStreamD m
15071502
15081503-- | Like 'mapMaybe' but maps a monadic function.
15091504--
src/Streamly/Internal/Data/Stream/IsStream/Type.hs+11−28
@@ -17,8 +17,6 @@ module Streamly.Internal.Data.Stream.IsStream.Type
1717 , K.Stream (..)
1818
1919 -- * Type Conversion
20− , fromStreamS
21− , toStreamS
2220 , fromStreamD
2321 , toStreamD
2422 , adapt
@@ -121,12 +119,6 @@ import qualified Streamly.Internal.Data.Stream.Serial as Serial
121119import qualified Streamly.Internal.Data.Stream.WSerial as WSerial
122120import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
123121import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
124−#ifdef USE_STREAMK_ONLY
125−import qualified Streamly.Internal.Data.Stream.StreamK as S
126−import qualified Streamly.Internal.Data.Stream.StreamK.Type as S
127−#else
128−import qualified Streamly.Internal.Data.Stream.StreamD.Type as S
129−#endif
130122import qualified Streamly.Internal.Data.Stream.Type as Stream
131123import qualified Streamly.Internal.Data.Stream.Zip as Zip
132124import qualified Streamly.Internal.Data.Stream.ZipAsync as ZipAsync
@@ -230,15 +222,6 @@ toConsK cns x xs = toStream $ x `cns` fromStream xs
230222-- Conversion to and from direct style stream
231223------------------------------------------------------------------------------
232224
233−-- These definitions are dependent on what is imported as S
234−{-# INLINE fromStreamS #-}
235−fromStreamS :: (IsStream t, Monad m) => S.Stream m a -> t m a
236−fromStreamS = fromStream . S.toStreamK
237−
238−{-# INLINE toStreamS #-}
239−toStreamS :: (IsStream t, Monad m) => t m a -> S.Stream m a
240−toStreamS = S.fromStreamK . toStream
241−
242225{-# INLINE toStreamD #-}
243226toStreamD :: (IsStream t, Monad m) => t m a -> D.Stream m a
244227toStreamD = D.fromStreamK . toStream
@@ -289,16 +272,16 @@ cmpBy f m1 m2 = D.cmpBy f (toStreamD m1) (toStreamD m2)
289272-- @since 0.4.0
290273{-# INLINE_EARLY fromList #-}
291274fromList :: (Monad m, IsStream t) => [a] -> t m a
292−fromList = fromStreamS . S.fromList
275+fromList = fromStreamD . D.fromList
293276{-# RULES "fromList fallback to StreamK" [1]
294− forall a. S.toStreamK (S.fromList a) = K.fromFoldable a #-}
277+ forall a. D.toStreamK (D.fromList a) = K.fromFoldable a #-}
295278
296279-- | Convert a stream into a list in the underlying monad.
297280--
298281-- @since 0.1.0
299282{-# INLINE toList #-}
300283toList :: (IsStream t, Monad m) => t m a -> m [a]
301−toList m = S.toList $ toStreamS m
284+toList m = D.toList $ toStreamD m
302285
303286------------------------------------------------------------------------------
304287-- Building a stream
@@ -364,7 +347,7 @@ foldrMx step final project m = D.foldrMx step final project $ toStreamD m
364347foldlMx' ::
365348 (IsStream t, Monad m)
366349 => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
367−foldlMx' step begin done m = S.foldlMx' step begin done $ toStreamS m
350+foldlMx' step begin done m = D.foldlMx' step begin done $ toStreamD m
368351
369352-- | Strict left fold with an extraction function. Like the standard strict
370353-- left fold, but applies a user supplied extraction function (the third
@@ -375,7 +358,7 @@ foldlMx' step begin done m = S.foldlMx' step begin done $ toStreamS m
375358{-# INLINE foldlx' #-}
376359foldlx' ::
377360 (IsStream t, Monad m) => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
378−foldlx' step begin done m = S.foldlx' step begin done $ toStreamS m
361+foldlx' step begin done m = D.foldlx' step begin done $ toStreamD m
379362
380363-- | Strict left associative fold.
381364--
@@ -383,12 +366,12 @@ foldlx' step begin done m = S.foldlx' step begin done $ toStreamS m
383366{-# INLINE foldl' #-}
384367foldl' ::
385368 (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> m b
386−foldl' step begin m = S.foldl' step begin $ toStreamS m
369+foldl' step begin m = D.foldl' step begin $ toStreamD m
387370
388371
389372{-# INLINE fold #-}
390373fold :: (IsStream t, Monad m) => Fold m a b -> t m a -> m b
391−fold fld m = S.fold fld $ toStreamS m
374+fold fld m = D.fold fld $ toStreamD m
392375
393376------------------------------------------------------------------------------
394377-- Folding a stream
@@ -746,8 +729,8 @@ concatMapFoldableWith f g = Prelude.foldr (f . g) nil
746729-- Equivalent to:
747730--
748731-- @
749−-- concatForFoldableWith f xs g = Prelude.foldr (f . g) S.nil xs
750−-- concatForFoldableWith f = flip (S.concatMapFoldableWith f)
732+-- concatForFoldableWith f xs g = Prelude.foldr (f . g) D.nil xs
733+-- concatForFoldableWith f = flip (D.concatMapFoldableWith f)
751734-- @
752735--
753736-- /Since: 0.8.0 (Renamed forEachWith to concatForFoldableWith)/
@@ -766,8 +749,8 @@ concatForFoldableWith f = flip (concatMapFoldableWith f)
766749-- Equivalent to:
767750--
768751-- @
769−-- concatFoldableWith f = Prelude.foldr f S.nil
770−-- concatFoldableWith f = S.concatMapFoldableWith f id
752+-- concatFoldableWith f = Prelude.foldr f D.nil
753+-- concatFoldableWith f = D.concatMapFoldableWith f id
771754-- @
772755--
773756-- /Since: 0.8.0 (Renamed foldWith to concatFoldableWith)/
src/inline.hs+1−1
@@ -9,7 +9,7 @@
99--
1010-- {-# INLINE_EARLY unfoldr #-}
1111-- unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
12−-- unfoldr step seed = fromStreamS (S.unfoldr step seed)
12+-- unfoldr step seed = fromStreamD (S.unfoldr step seed)
1313-- {-# RULES "unfoldr fallback to StreamK" [1]
1414-- forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}```
1515--
streamly.cabal−8
@@ -285,11 +285,6 @@ flag has-llvm
285285 manual: True
286286 default: False
287287
288−flag streamk
289− description: Use CPS style streams when possible
290− manual: True
291− default: False
292−
293288flag use-c-malloc
294289 description: Use C malloc instead of GHC malloc
295290 manual: True
@@ -321,9 +316,6 @@ common compile-options
321316 if os(windows)
322317 cpp-options: -DCABAL_OS_WINDOWS
323318
324− if flag(streamk)
325− cpp-options: -DUSE_STREAMK_ONLY
326−
327319 if flag(dev)
328320 cpp-options: -DDEVBUILD
329321