Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export mkThunkInfo #53

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ghc: ["8.10", "9.0", "9.2", "9.4", "9.6", "9.8"]
ghc: ["8.10", "9.0", "9.2", "9.4", "9.6", "9.8", "9.10"]
steps:
- uses: actions/checkout@v4
- name: "Setup haskell"
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nothunks.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +16,7 @@ maintainer: Marcin Szamotulski <[email protected]>
copyright: 2018-2024 Input Output Global Inc (IOG)
category: Development
extra-doc-files: README.md CHANGELOG.md
tested-with: GHC == {8.10, 9.0, 9.2, 9.4, 9.6, 9.8}
tested-with: GHC == {8.10, 9.0, 9.2, 9.4, 9.6, 9.8, 9.10}

source-repository head
type: git
Expand Down
14 changes: 9 additions & 5 deletions src/NoThunks/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module NoThunks.Class (
-- * Check a value for unexpected thunks
NoThunks(..)
, ThunkInfo(..)
, mkThunkInfo
, Context
, Info
, unsafeNoThunks
Expand Down Expand Up @@ -139,7 +140,7 @@ class NoThunks a where
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
Expand Down Expand Up @@ -229,17 +230,20 @@ type Info = String
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,
ipLabel, ipTyDesc } =
ipLabel ++ " :: " ++ ipTyDesc
++ " @ " ++ ipSrcFile ++ ":" ++ ipSrcSpan
#else
getThunkInfo ctxt _ = return (ThunkInfo (Left ctxt))
mkThunkInfo ctxt _ = return (ThunkInfo (Left ctxt))
#endif


Expand Down Expand Up @@ -388,7 +392,7 @@ instance KnownSymbol name => NoThunks (InspectHeapNamed name a) where
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
Expand Down
Loading