Skip to content

Commit

Permalink
Release a RefTracker even if the corresponding finaliser throws an …
Browse files Browse the repository at this point in the history
…error
  • Loading branch information
jorisdral committed Dec 30, 2024
1 parent e80f7f2 commit c43a654
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src-control/Control/RefCount.hs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ releaseRef ::
-> m ()
releaseRef ref@Ref{refobj} = do
assertNoDoubleRelease ref
decrementRefCounter (getRefCounter refobj)
releaseRefTracker ref
withReleaseRefTracker ref (decrementRefCounter (getRefCounter refobj))

{-# COMPLETE DeRef #-}
#if MIN_VERSION_GLASGOW_HASKELL(9,0,0,0)
Expand Down Expand Up @@ -387,6 +386,10 @@ instance Exception RefException where
releaseRefTracker :: PrimMonad m => Ref a -> m ()
releaseRefTracker _ = return ()

Check failure on line 387 in src-control/Control/RefCount.hs

View workflow job for this annotation

GitHub Actions / build (9.6.4, 3.10.2.1, ubuntu-latest, cabal.project.release)

Defined but not used: ‘releaseRefTracker’

{-# INLINE withReleaseRefTracker #-}
withReleaseRefTracker :: PrimMonad m => Ref a -> m () -> m ()

Check failure on line 390 in src-control/Control/RefCount.hs

View workflow job for this annotation

GitHub Actions / build (9.6.4, 3.10.2.1, ubuntu-latest, cabal.project.release)

Redundant constraint: PrimMonad m
withReleaseRefTracker _ref k = k

{-# INLINE assertNoUseAfterRelease #-}
assertNoUseAfterRelease :: PrimMonad m => Ref a -> m ()
assertNoUseAfterRelease _ = return ()
Expand Down Expand Up @@ -438,6 +441,9 @@ releaseRefTracker Ref { reftracker = RefTracker _refid _weak outer } =
inner <- readIORef outer
writeIORef inner True

withReleaseRefTracker :: (PrimMonad m, MonadThrow m) => Ref a -> m () -> m ()
withReleaseRefTracker ref k = k `finally` releaseRefTracker ref

finaliserRefTracker :: IORef Bool -> RefId -> CallStack -> IO ()
finaliserRefTracker inner refid callsite = do
released <- readIORef inner
Expand Down

0 comments on commit c43a654

Please sign in to comment.