Description
Since I've added some doctests for grow
function we've been experiencing some occasional segfaults on CI, but it was hard to spot where exactly the problem is lurking, since examples themselves seem to be correct and problem can't be replicated outside of doctests. I've experienced very similar problem elsewhere with boxed MutableArray#
and SmallMutableArray#
, so I had a hunch (#382 (comment)) that it had to do with boxed arrays and today we got this error on CI:
src/Data/Vector/Mutable.hs:368: failure in expression `V.unsafeFreeze mv''
expected: [10,20,888,999,777]
but got: [10,20,283563033355,999,777]
^
Examples: 339 Tried: 338 Errors: 0 Failures: 1
See https://github.com/haskell/vector/runs/2461343762?check_suite_focus=true
I'll inline example from haddock for the record:
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Vector.Mutable as MV
-- >>> mv <- V.thaw $ V.fromList ([10, 20, 30] :: [Integer])
-- >>> mv' <- MV.grow mv 2
--
-- The two extra elements at the end of the newly allocated vector will be
-- uninitialized and will result in an error if evaluated, so me must overwrite
-- them with new values first:
--
-- >>> MV.write mv' 3 999
-- >>> MV.write mv' 4 777
-- >>> V.unsafeFreeze mv'
-- [10,20,30,999,777]
--
-- It is important to note that the source mutable vector is not affected when
-- the newly allocated one is mutated.
--
-- >>> MV.write mv' 2 888
-- >>> V.unsafeFreeze mv'
-- [10,20,888,999,777]
-- >>> V.unsafeFreeze mv
-- [10,20,30]
It is clear that there is something really weird going on. I am not 100% sure where the problem is really coming from, although I do suspect it probably is doctests
, but since it originated here I'd like to have it as a starting point.
@Shimuuar You've expressed interest in investigating it. Any ideas?