on master help sign in
Fix inspection tests
commit89b9e233ba0ddd87f21a28ad5b45981e6c5ed2a2 authorHarendra Kumar <harendra@composewell.com> dateThu 9 Jul 2020, 00:25 (6 years ago) parentbc6b4ee
6 files changed+121−157
benchmark/Streamly/Benchmark/FileSystem/Handle.hs−6 benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+44−52 benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+73−99 src/Streamly/Internal/Data/Unfold.hs+1 src/Streamly/Internal/Memory/Array.hs+1 src/Streamly/Internal/Memory/Array/Types.hs+2
benchmark/Streamly/Benchmark/FileSystem/Handle.hs−6
@@ -35,12 +35,6 @@ import Gauge hiding (env)
3535import Streamly.Benchmark.Common
3636import Handle.Common
3737
38−#ifdef INSPECTION
39−import Foreign.Storable (Storable)
40−import Streamly.Internal.Data.Stream.StreamD.Type (Step(..), GroupState)
41−import Test.Inspection
42−#endif
43−
4438-------------------------------------------------------------------------------
4539--
4640-------------------------------------------------------------------------------
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+44−52
@@ -43,19 +43,20 @@ import qualified Streamly.Internal.Data.Parser as PR
4343import qualified Streamly.Internal.Data.Stream.StreamD as D
4444import qualified Streamly.Internal.Data.Unicode.Stream as IUS
4545import qualified Streamly.Internal.FileSystem.Handle as IFH
46−import qualified Streamly.Internal.Memory.Array as IA
46+import qualified Streamly.Internal.Memory.Array as A
4747import qualified Streamly.Internal.Memory.Array.Types as AT
4848import qualified Streamly.Internal.Memory.ArrayStream as AS
4949import qualified Streamly.Internal.Prelude as IP
50−import qualified Streamly.Memory.Array as A
5150import qualified Streamly.Prelude as S
5251
5352import Gauge hiding (env)
5453import Handle.Common
5554
5655#ifdef INSPECTION
57−import Foreign.Storable (Storable)
5856import Streamly.Internal.Data.Stream.StreamD.Type (Step(..), GroupState)
57+
58+import qualified Streamly.Internal.Data.Unfold as IUF
59+
5960import Test.Inspection
6061#endif
6162
@@ -70,7 +71,7 @@ toChunksLast inh = do
7071 larr <- S.last s
7172 return $ case larr of
7273 Nothing -> Nothing
73− Just arr -> IA.readIndex arr (A.length arr - 1)
74+ Just arr -> A.readIndex arr (A.length arr - 1)
7475
7576#ifdef INSPECTION
7677inspect $ hasNoTypeClasses 'toChunksLast
@@ -110,7 +111,7 @@ inspect $ 'toChunksSplitOn `hasNoType` ''Step
110111-- | Sum the bytes in a file.
111112toChunksCountBytes :: Handle -> IO Word8
112113toChunksCountBytes inh = do
113− let foldlArr' f z = runIdentity . S.foldl' f z . IA.toStream
114+ let foldlArr' f z = runIdentity . S.foldl' f z . A.toStream
114115 let s = IFH.toChunks inh
115116 S.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
116117
@@ -119,38 +120,34 @@ inspect $ hasNoTypeClasses 'toChunksCountBytes
119120inspect $ 'toChunksCountBytes `hasNoType` ''Step
120121#endif
121122
122−toChunksWithBufferOfDecodeUtf8ArraysLenient :: Handle -> IO ()
123−toChunksWithBufferOfDecodeUtf8ArraysLenient inh =
124− S.drain
125− $ IUS.decodeUtf8ArraysLenient
126− $ IFH.toChunksWithBufferOf (1024*1024) inh
123+toChunksDecodeUtf8ArraysLenient :: Handle -> IO ()
124+toChunksDecodeUtf8ArraysLenient =
125+ S.drain . IUS.decodeUtf8ArraysLenient . IFH.toChunks
127126
128127#ifdef INSPECTION
129−inspect $ hasNoTypeClasses 'decodeUtf8Lenient
130−-- inspect $ 'decodeUtf8Lenient `hasNoType` ''Step
131−-- inspect $ 'decodeUtf8Lenient `hasNoType` ''AT.FlattenState
132−-- inspect $ 'decodeUtf8Lenient `hasNoType` ''D.ConcatMapUState
128+inspect $ hasNoTypeClasses 'toChunksDecodeUtf8ArraysLenient
129+-- inspect $ 'toChunksDecodeUtf8ArraysLenient `hasNoType` ''Step
133130#endif
134131
135132o_1_space_read_chunked :: BenchEnv -> [Benchmark]
136133o_1_space_read_chunked env =
137134 -- read using toChunks instead of read
138135 [ bgroup "reduce/toChunks"
139− [ mkBench "S.last (32K)" env $ \inH _ ->
136+ [ mkBench "S.last" env $ \inH _ ->
140137 toChunksLast inH
141138 -- Note: this cannot be fairly compared with GNU wc -c or wc -m as
142139 -- wc uses lseek to just determine the file size rather than reading
143140 -- and counting characters.
144− , mkBench "S.sum . S.map A.length (32K)" env $ \inH _ ->
141+ , mkBench "S.sum . S.map A.length" env $ \inH _ ->
145142 toChunksSumLengths inH
146− , mkBench "AS.splitOnSuffix (32K)" env $ \inH _ ->
143+ , mkBench "AS.splitOnSuffix" env $ \inH _ ->
147144 toChunksSplitOnSuffix inH
148− , mkBench "AS.splitOn (32K)" env $ \inH _ ->
145+ , mkBench "AS.splitOn" env $ \inH _ ->
149146 toChunksSplitOn inH
150− , mkBench "countBytes (32K)" env $ \inH _ ->
147+ , mkBench "countBytes" env $ \inH _ ->
151148 toChunksCountBytes inH
152− , mkBenchSmall "US.decodeUtf8ArraysLenient (1MB)" env $ \inH _ ->
153− toChunksWithBufferOfDecodeUtf8ArraysLenient inH
149+ , mkBenchSmall "US.decodeUtf8ArraysLenient" env $ \inH _ ->
150+ toChunksDecodeUtf8ArraysLenient inH
154151 ]
155152 ]
156153
@@ -166,9 +163,9 @@ readLast = S.last . S.unfold FH.read
166163
167164#ifdef INSPECTION
168165inspect $ hasNoTypeClasses 'readLast
169−inspect $ 'readLast `hasNoType` ''Step
170−inspect $ 'readLast `hasNoType` ''AT.FlattenState
171−inspect $ 'readLast `hasNoType` ''D.ConcatMapUState
166+inspect $ 'readLast `hasNoType` ''Step -- S.unfold
167+inspect $ 'readLast `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
168+inspect $ 'readLast `hasNoType` ''A.ReadUState -- FH.read/A.read
172169#endif
173170
174171-- assert that flattenArrays constructors are not present
@@ -177,10 +174,10 @@ readCountBytes :: Handle -> IO Int
177174readCountBytes = S.length . S.unfold FH.read
178175
179176#ifdef INSPECTION
180−inspect $ hasNoTypeClasses 'countBytes
181−inspect $ 'countBytes `hasNoType` ''Step
182−inspect $ 'countBytes `hasNoType` ''AT.FlattenState
183−inspect $ 'countBytes `hasNoType` ''D.ConcatMapUState
177+inspect $ hasNoTypeClasses 'readCountBytes
178+inspect $ 'readCountBytes `hasNoType` ''Step -- S.unfold
179+inspect $ 'readCountBytes `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
180+inspect $ 'readCountBytes `hasNoType` ''A.ReadUState -- FH.read/A.read
184181#endif
185182
186183-- | Count the number of lines in a file.
@@ -194,8 +191,8 @@ readCountLines =
194191#ifdef INSPECTION
195192inspect $ hasNoTypeClasses 'readCountLines
196193inspect $ 'readCountLines `hasNoType` ''Step
197−inspect $ 'readCountLines `hasNoType` ''AT.FlattenState
198−inspect $ 'readCountLines `hasNoType` ''D.ConcatMapUState
194+inspect $ 'readCountLines `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
195+inspect $ 'readCountLines `hasNoType` ''A.ReadUState -- FH.read/A.read
199196#endif
200197
201198-- | Count the number of words in a file.
@@ -209,7 +206,6 @@ readCountWords =
209206#ifdef INSPECTION
210207inspect $ hasNoTypeClasses 'readCountWords
211208-- inspect $ 'readCountWords `hasNoType` ''Step
212−-- inspect $ 'readCountWords `hasNoType` ''D.ConcatMapUState
213209#endif
214210
215211-- | Sum the bytes in a file.
@@ -219,8 +215,8 @@ readSumBytes = S.sum . S.unfold FH.read
219215#ifdef INSPECTION
220216inspect $ hasNoTypeClasses 'readSumBytes
221217inspect $ 'readSumBytes `hasNoType` ''Step
222−inspect $ 'readSumBytes `hasNoType` ''AT.FlattenState
223−inspect $ 'readSumBytes `hasNoType` ''D.ConcatMapUState
218+inspect $ 'readSumBytes `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
219+inspect $ 'readSumBytes `hasNoType` ''A.ReadUState -- FH.read/A.read
224220#endif
225221
226222-- XXX When we mark this with INLINE and we have two benchmarks using S.drain
@@ -253,8 +249,6 @@ readDecodeUtf8Lax inh =
253249#ifdef INSPECTION
254250inspect $ hasNoTypeClasses 'readDecodeUtf8Lax
255251-- inspect $ 'readDecodeUtf8Lax `hasNoType` ''Step
256−-- inspect $ 'readDecodeUtf8Lax `hasNoType` ''AT.FlattenState
257−-- inspect $ 'readDecodeUtf8Lax `hasNoType` ''D.ConcatMapUState
258252#endif
259253
260254o_1_space_reduce_read :: BenchEnv -> [Benchmark]
@@ -298,9 +292,9 @@ toChunksConcatUnfoldCountLines inh =
298292 $ S.concatUnfold A.read (IFH.toChunks inh)
299293
300294#ifdef INSPECTION
301−inspect $ hasNoTypeClasses 'countLinesU
302−inspect $ 'countLinesU `hasNoType` ''Step
303−inspect $ 'countLinesU `hasNoType` ''D.ConcatMapUState
295+inspect $ hasNoTypeClasses 'toChunksConcatUnfoldCountLines
296+inspect $ 'toChunksConcatUnfoldCountLines `hasNoType` ''Step
297+inspect $ 'toChunksConcatUnfoldCountLines `hasNoType` ''D.ConcatMapUState
304298#endif
305299
306300o_1_space_reduce_toBytes :: BenchEnv -> [Benchmark]
@@ -336,9 +330,10 @@ chunksOf n inh =
336330#ifdef INSPECTION
337331inspect $ hasNoTypeClasses 'chunksOf
338332inspect $ 'chunksOf `hasNoType` ''Step
339−inspect $ 'chunksOf `hasNoType` ''AT.FlattenState
340−inspect $ 'chunksOf `hasNoType` ''D.ConcatMapUState
341333inspect $ 'chunksOf `hasNoType` ''GroupState
334+inspect $ 'chunksOf `hasNoType` ''AT.ArrayUnsafe -- AT.writeNUnsafe
335+inspect $ 'chunksOf `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
336+inspect $ 'chunksOf `hasNoType` ''A.ReadUState -- FH.read/A.read
342337#endif
343338
344339-- This is to make sure that the concatMap in FH.read, groupsOf and foldlM'
@@ -355,8 +350,9 @@ _chunksOfD n inh =
355350inspect $ hasNoTypeClasses '_chunksOfD
356351inspect $ '_chunksOfD `hasNoType` ''Step
357352inspect $ '_chunksOfD `hasNoType` ''GroupState
358−inspect $ '_chunksOfD `hasNoType` ''AT.FlattenState
359−inspect $ '_chunksOfD `hasNoType` ''D.ConcatMapUState
353+inspect $ '_chunksOfD `hasNoType` ''AT.ArrayUnsafe -- AT.writeNUnsafe
354+inspect $ '_chunksOfD `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
355+inspect $ '_chunksOfD `hasNoType` ''A.ReadUState -- FH.read/A.read
360356#endif
361357
362358o_1_space_reduce_read_grouped :: BenchEnv -> [Benchmark]
@@ -405,8 +401,8 @@ splitOn inh =
405401#ifdef INSPECTION
406402inspect $ hasNoTypeClasses 'splitOn
407403inspect $ 'splitOn `hasNoType` ''Step
408−inspect $ 'splitOn `hasNoType` ''AT.FlattenState
409−inspect $ 'splitOn `hasNoType` ''D.ConcatMapUState
404+inspect $ 'splitOn `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
405+inspect $ 'splitOn `hasNoType` ''A.ReadUState -- FH.read/A.read
410406#endif
411407
412408-- | Split suffix on line feed.
@@ -418,8 +414,8 @@ splitOnSuffix inh =
418414#ifdef INSPECTION
419415inspect $ hasNoTypeClasses 'splitOnSuffix
420416inspect $ 'splitOnSuffix `hasNoType` ''Step
421−inspect $ 'splitOnSuffix `hasNoType` ''AT.FlattenState
422−inspect $ 'splitOnSuffix `hasNoType` ''D.ConcatMapUState
417+inspect $ 'splitOnSuffix `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
418+inspect $ 'splitOnSuffix `hasNoType` ''A.ReadUState -- FH.read/A.read
423419#endif
424420
425421-- | Split on line feed.
@@ -437,8 +433,8 @@ wordsBy inh =
437433#ifdef INSPECTION
438434inspect $ hasNoTypeClasses 'wordsBy
439435inspect $ 'wordsBy `hasNoType` ''Step
440−inspect $ 'wordsBy `hasNoType` ''AT.FlattenState
441−inspect $ 'wordsBy `hasNoType` ''D.ConcatMapUState
436+inspect $ 'wordsBy `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
437+inspect $ 'wordsBy `hasNoType` ''A.ReadUState -- FH.read/A.read
442438#endif
443439
444440-- | Split on a word8 sequence.
@@ -450,8 +446,6 @@ splitOnSeq str inh =
450446#ifdef INSPECTION
451447-- inspect $ hasNoTypeClasses 'splitOnSeq
452448-- inspect $ 'splitOnSeq `hasNoType` ''Step
453−-- inspect $ 'splitOnSeq `hasNoType` ''AT.FlattenState
454−-- inspect $ 'splitOnSeq `hasNoType` ''D.ConcatMapUState
455449#endif
456450
457451-- | Split on suffix sequence.
@@ -463,8 +457,6 @@ splitOnSuffixSeq str inh =
463457#ifdef INSPECTION
464458-- inspect $ hasNoTypeClasses 'splitOnSuffixSeq
465459-- inspect $ 'splitOnSuffixSeq `hasNoType` ''Step
466−-- inspect $ 'splitOnSuffixSeq `hasNoType` ''AT.FlattenState
467−-- inspect $ 'splitOnSuffixSeq `hasNoType` ''D.ConcatMapUState
468460#endif
469461
470462o_1_space_reduce_read_split :: BenchEnv -> [Benchmark]
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+73−99
@@ -44,7 +44,13 @@ import Handle.Common
4444
4545#ifdef INSPECTION
4646import Foreign.Storable (Storable)
47−import Streamly.Internal.Data.Stream.StreamD.Type (Step(..), GroupState)
47+import Streamly.Internal.Data.Stream.StreamD.Type (Step(..))
48+
49+import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
50+import qualified Streamly.Internal.Data.Strict as Strict
51+import qualified Streamly.Internal.Memory.Array as A
52+import qualified Streamly.Internal.Memory.Array.Types as AT
53+
4854import Test.Inspection
4955#endif
5056
@@ -52,25 +58,13 @@ import Test.Inspection
5258-- copy chunked
5359-------------------------------------------------------------------------------
5460
55−-- | Send the file contents to /dev/null
56−toChunksWithBufferOf :: Handle -> Handle -> IO ()
57−toChunksWithBufferOf inh devNull =
58− S.fold (IFH.writeChunks devNull) $ IFH.toChunksWithBufferOf (256*1024) inh
59−
60−#ifdef INSPECTION
61−inspect $ hasNoTypeClasses 'toChunksWithBufferOf
62−inspect $ 'toChunksWithBufferOf `hasNoType` ''Step
63−#endif
64−
6561-- | Copy file
6662copyChunks :: Handle -> Handle -> IO ()
67−copyChunks inh outh =
68− let s = IFH.toChunks inh
69− in S.fold (IFH.writeChunks outh) s
63+copyChunks inh outh = S.fold (IFH.writeChunks outh) $ IFH.toChunks inh
7064
7165#ifdef INSPECTION
72−inspect $ hasNoTypeClasses 'toChunksWriteChunks
73−inspect $ 'toChunksWriteChunks `hasNoType` ''Step
66+inspect $ hasNoTypeClasses 'copyChunks
67+inspect $ 'copyChunks `hasNoType` ''Step
7468#endif
7569
7670-- | Copy file
@@ -79,20 +73,18 @@ copyCodecUtf8ArraysLenient inh outh =
7973 S.fold (FH.write outh)
8074 $ SS.encodeUtf8
8175 $ IUS.decodeUtf8ArraysLenient
82− $ IFH.toChunksWithBufferOf (1024*1024) inh
76+ $ IFH.toChunks inh
8377
8478#ifdef INSPECTION
8579inspect $ hasNoTypeClasses 'copyCodecUtf8ArraysLenient
8680-- inspect $ 'copyCodecUtf8ArraysLenient `hasNoType` ''Step
87−-- inspect $ 'copyCodecUtf8ArraysLenient `hasNoType` ''AT.FlattenState
88−-- inspect $ 'copyCodecUtf8ArraysLenient `hasNoType` ''D.ConcatMapUState
8981#endif
9082
9183o_1_space_copy_chunked :: BenchEnv -> [Benchmark]
9284o_1_space_copy_chunked env =
9385 [ bgroup "copy/toChunks"
94− [ mkBench "toNull (256K)" env $ \inH _ ->
95− toChunksWithBufferOf inH (nullH env)
86+ [ mkBench "toNull" env $ \inH _ ->
87+ copyChunks inH (nullH env)
9688 , mkBench "raw" env $ \inH outH ->
9789 copyChunks inH outH
9890 , mkBenchSmall "decodeEncodeUtf8Lenient" env $ \inH outH ->
@@ -107,44 +99,41 @@ o_1_space_copy_chunked env =
10799-------------------------------------------------------------------------------
108100
109101-- | Send the file contents to /dev/null with exception handling
110−readChunksWithBufferOfOnExceptionUnfold :: Handle -> Handle -> IO ()
111−readChunksWithBufferOfOnExceptionUnfold inh devNull =
112− let readEx = IUF.onException (\_ -> hClose inh)
113− (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
102+readChunksOnException :: Handle -> Handle -> IO ()
103+readChunksOnException inh devNull =
104+ let readEx = IUF.onException (\_ -> hClose inh) FH.readChunks
114105 in IUF.fold readEx (IFH.writeChunks devNull) inh
115106
116107#ifdef INSPECTION
117−inspect $ hasNoTypeClasses 'readChunksWithBufferOfOnExceptionUnfold
118−-- inspect $ 'readChunksWithBufferOfOnExceptionUnfold `hasNoType` ''Step
108+inspect $ hasNoTypeClasses 'readChunksOnException
109+-- inspect $ 'readChunksOnException `hasNoType` ''Step
119110#endif
120111
121112-- | Send the file contents to /dev/null with exception handling
122−readChunksWithBufferOfBracketUnfold :: Handle -> Handle -> IO ()
123−readChunksWithBufferOfBracketUnfold inh devNull =
124− let readEx = IUF.bracket return (\_ -> hClose inh)
125− (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
113+readChunksBracket :: Handle -> Handle -> IO ()
114+readChunksBracket inh devNull =
115+ let readEx = IUF.bracket return (\_ -> hClose inh) FH.readChunks
126116 in IUF.fold readEx (IFH.writeChunks devNull) inh
127117
128118#ifdef INSPECTION
129−inspect $ hasNoTypeClasses 'readChunksWithBufferOfBracketUnfold
130−-- inspect $ 'readChunksWithBufferOfBracketUnfold `hasNoType` ''Step
119+inspect $ hasNoTypeClasses 'readChunksBracket
120+-- inspect $ 'readChunksBracket `hasNoType` ''Step
131121#endif
132122
133−readChunksWithBufferOfBracketIOUnfold :: Handle -> Handle -> IO ()
134−readChunksWithBufferOfBracketIOUnfold inh devNull =
135− let readEx = IUF.bracketIO return (\_ -> hClose inh)
136− (IUF.supplyFirst FH.readChunksWithBufferOf (256*1024))
123+readChunksBracketIO :: Handle -> Handle -> IO ()
124+readChunksBracketIO inh devNull =
125+ let readEx = IUF.bracketIO return (\_ -> hClose inh) FH.readChunks
137126 in IUF.fold readEx (IFH.writeChunks devNull) inh
138127
139128o_1_space_copy_exceptions_readChunks :: BenchEnv -> [Benchmark]
140129o_1_space_copy_exceptions_readChunks env =
141− [ bgroup "copy/exceptions/unfold/readChunks"
142− [ mkBench "onException (256K)" env $ \inH _ ->
143− readChunksWithBufferOfOnExceptionUnfold inH (nullH env)
144− , mkBench "bracket (256K)" env $ \inH _ ->
145− readChunksWithBufferOfBracketUnfold inH (nullH env)
146− , mkBench "bracketIO (256K)" env $ \inH _ ->
147− readChunksWithBufferOfBracketIOUnfold inH (nullH env)
130+ [ bgroup "copy/readChunks/exceptions"
131+ [ mkBench "UF.onException" env $ \inH _ ->
132+ readChunksOnException inH (nullH env)
133+ , mkBench "UF.bracket" env $ \inH _ ->
134+ readChunksBracket inH (nullH env)
135+ , mkBench "UF.bracketIO" env $ \inH _ ->
136+ readChunksBracketIO inH (nullH env)
148137 ]
149138 ]
150139
@@ -153,30 +142,34 @@ o_1_space_copy_exceptions_readChunks env =
153142-------------------------------------------------------------------------------
154143
155144-- | Send the file contents to /dev/null with exception handling
156−toChunksWithBufferOfBracketStream :: Handle -> Handle -> IO ()
157−toChunksWithBufferOfBracketStream inh devNull =
158− let readEx = S.bracket (return ()) (\_ -> hClose inh)
159− (\_ -> IFH.toChunksWithBufferOf (256*1024) inh)
145+toChunksBracket :: Handle -> Handle -> IO ()
146+toChunksBracket inh devNull =
147+ let readEx = S.bracket
148+ (return ())
149+ (\_ -> hClose inh)
150+ (\_ -> IFH.toChunks inh)
160151 in S.fold (IFH.writeChunks devNull) $ readEx
161152
162153#ifdef INSPECTION
163−inspect $ hasNoTypeClasses 'toChunksWithBufferOfBracketStream
164−-- inspect $ 'toChunksWithBufferOfBracketStream `hasNoType` ''Step
154+inspect $ hasNoTypeClasses 'toChunksBracket
155+-- inspect $ 'toChunksBracket `hasNoType` ''Step
165156#endif
166157
167−toChunksWithBufferOfBracketIOStream :: Handle -> Handle -> IO ()
168−toChunksWithBufferOfBracketIOStream inh devNull =
169− let readEx = IP.bracketIO (return ()) (\_ -> hClose inh)
170− (\_ -> IFH.toChunksWithBufferOf (256*1024) inh)
158+toChunksBracketIO :: Handle -> Handle -> IO ()
159+toChunksBracketIO inh devNull =
160+ let readEx = IP.bracketIO
161+ (return ())
162+ (\_ -> hClose inh)
163+ (\_ -> IFH.toChunks inh)
171164 in S.fold (IFH.writeChunks devNull) $ readEx
172165
173166o_1_space_copy_exceptions_toChunks :: BenchEnv -> [Benchmark]
174167o_1_space_copy_exceptions_toChunks env =
175− [ bgroup "copy/exceptions/stream/toChunks"
176− [ mkBench "bracket (256K)" env $ \inH _ ->
177− toChunksWithBufferOfBracketStream inH (nullH env)
178− , mkBench "bracketIO (256K)" env $ \inH _ ->
179− toChunksWithBufferOfBracketIOStream inH (nullH env)
168+ [ bgroup "copy/toChunks/exceptions"
169+ [ mkBench "S.bracket" env $ \inH _ ->
170+ toChunksBracket inH (nullH env)
171+ , mkBench "S.bracketIO" env $ \inH _ ->
172+ toChunksBracketIO inH (nullH env)
180173 ]
181174 ]
182175
@@ -184,26 +177,17 @@ o_1_space_copy_exceptions_toChunks env =
184177-- copy unfold
185178-------------------------------------------------------------------------------
186179
187−-- | Send the file contents to /dev/null
188−readWriteNull :: Handle -> Handle -> IO ()
189−readWriteNull inh devNull = S.fold (FH.write devNull) $ S.unfold FH.read inh
190−
191−#ifdef INSPECTION
192−inspect $ hasNoTypeClasses 'readWriteNull
193−inspect $ 'readWriteNull `hasNoType` ''Step
194−inspect $ 'readWriteNull `hasNoType` ''AT.FlattenState
195−inspect $ 'readWriteNull `hasNoType` ''D.ConcatMapUState
196−#endif
197−
198180-- | Copy file
199181copyStream :: Handle -> Handle -> IO ()
200182copyStream inh outh = S.fold (FH.write outh) (S.unfold FH.read inh)
201183
202184#ifdef INSPECTION
203185inspect $ hasNoTypeClasses 'copyStream
204−inspect $ 'copyStream `hasNoType` ''Step
205−inspect $ 'copyStream `hasNoType` ''AT.FlattenState
206−inspect $ 'copyStream `hasNoType` ''D.ConcatMapUState
186+inspect $ 'copyStream `hasNoType` ''Step -- S.unfold
187+inspect $ 'copyStream `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
188+inspect $ 'copyStream `hasNoType` ''A.ReadUState -- FH.read/A.read
189+inspect $ 'copyStream `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
190+inspect $ 'copyStream `hasNoType` ''Strict.Tuple3' -- FH.write/lchunksOf
207191#endif
208192
209193-- | Copy file
@@ -217,8 +201,10 @@ copyStreamLatin1 inh outh =
217201#ifdef INSPECTION
218202inspect $ hasNoTypeClasses 'copyStreamLatin1
219203inspect $ 'copyStreamLatin1 `hasNoType` ''Step
220−inspect $ 'copyStreamLatin1 `hasNoType` ''AT.FlattenState
221−inspect $ 'copyStreamLatin1 `hasNoType` ''D.ConcatMapUState
204+inspect $ 'copyStreamLatin1 `hasNoType` ''IUF.ConcatState -- FH.read/UF.concat
205+inspect $ 'copyStreamLatin1 `hasNoType` ''A.ReadUState -- FH.read/A.read
206+inspect $ 'copyStreamLatin1 `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
207+inspect $ 'copyStreamLatin1 `hasNoType` ''Strict.Tuple3' -- FH.write/lchunksOf
222208#endif
223209
224210-- | Copy file
@@ -255,7 +241,7 @@ o_1_space_copy_read :: BenchEnv -> [Benchmark]
255241o_1_space_copy_read env =
256242 [ bgroup "copy/read"
257243 [ mkBench "rawToNull" env $ \inh _ ->
258− readWriteNull inh (nullH env)
244+ copyStream inh (nullH env)
259245 , mkBench "rawToFile" env $ \inh outh ->
260246 copyStream inh outh
261247 -- This needs an ascii file, as decode just errors out.
@@ -279,10 +265,11 @@ readFromBytesNull :: Handle -> Handle -> IO ()
279265readFromBytesNull inh devNull = IFH.fromBytes devNull $ S.unfold FH.read inh
280266
281267#ifdef INSPECTION
282−inspect $ hasNoTypeClasses 'catStreamWrite
283−inspect $ 'catStreamWrite `hasNoType` ''Step
284−inspect $ 'catStreamWrite `hasNoType` ''AT.FlattenState
285−inspect $ 'catStreamWrite `hasNoType` ''D.ConcatMapUState
268+inspect $ hasNoTypeClasses 'readFromBytesNull
269+inspect $ 'readFromBytesNull `hasNoType` ''Step
270+inspect $ 'readFromBytesNull `hasNoType` ''AT.SpliceState
271+inspect $ 'readFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.arraysOf
272+inspect $ 'readFromBytesNull `hasNoType` ''D.GroupState
286273#endif
287274
288275o_1_space_copy_fromBytes :: BenchEnv -> [Benchmark]
@@ -306,8 +293,6 @@ readWriteOnExceptionUnfold inh devNull =
306293#ifdef INSPECTION
307294inspect $ hasNoTypeClasses 'readWriteOnExceptionUnfold
308295-- inspect $ 'readWriteOnExceptionUnfold `hasNoType` ''Step
309−-- inspect $ 'readWriteOnExceptionUnfold `hasNoType` ''AT.FlattenState
310−-- inspect $ 'readWriteOnExceptionUnfold `hasNoType` ''D.ConcatMapUState
311296#endif
312297
313298-- | Send the file contents to /dev/null with exception handling
@@ -320,8 +305,6 @@ readWriteHandleExceptionUnfold inh devNull =
320305#ifdef INSPECTION
321306inspect $ hasNoTypeClasses 'readWriteHandleExceptionUnfold
322307-- inspect $ 'readWriteHandleExceptionUnfold `hasNoType` ''Step
323−-- inspect $ 'readWriteHandleExceptionUnfold `hasNoType` ''AT.FlattenState
324−-- inspect $ 'readWriteHandleExceptionUnfold `hasNoType` ''D.ConcatMapUState
325308#endif
326309
327310-- | Send the file contents to /dev/null with exception handling
@@ -333,8 +316,6 @@ readWriteFinallyUnfold inh devNull =
333316#ifdef INSPECTION
334317inspect $ hasNoTypeClasses 'readWriteFinallyUnfold
335318-- inspect $ 'readWriteFinallyUnfold `hasNoType` ''Step
336−-- inspect $ 'readWriteFinallyUnfold `hasNoType` ''AT.FlattenState
337−-- inspect $ 'readWriteFinallyUnfold `hasNoType` ''D.ConcatMapUState
338319#endif
339320
340321readWriteFinallyIOUnfold :: Handle -> Handle -> IO ()
@@ -351,8 +332,6 @@ readWriteBracketUnfold inh devNull =
351332#ifdef INSPECTION
352333inspect $ hasNoTypeClasses 'readWriteBracketUnfold
353334-- inspect $ 'readWriteBracketUnfold `hasNoType` ''Step
354−-- inspect $ 'readWriteBracketUnfold `hasNoType` ''AT.FlattenState
355−-- inspect $ 'readWriteBracketUnfold `hasNoType` ''D.ConcatMapUState
356335#endif
357336
358337readWriteBracketIOUnfold :: Handle -> Handle -> IO ()
@@ -414,8 +393,8 @@ fromToBytesBracketStream inh devNull =
414393 in IFH.fromBytes devNull $ readEx
415394
416395#ifdef INSPECTION
417−inspect $ hasNoTypeClasses 'readWriteBracketStream
418−-- inspect $ 'readWriteBracketStream `hasNoType` ''Step
396+inspect $ hasNoTypeClasses 'fromToBytesBracketStream
397+-- inspect $ 'fromToBytesBracketStream `hasNoType` ''Step
419398#endif
420399
421400fromToBytesBracketIOStream :: Handle -> Handle -> IO ()
@@ -451,10 +430,10 @@ o_1_space_copy_stream_exceptions env =
451430-- | Lines and unlines
452431copyChunksSplitInterposeSuffix :: Handle -> Handle -> IO ()
453432copyChunksSplitInterposeSuffix inh outh =
454− S.fold (IFH.writeWithBufferOf (1024*1024) outh)
433+ S.fold (IFH.write outh)
455434 $ AS.interposeSuffix 10
456435 $ AS.splitOnSuffix 10
457− $ IFH.toChunksWithBufferOf (1024*1024) inh
436+ $ IFH.toChunks inh
458437
459438#ifdef INSPECTION
460439inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterposeSuffix [''Storable]
@@ -464,11 +443,11 @@ inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterposeSuffix [''Storable]
464443-- | Words and unwords
465444copyChunksSplitInterpose :: Handle -> Handle -> IO ()
466445copyChunksSplitInterpose inh outh =
467− S.fold (IFH.writeWithBufferOf (1024*1024) outh)
446+ S.fold (IFH.write outh)
468447 $ AS.interpose 32
469448 -- XXX this is not correct word splitting combinator
470449 $ AS.splitOn 32
471− $ IFH.toChunksWithBufferOf (1024*1024) inh
450+ $ IFH.toChunks inh
472451
473452#ifdef INSPECTION
474453inspect $ hasNoTypeClassesExcept 'copyChunksSplitInterpose [''Storable]
@@ -519,8 +498,6 @@ linesUnlinesArrayCharCopy inh outh =
519498#ifdef INSPECTION
520499inspect $ hasNoTypeClassesExcept 'linesUnlinesArrayCharCopy [''Storable]
521500-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''Step
522−-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''AT.FlattenState
523−-- inspect $ 'linesUnlinesArrayCharCopy `hasNoType` ''D.ConcatMapUState
524501#endif
525502
526503-- XXX to write this we need to be able to map decodeUtf8 on the A.read fold.
@@ -548,7 +525,6 @@ wordsUnwordsCopyWord8 inh outh =
548525#ifdef INSPECTION
549526inspect $ hasNoTypeClasses 'wordsUnwordsCopyWord8
550527-- inspect $ 'wordsUnwordsCopyWord8 `hasNoType` ''Step
551−-- inspect $ 'wordsUnwordsCopyWord8 `hasNoType` ''D.ConcatMapUState
552528#endif
553529
554530-- | Word, unwords and copy
@@ -572,8 +548,6 @@ wordsUnwordsCopy inh outh =
572548#ifdef INSPECTION
573549-- inspect $ hasNoTypeClasses 'wordsUnwordsCopy
574550-- inspect $ 'wordsUnwordsCopy `hasNoType` ''Step
575−-- inspect $ 'wordsUnwordsCopy `hasNoType` ''AT.FlattenState
576−-- inspect $ 'wordsUnwordsCopy `hasNoType` ''D.ConcatMapUState
577551#endif
578552
579553wordsUnwordsCharArrayCopy :: Handle -> Handle -> IO ()
src/Streamly/Internal/Data/Unfold.hs+1
@@ -102,6 +102,7 @@ module Streamly.Internal.Data.Unfold
102102 , teeZipWith
103103
104104 -- * Nesting
105+ , ConcatState (..)
105106 , concat
106107 , concatMapM
107108 , outerProduct
src/Streamly/Internal/Memory/Array.hs+1
@@ -61,6 +61,7 @@ module Streamly.Internal.Memory.Array
6161 , toStream
6262 , toStreamRev
6363 , read
64+ , ReadUState (..)
6465 , unsafeRead
6566 -- , readChunksOf
6667
src/Streamly/Internal/Memory/Array/Types.hs+2
@@ -37,6 +37,7 @@ module Streamly.Internal.Memory.Array.Types
3737 , flattenArrays
3838 , flattenArraysRev
3939 , packArraysChunksOf
40+ , SpliceState (..)
4041 , lpackArraysChunksOf
4142#if !defined(mingw32_HOST_OS)
4243 , groupIOVecsOf
@@ -62,6 +63,7 @@ module Streamly.Internal.Memory.Array.Types
6263 , toArrayMinChunk
6364 , writeN
6465 , writeNUnsafe
66+ , ArrayUnsafe (..)
6567 , writeNAligned
6668 , writeNAlignedUnmanaged
6769 , write