streamly
streamly copied to clipboard
Unreproducible failure in Unicode.Stream test suite
On GHC-8.6.5, in a PR based on 5d096dfad
Failures:
Streamly/Test/Unicode/Stream.hs:177:9:
1) Unicode.Stream, UTF8 - Encoding / Decoding, Arrays Streamly.Data.String.lines == Prelude.lines
Assertion failed (after 766 tests):
zipAsyncly Compose three - empty in the middle [✔]
[48,89,237,128,185,236,161,51,229,204,167,5,154,15,252,80,71,15,179,204]
To rerun use: --match "/Unicode.Stream/UTF8 - Encoding / Decoding/Arrays Streamly.Data.String.lines == Prelude.lines/" --seed 1380626044
+++ OK, passed 100 tests.
Randomized with seed 1380626044
The relevant test is:
testLinesArray :: Property
testLinesArray =
forAll genWord8 $ \list ->
monadicIO $ do
xs <- Stream.toList
$ fmap A.toList
$ AS.splitOnSuffix 10
$ Stream.fromPure (A.fromList list)
assert (xs == map (map (fromIntegral . ord))
(lines (map (chr . fromIntegral) list)))
Could be an issue with AS.splitOnSuffix?
{-# INLINE splitOnSuffix #-}
splitOnSuffix
:: (MonadIO m)
=> Word8
-> Stream m (Array Word8)
-> Stream m (Array Word8)
splitOnSuffix = Array.compactOnByteSuffix
{-# INLINE compactOnByteSuffix #-}
compactOnByteSuffix
:: (MonadIO m)
=> Word8
-> Stream m (Array Word8)
-> Stream m (Array Word8)
compactOnByteSuffix byte =
fmap unsafeFreeze . MA.compactOnByteSuffix byte . fmap unsafeThaw
{-# INLINE compactOnByteSuffix #-}
compactOnByteSuffix
:: (MonadIO m)
=> Word8
-> Stream m (MutArray Word8)
-> Stream m (MutArray Word8)
compactOnByteSuffix byte =
-- XXX use spliceExp and rightSize?
Stream.splitInnerBySuffix
(\arr -> byteLength arr == 0) (breakOn byte) splice
breakOn uses unpinned pointer in memcpy, could it be because of that?
PR #2818 fixes the issue by using correct FFI semantics, avoiding garbage collection between getting a pointer and invoking FFI call.