Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cebd6ac
Move CommonImports include file in the tests
harendra-kumar Jun 13, 2026
105be48
Merge the Array Stream test in the main Array test suite
harendra-kumar Jun 13, 2026
5864eac
Cleanup test order and grouping in Array tests
harendra-kumar Jun 13, 2026
c351a5e
Move the MutArray tests to the MutArray test suite
harendra-kumar Jun 13, 2026
6112112
Cleanup and flatten the test list in Generic array
harendra-kumar Jun 13, 2026
e4339d7
Push common array tests in the common module
harendra-kumar Jun 13, 2026
a756ba5
Move the Show/Read instance test from Generic to Common
harendra-kumar Jun 13, 2026
3876bf0
Move Array tests to Common to share with Generic
harendra-kumar Jun 13, 2026
3bb6919
Add a note about adding new tests
harendra-kumar Jun 13, 2026
0395d42
Add a MutArray.Generic test suite
harendra-kumar Jun 14, 2026
64090a8
Add more tests to the MutArray test-suite
harendra-kumar Jun 14, 2026
e95885a
Add missing tests in the MutArray test suite
harendra-kumar Jun 14, 2026
fed8ae8
Fix Generic Array "clone" and MutArray indexReader
harendra-kumar Jun 14, 2026
88a44f9
Restructure MutArray tests mirroring source modules
harendra-kumar Jun 14, 2026
51bfe58
Move tests from Type module to the MutArray module
harendra-kumar Jun 14, 2026
1f4d3db
Create a Type module from Data.Array test module
harendra-kumar Jun 14, 2026
32392f8
Rename MutArray/Type to TypeCommon
harendra-kumar Jun 14, 2026
0022b28
Factor out tests common across all array types
harendra-kumar Jun 14, 2026
62f3d15
Fix SmallArray test build failure
harendra-kumar Jun 14, 2026
336e2d5
Split ParserK tests into Parserk, Chunked, Generic
harendra-kumar Jun 14, 2026
fe06b16
Move ParserK tests from Parser to ParserK
harendra-kumar Jun 14, 2026
1532e10
Move Unbox instance existence tests to Data.Unbox
harendra-kumar Jun 15, 2026
034bb64
Move Array serialization to Data.Array test-suite
harendra-kumar Jun 15, 2026
9e79aeb
Rename Serialize test-suite to MutByteArray
harendra-kumar Jun 15, 2026
0954f46
Move Unbox instance existence tests to Unbox/TH.hs
harendra-kumar Jun 15, 2026
7d0a382
Rename Unbox.hs to MutByteArray/DeriveInstances.hs
harendra-kumar Jun 15, 2026
91ab78f
Move Unbox/TH.hs to MutByteArray/DeriveUnbox.hs
harendra-kumar Jun 15, 2026
ef18e60
Cleanup the MutByteArray test/bench naming mess
harendra-kumar Jun 15, 2026
85de3a5
Move MutByteArray bench files to its own dir
harendra-kumar Jun 15, 2026
5fdf31f
Disable dist checks for docspec CI
harendra-kumar Jun 15, 2026
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ jobs:
GHCVER: "9.14.1"
CABAL_PROJECT: "cabal.project.doctest"
DISABLE_SDIST_BUILD: "y"
DISABLE_DIST_CHECKS: "y"
DISABLE_TEST: "y"
DISABLE_BENCH: "y"
DISABLE_DOCS: "y"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/regression-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ jobs:
Data.Array.Stream
Data.Fold
Data.MutArray
Data.MutByteArray.DeriveSerialize
Data.MutByteArray.DeriveUnboxGeneric
Data.MutByteArray.DeriveUnboxTH
Data.Parser
Data.ParserK
Data.ParserK.Chunked
Data.ParserK.Chunked.Generic
Data.RingArray
Data.Scanl
Data.Scanl.Concurrent
Data.Serialize
Data.Stream
Data.Stream.Concurrent
Data.Stream.ConcurrentEager
Data.Stream.ConcurrentInterleaved
Data.Stream.ConcurrentOrdered
Data.Stream.Prelude
Data.StreamK:6
Data.Unbox
Data.Unbox.Derive.TH
Data.Unfold
Data.Unfold.Prelude
FileSystem.DirIO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}

module Streamly.Benchmark.Data.Serialize.RecCompatible
module Streamly.Benchmark.Data.MutByteArray.RecCompatible
( RecCompatible(..)
, valRecCompatible
) where
Expand All @@ -10,7 +10,7 @@ module Streamly.Benchmark.Data.Serialize.RecCompatible
--------------------------------------------------------------------------------

