on master help sign in
test the absence of flattening/grouping state in inspection tests
8f3f6e0Harendra Kumar
src/Streamly/Benchmark/FileIO/Stream.hs+42−3
@@ -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)
42
42
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
45
46
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
52
55
53import Test.Inspection
56import Test.Inspection
54
57
@@ -59,7 +62,9 @@ last = S.last . FH.read
59
62
60hinspect $ hasNoTypeClasses 'last
63hinspect $ hasNoTypeClasses 'last
61hinspect $ 'last `hasNoType` ''Step
64hinspect $ 'last `hasNoType` ''Step
65+hinspect $ 'last `hasNoType` ''AT.FlattenState
62
66
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
67
72
68hinspect $ hasNoTypeClasses 'countBytes
73hinspect $ hasNoTypeClasses 'countBytes
69hinspect $ 'countBytes `hasNoType` ''Step
74hinspect $ 'countBytes `hasNoType` ''Step
75+hinspect $ 'countBytes `hasNoType` ''AT.FlattenState
70
76
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 =
79
85
80hinspect $ hasNoTypeClasses 'countLines
86hinspect $ hasNoTypeClasses 'countLines
81hinspect $ 'countLines `hasNoType` ''Step
87hinspect $ 'countLines `hasNoType` ''Step
88+hinspect $ 'countLines `hasNoType` ''AT.FlattenState
82
89
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 =
91
98
92hinspect $ hasNoTypeClasses 'countLinesU
99hinspect $ hasNoTypeClasses 'countLinesU
93hinspect $ 'countLinesU `hasNoType` ''Step
100hinspect $ 'countLinesU `hasNoType` ''Step
101+hinspect $ 'countLinesU `hasNoType` ''Either
94
102
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
99
107
100hinspect $ hasNoTypeClasses 'sumBytes
108hinspect $ hasNoTypeClasses 'sumBytes
101hinspect $ 'sumBytes `hasNoType` ''Step
109hinspect $ 'sumBytes `hasNoType` ''Step
110+hinspect $ 'sumBytes `hasNoType` ''AT.FlattenState
102
111
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
107
116
108hinspect $ hasNoTypeClasses 'cat
117hinspect $ hasNoTypeClasses 'cat
109hinspect $ 'cat `hasNoType` ''Step
118hinspect $ 'cat `hasNoType` ''Step
119+hinspect $ 'cat `hasNoType` ''AT.FlattenState
110
120
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
115
125
116hinspect $ hasNoTypeClasses 'catStreamWrite
126hinspect $ hasNoTypeClasses 'catStreamWrite
117hinspect $ 'catStreamWrite `hasNoType` ''Step
127hinspect $ 'catStreamWrite `hasNoType` ''Step
128+hinspect $ 'catStreamWrite `hasNoType` ''AT.FlattenState
118
129
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)
123
134
124hinspect $ hasNoTypeClasses 'copy
135hinspect $ hasNoTypeClasses 'copy
125hinspect $ 'copy `hasNoType` ''Step
136hinspect $ 'copy `hasNoType` ''Step
137+hinspect $ 'copy `hasNoType` ''AT.FlattenState
126
138
127-- | Copy file
139-- | Copy file
128{-# INLINE copyCodecChar8 #-}
140{-# INLINE copyCodecChar8 #-}
@@ -135,6 +147,7 @@ copyCodecChar8 inh outh =
135
147
136hinspect $ hasNoTypeClasses 'copyCodecChar8
148hinspect $ hasNoTypeClasses 'copyCodecChar8
137hinspect $ 'copyCodecChar8 `hasNoType` ''Step
149hinspect $ 'copyCodecChar8 `hasNoType` ''Step
150+hinspect $ 'copyCodecChar8 `hasNoType` ''AT.FlattenState
138
151
139-- | Copy file
152-- | Copy file
140{-# INLINE copyCodecUtf8 #-}
153{-# INLINE copyCodecUtf8 #-}
@@ -147,15 +160,34 @@ copyCodecUtf8 inh outh =
147
160
148hinspect $ hasNoTypeClasses 'copyCodecUtf8
161hinspect $ hasNoTypeClasses 'copyCodecUtf8
149-- hinspect $ 'copyCodecUtf8 `hasNoType` ''Step
162-- hinspect $ 'copyCodecUtf8 `hasNoType` ''Step
163+-- hinspect $ 'copyCodecUtf8 `hasNoType` ''AT.FlattenState
150
164
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)
156
170
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
175+
176+-- This is to make sure that the concatMap in FH.read, groupsOf and foldlM'
177+-- together can fuse.
178+--
179+-- | Slice in chunks of size n and get the count of chunks.
180+{-# INLINE chunksOfD #-}
181+chunksOfD :: Int -> Handle -> IO Int
182+chunksOfD n inh =
183+ D.foldlM' (\i _ -> return $ i + 1) 0
184+ $ D.groupsOf n (AT.writeNUnsafe n)
185+ $ D.fromStreamK (FH.read inh)
186+
187+hinspect $ hasNoTypeClasses 'chunksOf
188+hinspect $ 'chunksOf `hasNoType` ''Step
189+-- hinspect $ 'chunksOfD `hasNoType` ''GroupState
190+-- hinspect $ 'chunksOfD `hasNoType` ''AT.FlattenState
159
191
160-- | Lines and unlines
192-- | Lines and unlines
161{-# INLINE linesUnlinesCopy #-}
193{-# INLINE linesUnlinesCopy #-}
@@ -170,6 +202,7 @@ linesUnlinesCopy inh outh =
170
202
171-- hinspect $ hasNoTypeClasses 'linesUnlinesCopy
203-- hinspect $ hasNoTypeClasses 'linesUnlinesCopy
172-- hinspect $ 'linesUnlinesCopy `hasNoType` ''Step
204-- hinspect $ 'linesUnlinesCopy `hasNoType` ''Step
205+-- hinspect $ 'linesUnlinesCopy `hasNoType` ''AT.FlattenState
173
206
174-- | Word, unwords and copy
207-- | Word, unwords and copy
175{-# INLINE wordsUnwordsCopy #-}
208{-# INLINE wordsUnwordsCopy #-}
@@ -184,6 +217,7 @@ wordsUnwordsCopy inh outh =
184
217
185-- hinspect $ hasNoTypeClasses 'wordsUnwordsCopy
218-- hinspect $ hasNoTypeClasses 'wordsUnwordsCopy
186-- hinspect $ 'wordsUnwordsCopy `hasNoType` ''Step
219-- hinspect $ 'wordsUnwordsCopy `hasNoType` ''Step
220+-- hinspect $ 'wordsUnwordsCopy `hasNoType` ''AT.FlattenState
187
221
188lf :: Word8
222lf :: Word8
189lf = fromIntegral (ord '\n')
223lf = fromIntegral (ord '\n')
@@ -221,6 +255,7 @@ splitOn inh =
221
255
222hinspect $ hasNoTypeClasses 'splitOn
256hinspect $ hasNoTypeClasses 'splitOn
223hinspect $ 'splitOn `hasNoType` ''Step
257hinspect $ 'splitOn `hasNoType` ''Step
258+hinspect $ 'splitOn `hasNoType` ''AT.FlattenState
224
259
225-- | Split suffix on line feed.
260-- | Split suffix on line feed.
226{-# INLINE splitOnSuffix #-}
261{-# INLINE splitOnSuffix #-}
@@ -231,6 +266,7 @@ splitOnSuffix inh =
231
266
232hinspect $ hasNoTypeClasses 'splitOnSuffix
267hinspect $ hasNoTypeClasses 'splitOnSuffix
233hinspect $ 'splitOnSuffix `hasNoType` ''Step
268hinspect $ 'splitOnSuffix `hasNoType` ''Step
269+hinspect $ 'splitOnSuffix `hasNoType` ''AT.FlattenState
234
270
235-- | Words by space
271-- | Words by space
236{-# INLINE wordsBy #-}
272{-# INLINE wordsBy #-}
@@ -241,6 +277,7 @@ wordsBy inh =
241
277
242hinspect $ hasNoTypeClasses 'wordsBy
278hinspect $ hasNoTypeClasses 'wordsBy
243hinspect $ 'wordsBy `hasNoType` ''Step
279hinspect $ 'wordsBy `hasNoType` ''Step
280+hinspect $ 'wordsBy `hasNoType` ''AT.FlattenState
244
281
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 =
251
288
252hinspect $ hasNoTypeClasses 'splitOnSeq
289hinspect $ hasNoTypeClasses 'splitOnSeq
253-- hinspect $ 'splitOnSeq `hasNoType` ''Step
290-- hinspect $ 'splitOnSeq `hasNoType` ''Step
291+-- hinspect $ 'splitOnSeq `hasNoType` ''AT.FlattenState
254
292
255-- | Split on suffix sequence.
293-- | Split on suffix sequence.
256{-# INLINE splitOnSuffixSeq #-}
294{-# INLINE splitOnSuffixSeq #-}
@@ -261,3 +299,4 @@ splitOnSuffixSeq str inh =
261
299
262hinspect $ hasNoTypeClasses 'splitOnSuffixSeq
300hinspect $ hasNoTypeClasses 'splitOnSuffixSeq
263-- hinspect $ 'splitOnSuffixSeq `hasNoType` ''Step
301-- hinspect $ 'splitOnSuffixSeq `hasNoType` ''Step
302+-- hinspect $ 'splitOnSuffixSeq `hasNoType` ''AT.FlattenState
src/Streamly/Internal.hs+2−1
@@ -75,6 +75,7 @@ module Streamly.Internal
75 -- * Streamly.Memory.Array
75 -- * Streamly.Memory.Array
76 , readU
76 , readU
77 , A.arraysOf
77 , A.arraysOf
78+ , writeNUnsafe
78
79
79 -- * Streamly.FileSystem.Handle
80 -- * Streamly.FileSystem.Handle
80 , writeS
81 , writeS
@@ -84,7 +85,7 @@ where
84import Prelude hiding (break, span, splitAt)
85import Prelude hiding (break, span, splitAt)
85
86
86import Streamly.FileSystem.Handle.Internal (writeS)
87import Streamly.FileSystem.Handle.Internal (writeS)
87−import Streamly.Memory.Array.Types (readU)
88+import Streamly.Memory.Array.Types (readU, writeNUnsafe)
88import Streamly.Streams.Combinators (inspectMode)
89import Streamly.Streams.Combinators (inspectMode)
89import Streamly.Streams.Parallel (tapAsync)
90import Streamly.Streams.Parallel (tapAsync)
90import Streamly.Unfold.Types (Unfold(..))
91import Streamly.Unfold.Types (Unfold(..))
src/Streamly/Memory/Array/Types.hs+1
@@ -36,6 +36,7 @@ module Streamly.Memory.Array.Types
36
36
37 -- * Streams of arrays
37 -- * Streams of arrays
38 , fromStreamDArraysOf
38 , fromStreamDArraysOf
39+ , FlattenState (..) -- for inspection testing
39 , flattenArrays
40 , flattenArrays
40 , flattenArraysRev
41 , flattenArraysRev
41 , packArraysChunksOf
42 , packArraysChunksOf
src/Streamly/Streams/StreamD/Type.hs+1
@@ -60,6 +60,7 @@ module Streamly.Streams.StreamD.Type
60 , eqBy
60 , eqBy
61 , cmpBy
61 , cmpBy
62 , take
62 , take
63+ , GroupState (..) -- for inspection testing
63 , groupsOf
64 , groupsOf
64 )
65 )
65where
66where
streamly.cabal+1−1
@@ -261,7 +261,7 @@ library
261 , Streamly.Benchmark.FileIO.Stream
261 , Streamly.Benchmark.FileIO.Stream
262
262
263 default-language: Haskell2010
263 default-language: Haskell2010
264− ghc-options: -Wall -fspec-constr-recursive=10
264+ ghc-options: -Wall -O2 -fspec-constr-recursive=10
265
265
266 if flag(has-llvm)
266 if flag(has-llvm)
267 ghc-options: -fllvm
267 ghc-options: -fllvm