Repository navigation
More fixes in Serialize, RingArray and friends - #3256
Merged
Merged
Conversation
harendra-kumar
force-pushed
the
ring-serialize-fixes
branch
from
October 15, 2026 07:54
87f64d7 to
b941e35
Compare
show (Just arr) produced "Just fromList [...]" which cannot be read back, and Read failed on parenthesized input or leading whitespace. Use showsPrec with showParen, and parens/prec/lexP in readPrec, the same as the Stream instances.
unsafeByteCmp returned the result of compareByteArrays# as a thunk, the bytes were compared when the result was evaluated. If either array was modified in between, the result was that of the modified bytes.
The Serialize instances of () and Proxy advanced the offset by one byte
without writing it, leaving the byte uninitialized. The Serialize class
guarantees that the same value always serializes to the same bytes, which
these instances did not satisfy. Write a 0 to the byte.
Document which bytes Unbox does not write ("Unwritten bytes" in
Streamly.Internal.Data.Unbox), the deterministic encoding of Serialize and
its unit types ("Deterministic encoding" in
Streamly.Internal.Data.Serialize.Type), and the user facing summary in
Streamly.Data.MutByteArray. The Serialize instance of Array copies the
Unbox bytes of its elements and is not deterministic for element types whose
Unbox instance leaves bytes unwritten, add a TODO for it.
The Serialize instance of Proxy and the derived instances of types with a single constructor without fields did not check the buffer bounds, they deserialized a value one byte beyond the end of the buffer. A list of such values with a corrupt length deserialized past the end of the buffer without an error, a length of -1 never terminated.
Deserializing a list with a negative length did not stop at zero elements, it read elements until it ran past the end of the buffer, or never terminated if the elements took no space to deserialize.
Deserializing an Array with a negative length passed the bounds check and failed later with "newByteArray: size must be >= 0". A length close to maxBound made the end offset overflow and pass the bounds check. Check for a negative length and compare the length with the remaining bytes in the buffer.
getIndex compared the element index with the ring size in bytes, so an index from the length up to the byte size wrapped around instead of returning Nothing. getIndex 5 on a 5-element Int ring returned the head element.
cast checked only that the ring byte length is a multiple of the target element size. A ring head at a byte offset that is not a multiple of the target element size makes elements straddle the end of the ring, so reads go past the end of the memory. cast now returns Nothing in that case.
fold read the element at the head before checking the ring size, so a zero-sized ring folded one garbage element. createOfLast returns a zero-sized ring for an empty stream, so RingArray.fold Fold.toList on it returned [0] instead of []. foldlM' uses fold and had the same problem.
eqArray and eqArrayN compared the ring with the bytes from offset 0 of the array's memory instead of from the array's start offset, so they gave wrong results when the array is a slice.
The read tests and the writeChunks test did not close the Handles they opened, the finalizers closed them later at arbitrary times. On the JS backend before GHC 9.14.1, a close can remove the table entry of a file descriptor reused by a file opened at the same time (h$base_closeFile in base.js), closing that file then fails with EINVAL. A close from a finalizer races with the test running at that time even when the tests run serially, and a close in a parallel test races with an open in another. Close all the Handles in the tests and run the tests sequentially on JS before GHC 9.14.
The listDir*Par* tests crash the JS runtime intermittently, with "h$ap_1_1_fast: unexpected closure type: 2" or "TypeError: Cannot read properties of undefined (reading 't')". Mark them pending on JS.
Add a section to Streamly.Data.MutByteArray on choosing between Unbox and Serialize: the purpose, the supported types, bounds checks, word size, deterministic bytes, schema options and byte order. Remove the claim that Serialize is a superset of Unbox. The Unbox and Serialize class docs point to this section. A blank line ended the module header doc, the sections after the FFI section were not rendered by haddock. Join them to the module header.
harendra-kumar
force-pushed
the
ring-serialize-fixes
branch
from
October 15, 2026 08:26
b941e35 to
d908591
Compare
Git for Windows 2.56 moved /mingw64 to /ucrt64, so curl and other tools were not found in the PATH passed to packcheck. The macOS image ships Command Line Tools 27.0 with default Xcode 26.6; linking against the CLT SDK fails with a tapi "unknown architecture arm64e.x1-macos" error. Select the default Xcode so that the compiler, linker and SDK come from the same toolchain. GHC records the SDK library path when it is installed, and the GHC restored from the cache passed the CLT SDK path to the linker. Add the Xcode version and build to the macOS GHC and dependency cache keys, so that a runner image with a different Xcode installs GHC afresh.
harendra-kumar
force-pushed
the
ring-serialize-fixes
branch
from
October 15, 2026 09:14
d908591 to
e5c153d
Compare
With the default -j, 4 on the 4 CPU VM, the VM with 6 GB of memory killed cabal while it was building fusion-plugin and other dependencies in parallel. Limiting the parallelism keeps the job within the default VM size.
The network package fails to build on the old Windows images that AppVeyor uses, the AppVeyor webhook is deactivated. The GitHub Actions Windows build covers Windows.
The x86_64 stack binary that packcheck downloaded ran under Rosetta on the arm64 macOS runner and installed an x86_64 GHC, whose link failed with the Command Line Tools SDK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code review fixes, mostly in Serialize and RingArray, plus some CI fixes.
Serialize
RingArray
Misc
CI