import Streamly.Internal.Data.MutByteArray (Serialize)
import Streamly.Benchmark.Data.Serialize.TH (genLargeRecord)
import Streamly.Benchmark.Data.MutByteArray.TH (genLargeRecord)

import qualified Streamly.Internal.Data.MutByteArray as Serialize

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}

module Streamly.Benchmark.Data.Serialize.RecNonCompatible
module Streamly.Benchmark.Data.MutByteArray.RecNonCompatible
( RecNonCompatible(..)
, valRecNonCompatible
) where
Expand All @@ -9,7 +9,7 @@ module Streamly.Benchmark.Data.Serialize.RecNonCompatible
-- Imports
--------------------------------------------------------------------------------

import Streamly.Benchmark.Data.Serialize.TH (genLargeRecord)
import Streamly.Benchmark.Data.MutByteArray.TH (genLargeRecord)

import qualified Streamly.Internal.Data.MutByteArray as Serialize

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#endif

-- |
-- Module : Streamly.Benchmark.Data.Serialize
-- Module : Streamly.Benchmark.Data.MutByteArray.Serialize
-- Copyright : (c) 2023 Composewell
-- License : BSD-3-Clause
-- Maintainer : streamly@composewell.com
Expand Down Expand Up @@ -39,8 +39,8 @@ import Test.Tasty.Bench
import Streamly.Benchmark.Common

#ifndef USE_UNBOX
import Streamly.Benchmark.Data.Serialize.RecCompatible
import Streamly.Benchmark.Data.Serialize.RecNonCompatible
import Streamly.Benchmark.Data.MutByteArray.RecCompatible
import Streamly.Benchmark.Data.MutByteArray.RecNonCompatible
#endif

#ifdef USE_UNBOX
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}

module Streamly.Benchmark.Data.Serialize.TH (genLargeRecord) where
module Streamly.Benchmark.Data.MutByteArray.TH (genLargeRecord) where

--------------------------------------------------------------------------------
-- Imports
Expand Down
55 changes: 27 additions & 28 deletions benchmark/streamly-benchmarks.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,33 @@ benchmark Data.MutArray
else
buildable: True

benchmark Data.MutByteArray.DeriveSerialize
import: bench-options
type: exitcode-stdio-1.0
hs-source-dirs: .
cpp-options: -DUSE_TH
main-is: Streamly/Benchmark/Data/MutByteArray/Serialize.hs
build-depends: QuickCheck, template-haskell
other-modules:
Streamly.Benchmark.Data.MutByteArray.TH
Streamly.Benchmark.Data.MutByteArray.RecCompatible
Streamly.Benchmark.Data.MutByteArray.RecNonCompatible

benchmark Data.MutByteArray.DeriveUnboxGeneric
import: bench-options
type: exitcode-stdio-1.0
hs-source-dirs: .
cpp-options: -DUSE_UNBOX
main-is: Streamly/Benchmark/Data/MutByteArray/Serialize.hs

benchmark Data.MutByteArray.DeriveUnboxTH
import: bench-options
type: exitcode-stdio-1.0
hs-source-dirs: .
cpp-options: -DUSE_UNBOX
cpp-options: -DUSE_TH
main-is: Streamly/Benchmark/Data/MutByteArray/Serialize.hs

benchmark Data.Parser
import: bench-options
type: exitcode-stdio-1.0
Expand Down Expand Up @@ -407,19 +434,6 @@ benchmark Data.Scanl.Concurrent
else
buildable: True

-- XXX Should be renamed to MutByteArray
benchmark Data.Serialize
import: bench-options
type: exitcode-stdio-1.0
hs-source-dirs: .
cpp-options: -DUSE_TH
main-is: Streamly/Benchmark/Data/Serialize.hs
build-depends: QuickCheck, template-haskell
other-modules:
Streamly.Benchmark.Data.Serialize.TH
Streamly.Benchmark.Data.Serialize.RecCompatible
Streamly.Benchmark.Data.Serialize.RecNonCompatible

benchmark Data.SmallArray
import: bench-options
type: exitcode-stdio-1.0
Expand Down Expand Up @@ -585,21 +599,6 @@ benchmark Data.StreamK.StreamKAlt
if !flag(dev) || impl(ghcjs)
buildable: False

