-
Notifications
You must be signed in to change notification settings - Fork 57
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
feat: Add lazy isolation mode #111
base: master
Are you sure you want to change the base?
Conversation
`ensure` is a publically exported function, which has some odd behaviour when given a byte length of zero or less. It raises an error when the value is zero, but happily returns a value when the byte length is negative. I've switched these two behaviours around. ``` λ> runGet (ensure (-1)) "0123" Right "0123" λ> runGet (isolate 0 getWord8) "0123" Left "too few bytes\nFrom:\tdemandInput\n\n" ``` ``` λ> runGet (ensure (-1)) "0123" Left "Failed reading: Attempted to ensure negative amount of bytes\nEmpty call stack\n" λ> runGet (ensure 0) "0123" Right "" ```
This adds an internal variant, `ensure'`, which is used to avoid checking for `0` and `<0` more than once in a given code path.
18d321e
to
5f137ef
Compare
5f137ef
to
2dc6b02
Compare
8fbf050
to
ac8c7be
Compare
Taking this out of draft mode, because I've got it integrated with |
@glguy quick ping, because you're the last committer/merger to the repo. It doesn't look like there have been any major updates to |
@glguy would you be able to take a look at this please? Or do you know of someone who could? |
@elliottt any chance of a review, or an opinion on this change? I'd really appreciate it. |
I'll take a week this weekend 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this, I like this new version of isolate
! I had a few questions before approving.
9e3137e
to
e585e8d
Compare
e585e8d
to
ec27184
Compare
a4a2e18
to
c97df67
Compare
This adds a lazy (incremental) isolation combinator.
The use case I have for it is this:
pinch
, which decodes thrift messages usingcereal
isolate
s parsing the apparently astronomically huge message hereBy introducing an incremental isolation primitive, users can make sure the data they're parsing is valid before it all hits main memory.
Implementation notes
I tried to make sure the errors were as close as possible between
isolate
andisolateLazy
. This is useful for fuzzing the implementation with quickcheck, as well as just good practice. This meant I had to expose more of the failure API. I could have added an internal partial runner, which exposes this information, but that seemed like it would require a lot of changes, so I opted for adding the info to the current partial runner, and added a pattern synonym so that users (shouldn't) notice a difference.These changes are stacked on #110