@@ -40,15 +40,18 @@ import Data.Word (Word8)
40import System.IO (Handle)
40import System.IO (Handle)
41import Prelude hiding (last, length)
41import Prelude hiding (last, length)
43−import Streamly.Streams.StreamD.Type (Step(..))
43+import Streamly.Streams.StreamD.Type (Step(..), GroupState)
44import Streamly.Benchmark.Inspection (hinspect)
44import Streamly.Benchmark.Inspection (hinspect)
45+import qualified Streamly.Memory.Array.Types as AT
46import qualified Streamly.FileSystem.Handle as FH
47import qualified Streamly.FileSystem.Handle as FH
48+import qualified Streamly.FileSystem.Handle.Internal as FH
47import qualified Streamly.Memory.Array as A
49import qualified Streamly.Memory.Array as A
48−import qualified Streamly.Prelude as S
50+import qualified Streamly.Prelude.Internal as S
49import qualified Streamly.Fold as FL
51import qualified Streamly.Fold as FL
50import qualified Streamly.Data.String as SS
52import qualified Streamly.Data.String as SS
51import qualified Streamly.Internal as Internal
53import qualified Streamly.Internal as Internal
54+import qualified Streamly.Streams.StreamD as D
53import Test.Inspection
56import Test.Inspection
@@ -59,7 +62,9 @@ last = S.last . FH.read
60hinspect $ hasNoTypeClasses 'last
63hinspect $ hasNoTypeClasses 'last
61hinspect $ 'last `hasNoType` ''Step
64hinspect $ 'last `hasNoType` ''Step
65+hinspect $ 'last `hasNoType` ''AT.FlattenState
67+-- assert that flattenArrays constructors are not present
63-- | Count the number of bytes in a file.
68-- | Count the number of bytes in a file.
64{-# INLINE countBytes #-}
69{-# INLINE countBytes #-}
65countBytes :: Handle -> IO Int
70countBytes :: Handle -> IO Int
@@ -67,6 +72,7 @@ countBytes = S.length . FH.read
68hinspect $ hasNoTypeClasses 'countBytes
73hinspect $ hasNoTypeClasses 'countBytes
69hinspect $ 'countBytes `hasNoType` ''Step
74hinspect $ 'countBytes `hasNoType` ''Step
75+hinspect $ 'countBytes `hasNoType` ''AT.FlattenState
71-- | Count the number of lines in a file.
77-- | Count the number of lines in a file.
72{-# INLINE countLines #-}
78{-# INLINE countLines #-}
@@ -79,6 +85,7 @@ countLines =
80hinspect $ hasNoTypeClasses 'countLines
86hinspect $ hasNoTypeClasses 'countLines
81hinspect $ 'countLines `hasNoType` ''Step
87hinspect $ 'countLines `hasNoType` ''Step
88+hinspect $ 'countLines `hasNoType` ''AT.FlattenState
83-- | Count the number of lines in a file.
90-- | Count the number of lines in a file.
84{-# INLINE countLinesU #-}
91{-# INLINE countLinesU #-}
@@ -91,6 +98,7 @@ countLinesU inh =
92hinspect $ hasNoTypeClasses 'countLinesU
99hinspect $ hasNoTypeClasses 'countLinesU
93hinspect $ 'countLinesU `hasNoType` ''Step
100hinspect $ 'countLinesU `hasNoType` ''Step
101+hinspect $ 'countLinesU `hasNoType` ''Either
95-- | Sum the bytes in a file.
103-- | Sum the bytes in a file.
96{-# INLINE sumBytes #-}
104{-# INLINE sumBytes #-}
@@ -99,6 +107,7 @@ sumBytes = S.sum . FH.read
100hinspect $ hasNoTypeClasses 'sumBytes
108hinspect $ hasNoTypeClasses 'sumBytes
101hinspect $ 'sumBytes `hasNoType` ''Step
109hinspect $ 'sumBytes `hasNoType` ''Step
110+hinspect $ 'sumBytes `hasNoType` ''AT.FlattenState
103-- | Send the file contents to /dev/null
112-- | Send the file contents to /dev/null
104{-# INLINE cat #-}
113{-# INLINE cat #-}
@@ -107,6 +116,7 @@ cat devNull inh = S.runFold (FH.write devNull) $ FH.read inh
108hinspect $ hasNoTypeClasses 'cat
117hinspect $ hasNoTypeClasses 'cat
109hinspect $ 'cat `hasNoType` ''Step
118hinspect $ 'cat `hasNoType` ''Step
119+hinspect $ 'cat `hasNoType` ''AT.FlattenState
111-- | Send the file contents to /dev/null
121-- | Send the file contents to /dev/null
112{-# INLINE catStreamWrite #-}
122{-# INLINE catStreamWrite #-}
@@ -115,6 +125,7 @@ catStreamWrite devNull inh = Internal.writeS devNull $ FH.read inh
116hinspect $ hasNoTypeClasses 'catStreamWrite
126hinspect $ hasNoTypeClasses 'catStreamWrite
117hinspect $ 'catStreamWrite `hasNoType` ''Step
127hinspect $ 'catStreamWrite `hasNoType` ''Step
128+hinspect $ 'catStreamWrite `hasNoType` ''AT.FlattenState
119-- | Copy file
130-- | Copy file
120{-# INLINE copy #-}
131{-# INLINE copy #-}
@@ -123,6 +134,7 @@ copy inh outh = S.runFold (FH.write outh) (FH.read inh)
124hinspect $ hasNoTypeClasses 'copy
135hinspect $ hasNoTypeClasses 'copy
125hinspect $ 'copy `hasNoType` ''Step
136hinspect $ 'copy `hasNoType` ''Step
137+hinspect $ 'copy `hasNoType` ''AT.FlattenState
127-- | Copy file
139-- | Copy file
128{-# INLINE copyCodecChar8 #-}
140{-# INLINE copyCodecChar8 #-}
@@ -135,6 +147,7 @@ copyCodecChar8 inh outh =
136hinspect $ hasNoTypeClasses 'copyCodecChar8
148hinspect $ hasNoTypeClasses 'copyCodecChar8
137hinspect $ 'copyCodecChar8 `hasNoType` ''Step
149hinspect $ 'copyCodecChar8 `hasNoType` ''Step
150+hinspect $ 'copyCodecChar8 `hasNoType` ''AT.FlattenState
139-- | Copy file
152-- | Copy file
140{-# INLINE copyCodecUtf8 #-}
153{-# INLINE copyCodecUtf8 #-}
@@ -147,15 +160,34 @@ copyCodecUtf8 inh outh =
148hinspect $ hasNoTypeClasses 'copyCodecUtf8
161hinspect $ hasNoTypeClasses 'copyCodecUtf8
149-- hinspect $ 'copyCodecUtf8 `hasNoType` ''Step
162-- hinspect $ 'copyCodecUtf8 `hasNoType` ''Step
163+-- hinspect $ 'copyCodecUtf8 `hasNoType` ''AT.FlattenState
151-- | Slice in chunks of size n and get the count of chunks.
165-- | Slice in chunks of size n and get the count of chunks.
152{-# INLINE chunksOf #-}
166{-# INLINE chunksOf #-}
153chunksOf :: Int -> Handle -> IO Int
167chunksOf :: Int -> Handle -> IO Int
154chunksOf n inh =
168chunksOf n inh =
155− S.length $ S.chunksOf n (A.writeN n) (FH.read inh)
169+ S.length $ S.chunksOf n (AT.writeNUnsafe n) (FH.read inh)
157hinspect $ hasNoTypeClasses 'chunksOf
171hinspect $ hasNoTypeClasses 'chunksOf
158hinspect $ 'chunksOf `hasNoType` ''Step
172hinspect $ 'chunksOf `hasNoType` ''Step
173+-- hinspect $ 'chunksOf `hasNoType` ''AT.FlattenState
174+-- hinspect $ 'chunksOf `hasNoType` ''GroupState
176+-- This is to make sure that the concatMap in FH.read, groupsOf and foldlM'
177+-- together can fuse.
179+-- | Slice in chunks of size n and get the count of chunks.
180+{-# INLINE chunksOfD #-}
181+chunksOfD :: Int -> Handle -> IO Int
183+ D.foldlM' (\i _ -> return $ i + 1) 0
184+ $ D.groupsOf n (AT.writeNUnsafe n)
185+ $ D.fromStreamK (FH.read inh)
187+hinspect $ hasNoTypeClasses 'chunksOf
188+hinspect $ 'chunksOf `hasNoType` ''Step
189+-- hinspect $ 'chunksOfD `hasNoType` ''GroupState
190+-- hinspect $ 'chunksOfD `hasNoType` ''AT.FlattenState
160-- | Lines and unlines
192-- | Lines and unlines
161{-# INLINE linesUnlinesCopy #-}
193{-# INLINE linesUnlinesCopy #-}
@@ -170,6 +202,7 @@ linesUnlinesCopy inh outh =
171-- hinspect $ hasNoTypeClasses 'linesUnlinesCopy
203-- hinspect $ hasNoTypeClasses 'linesUnlinesCopy
172-- hinspect $ 'linesUnlinesCopy `hasNoType` ''Step
204-- hinspect $ 'linesUnlinesCopy `hasNoType` ''Step
205+-- hinspect $ 'linesUnlinesCopy `hasNoType` ''AT.FlattenState
174-- | Word, unwords and copy
207-- | Word, unwords and copy
175{-# INLINE wordsUnwordsCopy #-}
208{-# INLINE wordsUnwordsCopy #-}
@@ -184,6 +217,7 @@ wordsUnwordsCopy inh outh =
185-- hinspect $ hasNoTypeClasses 'wordsUnwordsCopy
218-- hinspect $ hasNoTypeClasses 'wordsUnwordsCopy
186-- hinspect $ 'wordsUnwordsCopy `hasNoType` ''Step
219-- hinspect $ 'wordsUnwordsCopy `hasNoType` ''Step
220+-- hinspect $ 'wordsUnwordsCopy `hasNoType` ''AT.FlattenState
188lf :: Word8
222lf :: Word8
189lf = fromIntegral (ord '\n')
223lf = fromIntegral (ord '\n')
@@ -221,6 +255,7 @@ splitOn inh =
222hinspect $ hasNoTypeClasses 'splitOn
256hinspect $ hasNoTypeClasses 'splitOn
223hinspect $ 'splitOn `hasNoType` ''Step
257hinspect $ 'splitOn `hasNoType` ''Step
258+hinspect $ 'splitOn `hasNoType` ''AT.FlattenState
225-- | Split suffix on line feed.
260-- | Split suffix on line feed.
226{-# INLINE splitOnSuffix #-}
261{-# INLINE splitOnSuffix #-}
@@ -231,6 +266,7 @@ splitOnSuffix inh =
232hinspect $ hasNoTypeClasses 'splitOnSuffix
267hinspect $ hasNoTypeClasses 'splitOnSuffix
233hinspect $ 'splitOnSuffix `hasNoType` ''Step
268hinspect $ 'splitOnSuffix `hasNoType` ''Step
269+hinspect $ 'splitOnSuffix `hasNoType` ''AT.FlattenState
235-- | Words by space
271-- | Words by space
236{-# INLINE wordsBy #-}
272{-# INLINE wordsBy #-}
@@ -241,6 +277,7 @@ wordsBy inh =
242hinspect $ hasNoTypeClasses 'wordsBy
278hinspect $ hasNoTypeClasses 'wordsBy
243hinspect $ 'wordsBy `hasNoType` ''Step
279hinspect $ 'wordsBy `hasNoType` ''Step
280+hinspect $ 'wordsBy `hasNoType` ''AT.FlattenState
245-- | Split on a character sequence.
282-- | Split on a character sequence.
246{-# INLINE splitOnSeq #-}
283{-# INLINE splitOnSeq #-}
@@ -251,6 +288,7 @@ splitOnSeq str inh =
252hinspect $ hasNoTypeClasses 'splitOnSeq
289hinspect $ hasNoTypeClasses 'splitOnSeq
253-- hinspect $ 'splitOnSeq `hasNoType` ''Step
290-- hinspect $ 'splitOnSeq `hasNoType` ''Step
291+-- hinspect $ 'splitOnSeq `hasNoType` ''AT.FlattenState
255-- | Split on suffix sequence.
293-- | Split on suffix sequence.
256{-# INLINE splitOnSuffixSeq #-}
294{-# INLINE splitOnSuffixSeq #-}
@@ -261,3 +299,4 @@ splitOnSuffixSeq str inh =
262hinspect $ hasNoTypeClasses 'splitOnSuffixSeq
300hinspect $ hasNoTypeClasses 'splitOnSuffixSeq
263-- hinspect $ 'splitOnSuffixSeq `hasNoType` ''Step
301-- hinspect $ 'splitOnSuffixSeq `hasNoType` ''Step
302+-- hinspect $ 'splitOnSuffixSeq `hasNoType` ''AT.FlattenState