Skip to content

Make ParserD consistent with ParserK#2811

Merged
harendra-kumar merged 20 commits intomasterfrom
parser-mod
Jun 21, 2025
Merged

Make ParserD consistent with ParserK#2811
harendra-kumar merged 20 commits intomasterfrom
parser-mod

Conversation

@adithyaov
Copy link
Copy Markdown
Member

This needs to be reviewed very carefully.

Comment thread core/src/Streamly/Internal/Data/Fold/Chunked.hs Outdated
Comment thread core/src/Streamly/Internal/Data/ParserK/Type.hs Outdated
@adithyaov adithyaov linked an issue Oct 4, 2024 that may be closed by this pull request
@adithyaov adithyaov force-pushed the parser-mod branch 2 times, most recently from 2c79b5b to 039bc03 Compare October 5, 2024 06:10
@adithyaov adithyaov force-pushed the parser-mod branch 7 times, most recently from d047c6a to 0dc282e Compare November 7, 2024 11:02
assert (n >= 0)
(return $ Continue (- n) (parseCont (count - n) pst1))
ParserD.SDone m b ->
let n = 1 - m
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks incorrect based on the IMPORTANT note above. But why is no test failing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Was the IMPORTANT note incorrect?

assert (n >= 0)
(return $ Continue (- n) (parseCont (count - n) pst1))
ParserD.SDone m b ->
let n = 1 - m
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks incorrect based on the IMPORTANT note above. But why is no test failing?

let n = Prelude.length backBuf
arr0 = fromListN n (Prelude.reverse backBuf)
return (Left (ParseError err), StreamK.fromPure arr0)
-}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Why did you comment this out?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is redundant and requires unnecessary maintenance, should perhaps be removed.

if not (cond a)
then return res
else extractStep pextract res
else
Copy link
Copy Markdown
Member Author

@adithyaov adithyaov Jun 11, 2025

Choose a reason for hiding this comment

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

Was the previous code on origin/master incorrect?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think so. It has to be changed because of the extract changes.

-- If the parser is backtracking we let it backtrack even if the
-- predicate is true.
fmap (first Left') $ case res of
SPartial 1 s1 -> mapCount (+1) <$> pextract s1
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Please verify: The reason we do this is because extract does not need to account for the current element whereas step has to.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes.

let taken = cnt1 - n
SPartial _ _ -> error "takeP: SPartial in extract"
SPartial n s -> do
let taken = cnt + n
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Shouldn't this be cnt + n - 1?

Copy link
Copy Markdown
Member Author

@adithyaov adithyaov Jun 11, 2025

Choose a reason for hiding this comment

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

Oh nvm, I misread. cnt1 vs cnt. cnt1 == cnt + 1

Comment thread core/src/Streamly/Internal/Data/Parser.hs
pRes <- pstep pst x
case pRes of
PR.Partial 0 pst1 ->
PR.SPartial 1 pst1 ->
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The accounting in goExtract should be similar to goStop?
Partial n == SPartial -n
So SPartial 0 here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Similar changes need to be made to the rest of the function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We are running pstep pst x above feeding it one element, therefore we need to take into account the element we fed. In goStop we are calling extract instead which is different.

Comment on lines -444 to -446
-- IMPORTANT: the n here is from the byte stream parser, that means
-- it is the backtrack element count and not the stream position
-- index into the current input chunk.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is this note incorrect?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, this is what we changed to make ParserD and ParserK consistent.

Copy link
Copy Markdown
Member Author

@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.

1 bug. The rest looks good.

@harendra-kumar harendra-kumar merged commit 0ddbd48 into master Jun 21, 2025
18 of 21 checks passed
@harendra-kumar harendra-kumar deleted the parser-mod branch June 21, 2025 12:45
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.

Parser Step representation: make ParserK and ParserD consistent

2 participants