Skip to content

Commit

Permalink
Re-enable NoThunks tests (#444)
Browse files Browse the repository at this point in the history
Tests are re-enabled, but in cases where I expect failures related to
`StrictMVar`s, we ignore the thunk and keep checking further into the `MVar`
contents.
  • Loading branch information
jorisdral committed Nov 26, 2024
1 parent 11738bd commit 7e17707
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions lsm-tree.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ library extras
, contra-tracer
, deepseq
, fs-api
, fs-sim
, io-classes:strict-mvar
, io-classes:strict-stm
, lsm-tree
Expand Down
32 changes: 26 additions & 6 deletions src-extras/Database/LSMTree/Extras/NoThunks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import KMerge.Heap
import NoThunks.Class
import System.FS.API
import System.FS.BlockIO.API
import System.FS.IO
import System.FS.Sim.MockFS
import Test.QuickCheck (Property, Testable (..), counterexample)
import Unsafe.Coerce

Expand Down Expand Up @@ -542,7 +544,7 @@ instance (NoThunks a, Typeable s, Typeable a) => NoThunks (MutableHeap s a) wher
-- a)@, can not be satisfied for arbitrary @m@\/@s@, and must be instantiated
-- for a concrete @m@\/@s@, like @IO@\/@RealWorld@.
class ( forall a. NoThunks a => NoThunks (StrictTVar m a)
, forall a. NoThunks a => NoThunks (StrictMVar m a)
, forall a. (NoThunks a, Typeable a) => NoThunks (StrictMVar m a)
) => NoThunksIOLike' m s

instance NoThunksIOLike' IO RealWorld
Expand All @@ -564,11 +566,29 @@ instance NoThunks a => NoThunks (StrictTVar IO a) where
#endif
#endif

instance NoThunks a => NoThunks (StrictMVar IO a) where
showTypeOf (_ :: Proxy (StrictMVar IO a)) = "StrictMVar IO"
wNoThunks ctx var = do
x <- readMVar var
noThunks ctx x
-- TODO: in some cases, strict-mvar functions leave thunks behind, in particular
-- modifyMVarMasked and modifyMVarMasked_. So in some specific cases we evaluate
-- the contents of the MVar to WHNF, and keep checking nothunks from there. See
-- lsm-tree#444.
instance (NoThunks a, Typeable a) => NoThunks (StrictMVar IO a) where
showTypeOf (p :: Proxy (StrictMVar IO a)) = show $ typeRep p
wNoThunks ctx var
| Just (Proxy :: Proxy (MergingRunState IO HandleIO))
<- gcast (Proxy @a)
= workAroundCheck
| Just (Proxy :: Proxy (MergingRunState IO HandleMock))
<- gcast (Proxy @a)
= workAroundCheck
| otherwise
= properCheck
where
properCheck = do
x <- readMVar var
noThunks ctx x

workAroundCheck = do
!x <- readMVar var
noThunks ctx x

{-------------------------------------------------------------------------------
vector
Expand Down
3 changes: 1 addition & 2 deletions test/Test/Database/LSMTree/Normal/StateMachine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,7 @@ runIO action lookUp = ReaderT $ \(session, handler) -> do
x <- aux (unwrapSession session) handler action
case session of
WrapSession sesh ->
-- TODO: Re-enable NoThunks assertions. See lsm-tree#444.
const id (assertNoThunks sesh) $ pure ()
assertNoThunks sesh $ pure ()
pure x
where
aux ::
Expand Down

0 comments on commit 7e17707

Please sign in to comment.