on master help sign in
Mk non-functional naming changes for continuation parsers & friends
5322566Adithya Kumar
benchmark/Streamly/Benchmark/Data/ParserK.hs+9−9
@@ -5,9 +5,9 @@
5-- License : BSD-3-Clause
5-- License : BSD-3-Clause
6-- Maintainer : streamly@composewell.com
6-- Maintainer : streamly@composewell.com
7
7
8−-- BENCH_CHUNKED -> fromParser
8+-- BENCH_CHUNKED -> adaptC
9−-- BENCH_CHUNKED_GENERIC -> fromParserGeneric
9+-- BENCH_CHUNKED_GENERIC -> adaptCG
10−-- BENCH_SINGULAR -> fromParserSingular
10+-- BENCH_SINGULAR -> adapt
11
11
12{-# LANGUAGE CPP #-}
12{-# LANGUAGE CPP #-}
13{-# LANGUAGE FlexibleContexts #-}
13{-# LANGUAGE FlexibleContexts #-}
@@ -58,7 +58,7 @@ import Streamly.Benchmark.Common
58#ifdef BENCH_CHUNKED
58#ifdef BENCH_CHUNKED
59
59
60#define PARSE_OP StreamK.parseChunks
60#define PARSE_OP StreamK.parseChunks
61−#define FROM_PARSER fromParser
61+#define FROM_PARSER adaptC
62#define INPUT (Array a)
62#define INPUT (Array a)
63#define PARSE_ELEM (Array Int)
63#define PARSE_ELEM (Array Int)
64#define CONSTRAINT_IO (MonadIO m, Unbox a)
64#define CONSTRAINT_IO (MonadIO m, Unbox a)
@@ -69,8 +69,8 @@ import Streamly.Benchmark.Common
69
69
70#ifdef BENCH_CHUNKED_GENERIC
70#ifdef BENCH_CHUNKED_GENERIC
71
71
72−#define PARSE_OP StreamK.parseGenericChunks
72+#define PARSE_OP StreamK.parseChunksGeneric
73−#define FROM_PARSER fromParserGeneric
73+#define FROM_PARSER adaptCG
74#define INPUT (Array a)
74#define INPUT (Array a)
75#define PARSE_ELEM (Array Int)
75#define PARSE_ELEM (Array Int)
76#define CONSTRAINT_IO (MonadIO m)
76#define CONSTRAINT_IO (MonadIO m)
@@ -81,13 +81,13 @@ import Streamly.Benchmark.Common
81
81
82#ifdef BENCH_SINGULAR
82#ifdef BENCH_SINGULAR
83
83
84−#define PARSE_OP StreamK.parseSingular
84+#define PARSE_OP StreamK.parse
85−#define FROM_PARSER fromParserSingular
85+#define FROM_PARSER adapt
86#define INPUT a
86#define INPUT a
87#define PARSE_ELEM Int
87#define PARSE_ELEM Int
88#define CONSTRAINT_IO (MonadIO m)
88#define CONSTRAINT_IO (MonadIO m)
89#define CONSTRAINT (Monad m)
89#define CONSTRAINT (Monad m)
90−#define MODULE_NAME "ParserK.Singular"
90+#define MODULE_NAME "ParserK"
91
91
92#endif
92#endif
93
93
benchmark/streamly-benchmarks.cabal+3−19
@@ -415,7 +415,7 @@ benchmark Data.Parser
415 else
415 else
416 ghc-options: +RTS -M2000M -RTS
416 ghc-options: +RTS -M2000M -RTS
417
417
418−benchmark Data.ParserK.Singular
418+benchmark Data.ParserK
419 import: bench-options
419 import: bench-options
420 type: exitcode-stdio-1.0
420 type: exitcode-stdio-1.0
421 hs-source-dirs: Streamly/Benchmark/Data
421 hs-source-dirs: Streamly/Benchmark/Data
@@ -427,7 +427,7 @@ benchmark Data.ParserK.Singular
427 buildable: True
427 buildable: True
428 build-depends: exceptions >= 0.8 && < 0.11
428 build-depends: exceptions >= 0.8 && < 0.11
429
429
430−benchmark Data.ParserK
430+benchmark Data.ParserK.Chunked
431 import: bench-options
431 import: bench-options
432 type: exitcode-stdio-1.0
432 type: exitcode-stdio-1.0
433 hs-source-dirs: Streamly/Benchmark/Data
433 hs-source-dirs: Streamly/Benchmark/Data
@@ -439,7 +439,7 @@ benchmark Data.ParserK
439 buildable: True
439 buildable: True
440 build-depends: exceptions >= 0.8 && < 0.11
440 build-depends: exceptions >= 0.8 && < 0.11
441
441
442−benchmark Data.ParserK.Generic
442+benchmark Data.ParserK.Chunked.Generic
443 import: bench-options
443 import: bench-options
444 type: exitcode-stdio-1.0
444 type: exitcode-stdio-1.0
445 hs-source-dirs: Streamly/Benchmark/Data
445 hs-source-dirs: Streamly/Benchmark/Data
@@ -451,22 +451,6 @@ benchmark Data.ParserK.Generic
451 buildable: True
451 buildable: True
452 build-depends: exceptions >= 0.8 && < 0.11
452 build-depends: exceptions >= 0.8 && < 0.11
453
453
454−-- Note: to use this we have to set DISABLE_FUSION in ParserD.hs so that
455−-- the rewrite rules are disabled. We can also use the "no-fusion" build
456−-- flag but we need to keep in mind that it disables fusion for streams
457−-- as well.
458−-- benchmark Data.FromParserK
459−-- import: bench-options
460−-- type: exitcode-stdio-1.0
461−-- hs-source-dirs: Streamly/Benchmark/Data
462−-- cpp-options: -DFROM_PARSERK
463−-- main-is: ParserK.hs
464−-- if flag(use-streamly-core) || impl(ghcjs)
465−-- buildable: False
466−-- else
467−-- buildable: True
468−-- build-depends: exceptions >= 0.8 && < 0.11
469−
470-------------------------------------------------------------------------------
454-------------------------------------------------------------------------------
471-- Raw Streams
455-- Raw Streams
472-------------------------------------------------------------------------------
456-------------------------------------------------------------------------------
core/src/Streamly/Data/ParserK.hs+13−5
@@ -18,14 +18,17 @@ module Streamly.Data.ParserK
18
18
19 -- * Parsers
19 -- * Parsers
20 -- ** Conversions
20 -- ** Conversions
21− , fromFold
21+ , adaptC
22− , fromParser
23 -- , toParser
22 -- , toParser
24
23
25 -- ** Without Input
24 -- ** Without Input
26 , fromPure
25 , fromPure
27 , fromEffect
26 , fromEffect
28 , die
27 , die
28+
29+ -- * Deprecated
30+ , fromFold
31+ , fromParser
29 )
32 )
30
33
31where
34where
@@ -38,8 +41,13 @@ import qualified Streamly.Internal.Data.Parser as ParserD
38
41
39import Streamly.Internal.Data.Parser.ParserK.Type
42import Streamly.Internal.Data.Parser.ParserK.Type
40
43
41−-- | Convert a 'Fold' to a 'ParserK'.
44+{-# DEPRECATED fromFold "Please use \"ParserK.adaptC . Parser.fromFold\" instead." #-}
42−--
43{-# INLINE fromFold #-}
45{-# INLINE fromFold #-}
44fromFold :: (MonadIO m, Unbox a) => Fold m a b -> ParserK (Array a) m b
46fromFold :: (MonadIO m, Unbox a) => Fold m a b -> ParserK (Array a) m b
45−fromFold = fromParser . ParserD.fromFold
47+fromFold = adaptC . ParserD.fromFold
48+
49+{-# DEPRECATED fromParser "Please use \"adaptC\" instead." #-}
50+{-# INLINE fromParser #-}
51+fromParser ::
52+ (MonadIO m, Unbox a) => ParserD.Parser a m b -> ParserK (Array a) m b
53+fromParser = adaptC
core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+29−29
@@ -27,9 +27,9 @@ module Streamly.Internal.Data.Parser.ParserK.Type
27 , Input (..)
27 , Input (..)
28 , ParseResult (..)
28 , ParseResult (..)
29 , ParserK (..)
29 , ParserK (..)
30− , fromParser
30+ , adaptC
31− , fromParserSingular
31+ , adapt
32− , fromParserGeneric
32+ , adaptCG
33 -- , toParser
33 -- , toParser
34 , fromPure
34 , fromPure
35 , fromEffect
35 , fromEffect
@@ -380,8 +380,8 @@ instance MonadTrans (ParserK a) where
380-- Chunked
380-- Chunked
381--------------------------------------------------------------------------------
381--------------------------------------------------------------------------------
382
382
383−{-# INLINE parseDToK #-}
383+{-# INLINE adaptCWith #-}
384−parseDToK
384+adaptCWith
385 :: forall m a s b r. (Monad m, Unbox a)
385 :: forall m a s b r. (Monad m, Unbox a)
386 => (s -> a -> m (ParserD.Step s b))
386 => (s -> a -> m (ParserD.Step s b))
387 -> m (ParserD.Initial s b)
387 -> m (ParserD.Initial s b)
@@ -391,7 +391,7 @@ parseDToK
391 -> Int
391 -> Int
392 -> Input (Array a)
392 -> Input (Array a)
393 -> m (Step (Array a) m r)
393 -> m (Step (Array a) m r)
394−parseDToK pstep initial extract cont !offset0 !usedCount !input = do
394+adaptCWith pstep initial extract cont !offset0 !usedCount !input = do
395 res <- initial
395 res <- initial
396 case res of
396 case res of
397 ParserD.IPartial pst -> do
397 ParserD.IPartial pst -> do
@@ -495,7 +495,7 @@ parseDToK pstep initial extract cont !offset0 !usedCount !input = do
495 -- XXX It is called only when there is no input arr. So using 0
495 -- XXX It is called only when there is no input arr. So using 0
496 -- as the position is correct?
496 -- as the position is correct?
497 cont (Failure 0 err) count None
497 cont (Failure 0 err) count None
498− ParserD.Partial _ _ -> error "Bug: parseDToK Partial unreachable"
498+ ParserD.Partial _ _ -> error "Bug: adaptCWith Partial unreachable"
499
499
500 -- XXX Maybe we can use two separate continuations instead of using
500 -- XXX Maybe we can use two separate continuations instead of using
501 -- Just/Nothing cases here. That may help in avoiding the parseContJust
501 -- Just/Nothing cases here. That may help in avoiding the parseContJust
@@ -508,17 +508,17 @@ parseDToK pstep initial extract cont !offset0 !usedCount !input = do
508--
508--
509-- /Pre-release/
509-- /Pre-release/
510--
510--
511−{-# INLINE_LATE fromParser #-}
511+{-# INLINE_LATE adaptC #-}
512−fromParser :: (Monad m, Unbox a) => ParserD.Parser a m b -> ParserK (Array a) m b
512+adaptC :: (Monad m, Unbox a) => ParserD.Parser a m b -> ParserK (Array a) m b
513−fromParser (ParserD.Parser step initial extract) =
513+adaptC (ParserD.Parser step initial extract) =
514− MkParser $ parseDToK step initial extract
514+ MkParser $ adaptCWith step initial extract
515
515
516--------------------------------------------------------------------------------
516--------------------------------------------------------------------------------
517-- Singular
517-- Singular
518--------------------------------------------------------------------------------
518--------------------------------------------------------------------------------
519
519
520−{-# INLINE parseDToKSingular #-}
520+{-# INLINE adaptWith #-}
521−parseDToKSingular
521+adaptWith
522 :: forall m a s b r. (Monad m)
522 :: forall m a s b r. (Monad m)
523 => (s -> a -> m (ParserD.Step s b))
523 => (s -> a -> m (ParserD.Step s b))
524 -> m (ParserD.Initial s b)
524 -> m (ParserD.Initial s b)
@@ -528,7 +528,7 @@ parseDToKSingular
528 -> Int
528 -> Int
529 -> Input a
529 -> Input a
530 -> m (Step a m r)
530 -> m (Step a m r)
531−parseDToKSingular pstep initial extract cont !relPos !usedCount !input = do
531+adaptWith pstep initial extract cont !relPos !usedCount !input = do
532 res <- initial
532 res <- initial
533 case res of
533 case res of
534 ParserD.IPartial pst -> do
534 ParserD.IPartial pst -> do
@@ -597,7 +597,7 @@ parseDToKSingular pstep initial extract cont !relPos !usedCount !input = do
597 -- XXX It is called only when there is no input arr. So using 0
597 -- XXX It is called only when there is no input arr. So using 0
598 -- as the position is correct?
598 -- as the position is correct?
599 cont (Failure 0 err) count None
599 cont (Failure 0 err) count None
600− ParserD.Partial _ _ -> error "Bug: parseDToK Partial unreachable"
600+ ParserD.Partial _ _ -> error "Bug: adaptCWith Partial unreachable"
601
601
602 -- XXX Maybe we can use two separate continuations instead of using
602 -- XXX Maybe we can use two separate continuations instead of using
603 -- Just/Nothing cases here. That may help in avoiding the parseContJust
603 -- Just/Nothing cases here. That may help in avoiding the parseContJust
@@ -606,19 +606,19 @@ parseDToKSingular pstep initial extract cont !relPos !usedCount !input = do
606 parseCont !cnt !pst (Chunk arr) = parseContChunk cnt pst arr
606 parseCont !cnt !pst (Chunk arr) = parseContChunk cnt pst arr
607 parseCont !cnt !pst None = parseContNothing cnt pst
607 parseCont !cnt !pst None = parseContNothing cnt pst
608
608
609−-- | Similar to "fromParser" but for singular elements.
609+-- | Similar to "adaptC" but for non-chunked input.
610--
610--
611−{-# INLINE_LATE fromParserSingular #-}
611+{-# INLINE_LATE adapt #-}
612−fromParserSingular :: Monad m => ParserD.Parser a m b -> ParserK a m b
612+adapt :: Monad m => ParserD.Parser a m b -> ParserK a m b
613−fromParserSingular (ParserD.Parser step initial extract) =
613+adapt (ParserD.Parser step initial extract) =
614− MkParser $ parseDToKSingular step initial extract
614+ MkParser $ adaptWith step initial extract
615
615
616--------------------------------------------------------------------------------
616--------------------------------------------------------------------------------
617-- Chunked Generic
617-- Chunked Generic
618--------------------------------------------------------------------------------
618--------------------------------------------------------------------------------
619
619
620−{-# INLINE parseDToKGeneric #-}
620+{-# INLINE adaptCGWith #-}
621−parseDToKGeneric
621+adaptCGWith
622 :: forall m a s b r. (Monad m)
622 :: forall m a s b r. (Monad m)
623 => (s -> a -> m (ParserD.Step s b))
623 => (s -> a -> m (ParserD.Step s b))
624 -> m (ParserD.Initial s b)
624 -> m (ParserD.Initial s b)
@@ -628,7 +628,7 @@ parseDToKGeneric
628 -> Int
628 -> Int
629 -> Input (GenArr.Array a)
629 -> Input (GenArr.Array a)
630 -> m (Step (GenArr.Array a) m r)
630 -> m (Step (GenArr.Array a) m r)
631−parseDToKGeneric pstep initial extract cont !offset0 !usedCount !input = do
631+adaptCGWith pstep initial extract cont !offset0 !usedCount !input = do
632 res <- initial
632 res <- initial
633 case res of
633 case res of
634 ParserD.IPartial pst -> do
634 ParserD.IPartial pst -> do
@@ -728,19 +728,19 @@ parseDToKGeneric pstep initial extract cont !offset0 !usedCount !input = do
728 -- XXX It is called only when there is no input arr. So using 0
728 -- XXX It is called only when there is no input arr. So using 0
729 -- as the position is correct?
729 -- as the position is correct?
730 cont (Failure 0 err) count None
730 cont (Failure 0 err) count None
731− ParserD.Partial _ _ -> error "Bug: parseDToKGeneric Partial unreachable"
731+ ParserD.Partial _ _ -> error "Bug: adaptCGWith Partial unreachable"
732
732
733 {-# INLINE parseCont #-}
733 {-# INLINE parseCont #-}
734 parseCont !cnt !pst (Chunk arr) = parseContChunk cnt 0 pst arr
734 parseCont !cnt !pst (Chunk arr) = parseContChunk cnt 0 pst arr
735 parseCont !cnt !pst None = parseContNothing cnt pst
735 parseCont !cnt !pst None = parseContNothing cnt pst
736
736
737−-- | Similar to "fromParser" but is not constrained.
737+-- | Similar to "adaptC" but is not constrained.
738--
738--
739−{-# INLINE_LATE fromParserGeneric #-}
739+{-# INLINE_LATE adaptCG #-}
740−fromParserGeneric ::
740+adaptCG ::
741 Monad m => ParserD.Parser a m b -> ParserK (GenArr.Array a) m b
741 Monad m => ParserD.Parser a m b -> ParserK (GenArr.Array a) m b
742−fromParserGeneric (ParserD.Parser step initial extract) =
742+adaptCG (ParserD.Parser step initial extract) =
743− MkParser $ parseDToKGeneric step initial extract
743+ MkParser $ adaptCGWith step initial extract
744
744
745{-
745{-
746-------------------------------------------------------------------------------
746-------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/StreamK.hs+17−17
@@ -47,10 +47,10 @@ module Streamly.Internal.Data.StreamK
47 , parseD
47 , parseD
48 , parseBreakChunks
48 , parseBreakChunks
49 , parseChunks
49 , parseChunks
50− , parseBreakSingular
50+ , parseBreak
51− , parseSingular
51+ , parse
52− , parseBreakGenericChunks
52+ , parseBreakChunksGeneric
53− , parseGenericChunks
53+ , parseChunksGeneric
54
54
55 -- ** Specialized Folds
55 -- ** Specialized Folds
56 , head
56 , head
@@ -1448,13 +1448,13 @@ backTrackSingular = go
1448
1448
1449-- | Similar to 'parseBreak' but works on singular elements.
1449-- | Similar to 'parseBreak' but works on singular elements.
1450--
1450--
1451−{-# INLINE_NORMAL parseBreakSingular #-}
1451+{-# INLINE_NORMAL parseBreak #-}
1452−parseBreakSingular
1452+parseBreak
1453 :: forall m a b. Monad m
1453 :: forall m a b. Monad m
1454 => ParserK.ParserK a m b
1454 => ParserK.ParserK a m b
1455 -> StreamK m a
1455 -> StreamK m a
1456 -> m (Either ParseError b, StreamK m a)
1456 -> m (Either ParseError b, StreamK m a)
1457−parseBreakSingular parser input = do
1457+parseBreak parser input = do
1458 let parserk = ParserK.runParser parser parserDone 0 0
1458 let parserk = ParserK.runParser parser parserDone 0 0
1459 in go [] parserk input
1459 in go [] parserk input
1460
1460
@@ -1495,7 +1495,7 @@ parseBreakSingular parser input = do
1495 ParserK.Error _ err -> return (Left (ParseError err), nil)
1495 ParserK.Error _ err -> return (Left (ParseError err), nil)
1496
1496
1497 seekErr n =
1497 seekErr n =
1498− error $ "parseBreakSingular: Partial: forward seek not implemented n = "
1498+ error $ "parseBreak: Partial: forward seek not implemented n = "
1499 ++ show n
1499 ++ show n
1500
1500
1501 yieldk
1501 yieldk
@@ -1553,10 +1553,10 @@ parseBreakSingular parser input = do
1553
1553
1554-- | Run a 'ParserK' over a 'StreamK'. Please use 'parseChunks' where possible,
1554-- | Run a 'ParserK' over a 'StreamK'. Please use 'parseChunks' where possible,
1555-- for better performance.
1555-- for better performance.
1556−{-# INLINE parseSingular #-}
1556+{-# INLINE parse #-}
1557−parseSingular :: Monad m =>
1557+parse :: Monad m =>
1558 ParserK.ParserK a m b -> StreamK m a -> m (Either ParseError b)
1558 ParserK.ParserK a m b -> StreamK m a -> m (Either ParseError b)
1559−parseSingular f = fmap fst . parseBreakSingular f
1559+parse f = fmap fst . parseBreak f
1560
1560
1561-------------------------------------------------------------------------------
1561-------------------------------------------------------------------------------
1562-- ParserK Chunked Generic
1562-- ParserK Chunked Generic
@@ -1586,13 +1586,13 @@ backTrackGenericChunks = go
1586
1586
1587-- | Similar to 'parseBreak' but works on generic arrays
1587-- | Similar to 'parseBreak' but works on generic arrays
1588--
1588--
1589−{-# INLINE_NORMAL parseBreakGenericChunks #-}
1589+{-# INLINE_NORMAL parseBreakChunksGeneric #-}
1590−parseBreakGenericChunks
1590+parseBreakChunksGeneric
1591 :: forall m a b. Monad m
1591 :: forall m a b. Monad m
1592 => ParserK.ParserK (GenArr.Array a) m b
1592 => ParserK.ParserK (GenArr.Array a) m b
1593 -> StreamK m (GenArr.Array a)
1593 -> StreamK m (GenArr.Array a)
1594 -> m (Either ParseError b, StreamK m (GenArr.Array a))
1594 -> m (Either ParseError b, StreamK m (GenArr.Array a))
1595−parseBreakGenericChunks parser input = do
1595+parseBreakChunksGeneric parser input = do
1596 let parserk = ParserK.runParser parser parserDone 0 0
1596 let parserk = ParserK.runParser parser parserDone 0 0
1597 in go [] parserk input
1597 in go [] parserk input
1598
1598
@@ -1695,13 +1695,13 @@ parseBreakGenericChunks parser input = do
1695 in foldStream
1695 in foldStream
1696 defState (yieldk backBuf parserk) single stop stream
1696 defState (yieldk backBuf parserk) single stop stream
1697
1697
1698−{-# INLINE parseGenericChunks #-}
1698+{-# INLINE parseChunksGeneric #-}
1699−parseGenericChunks ::
1699+parseChunksGeneric ::
1700 (Monad m)
1700 (Monad m)
1701 => ParserK.ParserK (GenArr.Array a) m b
1701 => ParserK.ParserK (GenArr.Array a) m b
1702 -> StreamK m (GenArr.Array a)
1702 -> StreamK m (GenArr.Array a)
1703 -> m (Either ParseError b)
1703 -> m (Either ParseError b)
1704−parseGenericChunks f = fmap fst . parseBreakGenericChunks f
1704+parseChunksGeneric f = fmap fst . parseBreakChunksGeneric f
1705
1705
1706-------------------------------------------------------------------------------
1706-------------------------------------------------------------------------------
1707-- Sorting
1707-- Sorting