@@ -460,9 +460,31 @@ deriving anyclass instance Typeable s
460460 GrowingVector
461461-------------------------------------------------------------------------------}
462462
463- deriving stock instance Generic (GrowingVector s a )
464- deriving anyclass instance (Typeable s , Typeable a , NoThunks a )
465- => NoThunks (GrowingVector s a )
463+ instance (NoThunks a , Typeable s , Typeable a ) => NoThunks (GrowingVector s a ) where
464+ showTypeOf (p :: Proxy (GrowingVector s a )) = show $ typeRep p
465+ wNoThunks ctx
466+ (GrowingVector (a :: STRef s (VM. MVector s a )) (b :: PrimVar s Int ))
467+ = allNoThunks [
468+ noThunks ctx b
469+ -- Check that the STRef is in WHNF
470+ , noThunks ctx $ OnlyCheckWhnf a
471+ -- Check that the MVector is in WHNF
472+ , do
473+ mvec <- unsafeSTToIO $ readSTRef a
474+ noThunks ctx' $ OnlyCheckWhnf mvec
475+ -- Check that the vector elements contain no thunks. The vector
476+ -- contains undefined elements after the first @n@ elements
477+ , do
478+ n <- unsafeSTToIO $ readPrimVar b
479+ mvec <- unsafeSTToIO $ readSTRef a
480+ allNoThunks [
481+ unsafeSTToIO (VM. read mvec i) >>= \ x -> noThunks ctx'' x
482+ | i <- [0 .. n- 1 ]
483+ ]
484+ ]
485+ where
486+ ctx' = showTypeOf (Proxy @ (STRef s (VM. MVector s a ))) : ctx
487+ ctx'' = showTypeOf (Proxy @ (VM. MVector s a )) : ctx'
466488
467489{- ------------------------------------------------------------------------------
468490 Baler
@@ -662,15 +684,21 @@ instance (NoThunks a, Typeable s, Typeable a) => NoThunks (MutableHeap s a) wher
662684 (MH (a :: PrimVar s Int ) (b :: SmallMutableArray s a ))
663685 = allNoThunks [
664686 noThunks ctx a
665- -- the small array may contain bogus/undefined placeholder values
666- -- after the first @n@ elements in the heap
667- , noThunks ctx $! do
687+ -- Check that the array is in WHNF
688+ , noThunks ctx (OnlyCheckWhnf b)
689+ -- Check that the array elements contain no thunks. The small array
690+ -- may contain undefined placeholder values after the first @n@
691+ -- elements in the array. The very first element of the array can also
692+ -- be undefined.
693+ , do
668694 n <- unsafeSTToIO (readPrimVar a)
669695 allNoThunks [
670- unsafeSTToIO (readSmallArray b i) >>= \ x -> noThunks ctx x
671- | i <- [0 .. n- 1 ]
696+ unsafeSTToIO (readSmallArray b i) >>= \ x -> noThunks ctx' x
697+ | i <- [1 .. n- 1 ]
672698 ]
673699 ]
700+ where
701+ ctx' = showTypeOf (Proxy @ (SmallMutableArray s a )) : ctx
674702
675703{- ------------------------------------------------------------------------------
676704 IOLike
0 commit comments