Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Data.Parser.ParserD.deintercalate #843

Closed
wants to merge 1 commit into from

Conversation

specdrake
Copy link
Collaborator

No description provided.

@specdrake specdrake marked this pull request as ready for review December 19, 2020 19:53
@adithyaov
Copy link
Member

@specdrake Can you resolve the conflicts? I'll review it after.

@specdrake
Copy link
Collaborator Author

@specdrake Can you resolve the conflicts? I'll review it after.

Can you take a look at this now?

Comment on lines +782 to +788
deintercalate fld1 prsr1 fld2 prsr2 =
K.toParserK $
D.deintercalate
fld1
(K.fromParserK prsr1)
fld2
(K.fromParserK prsr2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
deintercalate fld1 prsr1 fld2 prsr2 =
K.toParserK $
D.deintercalate
fld1
(K.fromParserK prsr1)
fld2
(K.fromParserK prsr2)
deintercalate f1 p1 f2 p2 =
K.toParserK $ D.deintercalate f1 (K.fromParserK p1) f2 (K.fromParserK p2)

pinit1 <- pinitial1
finit2 <- finitial2
pinit2 <- pinitial2
return (finit1, pinit1, finit2, pinit2, Parser1, 0::Int)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the benchmarks, you might want to use a strict state, Tuple6'

pinit2 <- pinitial2
return (finit1, pinit1, finit2, pinit2, Parser1, 0::Int)

step (fs1, ps1, fs2, ps2, currentParser, numBuffered) a =
Copy link
Member

@adithyaov adithyaov Feb 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of currentParser you can probaly simplify this if you use Bool. Something like isParser1. Your call. You can try both and check the benchmarks. I suspect they won't differ much though.

st <- pstep1 ps1 a
case st of
Partial n ps1new ->
return $ Partial n (fs1, ps1new, fs2, ps2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the tuple on the same line?

Comment on lines +689 to +693
let
newNumBuffered =
if n==0
then numBuffered + 1
else numBuffered - n
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If numBuffered + 1 - n < 0 there is some flaw in the logic. You should use asserts instead.
Also, shouldn't it be numBuffered + 1 - n instead of numBuffered - n?

if n==0
then numBuffered + 1
else numBuffered - n
return $ Continue n (fs1, ps1new, fs2, ps2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the tuple on the same line?

Done n result -> do
res1 <- fstep1 fs1 result
pinit1 <- pinitial1
pinit2 <- pinitial2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are multiple unrequired initializations here.
Looks like ps2 is pinit2
If you don't need both the states at once, you can probably encode the parser state in the constructors themselves.

Parser2, numBuffered)
FL.Done result1 -> do
result2 <- fextract2 fs2
return $ Done numBuffered (result1, result2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just backtrack n elements here? Why numBuffered elements?

-- input definitively rejected by the first parser
pinit1 <- pinitial1
pinit2 <- pinitial2
return $ Partial numBuffered (fs1, pinit1, fs2, pinit2,
Copy link
Member

@adithyaov adithyaov Feb 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should backtrack numBuffered + 1 elements here instead of numBuffered?
And restart the buffer count from 0 instead of numBuffered - 1?

Parser2, numBuffered-1)
-- return $ Done numBuffered (result1, result2)

Parser2 -> do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments made above apply to this branch.

@@ -59,6 +59,11 @@ benchIOSink value name f =
-------------------------------------------------------------------------------
-- Parsers
-------------------------------------------------------------------------------
{-# INLINE deintercalate #-}
deintercalate :: MonadCatch m => Int -> SerialT m Int -> m ((), ())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need benchmarks for ParserD as well.

-- Left _ -> property False

deintercalate :: Property
deintercalate =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being tested in Parser as well. I guess you can skip testing this here.

Copy link
Member

@adithyaov adithyaov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments. I see some correctness issues but the tests give no failure.
Either I've misunderstood, if so, please revet back by responding to the comments.
Else we probably need more elaborarte tests hitting all the branches.

I see some indentation issues as well. That's not a big deal though.
I'll reindent this in the end. Diffing that with this will probably makes thing clear w.r.t indentation.

@specdrake
Copy link
Collaborator Author

Please address the comments. I see some correctness issues but the tests give no failure.
Either I've misunderstood, if so, please revet back by responding to the comments.
Else we probably need more elaborarte tests hitting all the branches.

I see some indentation issues as well. That's not a big deal though.
I'll reindent this in the end. Diffing that with this will probably makes thing clear w.r.t indentation.

I'll try to do this by today.

@specdrake
Copy link
Collaborator Author

specdrake commented Feb 17, 2021

Please address the comments. I see some correctness issues but the tests give no failure.
Either I've misunderstood, if so, please revet back by responding to the comments.
Else we probably need more elaborarte tests hitting all the branches.

I see some indentation issues as well. That's not a big deal though.
I'll reindent this in the end. Diffing that with this will probably makes thing clear w.r.t indentation.

I had made the changes but I am unable to benchmarks and tests because of the following errors:

    Module
    ‘Streamly.Internal.Data.Time.Clock’
    does not export
    ‘asyncClock’
   |
94 |     (Clock(Monotonic), asyncClock, readClock)
   |                        ^^^^^^^^^^

src/Streamly/Internal/Data/Stream/StreamD/Generate.hs:94:36: error:
    Module
    ‘Streamly.Internal.Data.Time.Clock’
    does not export
    ‘readClock’
   |
94 |     (Clock(Monotonic), asyncClock, readClock)

I have tried using cabal clean as suggested but it also removes chart executable and I have to run
nix-shell --argstr c2nix "--flag dev" --run "cabal build chart --flag dev" but running benchmarks/tests again shows the above error.

@harendra-kumar
Copy link
Member

Superseded by #1600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants