nothunks 0.3.1 → 0.3.2
raw patch · 3 files changed
+84/−16 lines, 3 filesdep +data-array-bytedep ~hedgehogdep ~timePVP ok
version bump matches the API change (PVP)
Dependencies added: data-array-byte
Dependency ranges changed: hedgehog, time
API changes (from Hackage documentation)
+ NoThunks.Class: instance NoThunks.Class.NoThunks (Data.Vector.Primitive.Vector a)
+ NoThunks.Class: instance NoThunks.Class.NoThunks (Data.Vector.Storable.Vector a)
+ NoThunks.Class: instance NoThunks.Class.NoThunks Data.Array.Byte.ByteArray
+ NoThunks.Class: instance NoThunks.Class.NoThunks a => NoThunks.Class.NoThunks (Data.Vector.Strict.Vector a)
Files
- CHANGELOG.md +6/−0
- nothunks.cabal +6/−4
- src/NoThunks/Class.hs +72/−12
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for nothunks +## 0.3.2 -- 2026-07-16++* `NoThunks` instance for `Data.Array.Byte.ByteArray`.+* `NoThunks` instances for `Data.Vector.Primitive`, `Data.Vector.Storable` and `Data.Vector.Strict`+* Improved formatting of `InfoProv` when it's available.+ ## 0.3.1 -- 2025-07-30 * Make it build with ghc-9.12.
nothunks.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: nothunks-version: 0.3.1+version: 0.3.2 synopsis: Examine values for unexpected thunks description: Long lived application data typically should not contain any thunks. This library can be used to examine values for@@ -43,13 +43,15 @@ build-depends: base >= 4.12 && < 5 , containers >= 0.5 && < 0.9 , stm >= 2.5 && < 2.6- , time >= 1.5 && < 1.15+ , time >= 1.5 && < 1.17 -- Whatever is bundled with ghc , ghc-heap + if impl(ghc < 9.4)+ build-depends: data-array-byte if impl(ghc >= 9.2)- build-depends: wherefrom-compat ^>= 0.2+ build-depends: wherefrom-compat >= 0.1.1 && < 0.3 if flag(bytestring) build-depends: bytestring >= 0.10 && < 0.13@@ -80,7 +82,7 @@ , ghc-prim -- Additional dependencies- , hedgehog >= 1.1 && < 1.6+ , hedgehog >= 1.1 && < 1.8 , random >= 1.1 && < 1.4 , tasty >= 1.3 && < 1.6 , tasty-hedgehog >= 1.1 && < 1.5
src/NoThunks/Class.hs view
@@ -77,6 +77,7 @@ import qualified Control.Concurrent.MVar as MVar import qualified Control.Concurrent.STM.TVar as TVar+import qualified Data.Array.Byte as ByteArray import qualified Data.IntMap as IntMap import qualified Data.IORef as IORef import qualified Data.Map as Map@@ -99,8 +100,14 @@ #ifdef MIN_VERSION_vector import qualified Data.Vector as Vector.Boxed+import qualified Data.Vector.Primitive as Vector.Primitive+import qualified Data.Vector.Storable as Vector.Storable import qualified Data.Vector.Unboxed as Vector.Unboxed++#if MIN_VERSION_vector(0,13,2)+import qualified Data.Vector.Strict as Vector.Boxed.Strict #endif+#endif {------------------------------------------------------------------------------- Check a value for unexpected thunks@@ -238,13 +245,36 @@ -- mkThunkInfo :: Context -> a -> IO ThunkInfo #if MIN_VERSION_base(4,16,0)-mkThunkInfo ctxt a = ThunkInfo ctxt . fmap fmt <$> whereFrom a+mkThunkInfo ctxt a = ThunkInfo ctxt . (>>= fmt) <$> whereFrom a where- fmt :: InfoProv -> Info- fmt InfoProv { ipSrcFile, ipSrcSpan,- ipLabel, ipTyDesc } =- ipLabel ++ " :: " ++ ipTyDesc- ++ " @ " ++ ipSrcFile ++ ":" ++ ipSrcSpan+ fmt :: InfoProv -> Maybe Info+ fmt InfoProv { ipSrcFile, ipSrcSpan, ipLabel, ipTyDesc }+ | null ipLabel+ , null ipSrcSpan+ , null ipSrcFile+ , null ipTyDesc+ = Nothing++ | otherwise+ = Just $+ cmb (cmb ipLabel " :: " ipTyDesc)+ " @ "+ (cmb ipSrcFile ":" ipSrcSpan)++ cmb x y z+ | not (null x)+ , not (null z)+ = x ++ y ++ z++ | not (null z)+ = z++ | not (null x)+ = x++ | otherwise+ = ""+ #else mkThunkInfo ctxt _ = return (ThunkInfo ctxt Nothing) #endif@@ -603,7 +633,24 @@ deriving via InspectHeap UTCTime instance NoThunks UTCTime deriving via InspectHeap ZonedTime instance NoThunks ZonedTime + {-------------------------------------------------------------------------------+ ByteArray+-------------------------------------------------------------------------------}++-- | Instance for byte-arrays+--+-- We have+--+-- > data ByteArray = ByteArray ByteArray#+--+-- values of this type consist of a tag followed by an _unboxed_ byte array,+-- which can't contain thunks. Therefore we only check WHNF.+-- This is the same as for ShortByteString.+deriving via OnlyCheckWhnfNamed "ByteArray" ByteArray.ByteArray+ instance NoThunks ByteArray.ByteArray++{------------------------------------------------------------------------------- ByteString -------------------------------------------------------------------------------} @@ -766,7 +813,22 @@ showTypeOf _ = "Unboxed.Vector" wNoThunks _ _ = return Nothing +instance NoThunks (Vector.Primitive.Vector a) where+ showTypeOf _ = "Primitive.Vector"+ wNoThunks _ _ = return Nothing++instance NoThunks (Vector.Storable.Vector a) where+ showTypeOf _ = "Storable.Vector"+ wNoThunks _ _ = return Nothing++#if MIN_VERSION_vector(0,13,2)++instance NoThunks a => NoThunks (Vector.Boxed.Strict.Vector a) where+ showTypeOf _ = "Boxed.Strict.Vector"+ wNoThunks ctxt = noThunksInValues ctxt . Vector.Boxed.Strict.toList+ #endif+#endif {------------------------------------------------------------------------------- Function types@@ -865,12 +927,10 @@ where go :: Box -> IO Bool go b = do- c <- getBoxedClosureData b- if closureIsThunk c then- return True- else do- c' <- getBoxedClosureData b- anyM go (allClosures c')+ c <- getBoxedClosureData b+ if closureIsThunk c+ then return True+ else anyM go (allClosures c) -- | Check if the given 'Closure' is a thunk. --