Skip to content

Fix splitSepByOneOf on large Word64 values - #3265

Merged
harendra-kumar merged 4 commits into
masterfrom
splitSepByOneOf-fixes
Oct 20, 2026
Merged

harendra-kumar merged 4 commits into
masterfrom
splitSepByOneOf-fixes

Conversation

@harendra-kumar

Copy link
Copy Markdown
Member

splitSepByOneOf hashed elements with fromEnum, which fails on Word64
values above maxBound :: Int. It now hashes the bytes of each element
instead, and no longer needs Enum.

The hash and word-packing helpers moved to a separate module, shared by the other sequence search functions.

Also adds pending tests for the same kinds of bugs in the other functions:
signed elements and large Word64 values. The fixes will come in a follow-up PR.

The Karp-Rabin hash called fromEnum, which fails on Word64 values above
maxBound :: Int. Hash the bytes of the elements instead, reading an
element of size 1, 2, 4 or 8 as one unsigned word; a hash match is
already confirmed by comparing bytes. splitSepByOneOf no longer needs an
Enum constraint.

The hash helpers are in the new Streamly.Internal.Data.SeqMatch module.

In the loop phase, read the falling-out element of the longest pattern
before overwriting it with the new element and the others after, in a
single zipWithM pass.
Move the word packing and decoding and the Karp-Rabin hash arithmetic
of Fold.takeEndBySeq, Fold.takeEndBySeq_ and, in Stream, takeEndBySeq,
takeEndBySeq_, splitSepBySeq_, splitOnSuffixSeq, dropMatches,
replaceMatches and dropSuffix to Streamly.Internal.Data.SeqMatch. The
code is unchanged, elements are still packed and hashed using fromEnum.
The tests are marked pending: packing a negative element into a word
without masking it gives a false match, decoding a buffered element
without sign extension fails for Int8, and the Karp-Rabin hash calls
fromEnum, which fails on Word64 values above maxBound :: Int.
The haddock build of streamly-core on GHC 9.8.4 needs more than the
500M set by limit-build-mem (it peaked at 522M in use). Override it
for packdiff only, via cabal.project.local which survives packdiff's
git checkouts.
@harendra-kumar
harendra-kumar merged commit 389e188 into master Oct 20, 2026
18 of 19 checks passed
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.

1 participant