Skip to content
Open
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
9 changes: 8 additions & 1 deletion lib/Echidna.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Echidna where

import Control.Concurrent (newChan)
import Control.Concurrent (forkIO, newChan, readChan)
import Control.Exception (SomeException, handle)
import Control.Monad (forever, void)
import Control.Monad.Catch (MonadThrow(..))
import Control.Monad.IO.Class (liftIO)
import Data.IORef (newIORef)
Expand Down Expand Up @@ -125,6 +127,11 @@ mkEnv cfg buildOutput tests world slitherInfo = do
codehashMap <- newIORef mempty
chainId <- Onchain.fetchChainIdFrom cfg.rpcUrl
eventQueue <- newChan
-- Consumers read events from their own 'dupChan', so this original read end
-- is never advanced and would otherwise pin every event ever written. Drain
-- it from a dedicated thread so the GC can reclaim delivered events.
void $ forkIO $ handle (\(_ :: SomeException) -> pure ()) $
forever $ void $ readChan eventQueue
coverageRefInit <- newIORef mempty
coverageRefRuntime <- newIORef mempty
corpusRef <- newIORef mempty
Expand Down
9 changes: 7 additions & 2 deletions lib/Echidna/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,10 @@ updateOpenTest vm reproducer test = do
, result
, workerId
}
pushWorkerEvent (TestFalsified test')
-- Publish a VM-free copy, forced strict so the event can't retain the
-- VM through a thunk. testRefs keeps the full 'test'' for shrinking.
let !vmFreeTest = test' { Test.vm = Nothing }
pushWorkerEvent (TestFalsified vmFreeTest)
pure $ Just test'

IntValue value' | value' > value -> do
Expand All @@ -660,7 +663,9 @@ updateOpenTest vm reproducer test = do
, vm = Just vm
, result
}
pushWorkerEvent (TestOptimized test')
-- VM-free copy, as in the TestFalsified case above.
let !vmFreeTest = test' { Test.vm = Nothing }
pushWorkerEvent (TestOptimized vmFreeTest)
pure $ Just test'
where
value =
Expand Down
Loading