nothunks 0.2.1.0 → 0.2.1.1
raw patch · 4 files changed
+37/−8 lines, 4 filesdep ~timenew-uploader
Dependency ranges changed: time
Files
- CHANGELOG.md +5/−0
- README.md +20/−0
- nothunks.cabal +3/−3
- src/NoThunks/Class.hs +9/−5
CHANGELOG.md view
@@ -2,6 +2,11 @@ ## 0.2.1.0 -- 2024-02-06 +* Exported `mkThunkInfo`.+* Test support of `ghc-9.10`.++## 0.2.1.0 -- 2024-02-06+ * Support `wherefrom` with `GHC-9.2` or newer. (Teo Camarasu, [#49](https://github.com/input-output-hk/nothunks/pull/49)) ## 0.2.0 -- 2024-01-27
+ README.md view
@@ -0,0 +1,20 @@+# nothunks++[](https://github.com/input-output-hk/nothunks/actions/workflows/ci.yml)+++Long lived application data typically should not contain any thunks. This+library can be used to examine values for unexpected thunks, which can then be+used in assertions. This can be invaluable in avoiding memory leaks, or tracking+down existing ones.++See my presentation+[MuniHac 2020: Being lazy without being bloated](https://www.youtube.com/watch?v=7t6wt7ByBWg)+for an overview, motivating the library and explaining how it is intended to be+used and how it works internally.+++`nothunks` will try to get source information from info tables. For that one+needs to use `GHC` `9.2` or newer and compile the code with+`-finfo-table-map`. More precise information will be available if+`-fdistinct-constructor-tables` flag is used as well.
nothunks.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: nothunks-version: 0.2.1.0+version: 0.2.1.1 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@@ -15,8 +15,8 @@ maintainer: Marcin Szamotulski <coot@coot.me> copyright: 2018-2024 Input Output Global Inc (IOG) category: Development-extra-doc-files: CHANGELOG.md-tested-with: GHC == {8.10, 9.0, 9.2, 9.4, 9.6, 9.8}+extra-doc-files: README.md CHANGELOG.md+tested-with: GHC == {8.10, 9.0, 9.2, 9.4, 9.6, 9.8, 9.10} source-repository head type: git
src/NoThunks/Class.hs view
@@ -18,6 +18,7 @@ -- * Check a value for unexpected thunks NoThunks(..) , ThunkInfo(..)+ , mkThunkInfo , Context , Info , unsafeNoThunks@@ -139,7 +140,7 @@ noThunks ctxt x = do isThunk <- checkIsThunk x let ctxt' = showTypeOf (Proxy @a) : ctxt- thunkInfo <- getThunkInfo ctxt' x+ thunkInfo <- mkThunkInfo ctxt' x if isThunk then return $ Just thunkInfo else wNoThunks ctxt' x@@ -229,9 +230,12 @@ newtype ThunkInfo = ThunkInfo { thunkInfo :: Either Context Info } deriving Show -getThunkInfo :: Context -> a -> IO ThunkInfo+-- | Construct `ThunkInfo` either from `Context` or information provided by+-- `GHC` about `a` (see `whereFrom`).+--+mkThunkInfo :: Context -> a -> IO ThunkInfo #if MIN_VERSION_base(4,16,0)-getThunkInfo ctxt a = ThunkInfo . maybe (Left ctxt) (Right . fmt) <$> whereFrom a+mkThunkInfo ctxt a = ThunkInfo . maybe (Left ctxt) (Right . fmt) <$> whereFrom a where fmt :: InfoProv -> Info fmt InfoProv { ipSrcFile, ipSrcSpan,@@ -239,7 +243,7 @@ ipLabel ++ " :: " ++ ipTyDesc ++ " @ " ++ ipSrcFile ++ ":" ++ ipSrcSpan #else-getThunkInfo ctxt _ = return (ThunkInfo (Left ctxt))+mkThunkInfo ctxt _ = return (ThunkInfo (Left ctxt)) #endif @@ -388,7 +392,7 @@ inspectHeap :: Context -> a -> IO (Maybe ThunkInfo) inspectHeap ctxt x = do containsThunks <- checkContainsThunks x- thunkInfo <- getThunkInfo ("..." : ctxt) x+ thunkInfo <- mkThunkInfo ("..." : ctxt) x return $ if containsThunks then Just thunkInfo else Nothing