Skip to content

Commit b915ea6

Browse files
committed
Update
1 parent 191b8a1 commit b915ea6

14 files changed

Lines changed: 250 additions & 250 deletions

File tree

core/src/Streamly/Internal/Data/Array.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ adaptCWith
11671167
:: forall m a s b r. (Monad m, Unbox a)
11681168
=> (s -> a -> m (ParserD.Step s b))
11691169
-> m (ParserD.Initial s b)
1170-
-> (s -> m (ParserD.Step s b))
1170+
-> (s -> m (ParserD.Final s b))
11711171
-> (ParseResult b -> Int -> Input (Array a) -> m (Step (Array a) m r))
11721172
-> Int
11731173
-> Int
@@ -1262,16 +1262,15 @@ adaptCWith pstep initial extract cont !offset0 !usedCount !input = do
12621262
parseContNothing !count !pst = do
12631263
r <- extract pst
12641264
case r of
1265-
ParserD.SDone n b ->
1265+
ParserD.FDone n b ->
12661266
assert (n <= 0) (cont (Success n b) (count + n) None)
1267-
ParserD.SContinue n pst1 ->
1267+
ParserD.FContinue n pst1 ->
12681268
assert (n <= 0)
12691269
(return $ Continue n (parseCont (count + n) pst1))
1270-
ParserD.Error err ->
1270+
ParserD.FError err ->
12711271
-- XXX It is called only when there is no input arr. So using 0
12721272
-- as the position is correct?
12731273
cont (Failure 0 err) count None
1274-
ParserD.SPartial _ _ -> error "Bug: adaptCWith Partial unreachable"
12751274

12761275
-- XXX Maybe we can use two separate continuations instead of using
12771276
-- Just/Nothing cases here. That may help in avoiding the parseContJust

core/src/Streamly/Internal/Data/Array/Generic.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ adaptCGWith
550550
:: forall m a s b r. (Monad m)
551551
=> (s -> a -> m (ParserD.Step s b))
552552
-> m (ParserD.Initial s b)
553-
-> (s -> m (ParserD.Step s b))
553+
-> (s -> m (ParserD.Final s b))
554554
-> (ParseResult b -> Int -> Input (Array a) -> m (Step (Array a) m r))
555555
-> Int
556556
-> Int
@@ -639,16 +639,15 @@ adaptCGWith pstep initial extract cont !offset0 !usedCount !input = do
639639
parseContNothing !count !pst = do
640640
r <- extract pst
641641
case r of
642-
ParserD.SDone n b ->
642+
ParserD.FDone n b ->
643643
assert (n <= 0) (cont (Success n b) (count + n) None)
644-
ParserD.SContinue n pst1 ->
644+
ParserD.FContinue n pst1 ->
645645
assert (n <= 1)
646646
(return $ Continue n (parseCont (count + n) pst1))
647-
ParserD.Error err ->
647+
ParserD.FError err ->
648648
-- XXX It is called only when there is no input arr. So using 0
649649
-- as the position is correct?
650650
cont (Failure 0 err) count None
651-
ParserD.SPartial _ _ -> error "Bug: adaptCGWith Partial unreachable"
652651

