Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions benchmark/Streamly/Benchmark/Data/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import Streamly.Benchmark.Data.Parser.Alternative as Alternative
import Streamly.Benchmark.Data.Parser.Applicative as Applicative
import Streamly.Benchmark.Data.Parser.Monad as Monad
import Streamly.Benchmark.Data.Parser.Sequence as Sequence
import Streamly.Benchmark.Data.Parser.Producer as Producer
import Streamly.Benchmark.Data.Parser.Interleave as Interleave
import Streamly.Benchmark.Data.Parser.Groups as Groups

Expand All @@ -46,13 +45,12 @@ benchmarkList ::
-> BenchEnv
-> [Array.Array Int]
-> [(SpaceComplexity, Benchmark)]
benchmarkList value env arrays =
benchmarkList value env _arrays =
Alternative.benchmarks value
++ Applicative.benchmarks value
++ Monad.benchmarks value
++ Sequence.benchmarks value
++ Sequence.benchmarksFileIO env
++ Producer.benchmarks value arrays
++ Groups.benchmarks value
++ Interleave.benchmarks value

Expand Down
67 changes: 0 additions & 67 deletions benchmark/Streamly/Benchmark/Data/Parser/Producer.hs

This file was deleted.

1 change: 0 additions & 1 deletion benchmark/streamly-benchmarks.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ benchmark Data.Parser
, Streamly.Benchmark.Data.Parser.Monad
, Streamly.Benchmark.Data.Parser.Interleave
, Streamly.Benchmark.Data.Parser.Sequence
, Streamly.Benchmark.Data.Parser.Producer
, Streamly.Benchmark.Data.Parser.Groups
if impl(ghcjs)
buildable: False
Expand Down
7 changes: 3 additions & 4 deletions core/src/Streamly/Internal/Data/Array/Generic/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ import qualified Streamly.Internal.Data.Fold.Type as FL
import qualified Streamly.Internal.Data.MutArray.Generic as MArray
import qualified Streamly.Internal.Data.Parser.Type as ParserD
import qualified Streamly.Internal.Data.ParserK.Type as ParserK
import qualified Streamly.Internal.Data.Producer as Producer
import qualified Streamly.Internal.Data.RingArray.Generic as RB
import qualified Streamly.Internal.Data.Stream.Type as D
import qualified Streamly.Internal.Data.Stream.Generate as D
import qualified Streamly.Internal.Data.Unfold.Type as Unfold
import qualified Text.ParserCombinators.ReadPrec as ReadPrec

