on master help sign in
separate inspection testing build from benchmark build
f5614c7Harendra Kumar
src/Streamly/Benchmark/FileIO/Array.hs+35−18
@@ -7,9 +7,12 @@
7-- Stability : experimental
7-- Stability : experimental
8-- Portability : GHC
8-- Portability : GHC
9
9
10−{-# LANGUAGE TemplateHaskell #-}
10+{-# LANGUAGE CPP #-}
11
11
12+#ifdef INSPECTION
13+{-# LANGUAGE TemplateHaskell #-}
12{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
14{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
15+#endif
13
16
14module Streamly.Benchmark.FileIO.Array
17module Streamly.Benchmark.FileIO.Array
15 (
18 (
@@ -28,15 +31,15 @@ import Data.Word (Word8)
28import System.IO (Handle)
31import System.IO (Handle)
29import Prelude hiding (last)
32import Prelude hiding (last)
30
33
31−import Streamly.Benchmark.Inspection (hinspect)
32−import Streamly.Streams.StreamD.Type (Step(..))
33−
34import qualified Streamly.FileSystem.Handle as FH
34import qualified Streamly.FileSystem.Handle as FH
35import qualified Streamly.Memory.Array as A
35import qualified Streamly.Memory.Array as A
36import qualified Streamly.Prelude as S
36import qualified Streamly.Prelude as S
37import qualified Streamly.Internal as Internal
37import qualified Streamly.Internal as Internal
38
38
39+#ifdef INSPECTION
40+import Streamly.Streams.StreamD.Type (Step(..))
39import Test.Inspection
41import Test.Inspection
42+#endif
40
43
41-- | Get the last byte from a file bytestream.
44-- | Get the last byte from a file bytestream.
42{-# INLINE last #-}
45{-# INLINE last #-}
@@ -48,8 +51,10 @@ last inh = do
48 Nothing -> Nothing
51 Nothing -> Nothing
49 Just arr -> A.readIndex arr (A.length arr - 1)
52 Just arr -> A.readIndex arr (A.length arr - 1)
50
53
54+#ifdef INSPECTION
51−hinspect $ hasNoTypeClasses 'last
55+inspect $ hasNoTypeClasses 'last
52−hinspect $ 'last `hasNoType` ''Step
56+inspect $ 'last `hasNoType` ''Step
57+#endif
53
58
54-- | Count the number of bytes in a file.
59-- | Count the number of bytes in a file.
55{-# INLINE countBytes #-}
60{-# INLINE countBytes #-}
@@ -58,16 +63,20 @@ countBytes inh =
58 let s = FH.readArrays inh
63 let s = FH.readArrays inh
59 in S.sum (S.map A.length s)
64 in S.sum (S.map A.length s)
60
65
66+#ifdef INSPECTION
61−hinspect $ hasNoTypeClasses 'countBytes
67+inspect $ hasNoTypeClasses 'countBytes
62−hinspect $ 'countBytes `hasNoType` ''Step
68+inspect $ 'countBytes `hasNoType` ''Step
69+#endif
63
70
64-- | Count the number of lines in a file.
71-- | Count the number of lines in a file.
65{-# INLINE countLines #-}
72{-# INLINE countLines #-}
66countLines :: Handle -> IO Int
73countLines :: Handle -> IO Int
67countLines = S.length . A.splitOn 10 . FH.readArrays
74countLines = S.length . A.splitOn 10 . FH.readArrays
68
75
76+#ifdef INSPECTION
69−hinspect $ hasNoTypeClasses 'countLines
77+inspect $ hasNoTypeClasses 'countLines
70−hinspect $ 'countLines `hasNoType` ''Step
78+inspect $ 'countLines `hasNoType` ''Step
79+#endif
71
80
72-- | Sum the bytes in a file.
81-- | Sum the bytes in a file.
73{-# INLINE sumBytes #-}
82{-# INLINE sumBytes #-}
@@ -77,8 +86,10 @@ sumBytes inh = do
77 let s = FH.readArrays inh
86 let s = FH.readArrays inh
78 S.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
87 S.foldl' (\acc arr -> acc + foldlArr' (+) 0 arr) 0 s
79
88
89+#ifdef INSPECTION
80−hinspect $ hasNoTypeClasses 'sumBytes
90+inspect $ hasNoTypeClasses 'sumBytes
81−hinspect $ 'sumBytes `hasNoType` ''Step
91+inspect $ 'sumBytes `hasNoType` ''Step
92+#endif
82
93
83-- | Send the file contents to /dev/null
94-- | Send the file contents to /dev/null
84{-# INLINE cat #-}
95{-# INLINE cat #-}
@@ -86,8 +97,10 @@ cat :: Handle -> Handle -> IO ()
86cat devNull inh =
97cat devNull inh =
87 S.runFold (FH.writeArrays devNull) $ FH.readArraysOf (256*1024) inh
98 S.runFold (FH.writeArrays devNull) $ FH.readArraysOf (256*1024) inh
88
99
100+#ifdef INSPECTION
89−hinspect $ hasNoTypeClasses 'cat
101+inspect $ hasNoTypeClasses 'cat
90−hinspect $ 'cat `hasNoType` ''Step
102+inspect $ 'cat `hasNoType` ''Step
103+#endif
91
104
92-- | Copy file
105-- | Copy file
93{-# INLINE copy #-}
106{-# INLINE copy #-}
@@ -96,8 +109,10 @@ copy inh outh =
96 let s = FH.readArrays inh
109 let s = FH.readArrays inh
97 in S.runFold (FH.writeArrays outh) s
110 in S.runFold (FH.writeArrays outh) s
98
111
112+#ifdef INSPECTION
99−hinspect $ hasNoTypeClasses 'copy
113+inspect $ hasNoTypeClasses 'copy
100−hinspect $ 'copy `hasNoType` ''Step
114+inspect $ 'copy `hasNoType` ''Step
115+#endif
101
116
102-- | Lines and unlines
117-- | Lines and unlines
103{-# INLINE linesUnlinesCopy #-}
118{-# INLINE linesUnlinesCopy #-}
@@ -108,5 +123,7 @@ linesUnlinesCopy inh outh =
108 $ A.splitOn 10
123 $ A.splitOn 10
109 $ FH.readArraysOf (1024*1024) inh
124 $ FH.readArraysOf (1024*1024) inh
110
125
126+#ifdef INSPECTION
111−-- hinspect $ hasNoTypeClasses 'linesUnlinesCopy
127+-- inspect $ hasNoTypeClasses 'linesUnlinesCopy
112−-- hinspect $ 'linesUnlinesCopy `hasNoType` ''Step
128+-- inspect $ 'linesUnlinesCopy `hasNoType` ''Step
129+#endif
src/Streamly/Benchmark/FileIO/Stream.hs+123−81
@@ -7,9 +7,12 @@
7-- Stability : experimental
7-- Stability : experimental
8-- Portability : GHC
8-- Portability : GHC
9
9
10+{-# LANGUAGE CPP #-}
11+#ifdef INSPECTION
10{-# LANGUAGE TemplateHaskell #-}
12{-# LANGUAGE TemplateHaskell #-}
11
13
12{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
14{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
15+#endif
13
16
14module Streamly.Benchmark.FileIO.Stream
17module Streamly.Benchmark.FileIO.Stream
15 (
18 (
@@ -27,6 +30,7 @@ module Streamly.Benchmark.FileIO.Stream
27 , copyCodecChar8
30 , copyCodecChar8
28 , copyCodecUtf8
31 , copyCodecUtf8
29 , chunksOf
32 , chunksOf
33+ , chunksOfD
30 , splitOn
34 , splitOn
31 , splitOnSuffix
35 , splitOnSuffix
32 , wordsBy
36 , wordsBy
@@ -40,30 +44,32 @@ import Data.Word (Word8)
40import System.IO (Handle)
44import System.IO (Handle)
41import Prelude hiding (last, length)
45import Prelude hiding (last, length)
42
46
43−import Streamly.Streams.StreamD.Type (Step(..), GroupState)
44−import Streamly.Benchmark.Inspection (hinspect)
45−import qualified Streamly.Memory.Array.Types as AT
46−
47import qualified Streamly.FileSystem.Handle as FH
47import qualified Streamly.FileSystem.Handle as FH
48import qualified Streamly.FileSystem.Handle.Internal as FH
48import qualified Streamly.FileSystem.Handle.Internal as FH
49import qualified Streamly.Memory.Array as A
49import qualified Streamly.Memory.Array as A
50+import qualified Streamly.Memory.Array.Types as AT
50import qualified Streamly.Prelude.Internal as S
51import qualified Streamly.Prelude.Internal as S
51import qualified Streamly.Fold as FL
52import qualified Streamly.Fold as FL
52import qualified Streamly.Data.String as SS
53import qualified Streamly.Data.String as SS
53import qualified Streamly.Internal as Internal
54import qualified Streamly.Internal as Internal
54import qualified Streamly.Streams.StreamD as D
55import qualified Streamly.Streams.StreamD as D
55
56
57+#ifdef INSPECTION
58+import Streamly.Streams.StreamD.Type (Step(..), GroupState)
56import Test.Inspection
59import Test.Inspection
60+#endif
57
61
58-- | Get the last byte from a file bytestream.
62-- | Get the last byte from a file bytestream.
59{-# INLINE last #-}
63{-# INLINE last #-}
60last :: Handle -> IO (Maybe Word8)
64last :: Handle -> IO (Maybe Word8)
61last = S.last . FH.read
65last = S.last . FH.read
62
66
67+#ifdef INSPECTION
63−hinspect $ hasNoTypeClasses 'last
68+inspect $ hasNoTypeClasses 'last
64−hinspect $ 'last `hasNoType` ''Step
69+inspect $ 'last `hasNoType` ''Step
65−hinspect $ 'last `hasNoType` ''AT.FlattenState
70+inspect $ 'last `hasNoType` ''AT.FlattenState
66−hinspect $ 'last `hasNoType` ''D.ConcatMapUState
71+inspect $ 'last `hasNoType` ''D.ConcatMapUState
72+#endif
67
73
68-- assert that flattenArrays constructors are not present
74-- assert that flattenArrays constructors are not present
69-- | Count the number of bytes in a file.
75-- | Count the number of bytes in a file.
@@ -71,10 +77,12 @@ hinspect $ 'last `hasNoType` ''D.ConcatMapUState
71countBytes :: Handle -> IO Int
77countBytes :: Handle -> IO Int
72countBytes = S.length . FH.read
78countBytes = S.length . FH.read
73
79
80+#ifdef INSPECTION
74−hinspect $ hasNoTypeClasses 'countBytes
81+inspect $ hasNoTypeClasses 'countBytes
75−hinspect $ 'countBytes `hasNoType` ''Step
82+inspect $ 'countBytes `hasNoType` ''Step
76−hinspect $ 'countBytes `hasNoType` ''AT.FlattenState
83+inspect $ 'countBytes `hasNoType` ''AT.FlattenState
77−hinspect $ 'countBytes `hasNoType` ''D.ConcatMapUState
84+inspect $ 'countBytes `hasNoType` ''D.ConcatMapUState
85+#endif
78
86
79-- | Count the number of lines in a file.
87-- | Count the number of lines in a file.
80{-# INLINE countLines #-}
88{-# INLINE countLines #-}
@@ -85,10 +93,12 @@ countLines =
85 . SS.decodeChar8
93 . SS.decodeChar8
86 . FH.read
94 . FH.read
87
95
96+#ifdef INSPECTION
88−hinspect $ hasNoTypeClasses 'countLines
97+inspect $ hasNoTypeClasses 'countLines
89−hinspect $ 'countLines `hasNoType` ''Step
98+inspect $ 'countLines `hasNoType` ''Step
90−hinspect $ 'countLines `hasNoType` ''AT.FlattenState
99+inspect $ 'countLines `hasNoType` ''AT.FlattenState
91−hinspect $ 'countLines `hasNoType` ''D.ConcatMapUState
100+inspect $ 'countLines `hasNoType` ''D.ConcatMapUState
101+#endif
92
102
93-- | Count the number of lines in a file.
103-- | Count the number of lines in a file.
94{-# INLINE countLinesU #-}
104{-# INLINE countLinesU #-}
@@ -99,49 +109,59 @@ countLinesU inh =
99 $ SS.decodeChar8
109 $ SS.decodeChar8
100 $ Internal.concatMapU Internal.readU (FH.readArrays inh)
110 $ Internal.concatMapU Internal.readU (FH.readArrays inh)
101
111
112+#ifdef INSPECTION
102−hinspect $ hasNoTypeClasses 'countLinesU
113+inspect $ hasNoTypeClasses 'countLinesU
103−hinspect $ 'countLinesU `hasNoType` ''Step
114+inspect $ 'countLinesU `hasNoType` ''Step
104−hinspect $ 'countLinesU `hasNoType` ''D.ConcatMapUState
115+inspect $ 'countLinesU `hasNoType` ''D.ConcatMapUState
116+#endif
105
117
106-- | Sum the bytes in a file.
118-- | Sum the bytes in a file.
107{-# INLINE sumBytes #-}
119{-# INLINE sumBytes #-}
108sumBytes :: Handle -> IO Word8
120sumBytes :: Handle -> IO Word8
109sumBytes = S.sum . FH.read
121sumBytes = S.sum . FH.read
110
122
123+#ifdef INSPECTION
111−hinspect $ hasNoTypeClasses 'sumBytes
124+inspect $ hasNoTypeClasses 'sumBytes
112−hinspect $ 'sumBytes `hasNoType` ''Step
125+inspect $ 'sumBytes `hasNoType` ''Step
113−hinspect $ 'sumBytes `hasNoType` ''AT.FlattenState
126+inspect $ 'sumBytes `hasNoType` ''AT.FlattenState
114−hinspect $ 'sumBytes `hasNoType` ''D.ConcatMapUState
127+inspect $ 'sumBytes `hasNoType` ''D.ConcatMapUState
128+#endif
115
129
116-- | Send the file contents to /dev/null
130-- | Send the file contents to /dev/null
117{-# INLINE cat #-}
131{-# INLINE cat #-}
118cat :: Handle -> Handle -> IO ()
132cat :: Handle -> Handle -> IO ()
119cat devNull inh = S.runFold (FH.write devNull) $ FH.read inh
133cat devNull inh = S.runFold (FH.write devNull) $ FH.read inh
120
134
135+#ifdef INSPECTION
121−hinspect $ hasNoTypeClasses 'cat
136+inspect $ hasNoTypeClasses 'cat
122−hinspect $ 'cat `hasNoType` ''Step
137+inspect $ 'cat `hasNoType` ''Step
123−hinspect $ 'cat `hasNoType` ''AT.FlattenState
138+inspect $ 'cat `hasNoType` ''AT.FlattenState
124−hinspect $ 'cat `hasNoType` ''D.ConcatMapUState
139+inspect $ 'cat `hasNoType` ''D.ConcatMapUState
140+#endif
125
141
126-- | Send the file contents to /dev/null
142-- | Send the file contents to /dev/null
127{-# INLINE catStreamWrite #-}
143{-# INLINE catStreamWrite #-}
128catStreamWrite :: Handle -> Handle -> IO ()
144catStreamWrite :: Handle -> Handle -> IO ()
129catStreamWrite devNull inh = FH.writeS devNull $ FH.read inh
145catStreamWrite devNull inh = FH.writeS devNull $ FH.read inh
130
146
147+#ifdef INSPECTION
131−hinspect $ hasNoTypeClasses 'catStreamWrite
148+inspect $ hasNoTypeClasses 'catStreamWrite
132−hinspect $ 'catStreamWrite `hasNoType` ''Step
149+inspect $ 'catStreamWrite `hasNoType` ''Step
133−hinspect $ 'catStreamWrite `hasNoType` ''AT.FlattenState
150+inspect $ 'catStreamWrite `hasNoType` ''AT.FlattenState
134−hinspect $ 'catStreamWrite `hasNoType` ''D.ConcatMapUState
151+inspect $ 'catStreamWrite `hasNoType` ''D.ConcatMapUState
152+#endif
135
153
136-- | Copy file
154-- | Copy file
137{-# INLINE copy #-}
155{-# INLINE copy #-}
138copy :: Handle -> Handle -> IO ()
156copy :: Handle -> Handle -> IO ()
139copy inh outh = S.runFold (FH.write outh) (FH.read inh)
157copy inh outh = S.runFold (FH.write outh) (FH.read inh)
140
158
159+#ifdef INSPECTION
141−hinspect $ hasNoTypeClasses 'copy
160+inspect $ hasNoTypeClasses 'copy
142−hinspect $ 'copy `hasNoType` ''Step
161+inspect $ 'copy `hasNoType` ''Step
143−hinspect $ 'copy `hasNoType` ''AT.FlattenState
162+inspect $ 'copy `hasNoType` ''AT.FlattenState
144−hinspect $ 'copy `hasNoType` ''D.ConcatMapUState
163+inspect $ 'copy `hasNoType` ''D.ConcatMapUState
164+#endif
145
165
146-- | Copy file
166-- | Copy file
147{-# INLINE copyCodecChar8 #-}
167{-# INLINE copyCodecChar8 #-}
@@ -152,10 +172,12 @@ copyCodecChar8 inh outh =
152 $ SS.decodeChar8
172 $ SS.decodeChar8
153 $ FH.read inh
173 $ FH.read inh
154
174
175+#ifdef INSPECTION
155−hinspect $ hasNoTypeClasses 'copyCodecChar8
176+inspect $ hasNoTypeClasses 'copyCodecChar8
156−hinspect $ 'copyCodecChar8 `hasNoType` ''Step
177+inspect $ 'copyCodecChar8 `hasNoType` ''Step
157−hinspect $ 'copyCodecChar8 `hasNoType` ''AT.FlattenState
178+inspect $ 'copyCodecChar8 `hasNoType` ''AT.FlattenState
158−hinspect $ 'copyCodecChar8 `hasNoType` ''D.ConcatMapUState
179+inspect $ 'copyCodecChar8 `hasNoType` ''D.ConcatMapUState
180+#endif
159
181
160-- | Copy file
182-- | Copy file
161{-# INLINE copyCodecUtf8 #-}
183{-# INLINE copyCodecUtf8 #-}
@@ -166,10 +188,12 @@ copyCodecUtf8 inh outh =
166 $ SS.decodeUtf8
188 $ SS.decodeUtf8
167 $ FH.read inh
189 $ FH.read inh
168
190
191+#ifdef INSPECTION
169−hinspect $ hasNoTypeClasses 'copyCodecUtf8
192+inspect $ hasNoTypeClasses 'copyCodecUtf8
170−-- hinspect $ 'copyCodecUtf8 `hasNoType` ''Step
193+-- inspect $ 'copyCodecUtf8 `hasNoType` ''Step
171−-- hinspect $ 'copyCodecUtf8 `hasNoType` ''AT.FlattenState
194+-- inspect $ 'copyCodecUtf8 `hasNoType` ''AT.FlattenState
172−-- hinspect $ 'copyCodecUtf8 `hasNoType` ''D.ConcatMapUState
195+-- inspect $ 'copyCodecUtf8 `hasNoType` ''D.ConcatMapUState
196+#endif
173
197
174-- | Slice in chunks of size n and get the count of chunks.
198-- | Slice in chunks of size n and get the count of chunks.
175{-# INLINE chunksOf #-}
199{-# INLINE chunksOf #-}
@@ -178,11 +202,13 @@ chunksOf n inh =
178 -- writeNUnsafe gives 2.5x boost here over writeN.
202 -- writeNUnsafe gives 2.5x boost here over writeN.
179 S.length $ S.chunksOf n (AT.writeNUnsafe n) (FH.read inh)
203 S.length $ S.chunksOf n (AT.writeNUnsafe n) (FH.read inh)
180
204
205+#ifdef INSPECTION
181−hinspect $ hasNoTypeClasses 'chunksOf
206+inspect $ hasNoTypeClasses 'chunksOf
182−hinspect $ 'chunksOf `hasNoType` ''Step
207+inspect $ 'chunksOf `hasNoType` ''Step
183−hinspect $ 'chunksOf `hasNoType` ''AT.FlattenState
208+inspect $ 'chunksOf `hasNoType` ''AT.FlattenState
184−hinspect $ 'chunksOf `hasNoType` ''D.ConcatMapUState
209+inspect $ 'chunksOf `hasNoType` ''D.ConcatMapUState
185−hinspect $ 'chunksOf `hasNoType` ''GroupState
210+inspect $ 'chunksOf `hasNoType` ''GroupState
211+#endif
186
212
187-- This is to make sure that the concatMap in FH.read, groupsOf and foldlM'
213-- This is to make sure that the concatMap in FH.read, groupsOf and foldlM'
188-- together can fuse.
214-- together can fuse.
@@ -195,11 +221,13 @@ chunksOfD n inh =
195 $ D.groupsOf n (AT.writeNUnsafe n)
221 $ D.groupsOf n (AT.writeNUnsafe n)
196 $ D.fromStreamK (FH.read inh)
222 $ D.fromStreamK (FH.read inh)
197
223
224+#ifdef INSPECTION
198−hinspect $ hasNoTypeClasses 'chunksOf
225+inspect $ hasNoTypeClasses 'chunksOf
199−hinspect $ 'chunksOf `hasNoType` ''Step
226+inspect $ 'chunksOf `hasNoType` ''Step
200−hinspect $ 'chunksOfD `hasNoType` ''GroupState
227+inspect $ 'chunksOfD `hasNoType` ''GroupState
201−hinspect $ 'chunksOfD `hasNoType` ''AT.FlattenState
228+inspect $ 'chunksOfD `hasNoType` ''AT.FlattenState
202−hinspect $ 'chunksOfD `hasNoType` ''D.ConcatMapUState
229+inspect $ 'chunksOfD `hasNoType` ''D.ConcatMapUState
230+#endif
203
231
204-- | Lines and unlines
232-- | Lines and unlines
205{-# INLINE linesUnlinesCopy #-}
233{-# INLINE linesUnlinesCopy #-}
@@ -212,10 +240,12 @@ linesUnlinesCopy inh outh =
212 $ SS.decodeChar8
240 $ SS.decodeChar8
213 $ FH.read inh
241 $ FH.read inh
214
242
243+#ifdef INSPECTION
215−-- hinspect $ hasNoTypeClasses 'linesUnlinesCopy
244+-- inspect $ hasNoTypeClasses 'linesUnlinesCopy
216−-- hinspect $ 'linesUnlinesCopy `hasNoType` ''Step
245+-- inspect $ 'linesUnlinesCopy `hasNoType` ''Step
217−-- hinspect $ 'linesUnlinesCopy `hasNoType` ''AT.FlattenState
246+-- inspect $ 'linesUnlinesCopy `hasNoType` ''AT.FlattenState
218−-- hinspect $ 'linesUnlinesCopy `hasNoType` ''D.ConcatMapUState
247+-- inspect $ 'linesUnlinesCopy `hasNoType` ''D.ConcatMapUState
248+#endif
219
249
220-- | Word, unwords and copy
250-- | Word, unwords and copy
221{-# INLINE wordsUnwordsCopy #-}
251{-# INLINE wordsUnwordsCopy #-}
@@ -228,10 +258,12 @@ wordsUnwordsCopy inh outh =
228 $ SS.decodeChar8
258 $ SS.decodeChar8
229 $ FH.read inh
259 $ FH.read inh
230
260
261+#ifdef INSPECTION
231−-- hinspect $ hasNoTypeClasses 'wordsUnwordsCopy
262+-- inspect $ hasNoTypeClasses 'wordsUnwordsCopy
232−-- hinspect $ 'wordsUnwordsCopy `hasNoType` ''Step
263+-- inspect $ 'wordsUnwordsCopy `hasNoType` ''Step
233−-- hinspect $ 'wordsUnwordsCopy `hasNoType` ''AT.FlattenState
264+-- inspect $ 'wordsUnwordsCopy `hasNoType` ''AT.FlattenState
234−-- hinspect $ 'wordsUnwordsCopy `hasNoType` ''D.ConcatMapUState
265+-- inspect $ 'wordsUnwordsCopy `hasNoType` ''D.ConcatMapUState
266+#endif
235
267
236lf :: Word8
268lf :: Word8
237lf = fromIntegral (ord '\n')
269lf = fromIntegral (ord '\n')
@@ -267,10 +299,12 @@ splitOn inh =
267 (S.length $ S.splitOn (== lf) FL.drain
299 (S.length $ S.splitOn (== lf) FL.drain
268 $ FH.read inh) -- >>= print
300 $ FH.read inh) -- >>= print
269
301
302+#ifdef INSPECTION
270−hinspect $ hasNoTypeClasses 'splitOn
303+inspect $ hasNoTypeClasses 'splitOn
271−hinspect $ 'splitOn `hasNoType` ''Step
304+inspect $ 'splitOn `hasNoType` ''Step
272−hinspect $ 'splitOn `hasNoType` ''AT.FlattenState
305+inspect $ 'splitOn `hasNoType` ''AT.FlattenState
273−hinspect $ 'splitOn `hasNoType` ''D.ConcatMapUState
306+inspect $ 'splitOn `hasNoType` ''D.ConcatMapUState
307+#endif
274
308
275-- | Split suffix on line feed.
309-- | Split suffix on line feed.
276{-# INLINE splitOnSuffix #-}
310{-# INLINE splitOnSuffix #-}
@@ -279,10 +313,12 @@ splitOnSuffix inh =
279 (S.length $ S.splitOnSuffix (== lf) FL.drain
313 (S.length $ S.splitOnSuffix (== lf) FL.drain
280 $ FH.read inh) -- >>= print
314 $ FH.read inh) -- >>= print
281
315
316+#ifdef INSPECTION
282−hinspect $ hasNoTypeClasses 'splitOnSuffix
317+inspect $ hasNoTypeClasses 'splitOnSuffix
283−hinspect $ 'splitOnSuffix `hasNoType` ''Step
318+inspect $ 'splitOnSuffix `hasNoType` ''Step
284−hinspect $ 'splitOnSuffix `hasNoType` ''AT.FlattenState
319+inspect $ 'splitOnSuffix `hasNoType` ''AT.FlattenState
285−hinspect $ 'splitOnSuffix `hasNoType` ''D.ConcatMapUState
320+inspect $ 'splitOnSuffix `hasNoType` ''D.ConcatMapUState
321+#endif
286
322
287-- | Words by space
323-- | Words by space
288{-# INLINE wordsBy #-}
324{-# INLINE wordsBy #-}
@@ -291,10 +327,12 @@ wordsBy inh =
291 (S.length $ S.wordsBy isSp FL.drain
327 (S.length $ S.wordsBy isSp FL.drain
292 $ FH.read inh) -- >>= print
328 $ FH.read inh) -- >>= print
293
329
330+#ifdef INSPECTION
294−hinspect $ hasNoTypeClasses 'wordsBy
331+inspect $ hasNoTypeClasses 'wordsBy
295−hinspect $ 'wordsBy `hasNoType` ''Step
332+inspect $ 'wordsBy `hasNoType` ''Step
296−hinspect $ 'wordsBy `hasNoType` ''AT.FlattenState
333+inspect $ 'wordsBy `hasNoType` ''AT.FlattenState
297−hinspect $ 'wordsBy `hasNoType` ''D.ConcatMapUState
334+inspect $ 'wordsBy `hasNoType` ''D.ConcatMapUState
335+#endif
298
336
299-- | Split on a character sequence.
337-- | Split on a character sequence.
300{-# INLINE splitOnSeq #-}
338{-# INLINE splitOnSeq #-}
@@ -303,10 +341,12 @@ splitOnSeq str inh =
303 (S.length $ Internal.splitOnSeq (toarr str) FL.drain
341 (S.length $ Internal.splitOnSeq (toarr str) FL.drain
304 $ FH.read inh) -- >>= print
342 $ FH.read inh) -- >>= print
305
343
344+#ifdef INSPECTION
306−hinspect $ hasNoTypeClasses 'splitOnSeq
345+inspect $ hasNoTypeClasses 'splitOnSeq
307−-- hinspect $ 'splitOnSeq `hasNoType` ''Step
346+-- inspect $ 'splitOnSeq `hasNoType` ''Step
308−-- hinspect $ 'splitOnSeq `hasNoType` ''AT.FlattenState
347+-- inspect $ 'splitOnSeq `hasNoType` ''AT.FlattenState
309−-- hinspect $ 'splitOnSeq `hasNoType` ''D.ConcatMapUState
348+-- inspect $ 'splitOnSeq `hasNoType` ''D.ConcatMapUState
349+#endif
310
350
311-- | Split on suffix sequence.
351-- | Split on suffix sequence.
312{-# INLINE splitOnSuffixSeq #-}
352{-# INLINE splitOnSuffixSeq #-}
@@ -315,7 +355,9 @@ splitOnSuffixSeq str inh =
315 (S.length $ Internal.splitOnSuffixSeq (toarr str) FL.drain
355 (S.length $ Internal.splitOnSuffixSeq (toarr str) FL.drain
316 $ FH.read inh) -- >>= print
356 $ FH.read inh) -- >>= print
317
357
358+#ifdef INSPECTION
318−hinspect $ hasNoTypeClasses 'splitOnSuffixSeq
359+inspect $ hasNoTypeClasses 'splitOnSuffixSeq
319−-- hinspect $ 'splitOnSuffixSeq `hasNoType` ''Step
360+-- inspect $ 'splitOnSuffixSeq `hasNoType` ''Step
320−-- hinspect $ 'splitOnSuffixSeq `hasNoType` ''AT.FlattenState
361+-- inspect $ 'splitOnSuffixSeq `hasNoType` ''AT.FlattenState
321−-- hinspect $ 'splitOnSuffixSeq `hasNoType` ''D.ConcatMapUState
362+-- inspect $ 'splitOnSuffixSeq `hasNoType` ''D.ConcatMapUState
363+#endif
src/Streamly/Benchmark/Inspection.hsdeleted−29
@@ -1,29 +0,0 @@
1−-- |
2−-- Module : Streamly.Benchmark.Inspection
3−-- Copyright : (c) 2019 Composewell Technologies
4−--
5−-- License : BSD3
6−-- Maintainer : harendra.kumar@gmail.com
7−-- Stability : experimental
8−-- Portability : GHC
9−
10−{-# LANGUAGE CPP #-}
11−{-# LANGUAGE TemplateHaskell #-}
12−
13−{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
14−
15−module Streamly.Benchmark.Inspection
16− (
17− hinspect
18− )
19−where
20−
21−import Test.Inspection
22−import Language.Haskell.TH (Q, Dec)
23−
24−hinspect :: Obligation -> Q [Dec]
25−#ifdef __HADDOCK_VERSION__
26−hinspect _ = return []
27−#else
28−hinspect = inspect
29−#endif
src/Streamly/Benchmark/Prelude.hs+34−16
@@ -10,9 +10,11 @@
10{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11{-# LANGUAGE DeriveAnyClass #-}
11{-# LANGUAGE DeriveAnyClass #-}
12{-# LANGUAGE DeriveGeneric #-}
12{-# LANGUAGE DeriveGeneric #-}
13−{-# LANGUAGE TemplateHaskell #-}
14
13
14+#ifdef INSPECTION
15+{-# LANGUAGE TemplateHaskell #-}
15{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
16{-# OPTIONS_GHC -fplugin Test.Inspection.Plugin #-}
17+#endif
16
18
17module Streamly.Benchmark.Prelude where
19module Streamly.Benchmark.Prelude where
18
20
@@ -31,10 +33,10 @@ import qualified Prelude as P
31import qualified Data.Foldable as F
33import qualified Data.Foldable as F
32import qualified GHC.Exts as GHC
34import qualified GHC.Exts as GHC
33
35
34−import Test.Inspection
36+#ifdef INSPECTION
35−
36import Streamly.Streams.StreamD.Type (Step(..))
37import Streamly.Streams.StreamD.Type (Step(..))
37−import Streamly.Benchmark.Inspection (hinspect)
38+import Test.Inspection
39+#endif
38
40
39import qualified Streamly as S hiding (foldMapWith, runStream)
41import qualified Streamly as S hiding (foldMapWith, runStream)
40import qualified Streamly.Prelude as S
42import qualified Streamly.Prelude as S
@@ -514,8 +516,10 @@ zipM' src = do
514zipM :: Int -> IO ()
516zipM :: Int -> IO ()
515zipM n = zipM' $ source n
517zipM n = zipM' $ source n
516
518
519+#ifdef INSPECTION
517−hinspect $ hasNoTypeClasses 'zipM
520+inspect $ hasNoTypeClasses 'zipM
518−-- hinspect $ 'zipM `hasNoType` ''Step
521+-- inspect $ 'zipM `hasNoType` ''Step
522+#endif
519
523
520{-# INLINE mergeBy' #-}
524{-# INLINE mergeBy' #-}
521mergeBy' :: Monad m => Stream m Int -> m ()
525mergeBy' :: Monad m => Stream m Int -> m ()
@@ -528,8 +532,11 @@ mergeBy' src = do
528mergeBy :: Int -> IO ()
532mergeBy :: Int -> IO ()
529mergeBy n = mergeBy' $ source n
533mergeBy n = mergeBy' $ source n
530
534
535+#ifdef INSPECTION
531−hinspect $ hasNoTypeClasses 'mergeBy
536+inspect $ hasNoTypeClasses 'mergeBy
532−-- hinspect $ 'mergeBy `hasNoType` ''Step
537+-- inspect $ 'mergeBy `hasNoType` ''Step
538+#endif
539+
533
540
534{-# INLINE isPrefixOf #-}
541{-# INLINE isPrefixOf #-}
535{-# INLINE isSubsequenceOf #-}
542{-# INLINE isSubsequenceOf #-}
@@ -573,15 +580,21 @@ eqBy' src = S.eqBy (==) src src
573eqBy :: Int -> IO Bool
580eqBy :: Int -> IO Bool
574eqBy n = eqBy' (source n)
581eqBy n = eqBy' (source n)
575
582
583+#ifdef INSPECTION
576−hinspect $ hasNoTypeClasses 'eqBy
584+inspect $ hasNoTypeClasses 'eqBy
577−hinspect $ 'eqBy `hasNoType` ''Step
585+inspect $ 'eqBy `hasNoType` ''Step
586+#endif
587+
578
588
579{-# INLINE eqByPure #-}
589{-# INLINE eqByPure #-}
580eqByPure :: Int -> Identity Bool
590eqByPure :: Int -> Identity Bool
581eqByPure n = eqBy' (sourceUnfoldr n)
591eqByPure n = eqBy' (sourceUnfoldr n)
582
592
593+#ifdef INSPECTION
583−hinspect $ hasNoTypeClasses 'eqByPure
594+inspect $ hasNoTypeClasses 'eqByPure
584−hinspect $ 'eqByPure `hasNoType` ''Step
595+inspect $ 'eqByPure `hasNoType` ''Step
596+#endif
597+
585
598
586{-# INLINE cmpBy' #-}
599{-# INLINE cmpBy' #-}
587cmpBy' :: (Monad m, P.Ord a) => Stream m a -> m P.Ordering
600cmpBy' :: (Monad m, P.Ord a) => Stream m a -> m P.Ordering
@@ -591,15 +604,20 @@ cmpBy' src = S.cmpBy P.compare src src
591cmpBy :: Int -> IO P.Ordering
604cmpBy :: Int -> IO P.Ordering
592cmpBy n = cmpBy' (source n)
605cmpBy n = cmpBy' (source n)
593
606
607+#ifdef INSPECTION
594−hinspect $ hasNoTypeClasses 'cmpBy
608+inspect $ hasNoTypeClasses 'cmpBy
595−hinspect $ 'cmpBy `hasNoType` ''Step
609+inspect $ 'cmpBy `hasNoType` ''Step
610+#endif
611+
596
612
597{-# INLINE cmpByPure #-}
613{-# INLINE cmpByPure #-}
598cmpByPure :: Int -> Identity P.Ordering
614cmpByPure :: Int -> Identity P.Ordering
599cmpByPure n = cmpBy' (sourceUnfoldr n)
615cmpByPure n = cmpBy' (sourceUnfoldr n)
600
616
617+#ifdef INSPECTION
601−hinspect $ hasNoTypeClasses 'cmpByPure
618+inspect $ hasNoTypeClasses 'cmpByPure
602−hinspect $ 'cmpByPure `hasNoType` ''Step
619+inspect $ 'cmpByPure `hasNoType` ''Step
620+#endif
603
621
604-- The worst case for concatMap, concat a 1 element stream n times.
622-- The worst case for concatMap, concat a 1 element stream n times.
605{-# INLINE concatMap #-}
623{-# INLINE concatMap #-}
streamly.cabal+12−6
@@ -137,6 +137,11 @@ flag benchmark
137 manual: True
137 manual: True
138 default: False
138 default: False
139
139
140+flag inspection
141+ description: Enable inspection testing
142+ manual: True
143+ default: False
144+
140flag dev
145flag dev
141 description: Development build
146 description: Development build
142 manual: True
147 manual: True
@@ -187,6 +192,9 @@ common compile-options
187 if flag(dev)
192 if flag(dev)
188 cpp-options: -DDEVBUILD
193 cpp-options: -DDEVBUILD
189
194
195+ if flag(inspection)
196+ cpp-options: -DINSPECTION
197+
190 ghc-options: -Wall
198 ghc-options: -Wall
191
199
192 if flag(has-llvm)
200 if flag(has-llvm)
@@ -326,8 +334,7 @@ library
326
334
327 if flag(benchmark)
335 if flag(benchmark)
328 exposed-modules:
336 exposed-modules:
329− Streamly.Benchmark.Inspection
337+ Streamly.Benchmark.FileIO.Array
330− , Streamly.Benchmark.FileIO.Array
331 , Streamly.Benchmark.FileIO.Stream
338 , Streamly.Benchmark.FileIO.Stream
332 , Streamly.Benchmark.Prelude
339 , Streamly.Benchmark.Prelude
333
340
@@ -348,9 +355,9 @@ library
348 , transformers >= 0.4 && < 0.6
355 , transformers >= 0.4 && < 0.6
349 , transformers-base >= 0.4 && < 0.5
356 , transformers-base >= 0.4 && < 0.5
350
357
351− if flag(benchmark)
358+ if flag(inspection)
352− build-depends: inspection-testing >= 0.4 && < 0.5
353− , template-haskell >= 2.14 && < 2.16
359+ build-depends: template-haskell >= 2.14 && < 2.16
360+ , inspection-testing >= 0.4 && < 0.5
354
361
355 if !impl(ghcjs)
362 if !impl(ghcjs)
356 build-depends:
363 build-depends:
@@ -621,7 +628,6 @@ benchmark fileio
621 streamly
628 streamly
622 , base >= 4.8 && < 5
629 , base >= 4.8 && < 5
623 , gauge >= 0.2.4 && < 0.3
630 , gauge >= 0.2.4 && < 0.3
624− , inspection-testing >= 0.4 && < 0.5
625 , typed-process >= 0.2.3 && < 0.3
631 , typed-process >= 0.2.3 && < 0.3
626 , deepseq >= 1.4.1 && < 1.5
632 , deepseq >= 1.4.1 && < 1.5
627 else
633 else