653652
{-# INLINE parseCont #-}
654653
parseCont !cnt !pst (Chunk arr) = parseContChunk cnt 0 pst arr

core/src/Streamly/Internal/Data/Array/Stream.hs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,24 @@ runArrayParserDBreak
418418
goStop backBuf pst = do
419419
pRes <- extract pst
420420
case pRes of
421-
PR.Partial _ _ -> error "Bug: runArrayParserDBreak: Partial in extract"
422-
PR.Continue 0 pst1 ->
421+
PR.FContinue 0 pst1 ->
423422
goStop backBuf pst1
424-
PR.Continue n pst1 -> do
423+
PR.FContinue n pst1 -> do
425424
assert
426425
(n <= sum (map Array.length (getList backBuf)))
427426
(return ())
428427
let (src0, buf1) = splitAtArrayListRev n (getList backBuf)
429428
src = Prelude.reverse src0
430429
goExtract SPEC src (List buf1) pst1
431-
PR.Done 0 b -> return (Right b, D.nil)
432-
PR.Done n b -> do
430+
PR.FDone 0 b -> return (Right b, D.nil)
431+
PR.FDone n b -> do
433432
assert
434433
(n <= sum (map Array.length (getList backBuf)))
435434
(return ())
436435
let src0 = takeArrayListRev n (getList backBuf)
437436
src = Prelude.reverse src0
438437
return (Right b, D.fromList src)
439-
PR.Error err -> do
438+
PR.FError err -> do
440439
let src0 = getList backBuf
441440
src = Prelude.reverse src0
442441
return (Left (ParseError err), D.fromList src)
@@ -683,26 +682,25 @@ runArrayFoldManyD
683682
stepOuter _ (ParseChunksStop backBuf pst) = do
684683
pRes <- extract pst
685684
case pRes of
686-
PR.Partial _ _ -> error "runArrayFoldManyD: Partial in extract"
687-
PR.Continue 0 pst1 ->
685+
PR.FContinue 0 pst1 ->
688686
return $ D.Skip $ ParseChunksStop backBuf pst1
689-
PR.Continue n pst1 -> do
687+
PR.FContinue n pst1 -> do
690688
assert (n <= sum (map Array.length backBuf)) (return ())
691689
let (src0, buf1) = splitAtArrayListRev n backBuf
692690
src = Prelude.reverse src0
693691
return $ D.Skip $ ParseChunksExtract src buf1 pst1
694-
PR.Done 0 b ->
692+
PR.FDone 0 b ->
695693
return
696694
$ D.Skip
697695
$ ParseChunksYield (Right b) (ParseChunksInitLeftOver [])
698-
PR.Done n b -> do
696+
PR.FDone n b -> do
699697
assert (n <= sum (map Array.length backBuf)) (return ())
700698
let src0 = takeArrayListRev n backBuf
701699
src = Prelude.reverse src0
702700
return
703701
$ D.Skip
704702
$ ParseChunksYield (Right b) (ParseChunksInitBuf src)
705-
PR.Error err -> do
703+
PR.FError err -> do
706704
let next = ParseChunksInitLeftOver []
707705
return
708706
$ D.Skip

core/src/Streamly/Internal/Data/Binary/Parser.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import qualified Streamly.Internal.Data.Array as A
6161
import qualified Streamly.Internal.Data.Parser as PR
6262
(fromPure, either, satisfy, takeEQ)
6363
import qualified Streamly.Internal.Data.Parser as PRD
64-
(Parser(..), Initial(..), Step(..))
64+
(Parser(..), Initial(..), Step(..), Final(..))
6565

6666
-- Note: The () type does not need to have an on-disk representation in theory.
6767
-- But we use a concrete representation for it so that we count how many ()
@@ -153,7 +153,7 @@ word16beD = PRD.Parser step initial extract
153153
step (Just' w) a =
154154
return $ PRD.SDone 1 (w .|. fromIntegral a)
155155

156-
extract _ = return $ PRD.Error "word16be: end of input"
156+
extract _ = return $ PRD.FError "word16be: end of input"
157157

158158
-- | Parse two bytes as a 'Word16', the first byte is the MSB of the Word16 and
159159
-- second byte is the LSB (big endian representation).
@@ -178,7 +178,7 @@ word16leD = PRD.Parser step initial extract
178178
step (Just' w) a =
179179
return $ PRD.SDone 1 (w .|. fromIntegral a `unsafeShiftL` 8)
180180

181-
extract _ = return $ PRD.Error "word16le: end of input"
181+
extract _ = return $ PRD.FError "word16le: end of input"
182182

183183
-- | Parse two bytes as a 'Word16', the first byte is the LSB of the Word16 and
184184
-- second byte is the MSB (little endian representation).
@@ -205,7 +205,7 @@ word32beD = PRD.Parser step initial extract
205205
in PRD.SContinue 1 (Tuple' w1 (sh - 8))
206206
else PRD.SDone 1 (w .|. fromIntegral a)
207207

208-
extract _ = return $ PRD.Error "word32beD: end of input"
208+
extract _ = return $ PRD.FError "word32beD: end of input"
209209

210210
-- | Parse four bytes as a 'Word32', the first byte is the MSB of the Word32
211211
-- and last byte is the LSB (big endian representation).
@@ -231,7 +231,7 @@ word32leD = PRD.Parser step initial extract
231231
then PRD.SContinue 1 (Tuple' w1 (sh + 8))
232232
else PRD.SDone 1 w1
233233

234-
extract _ = return $ PRD.Error "word32leD: end of input"
234+
extract _ = return $ PRD.FError "word32leD: end of input"
235235

236236
-- | Parse four bytes as a 'Word32', the first byte is the MSB of the Word32
237237
-- and last byte is the LSB (big endian representation).
@@ -258,7 +258,7 @@ word64beD = PRD.Parser step initial extract
258258
in PRD.SContinue 1 (Tuple' w1 (sh - 8))
259259
else PRD.SDone 1 (w .|. fromIntegral a)
260260

261-
extract _ = return $ PRD.Error "word64beD: end of input"
261+
extract _ = return $ PRD.FError "word64beD: end of input"
262262

263263
-- | Parse eight bytes as a 'Word64', the first byte is the MSB of the Word64
264264
-- and last byte is the LSB (big endian representation).
@@ -284,7 +284,7 @@ word64leD = PRD.Parser step initial extract
284284
then PRD.SContinue 1 (Tuple' w1 (sh + 8))
285285
else PRD.SDone 1 w1
286286

287-
extract _ = return $ PRD.Error "word64leD: end of input"
287+
extract _ = return $ PRD.FError "word64leD: end of input"
288288

289289
-- | Parse eight bytes as a 'Word64', the first byte is the MSB of the Word64
290290
-- and last byte is the LSB (big endian representation).

core/src/Streamly/Internal/Data/Fold/Chunked.hs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import Data.Proxy (Proxy(..))
7272
import Streamly.Internal.Data.Unbox (Unbox(..))
7373
import GHC.Types (SPEC(..))
7474
import Streamly.Internal.Data.Array (Array(..))
75-
import Streamly.Internal.Data.Parser (Initial(..), Step(..))
75+
import Streamly.Internal.Data.Parser (Initial(..), Step(..), Final(..))
7676
import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
7777

7878
import qualified Streamly.Internal.Data.Array.Type as Array
@@ -137,7 +137,7 @@ fromFold (Fold.Fold fstep finitial _ ffinal) =
137137
Fold.Partial fs1 ->
138138
goArray SPEC next fs1
139139

140-
extract = fmap (Done 0) . ffinal
140+
extract = fmap (FDone 0) . ffinal
141141

142142
-- | Convert an element 'ParserD.Parser' into an array stream fold. If the
143143
-- parser fails the fold would throw an exception.
@@ -320,8 +320,8 @@ take n (ChunkFold (ParserD.Parser step1 initial1 extract1)) =
320320
iextract s = do
321321
r <- extract1 s
322322
return $ case r of
323-
Done _ b -> IDone b
324-
Error err -> IError err
323+
FDone _ b -> IDone b
324+
FError err -> IError err
325325
_ -> error "Bug: ChunkFold take invalid state in initial"
326326

327327
initial = do
@@ -343,10 +343,9 @@ take n (ChunkFold (ParserD.Parser step1 initial1 extract1)) =
343343
-- i2 == i1 == j == 0
344344
r <- extract1 s
345345
return $ case r of
346-
Error err -> Error err
347-
Done n1 b -> Done n1 b
348-
Continue n1 s1 -> Continue n1 (Tuple' i2 s1)
349-
Partial _ _ -> error "Partial in extract"
346+
FError err -> Error err
347+
FDone n1 b -> Done n1 b
348+
FContinue n1 s1 -> Continue n1 (Tuple' i2 s1)
350349

351350
-- Tuple' (how many more items to take) (fold state)
352351
step (Tuple' i r) arr = do
@@ -369,11 +368,11 @@ take n (ChunkFold (ParserD.Parser step1 initial1 extract1)) =
369368
res <- step1 r arr1
370369
case res of
371370
Partial 0 s ->
372-
ParserD.bimapOverrideCount
371+
ParserD.bimapMorphOverrideCount
373372
remaining (Tuple' 0) id <$> extract1 s
374373
Partial j s -> return $ Partial (remaining + j) (Tuple' j s)
375374
Continue 0 s ->
376-
ParserD.bimapOverrideCount
375+
ParserD.bimapMorphOverrideCount
377376
remaining (Tuple' 0) id <$> extract1 s
378377
Continue j s -> return $ Continue (remaining + j) (Tuple' j s)
379378
Done j b -> return $ Done (remaining + j) b

core/src/Streamly/Internal/Data/MutArray/Type.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,8 +3738,8 @@ pCompactLeAs ps maxElems = Parser step initial extract
37383738
buf2 <- unsafeSplice buf1 arr
37393739
return $ Parser.SPartial 1 (Just buf2)
37403740

3741-
extract Nothing = return $ Parser.SDone 0 nil
3742-
extract (Just buf) = return $ Parser.SDone 0 buf
3741+
extract Nothing = return $ Parser.FDone 0 nil
3742+
extract (Just buf) = return $ Parser.FDone 0 buf
37433743

37443744
-- | Parser @createCompactMax maxElems@ coalesces adjacent arrays in the
37453745
-- input stream only if the combined size would be less than or equal to

0 commit comments

Comments
 (0)