benchmark Data.Unbox
import: bench-options
type: exitcode-stdio-1.0
hs-source-dirs: .
cpp-options: -DUSE_UNBOX
main-is: Streamly/Benchmark/Data/Serialize.hs

benchmark Data.Unbox.Derive.TH
import: bench-options
type: exitcode-stdio-1.0
hs-source-dirs: .
cpp-options: -DUSE_UNBOX
cpp-options: -DUSE_TH
main-is: Streamly/Benchmark/Data/Serialize.hs

benchmark Data.Unfold
import: bench-options
type: exitcode-stdio-1.0
Expand Down
5 changes: 3 additions & 2 deletions core/src/Streamly/Internal/Data/MutArray/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,9 @@ clone :: MonadIO m => MutArray a -> m (MutArray a)
clone src = do
let len = length src
dst <- emptyOf len
unsafePutSlice src 0 dst 0 len
return dst
let dst1 = dst { arrEnd = arrStart dst + len }
unsafePutSlice src 0 dst1 0 len
return dst1

-------------------------------------------------------------------------------
-- Size
Expand Down
4 changes: 3 additions & 1 deletion core/src/Streamly/Internal/Data/MutArray/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,9 @@ indexReaderWith liftio (D.Stream stepi sti) = Unfold step inject
r <- stepi defState st
case r of
D.Yield i s -> do
x <- liftio $ getIndex i (MutArray contents start end undefined)
-- We do not need arrBound but we cannot leave it undefined
-- because it is a strict field.
x <- liftio $ getIndex i (MutArray contents start end end)
case x of
Just v -> return $ D.Yield v (GetIndicesState contents start end s)
Nothing -> error "Invalid Index"
Expand Down
40 changes: 40 additions & 0 deletions src/Streamly/Internal/Data/SmallArray.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module Streamly.Internal.Data.SmallArray
, length

, createOf
, create
, createOfLast

, toStreamD
, toStreamDRev
Expand All @@ -33,8 +35,14 @@ module Streamly.Internal.Data.SmallArray
, reader

, fromListN
, fromList
, fromStreamDN
, fromStreamN
, fromStream

, toList
, unsafeGetIndex
, unsafeSliceOffLen

, streamFold
, fold
Expand All @@ -53,6 +61,9 @@ import Streamly.Data.Stream (Stream)
import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
import Streamly.Internal.Data.Unfold (Unfold(..))

import qualified Data.List as List
import qualified Streamly.Data.Fold as Fold

import qualified Streamly.Internal.Data.Stream as D
import qualified Streamly.Internal.Data.Fold as FL
(Fold (..), Step (Done, Partial))
Expand Down Expand Up @@ -157,6 +168,10 @@ fromStreamDN limit str = do
fromListN :: Int -> [a] -> SmallArray a
fromListN n xs = unsafePerformIO $ fromStreamDN n $ D.fromList xs