import Prelude hiding (Foldable(..), read)
Expand Down Expand Up @@ -206,9 +206,8 @@ length arr = arrEnd arr - arrStart arr
{-# INLINE_NORMAL reader #-}
reader :: Monad m => Unfold m (Array a) a
reader =
Producer.simplify
$ Producer.translate unsafeThaw unsafeFreeze
$ MArray.producerWith (return . unsafeInlineIO)
Unfold.lmap unsafeThaw
$ MArray.readerWith (return . unsafeInlineIO)

-------------------------------------------------------------------------------
-- Elimination - to streams
Expand Down
11 changes: 1 addition & 10 deletions core/src/Streamly/Internal/Data/Array/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ module Streamly.Internal.Data.Array.Type
, toList

-- *** Unfolds
, producer -- experimental
, unsafeReader
, reader
, readerRev
Expand Down Expand Up @@ -233,7 +232,6 @@ import GHC.ForeignPtr (ForeignPtr(..), ForeignPtrContents(..))

import GHC.IO (unsafePerformIO)
import GHC.Ptr (Ptr(..), nullPtr)
import Streamly.Internal.Data.Producer.Type (Producer(..))
import Streamly.Internal.Data.MutArray.Type (MutArray)
import Streamly.Internal.Data.MutByteArray.Type (MutByteArray)
import Streamly.Internal.Data.Fold.Type (Fold(..))
Expand All @@ -254,7 +252,6 @@ import qualified Streamly.Internal.Data.MutArray.Type as MA
import qualified Streamly.Internal.Data.Stream.Type as D
import qualified Streamly.Internal.Data.StreamK.Type as K
import qualified Streamly.Internal.Data.MutByteArray.Type as Unboxed
import qualified Streamly.Internal.Data.Producer as Producer
import qualified Streamly.Internal.Data.Scanl.Type as Scanl
import qualified Streamly.Internal.Data.Unfold.Type as Unfold
import qualified Text.ParserCombinators.ReadPrec as ReadPrec
Expand Down Expand Up @@ -987,17 +984,11 @@ byteLength = MA.byteLength . unsafeThaw
length :: Unbox a => Array a -> Int
length arr = MA.length (unsafeThaw arr)

{-# INLINE_NORMAL producer #-}
producer :: forall m a. (Monad m, Unbox a) => Producer m (Array a) a
producer =
Producer.translate unsafeThaw unsafeFreeze
$ MA.producerWith (return . unsafeInlineIO)

-- | Unfold an array into a stream.
--
{-# INLINE_NORMAL reader #-}
reader :: forall m a. (Monad m, Unbox a) => Unfold m (Array a) a
reader = Producer.simplify producer
reader = Unfold.lmap unsafeThaw $ MA.readerWith (return . unsafeInlineIO)

-- | Unfold an array into a stream, does not check the end of the array, the
-- user is responsible for terminating the stream within the array bounds. For
Expand Down
25 changes: 6 additions & 19 deletions core/src/Streamly/Internal/Data/MutArray/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ module Streamly.Internal.Data.MutArray.Generic
-- ** Unfolds
, reader
-- , readerRev
, producerWith -- experimental
, producer -- experimental
, readerWith

-- ** To containers
, read
Expand Down Expand Up @@ -200,13 +199,11 @@ import GHC.Base
import GHC.IO (IO(..))
import GHC.Int (Int(..))
import Streamly.Internal.Data.Fold.Type (Fold(..))
import Streamly.Internal.Data.Producer.Type (Producer (..))
import Streamly.Internal.Data.Unfold.Type (Unfold(..))
import Streamly.Internal.Data.Stream.Type (Stream)
import Streamly.Internal.Data.SVar.Type (adaptState)

import qualified Streamly.Internal.Data.Fold.Type as FL
import qualified Streamly.Internal.Data.Producer as Producer
import qualified Streamly.Internal.Data.Stream.Type as D
import qualified Streamly.Internal.Data.Stream.Generate as D
import qualified Streamly.Internal.Data.Stream.Lift as D
Expand Down Expand Up @@ -813,39 +810,29 @@ chunksOf n (D.Stream step state) =
-- Unfolds
-------------------------------------------------------------------------------

-- | Resumable unfold of an array.
-- | Unfold an array into a stream.
--
{-# INLINE_NORMAL producerWith #-}
producerWith :: Monad m => (forall b. IO b -> m b) -> Producer m (MutArray a) a
producerWith liftio = Producer step inject extract
{-# INLINE_NORMAL readerWith #-}
readerWith :: Monad m => (forall b. IO b -> m b) -> Unfold m (MutArray a) a
readerWith liftio = Unfold step inject

where

{-# INLINE inject #-}
inject arr = return (arr, 0)

{-# INLINE extract #-}
extract (arr, i) =
return $ arr {arrStart = arrStart arr + i}

{-# INLINE_LATE step #-}
step (arr, i)
| i == length arr = return D.Stop
step (arr, i) = do
x <- liftio $ unsafeGetIndex i arr
return $ D.Yield x (arr, i + 1)

-- | Resumable unfold of an array.
--
{-# INLINE_NORMAL producer #-}
producer :: MonadIO m => Producer m (MutArray a) a
producer = producerWith liftIO

-- | Unfold an array into a stream.
--
{-# INLINE_NORMAL reader #-}
reader :: MonadIO m => Unfold m (MutArray a) a
reader = Producer.simplify producer
reader = readerWith liftIO

--------------------------------------------------------------------------------
-- Appending arrays
Expand Down
23 changes: 6 additions & 17 deletions core/src/Streamly/Internal/Data/MutArray/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ module Streamly.Internal.Data.MutArray.Type

-- *** Unfolds
-- experimental
, producerWith
, producer
, readerWith

, reader
, readerRevWith
Expand Down Expand Up @@ -541,7 +540,6 @@ import GHC.Exts (byteArrayContents#, unsafeCoerce#)

import Streamly.Internal.Data.Fold.Type (Fold(..))
import Streamly.Internal.Data.MutByteArray.Type (isPower2, roundUpLargeArray)
import Streamly.Internal.Data.Producer.Type (Producer (..))
import Streamly.Internal.Data.Scanl.Type (Scanl (..))
import Streamly.Internal.Data.Stream.Type (Stream)
import Streamly.Internal.Data.Parser.Type (Parser (..))
Expand All @@ -555,7 +553,6 @@ import qualified Streamly.Internal.Data.Fold.Type as FL
import qualified Streamly.Internal.Data.MutByteArray.Type as Unboxed
import qualified Streamly.Internal.Data.Parser.Type as Parser
-- import qualified Streamly.Internal.Data.Fold.Type as Fold
import qualified Streamly.Internal.Data.Producer as Producer
import qualified Streamly.Internal.Data.Stream.Type as D
import qualified Streamly.Internal.Data.Stream.Lift as D
import qualified Streamly.Internal.Data.Stream.Generate as D
Expand Down Expand Up @@ -2174,11 +2171,11 @@ fromArrayUnsafe :: ArrayUnsafe a -> MutArray a
fromArrayUnsafe (ArrayUnsafe contents start end) =
MutArray contents start end end

{-# INLINE_NORMAL producerWith #-}
producerWith ::
{-# INLINE_NORMAL readerWith #-}
readerWith ::
forall m a. (Monad m, Unbox a)
=> (forall b. IO b -> m b) -> Producer m (MutArray a) a
producerWith liftio = Producer step (return . toArrayUnsafe) extract
=> (forall b. IO b -> m b) -> Unfold m (MutArray a) a
readerWith liftio = Unfold step (return . toArrayUnsafe)
where

{-# INLINE_LATE step #-}
Expand All @@ -2192,19 +2189,11 @@ producerWith liftio = Producer step (return . toArrayUnsafe) extract
!x <- liftio $ peekAt cur contents
return $ D.Yield x (ArrayUnsafe contents (INDEX_NEXT(cur,a)) end)

extract = return . fromArrayUnsafe

-- | Resumable unfold of an array.
--
{-# INLINE_NORMAL producer #-}
producer :: forall m a. (MonadIO m, Unbox a) => Producer m (MutArray a) a
producer = producerWith liftIO

-- | Unfold an array into a stream.
--
{-# INLINE_NORMAL reader #-}
reader :: forall m a. (MonadIO m, Unbox a) => Unfold m (MutArray a) a
reader = Producer.simplify producer
reader = readerWith liftIO

{-# INLINE_NORMAL readerRevWith #-}
readerRevWith ::
Expand Down
Loading
Loading