on master help sign in
Cleanup and make consistent the export lists of Array modules
commit11845277c76a5e6803f22f61c35cc6663a30ebcb authorHarendra Kumar <harendra@composewell.com> dateMon 1 Jan 2024, 07:54 (3 years ago) parentffea484
5 files changed+176−136
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+7−8 benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+8−9 benchmark/Streamly/Benchmark/Unicode/Stream.hs+4−3 core/src/Streamly/Internal/Data/Array/Type.hs+68−41 core/src/Streamly/Internal/Data/MutArray/Type.hs+89−75
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+7−8
@@ -33,7 +33,6 @@ import qualified Streamly.Data.Stream as Stream
3333import qualified Streamly.Data.Fold as Fold
3434import qualified Streamly.FileSystem.Handle as FH
3535import qualified Streamly.Internal.Data.Array as A
36−import qualified Streamly.Internal.Data.Array as AT
3736import qualified Streamly.Internal.Data.Fold as FL
3837import qualified Streamly.Internal.Data.Stream as IP
3938import qualified Streamly.Internal.FileSystem.Handle as IFH
@@ -48,7 +47,7 @@ import Streamly.Benchmark.Common.Handle
4847#ifdef INSPECTION
4948import Streamly.Internal.Data.Stream (Step(..), FoldMany)
5049
51−import qualified Streamly.Internal.Data.MutArray as MA
50+import qualified Streamly.Internal.Data.MutArray as MutArray
5251import qualified Streamly.Internal.Data.Stream as D
5352import qualified Streamly.Internal.Data.Unfold as IUF
5453
@@ -69,7 +68,7 @@ readLast = S.fold Fold.last . S.unfold FH.reader
6968inspect $ hasNoTypeClasses 'readLast
7069inspect $ 'readLast `hasNoType` ''Step -- S.unfold
7170inspect $ 'readLast `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
72−inspect $ 'readLast `hasNoType` ''MA.ArrayUnsafe -- FH.read/A.read
71+inspect $ 'readLast `hasNoType` ''MutArray.ArrayUnsafe -- FH.read/A.read
7372#endif
7473
7574-- assert that flattenArrays constructors are not present
@@ -81,7 +80,7 @@ readCountBytes = S.fold Fold.length . S.unfold FH.reader
8180inspect $ hasNoTypeClasses 'readCountBytes
8281inspect $ 'readCountBytes `hasNoType` ''Step -- S.unfold
8382inspect $ 'readCountBytes `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
84−inspect $ 'readCountBytes `hasNoType` ''MA.ArrayUnsafe -- FH.read/A.read
83+inspect $ 'readCountBytes `hasNoType` ''MutArray.ArrayUnsafe -- FH.read/A.read
8584#endif
8685
8786-- | Count the number of lines in a file.
@@ -96,7 +95,7 @@ readCountLines =
9695inspect $ hasNoTypeClasses 'readCountLines
9796inspect $ 'readCountLines `hasNoType` ''Step
9897inspect $ 'readCountLines `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
99−inspect $ 'readCountLines `hasNoType` ''MA.ArrayUnsafe -- FH.read/A.read
98+inspect $ 'readCountLines `hasNoType` ''MutArray.ArrayUnsafe -- FH.read/A.read
10099#endif
101100
102101-- | Count the number of words in a file.
@@ -120,7 +119,7 @@ readSumBytes = S.fold Fold.sum . S.unfold FH.reader
120119inspect $ hasNoTypeClasses 'readSumBytes
121120inspect $ 'readSumBytes `hasNoType` ''Step
122121inspect $ 'readSumBytes `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
123−inspect $ 'readSumBytes `hasNoType` ''MA.ArrayUnsafe -- FH.read/A.read
122+inspect $ 'readSumBytes `hasNoType` ''MutArray.ArrayUnsafe -- FH.read/A.read
124123#endif
125124
126125-- XXX When we mark this with INLINE and we have two benchmarks using S.drain
@@ -236,13 +235,13 @@ groupsOf :: Int -> Handle -> IO Int
236235groupsOf n inh =
237236 -- writeNUnsafe gives 2.5x boost here over writeN.
238237 S.fold Fold.length
239− $ IP.groupsOf n (AT.writeNUnsafe n) (S.unfold FH.reader inh)
238+ $ IP.groupsOf n (A.writeNUnsafe n) (S.unfold FH.reader inh)
240239
241240#ifdef INSPECTION
242241inspect $ hasNoTypeClasses 'groupsOf
243242inspect $ 'groupsOf `hasNoType` ''Step
244243inspect $ 'groupsOf `hasNoType` ''FoldMany
245−inspect $ 'groupsOf `hasNoType` ''AT.ArrayUnsafe -- AT.writeNUnsafe
244+inspect $ 'groupsOf `hasNoType` ''MutArray.ArrayUnsafe -- AT.writeNUnsafe
246245 -- FH.read/A.read
247246inspect $ 'groupsOf `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
248247#endif
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+8−9
@@ -42,8 +42,7 @@ import Streamly.Internal.Data.Stream (Step(..))
4242
4343import qualified Streamly.Internal.Data.Stream as D
4444import qualified Streamly.Internal.Data.Tuple.Strict as Strict
45−import qualified Streamly.Internal.Data.MutArray.Stream as MAS
46−import qualified Streamly.Internal.Data.Array as AT
45+import qualified Streamly.Internal.Data.MutArray as MutArray
4746
4847import Test.Inspection
4948#endif
@@ -83,7 +82,7 @@ copyStream inh outh = S.fold (FH.write outh) (S.unfold FH.reader inh)
8382inspect $ hasNoTypeClasses 'copyStream
8483inspect $ 'copyStream `hasNoType` ''Step -- S.unfold
8584inspect $ 'copyStream `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
86−inspect $ 'copyStream `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
85+inspect $ 'copyStream `hasNoType` ''MutArray.ArrayUnsafe -- FH.write/writeNUnsafe
8786 -- FH.read/A.read
8887inspect $ 'copyStream `hasNoType` ''Strict.Tuple3' -- FH.write/chunksOf
8988#endif
@@ -109,8 +108,8 @@ readFromBytesNull inh devNull = IFH.putBytes devNull $ S.unfold FH.reader inh
109108#ifdef INSPECTION
110109inspect $ hasNoTypeClasses 'readFromBytesNull
111110inspect $ 'readFromBytesNull `hasNoType` ''Step
112−inspect $ 'readFromBytesNull `hasNoType` ''MAS.SpliceState
113−inspect $ 'readFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.chunksOf
111+inspect $ 'readFromBytesNull `hasNoType` ''MutArray.SpliceState
112+inspect $ 'readFromBytesNull `hasNoType` ''MutArray.ArrayUnsafe -- FH.fromBytes/S.chunksOf
114113inspect $ 'readFromBytesNull `hasNoType` ''D.FoldMany
115114#endif
116115
@@ -123,8 +122,8 @@ readWithFromBytesNull inh devNull =
123122#ifdef INSPECTION
124123inspect $ hasNoTypeClasses 'readWithFromBytesNull
125124inspect $ 'readWithFromBytesNull `hasNoType` ''Step
126−inspect $ 'readWithFromBytesNull `hasNoType` ''MAS.SpliceState
127−inspect $ 'readWithFromBytesNull `hasNoType` ''AT.ArrayUnsafe -- FH.fromBytes/S.chunksOf
125+inspect $ 'readWithFromBytesNull `hasNoType` ''MutArray.SpliceState
126+inspect $ 'readWithFromBytesNull `hasNoType` ''MutArray.ArrayUnsafe -- FH.fromBytes/S.chunksOf
128127inspect $ 'readWithFromBytesNull `hasNoType` ''D.FoldMany
129128#endif
130129
@@ -171,7 +170,7 @@ writeReadWith inh devNull = IUF.fold fld unf (defaultChunkSize, inh)
171170inspect $ hasNoTypeClasses 'writeReadWith
172171inspect $ 'writeReadWith `hasNoType` ''Step
173172inspect $ 'writeReadWith `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
174−inspect $ 'writeReadWith `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
173+inspect $ 'writeReadWith `hasNoType` ''MutArray.ArrayUnsafe -- FH.write/writeNUnsafe
175174 -- FH.read/A.read
176175#endif
177176
@@ -188,7 +187,7 @@ writeRead inh devNull = IUF.fold fld unf inh
188187inspect $ hasNoTypeClasses 'writeRead
189188inspect $ 'writeRead `hasNoType` ''Step
190189inspect $ 'writeRead `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
191−inspect $ 'writeRead `hasNoType` ''AT.ArrayUnsafe -- FH.write/writeNUnsafe
190+inspect $ 'writeRead `hasNoType` ''MutArray.ArrayUnsafe -- FH.write/writeNUnsafe
192191 -- FH.read/A.read
193192#endif
194193
benchmark/Streamly/Benchmark/Unicode/Stream.hs+4−3
@@ -45,9 +45,10 @@ import Streamly.Benchmark.Common.Handle
4545#ifdef INSPECTION
4646import Streamly.Internal.Data.MutByteArray (Unbox)
4747import Streamly.Internal.Data.Stream (Step(..))
48+import qualified Streamly.Internal.Data.Array as Array
49+import qualified Streamly.Internal.Data.MutArray as MutArray
4850import qualified Streamly.Internal.Data.Fold as Fold
4951import qualified Streamly.Internal.Data.Tuple.Strict as Strict
50−import qualified Streamly.Internal.Data.Array as Array
5152
5253import Test.Inspection
5354#endif
@@ -223,7 +224,7 @@ inspect $ 'copyStreamLatin1' `hasNoType` ''Step
223224inspect $ 'copyStreamLatin1' `hasNoType` ''Unfold.ConcatState -- Handle.read/UF.many
224225
225226inspect $ 'copyStreamLatin1' `hasNoType` ''Fold.Step
226−inspect $ 'copyStreamLatin1' `hasNoType` ''Array.ArrayUnsafe -- Handle.write/writeNUnsafe
227+inspect $ 'copyStreamLatin1' `hasNoType` ''MutArray.ArrayUnsafe -- Handle.write/writeNUnsafe
227228 -- Handle.read/Array.read
228229inspect $ 'copyStreamLatin1' `hasNoType` ''Strict.Tuple3' -- Handle.write/chunksOf
229230#endif
@@ -244,7 +245,7 @@ inspect $ 'copyStreamLatin1 `hasNoType` ''Unfold.ConcatState -- Handle.read/UF.m
244245
245246inspect $ 'copyStreamLatin1 `hasNoType` ''Fold.ManyState
246247inspect $ 'copyStreamLatin1 `hasNoType` ''Fold.Step
247−inspect $ 'copyStreamLatin1 `hasNoType` ''Array.ArrayUnsafe -- Handle.write/writeNUnsafe
248+inspect $ 'copyStreamLatin1 `hasNoType` ''MutArray.ArrayUnsafe -- Handle.write/writeNUnsafe
248249 -- Handle.read/Array.read
249250inspect $ 'copyStreamLatin1 `hasNoType` ''Strict.Tuple3' -- Handle.write/chunksOf
250251#endif
core/src/Streamly/Internal/Data/Array/Type.hs+68−41
@@ -2,7 +2,6 @@
22-- |
33-- Module : Streamly.Internal.Data.Array.Type
44-- Copyright : (c) 2020 Composewell Technologies
5−--
65-- License : BSD3-3-Clause
76-- Maintainer : streamly@composewell.com
87-- Stability : experimental
@@ -10,33 +9,59 @@
109--
1110-- See notes in "Streamly.Internal.Data.MutArray.Type"
1211--
12+
1313module Streamly.Internal.Data.Array.Type
1414 (
1515 -- ** Type
1616 -- $arrayNotes
1717 Array (..)
18− , asPtrUnsafe
19− , nil
2018
21− -- ** Freezing and Thawing
19+ -- ** Conversion
20+ -- *** Mutable and Immutable
2221 , unsafeFreeze
2322 , unsafeFreezeWithShrink
2423 , unsafeThaw
2524
26− -- ** Pinning and Unpinning
25+ -- *** Pinned and Unpinned
2726 , pin
2827 , unpin
2928 , isPinned
3029
30+ -- *** Casting
31+ , asPtrUnsafe
32+
3133 -- ** Construction
32− , splice
34+ , nil
3335
34− , fromList
35− , pinnedFromList
36+ -- *** Cloning
37+ -- XXX Why would we clone an immutable array?
38+ , clone
39+ , pinnedClone
40+
41+ -- *** Slicing
42+ -- | Get a subarray without copying
43+ , splitAt
44+ , breakOn -- XXX requires MonadIO
45+
46+ -- *** Stream Folds
47+ , unsafeMakePure
48+ , writeWith
49+ , writeN
50+ , pinnedWriteN
51+ , writeNUnsafe
52+ , pinnedWriteNUnsafe
53+ -- , MA.ArrayUnsafe (..)
54+ , pinnedWriteNAligned
55+ , write
56+ , pinnedWrite
57+
58+ -- *** From containers
3659 , fromListN
3760 , pinnedFromListN
38− , fromListRev
61+ , fromList
62+ , pinnedFromList
3963 , fromListRevN
64+ , fromListRev
4065 , fromStreamN
4166 , fromStream
4267 , fromPureStreamN
@@ -46,56 +71,58 @@ module Streamly.Internal.Data.Array.Type
4671 , fromPtrN
4772 , fromChunksK
4873
49− -- ** Split
50− , breakOn
51− , splitAt
74+ -- ** Reading
5275
53− -- ** Cloning arrays
54− , clone
55− , pinnedClone
76+ -- *** Indexing
77+ , unsafeIndexIO -- XXX rename to getIndexUnsafeIO
78+ , getIndexUnsafe
5679
57− -- * Unfolds
58− , reader
59− , readerUnsafe
80+ -- *** To Streams
81+ , read
82+ , readRev
83+ , toStreamK
84+ , toStreamKRev
85+
86+ -- *** To Containers
87+ , toList
88+
89+ -- *** Unfolds
6090 , producer -- experimental
91+ , readerUnsafe
92+ , reader
93+ , readerRev
6194
62− -- ** Elimination
63− , unsafeIndexIO
64− , getIndexUnsafe
65− , byteLength
95+ -- *** Size
6696 , length
97+ , byteLength
6798
99+ -- ** Folding
68100 , foldl'
69101 , foldr
70−
71− , toStreamK
72− , toStreamKRev
73− , read
74− , readRev
75− , readerRev
76− , toList
77−
78− -- ** Folds
79− , writeWith
80− , writeN
81− , pinnedWriteN
82− , writeNUnsafe
83− , pinnedWriteNUnsafe
84− -- , MA.ArrayUnsafe (..)
85− , pinnedWriteNAligned
86− , write
87− , pinnedWrite
88− , unsafeMakePure
89102 , byteCmp
90103 , byteEq
91104
105+ -- ** Appending
106+ , splice -- XXX requires MonadIO
107+
92108 -- ** Streams of arrays
109+ -- *** Chunk
110+ -- | Group a stream into arrays.
93111 , chunksOf
94112 , pinnedChunksOf
95113 , buildChunks
114+
115+ -- *** Split
116+ -- | Split an array into slices.
117+
118+ -- *** Concat
119+ -- | Append the arrays in a stream to form a stream of elements.
96120 , concatChunks
97121 , concatChunksRev
98122
123+ -- *** Compact
124+ -- | Append the arrays in a stream to form a stream of larger arrays.
125+
99126 -- ** Deprecated
100127 , unsafeIndex
101128 , bufferChunks
core/src/Streamly/Internal/Data/MutArray/Type.hs+89−75
@@ -31,33 +31,44 @@ module Streamly.Internal.Data.MutArray.Type
3131 -- ** Type
3232 -- $arrayNotes
3333 MutArray (..)
34+
35+ -- ** Conversion
36+ -- *** Pinned and Unpinned
3437 , pin
3538 , unpin
3639 , isPinned
3740
38− -- -- * Constructing and Writing
41+ -- ** Casting
42+ , cast
43+ , castUnsafe
44+ , asBytes
45+ , asPtrUnsafe
46+ , asUnpinnedPtrUnsafe
47+
3948 -- ** Construction
4049 , nil
4150
42− -- *** Uninitialized Arrays
51+ -- *** New
52+ -- | New arrays are always empty arrays with some reserve capacity to
53+ -- extend the length without reallocating.
54+ , new
55+ , newArrayWith
4356 , pinnedNew
4457 , pinnedNewBytes
4558 , pinnedNewAligned
46− , new
47− , newArrayWith
4859
49− -- ** Cloning arrays
60+ -- *** Cloning
5061 , clone
5162 , pinnedClone
5263
53− -- ** Slicing
64+ -- *** Slicing
5465 -- | Get a subarray without copying
5566 , getSliceUnsafe
5667 , getSlice
5768 , splitAt -- XXX should be able to express using getSlice
5869 , breakOn
5970
60− -- *** From streams
71+ -- *** Stream Folds
6172 , ArrayUnsafe (..)
6273 , writeNWithUnsafe
6374 , writeNWith
@@ -107,65 +118,49 @@ module Streamly.Internal.Data.MutArray.Type
107118 , swapIndices
108119 , unsafeSwapIndices
109120
110− -- ** Growing and Shrinking
111− -- | Arrays grow only at the end, though it is possible to grow on both sides
112− -- and therefore have a cons as well as snoc. But that will require two
113− -- bounds in the array representation.
121+ -- ** Reading
114122
115− -- *** Appending elements
116− , snocWith
117− , snoc
118− , snocLinear
119− , snocMay
120− , snocUnsafe
121−
122− -- *** Appending streams
123− , writeAppendNUnsafe
124− , writeAppendN
125− , writeAppendWith
126− , writeAppend
127−
128− -- *** Appending arrays
129− , spliceCopy
130− , spliceWith
131− , splice
132− , spliceExp
133− , spliceUnsafe
134− -- , putSlice
135− -- , appendSlice
136− -- , appendSliceFrom
137−
138− -- ** Eliminating and Reading
139−
140− -- *** To streams
141− , reader
142− , readerRevWith
143− , readerRev
123+ -- *** Indexing
124+ , getIndex
125+ , getIndexUnsafe
126+ , getIndices -- XXX indexReader
127+ , getIndicesWith -- XXX indexReaderWith
128+ -- , getFromThenTo
129+ , getIndexRev
144130
145− -- *** To containers
146− , toStreamWith
147− , toStreamRevWith
148− , toStreamKWith
149− , toStreamKRevWith
131+ -- *** To Streams
150132 , read
151133 , readRev
134+ , toStreamWith
135+ , toStreamRevWith
152136 , toStreamK
137+ , toStreamKWith
153138 , toStreamKRev
139+ , toStreamKRevWith
140+
141+ -- *** To Containers
154142 , toList
155143
144+ -- *** Unfolds
156145 -- experimental
157146 , producerWith
158147 , producer
159148
160− -- *** Random reads
161− , getIndex
162− , getIndexUnsafe
163− , getIndices
164− , getIndicesWith
165− -- , getFromThenTo
166− , getIndexRev
149+ , reader
150+ , readerRevWith
151+ , readerRev
152+
153+ -- ** Size and Capacity
154+ -- *** Size
155+ , length
156+ , byteLength
167157
168− -- ** Memory Management
158+ -- *** Capacity
159+ -- , capacity
160+ , byteCapacity
161+ , bytesFree
162+
163+ -- *** Capacity Management
169164 , blockSize
170165 , arrayChunkBytes
171166 , allocBytesToElemCount
@@ -174,12 +169,11 @@ module Streamly.Internal.Data.MutArray.Type
174169 , resizeExp
175170 , rightSize
176171
177− -- ** Size
178− , length
179− , byteLength
180− -- , capacity
181− , byteCapacity
182− , bytesFree
172+ -- ** Folding
173+ , foldl'
174+ , foldr
175+ , byteCmp
176+ , byteEq
183177
184178 -- ** In-place Mutation Algorithms
185179 , strip
@@ -191,19 +185,33 @@ module Streamly.Internal.Data.MutArray.Type
191185 , mergeBy
192186 , bubble
193187
194− -- ** Casting
195− , cast
196− , castUnsafe
197− , asBytes
198− , asPtrUnsafe
199− , asUnpinnedPtrUnsafe
188+ -- ** Growing and Shrinking
189+ -- | Arrays grow only at the end, though it is possible to grow on both
190+ -- sides and therefore have a cons as well as snoc. But that will require
191+ -- both lower and upper bound in the array representation.
200192
201− -- ** Folding
202− , foldl'
203− , foldr
204− , cmp
205− , byteCmp
206− , byteEq
193+ -- *** Appending elements
194+ , snocWith
195+ , snoc
196+ , snocLinear
197+ , snocMay
198+ , snocUnsafe
199+
200+ -- *** Appending streams
201+ , writeAppendNUnsafe
202+ , writeAppendN
203+ , writeAppendWith
204+ , writeAppend
205+
206+ -- *** Appending arrays
207+ , spliceCopy
208+ , spliceWith
209+ , splice
210+ , spliceExp
211+ , spliceUnsafe
212+ -- , putSlice
213+ -- , appendSlice
214+ -- , appendSliceFrom
207215
208216 -- Arrays of arrays
209217 -- We can add dimensionality parameter to the array type to get
@@ -211,21 +219,26 @@ module Streamly.Internal.Data.MutArray.Type
211219 -- convenience wrapper on top of single dimensional arrays.
212220
213221 -- ** Streams of Arrays
214− -- *** Group a stream into arrays
222+ -- *** Chunk
223+ -- | Group a stream into arrays.
215224 , chunksOf
216225 , pinnedChunksOf
217226 , buildChunks
218227
219− -- *** Split an array into slices
228+ -- *** Split
229+ -- | Split an array into slices.
230+
220231 -- , getSlicesFromLenN
221232 , splitOn
222233 -- , slicesOf
223234
224− -- *** Flatten a stream of arrays
235+ -- *** Concat
236+ -- | Append the arrays in a stream to form a stream of elements.
225237 , concatChunks
226238 , concatChunksRev
227239
228− -- *** Compaction
240+ -- *** Compact
241+ -- | Append the arrays in a stream to form a stream of larger arrays.
229242 , SpliceState (..)
230243 , pCompactChunksLE
231244 , rCompactChunksLE
@@ -247,6 +260,7 @@ module Streamly.Internal.Data.MutArray.Type
247260 , fromArrayStreamK
248261 , fromStreamDN
249262 , fromStreamD
263+ , cmp
250264 )
251265where
252266