{-# INLINABLE fromList #-}
fromList :: [a] -> SmallArray a
fromList = smallArrayFromList

instance NFData a => NFData (SmallArray a) where
{-# INLINE rnf #-}
rnf = foldl' (\_ x -> rnf x) ()
Expand Down Expand Up @@ -191,6 +206,31 @@ fold f arr = D.fold f (toStreamD arr)
streamFold :: Monad m => (Stream m a -> m b) -> SmallArray a -> m b
streamFold f arr = f (read arr)

{-# INLINE toList #-}
toList :: SmallArray a -> [a]
toList = foldr (:) []

{-# INLINE create #-}
create :: MonadIO m => Fold m a (SmallArray a)
create = fmap fromList Fold.toList

{-# INLINE fromStream #-}
fromStream :: MonadIO m => Stream m a -> m (SmallArray a)
fromStream m = fmap fromList (D.fold Fold.toList m)

{-# INLINE unsafeGetIndex #-}
unsafeGetIndex :: Int -> SmallArray a -> a
unsafeGetIndex i arr = indexSmallArray arr i

{-# INLINE unsafeSliceOffLen #-}
unsafeSliceOffLen :: Int -> Int -> SmallArray a -> SmallArray a
unsafeSliceOffLen i n arr = cloneSmallArray arr i n

{-# INLINE createOfLast #-}
createOfLast :: MonadIO m => Int -> Fold m a (SmallArray a)
createOfLast n = fmap (fromList . takeLast) Fold.toList
where takeLast xs = drop (List.length xs - n) xs

{-# INLINE_NORMAL reader #-}
reader :: Monad m => Unfold m (SmallArray a) a
reader = Unfold step inject
Expand Down
23 changes: 7 additions & 16 deletions streamly.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ extra-source-files:
benchmark/Streamly/Benchmark/Data/Array/Stream.hs
benchmark/Streamly/Benchmark/Data/Fold/*.hs
benchmark/Streamly/Benchmark/Data/MutArray.hs
benchmark/Streamly/Benchmark/Data/MutByteArray/*.hs
benchmark/Streamly/Benchmark/Data/Parser/*.hs
benchmark/Streamly/Benchmark/Data/RingArray.hs
benchmark/Streamly/Benchmark/Data/Scanl/*.hs
benchmark/Streamly/Benchmark/Data/Serialize/*.hs
benchmark/Streamly/Benchmark/Data/Stream/*.hs
benchmark/Streamly/Benchmark/Data/Stream/Nesting/*.hs
benchmark/Streamly/Benchmark/Data/Stream/Parse/*.hs
Expand Down Expand Up @@ -123,16 +123,9 @@ extra-source-files:
src/inline.hs
test/Streamly/Test/Control/Exception.hs
test/Streamly/Test/Data/*.hs
test/Streamly/Test/Data/Array/CommonImports.hs
test/Streamly/Test/Data/Array/Common.hs
test/Streamly/Test/Data/Array/Generic.hs
test/Streamly/Test/Data/Array.hs
test/Streamly/Test/Data/MutArray.hs
test/Streamly/Test/Data/RingArray.hs
test/Streamly/Test/Data/Array/Stream.hs
test/Streamly/Test/Data/Parser.hs
test/Streamly/Test/Data/Parser/*.hs
test/Streamly/Test/Data/ParserK.hs
test/Streamly/Test/Data/Array/*.hs
test/Streamly/Test/Data/MutArray/*.hs
test/Streamly/Test/Data/ParserK/*.hs
test/Streamly/Test/Data/Stream/*.hs
test/Streamly/Test/Data/Stream/MkType/*.hs
test/Streamly/Test/Data/Stream/Prelude/*.hs
Expand All @@ -153,14 +146,12 @@ extra-source-files:
test/Streamly/Test/Data/Fold/*.hs
test/Streamly/Test/Unicode/ucd/NormalizationTest.txt
test/Streamly/Test/Unicode/extra/NormalizationTest.txt
test/Streamly/Test/Data/Unbox.hs
test/Streamly/Test/Data/Unbox/*.hs
test/Streamly/Test/Data/Serialize.hs
test/Streamly/Test/Data/Serialize/*.hs
test/Streamly/Test/Data/MutByteArray/*.hs
test/lib/Streamly/Test/Common.hs
test/lib/Streamly/Test/Control/Exception/Common.hs
test/lib/Streamly/Test/Prelude/Common.hs
test/lib/Streamly/Test/Parser/Common.hs
test/lib/Streamly/Test/Data/Parser/CommonTests.hs
test/lib/Streamly/Test/Data/Parser/CommonUtilities.hs
test/streamly-tests.cabal
test/version-bounds.hs

Expand Down
21 changes: 8 additions & 13 deletions targets/Targets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ targets =
]
)

, ("Data.Serialize",
, ("Data.MutByteArray.Serialize",
[ "mut_bytearray_grp"
, "streamly_core_grp"
, "noBench"
]
)
, ("Data.Serialize.Derive.TH",
, ("Data.MutByteArray.DeriveSerialize",
[ "mut_bytearray_grp"
, "noBench"
]
)
, ("Data.Serialize.ENABLE_constructorTagAsString",
, ("Data.MutByteArray.SerializeConstrTags",
[ "mut_bytearray_grp"
, "noBench"
]
Expand Down Expand Up @@ -201,20 +201,15 @@ targets =
]
)
-}
, ("Data.Unbox",
[ "noTest"
, "streamly_core_grp"
]
)
, ("Data.Unbox.Derive.Generic",
[ "noBench"
, ("Data.MutByteArray.DeriveUnboxGeneric",
[ "streamly_core_grp"
]
)
, ("Data.Unbox.Derive.TH",
, ("Data.MutByteArray.DeriveUnboxTH",
[ "streamly_core_grp"
]
)
, ("Data.Unbox.TH",
, ("Data.MutByteArray.DeriveUnboxTHCustom",
[ "noBench"
]
)
Expand Down
Loading
Loading