nothunks 0.1.0.0 → 0.1.1.0
raw patch · 3 files changed
+56/−33 lines, 3 filesdep ~basedep ~bytestringdep ~containers
Dependency ranges changed: base, bytestring, containers, ghc-heap, ghc-prim, hedgehog, random, tasty, tasty-hedgehog, text, time, vector
Files
- CHANGELOG.md +7/−1
- nothunks.cabal +28/−15
- src/NoThunks/Class.hs +21/−17
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for nothunks +## 0.1.1.0 -- 2020-09-29++* Export `Context` and `GWNoThunks`+* Fix typos in Haddocks+* Improve bounds (and add upper bounds)+ ## 0.1.0.0 -- 2020-09-09 -* Initial public release +* Initial public release
nothunks.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: nothunks-version: 0.1.0.0+version: 0.1.1.0 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@@ -22,13 +22,17 @@ library exposed-modules: NoThunks.Class+ build-depends: base >= 4.12 && < 5- , bytestring >= 0.10- , containers >= 0.6- , ghc-heap >= 8.6- , text >= 1.2- , time >= 1.8- , vector >= 0.12+ , bytestring >= 0.10 && < 0.11+ , containers >= 0.5 && < 0.7+ , text >= 1.2 && < 1.3+ , time >= 1.5 && < 1.11+ , vector >= 0.12 && < 0.13++ -- Whatever is bundled with ghc+ , ghc-heap+ hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall@@ -37,15 +41,24 @@ type: exitcode-stdio-1.0 main-is: Main.hs other-modules: Test.NoThunks.Class- build-depends: base >= 4.12- , containers >= 0.6- , ghc-prim >= 0.5- , hedgehog >= 1.0- , random >= 1.1- , tasty >= 1.2- , tasty-hedgehog >= 1.0- , text >= 1.2++ build-depends: base++ -- Self dependency , nothunks++ -- Dependencies shared with the lib+ , containers++ -- Whatever is bundled with ghc+ , ghc-prim++ -- Additional dependencies+ , hedgehog >= 1.0 && <= 1.1+ , random >= 1.1 && <= 1.3+ , tasty >= 1.3 && <= 1.4+ , tasty-hedgehog >= 1.0 && <= 1.1+ hs-source-dirs: test default-language: Haskell2010 ghc-options: -Wall
src/NoThunks/Class.hs view
@@ -9,16 +9,17 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE TypeFamilies #-} module NoThunks.Class ( -- * Check a value for unexpected thunks NoThunks(..) , ThunkInfo(..)+ , Context , unsafeNoThunks- -- * Helpders for defining instances+ -- * Helpers for defining instances , allNoThunks , noThunksInValues , noThunksInKeysAndValues@@ -29,6 +30,8 @@ , InspectHeapNamed(..) , AllowThunk(..) , AllowThunksIn(..)+ -- * Generic class+ , GWNoThunks(..) ) where import Data.Proxy@@ -46,7 +49,7 @@ import Data.Foldable (toList) import Data.Int import Data.IntMap (IntMap)-import Data.List.NonEmpty (NonEmpty(..))+import Data.List.NonEmpty (NonEmpty (..)) import Data.Map (Map) import Data.Ratio import Data.Sequence (Seq)@@ -78,11 +81,11 @@ -- -- For most datatypes, we should have that --- -- > noThunks ctxt x == NoThunks+ -- > noThunks ctxt x == Nothing -- -- if and only if --- -- > containsThunks x+ -- > checkContainsThunks x -- -- For some datatypes however, some thunks are expected. For example, the -- internal fingertree 'Data.Sequence.Sequence' might contain thunks (this is@@ -95,12 +98,12 @@ -- 'noThunks' to force such "expected thunks", as long as it always -- reports the /unexpected/ thunks. --- -- The default implementation of 'noThunks' checks that the argument- -- is in WHNF, and if so, adds the type into the context (using 'showTypeOf'),- -- and calls 'wNoThunks'. See 'UnexpectedThunkInfo' for a- -- detailed discussion of the type context.+ -- The default implementation of 'noThunks' checks that the argument is in+ -- WHNF, and if so, adds the type into the context (using 'showTypeOf'), and+ -- calls 'wNoThunks'. See 'ThunkInfo' for a detailed discussion of the type+ -- context. --- -- See also discussion of caveats listed for 'NF.containsThunks'.+ -- See also discussion of caveats listed for 'checkContainsThunks'. noThunks :: Context -> a -> IO (Maybe ThunkInfo) noThunks ctxt x = do isThunk <- checkIsThunk x@@ -188,6 +191,7 @@ deriving (Show) {-# NOINLINE unsafeNoThunks #-}+-- | Call 'noThunks' in a pure context (relies on 'unsafePerformIO'). unsafeNoThunks :: NoThunks a => a -> Maybe ThunkInfo unsafeNoThunks a = unsafePerformIO $ noThunks [] a @@ -272,7 +276,7 @@ -- | Newtype wrapper for use with @deriving via@ to inspect the heap directly -- -- This bypasses the class instances altogether, and inspects the GHC heap--- directly, checking that the value does not contain any thunks _anywhere_.+-- directly, checking that the value does not contain any thunks /anywhere/. -- Since we can do this without any type classes instances, this is useful for -- types that contain fields for which 'NoThunks' instances are not available. --@@ -621,15 +625,15 @@ -- | We do NOT check function closures for captured thunks by default ----- Since we have no type information about the values captured in a thunk,--- the only check we could possibly do is 'containsThunks': we can't recursively--- call 'noThunks' on those captured values, which is problematic if--- any of those captured values /requires/ a custom instance (for example,--- data types that depend on laziness, such as 'Seq').+-- Since we have no type information about the values captured in a thunk, the+-- only check we could possibly do is 'checkContainsThunks': we can't+-- recursively call 'noThunks' on those captured values, which is problematic if+-- any of those captured values /requires/ a custom instance (for example, data+-- types that depend on laziness, such as 'Seq'). -- -- By default we therefore /only/ check if the function is in WHNF, and don't -- check the captured values at all. If you want a stronger check, you can--- use @IsNormalForm (a -> b)@ instead.+-- use @'InspectHeap' (a -> b)@ instead. deriving via OnlyCheckWhnfNamed "->" (a -> b) instance NoThunks (a -> b) -- | We do not check IO actions for captured thunks by default