{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTSyntax #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-partial-fields #-}
module Control.Monad.IOSim.Types
( IOSim (..)
, runIOSim
, traceM
, traceSTM
, liftST
, SimA (..)
, StepId
, STMSim
, STM (..)
, runSTM
, StmA (..)
, StmTxResult (..)
, BranchStmA (..)
, StmStack (..)
, TimeoutException (..)
, setCurrentTime
, unshareClock
, ScheduleControl (..)
, ScheduleMod (..)
, ExplorationOptions (..)
, ExplorationSpec
, withScheduleBound
, withBranching
, withStepTimelimit
, withReplay
, stdExplorationOptions
, EventlogEvent (..)
, EventlogMarker (..)
, SimEventType (..)
, SimEvent (..)
, SimResult (..)
, SimTrace
, Trace.Trace (SimTrace, SimPORTrace, TraceMainReturn, TraceMainException, TraceDeadlock, TraceRacesFound, TraceLoop)
, ppTrace
, ppTrace_
, ppSimEvent
, ppDebug
, Labelled (..)
, module Control.Monad.IOSim.CommonTypes
, Thrower (..)
, Time (..)
, addTime
, diffTime
, Timeout (..)
, newTimeout
, readTimeout
, cancelTimeout
, awaitTimeout
, execReadTVar
) where
import Control.Applicative
import Control.Exception (ErrorCall (..), asyncExceptionFromException,
asyncExceptionToException)
import Control.Monad
import Control.Monad.Fix (MonadFix (..))
import Control.Concurrent.Class.MonadSTM.Strict.TVar (StrictTVar)
import qualified Control.Concurrent.Class.MonadSTM.Strict.TVar as StrictTVar
import Control.Monad.Class.MonadAsync hiding (Async)
import qualified Control.Monad.Class.MonadAsync as MonadAsync
import Control.Monad.Class.MonadEventlog
import Control.Monad.Class.MonadFork hiding (ThreadId)
import qualified Control.Monad.Class.MonadFork as MonadFork
import Control.Monad.Class.MonadMVar
import Control.Monad.Class.MonadST
import Control.Monad.Class.MonadSTM.Internal (MonadInspectSTM (..),
MonadLabelledSTM (..), MonadSTM, MonadTraceSTM (..),
TArrayDefault, TChanDefault, TMVarDefault, TSemDefault,
TraceValue, atomically, retry)
import qualified Control.Monad.Class.MonadSTM.Internal as MonadSTM
import Control.Monad.Class.MonadSay
import Control.Monad.Class.MonadTest
import Control.Monad.Class.MonadThrow as MonadThrow hiding
(getMaskingState)
import qualified Control.Monad.Class.MonadThrow as MonadThrow
import Control.Monad.Class.MonadTime
import Control.Monad.Class.MonadTime.SI
import Control.Monad.Class.MonadTimer
import Control.Monad.Class.MonadTimer.SI (TimeoutState (..))
import qualified Control.Monad.Class.MonadTimer.SI as SI
import Control.Monad.ST.Lazy
import qualified Control.Monad.ST.Strict as StrictST
import Control.Monad.ST.Unsafe (unsafeSTToIO)
import qualified Control.Monad.Catch as Exceptions
import qualified Control.Monad.Fail as Fail
import Data.Bifoldable
import Data.Bifunctor (bimap)
import Data.Dynamic (Dynamic, toDyn)
import qualified Data.List.Trace as Trace
import Data.Map.Strict (Map)
import Data.Maybe (fromMaybe)
import Data.Monoid (Endo (..))
import Data.STRef.Lazy
import Data.Semigroup (Max (..))
import Data.Time.Clock (diffTimeToPicoseconds)
import Data.Typeable
import Data.Word (Word64)
import qualified Debug.Trace as Debug
import NoThunks.Class (NoThunks (..))
import Text.Printf
import GHC.Exts (oneShot)
import GHC.Generics (Generic)
import Quiet (Quiet (..))
import Control.Monad.IOSim.CommonTypes
import Control.Monad.IOSim.STM
import Control.Monad.IOSimPOR.Types
import qualified System.IO.Error as IO.Error (userError)
{-# ANN module "HLint: ignore Use readTVarIO" #-}
newtype IOSim s a = IOSim { forall s a. IOSim s a -> forall r. (a -> SimA s r) -> SimA s r
unIOSim :: forall r. (a -> SimA s r) -> SimA s r }
runIOSim :: IOSim s a -> SimA s a
runIOSim :: forall s a. IOSim s a -> SimA s a
runIOSim (IOSim forall r. (a -> SimA s r) -> SimA s r
k) = forall r. (a -> SimA s r) -> SimA s r
k forall a s. a -> SimA s a
Return
traceM :: Typeable a => a -> IOSim s ()
traceM :: forall a s. Typeable a => a -> IOSim s ()
traceM a
x = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s b. Dynamic -> SimA s b -> SimA s b
Output (forall a. Typeable a => a -> Dynamic
toDyn a
x) (() -> SimA s r
k ())
traceSTM :: Typeable a => a -> STMSim s ()
traceSTM :: forall a s. Typeable a => a -> STMSim s ()
traceSTM a
x = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> StmA s r
k -> forall s b. Dynamic -> StmA s b -> StmA s b
OutputStm (forall a. Typeable a => a -> Dynamic
toDyn a
x) (() -> StmA s r
k ())
data Thrower = ThrowSelf | ThrowOther deriving (Eq Thrower
Thrower -> Thrower -> Bool
Thrower -> Thrower -> Ordering
Thrower -> Thrower -> Thrower
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Thrower -> Thrower -> Thrower
$cmin :: Thrower -> Thrower -> Thrower
max :: Thrower -> Thrower -> Thrower
$cmax :: Thrower -> Thrower -> Thrower
>= :: Thrower -> Thrower -> Bool
$c>= :: Thrower -> Thrower -> Bool
> :: Thrower -> Thrower -> Bool
$c> :: Thrower -> Thrower -> Bool
<= :: Thrower -> Thrower -> Bool
$c<= :: Thrower -> Thrower -> Bool
< :: Thrower -> Thrower -> Bool
$c< :: Thrower -> Thrower -> Bool
compare :: Thrower -> Thrower -> Ordering
$ccompare :: Thrower -> Thrower -> Ordering
Ord, Thrower -> Thrower -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Thrower -> Thrower -> Bool
$c/= :: Thrower -> Thrower -> Bool
== :: Thrower -> Thrower -> Bool
$c== :: Thrower -> Thrower -> Bool
Eq, Int -> Thrower -> String -> String
[Thrower] -> String -> String
Thrower -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [Thrower] -> String -> String
$cshowList :: [Thrower] -> String -> String
show :: Thrower -> String
$cshow :: Thrower -> String
showsPrec :: Int -> Thrower -> String -> String
$cshowsPrec :: Int -> Thrower -> String -> String
Show)
data SimA s a where
Return :: a -> SimA s a
Say :: String -> SimA s b -> SimA s b
Output :: Dynamic -> SimA s b -> SimA s b
LiftST :: StrictST.ST s a -> (a -> SimA s b) -> SimA s b
GetMonoTime :: (Time -> SimA s b) -> SimA s b
GetWallTime :: (UTCTime -> SimA s b) -> SimA s b
SetWallTime :: UTCTime -> SimA s b -> SimA s b
UnshareClock :: SimA s b -> SimA s b
StartTimeout :: DiffTime -> SimA s a -> (Maybe a -> SimA s b) -> SimA s b
UnregisterTimeout :: TimeoutId -> SimA s a -> SimA s a
RegisterDelay :: DiffTime -> (TVar s Bool -> SimA s b) -> SimA s b
ThreadDelay :: DiffTime -> SimA s b -> SimA s b
NewTimeout :: DiffTime -> (Timeout s -> SimA s b) -> SimA s b
CancelTimeout :: Timeout s -> SimA s b -> SimA s b
Throw :: SomeException -> SimA s a
Catch :: Exception e =>
SimA s a -> (e -> SimA s a) -> (a -> SimA s b) -> SimA s b
Evaluate :: a -> (a -> SimA s b) -> SimA s b
Fork :: IOSim s () -> (ThreadId -> SimA s b) -> SimA s b
GetThreadId :: (ThreadId -> SimA s b) -> SimA s b
LabelThread :: ThreadId -> String -> SimA s b -> SimA s b
Atomically :: STM s a -> (a -> SimA s b) -> SimA s b
ThrowTo :: SomeException -> ThreadId -> SimA s a -> SimA s a
SetMaskState :: MaskingState -> IOSim s a -> (a -> SimA s b) -> SimA s b
GetMaskState :: (MaskingState -> SimA s b) -> SimA s b
YieldSim :: SimA s a -> SimA s a
ExploreRaces :: SimA s b -> SimA s b
Fix :: (x -> IOSim s x) -> (x -> SimA s r) -> SimA s r
newtype STM s a = STM { forall s a. STM s a -> forall r. (a -> StmA s r) -> StmA s r
unSTM :: forall r. (a -> StmA s r) -> StmA s r }
instance Semigroup a => Semigroup (STM s a) where
STM s a
a <> :: STM s a -> STM s a -> STM s a
<> STM s a
b = forall a. Semigroup a => a -> a -> a
(<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM s a
a forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> STM s a
b
instance Monoid a => Monoid (STM s a) where
mempty :: STM s a
mempty = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
runSTM :: STM s a -> StmA s a
runSTM :: forall s a. STM s a -> StmA s a
runSTM (STM forall r. (a -> StmA s r) -> StmA s r
k) = forall r. (a -> StmA s r) -> StmA s r
k forall a s. a -> StmA s a
ReturnStm
data StmA s a where
ReturnStm :: a -> StmA s a
ThrowStm :: SomeException -> StmA s a
CatchStm :: StmA s a -> (SomeException -> StmA s a) -> (a -> StmA s b) -> StmA s b
NewTVar :: Maybe String -> x -> (TVar s x -> StmA s b) -> StmA s b
LabelTVar :: String -> TVar s a -> StmA s b -> StmA s b
ReadTVar :: TVar s a -> (a -> StmA s b) -> StmA s b
WriteTVar :: TVar s a -> a -> StmA s b -> StmA s b
Retry :: StmA s b
OrElse :: StmA s a -> StmA s a -> (a -> StmA s b) -> StmA s b
SayStm :: String -> StmA s b -> StmA s b
OutputStm :: Dynamic -> StmA s b -> StmA s b
TraceTVar :: forall s a b.
TVar s a
-> (Maybe a -> a -> ST s TraceValue)
-> StmA s b -> StmA s b
LiftSTStm :: StrictST.ST s a -> (a -> StmA s b) -> StmA s b
FixStm :: (x -> STM s x) -> (x -> StmA s r) -> StmA s r
type STMSim = STM
instance Functor (IOSim s) where
{-# INLINE fmap #-}
fmap :: forall a b. (a -> b) -> IOSim s a -> IOSim s b
fmap a -> b
f = \IOSim s a
d -> forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \b -> SimA s r
k -> forall s a. IOSim s a -> forall r. (a -> SimA s r) -> SimA s r
unIOSim IOSim s a
d (b -> SimA s r
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
instance Applicative (IOSim s) where
{-# INLINE pure #-}
pure :: forall a. a -> IOSim s a
pure = \a
x -> forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> SimA s r
k -> a -> SimA s r
k a
x
{-# INLINE (<*>) #-}
<*> :: forall a b. IOSim s (a -> b) -> IOSim s a -> IOSim s b
(<*>) = \IOSim s (a -> b)
df IOSim s a
dx -> forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \b -> SimA s r
k ->
forall s a. IOSim s a -> forall r. (a -> SimA s r) -> SimA s r
unIOSim IOSim s (a -> b)
df (\a -> b
f -> forall s a. IOSim s a -> forall r. (a -> SimA s r) -> SimA s r
unIOSim IOSim s a
dx (\a
x -> b -> SimA s r
k (a -> b
f a
x)))
{-# INLINE (*>) #-}
*> :: forall a b. IOSim s a -> IOSim s b -> IOSim s b
(*>) = \IOSim s a
dm IOSim s b
dn -> forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \b -> SimA s r
k -> forall s a. IOSim s a -> forall r. (a -> SimA s r) -> SimA s r
unIOSim IOSim s a
dm (\a
_ -> forall s a. IOSim s a -> forall r. (a -> SimA s r) -> SimA s r
unIOSim IOSim s b
dn b -> SimA s r
k)
instance Monad (IOSim s) where
return :: forall a. a -> IOSim s a
return = forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE (>>=) #-}
>>= :: forall a b. IOSim s a -> (a -> IOSim s b) -> IOSim s b
(>>=) = \IOSim s a
dm a -> IOSim s b
f -> forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \b -> SimA s r
k -> forall s a. IOSim s a -> forall r. (a -> SimA s r) -> SimA s r
unIOSim IOSim s a
dm (\a
m -> forall s a. IOSim s a -> forall r. (a -> SimA s r) -> SimA s r
unIOSim (a -> IOSim s b
f a
m) b -> SimA s r
k)
{-# INLINE (>>) #-}
>> :: forall a b. IOSim s a -> IOSim s b -> IOSim s b
(>>) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
#if !(MIN_VERSION_base(4,13,0))
fail = Fail.fail
#endif
instance Semigroup a => Semigroup (IOSim s a) where
<> :: IOSim s a -> IOSim s a -> IOSim s a
(<>) = forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall a. Semigroup a => a -> a -> a
(<>)
instance Monoid a => Monoid (IOSim s a) where
mempty :: IOSim s a
mempty = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
#if !(MIN_VERSION_base(4,11,0))
mappend = liftA2 mappend
#endif
instance Fail.MonadFail (IOSim s) where
fail :: forall a. String -> IOSim s a
fail String
msg = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> SimA s r
_ -> forall s a. SomeException -> SimA s a
Throw (forall e. Exception e => e -> SomeException
toException (String -> IOError
IO.Error.userError String
msg))
instance MonadFix (IOSim s) where
mfix :: forall a. (a -> IOSim s a) -> IOSim s a
mfix a -> IOSim s a
f = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> SimA s r
k -> forall a s r. (a -> IOSim s a) -> (a -> SimA s r) -> SimA s r
Fix a -> IOSim s a
f a -> SimA s r
k
instance Functor (STM s) where
{-# INLINE fmap #-}
fmap :: forall a b. (a -> b) -> STM s a -> STM s b
fmap a -> b
f = \STM s a
d -> forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \b -> StmA s r
k -> forall s a. STM s a -> forall r. (a -> StmA s r) -> StmA s r
unSTM STM s a
d (b -> StmA s r
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
instance Applicative (STM s) where
{-# INLINE pure #-}
pure :: forall a. a -> STM s a
pure = \a
x -> forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> StmA s r
k -> a -> StmA s r
k a
x
{-# INLINE (<*>) #-}
<*> :: forall a b. STM s (a -> b) -> STM s a -> STM s b
(<*>) = \STM s (a -> b)
df STM s a
dx -> forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \b -> StmA s r
k ->
forall s a. STM s a -> forall r. (a -> StmA s r) -> StmA s r
unSTM STM s (a -> b)
df (\a -> b
f -> forall s a. STM s a -> forall r. (a -> StmA s r) -> StmA s r
unSTM STM s a
dx (\a
x -> b -> StmA s r
k (a -> b
f a
x)))
{-# INLINE (*>) #-}
*> :: forall a b. STM s a -> STM s b -> STM s b
(*>) = \STM s a
dm STM s b
dn -> forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \b -> StmA s r
k -> forall s a. STM s a -> forall r. (a -> StmA s r) -> StmA s r
unSTM STM s a
dm (\a
_ -> forall s a. STM s a -> forall r. (a -> StmA s r) -> StmA s r
unSTM STM s b
dn b -> StmA s r
k)
instance Monad (STM s) where
return :: forall a. a -> STM s a
return = forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE (>>=) #-}
>>= :: forall a b. STM s a -> (a -> STM s b) -> STM s b
(>>=) = \STM s a
dm a -> STM s b
f -> forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \b -> StmA s r
k -> forall s a. STM s a -> forall r. (a -> StmA s r) -> StmA s r
unSTM STM s a
dm (\a
m -> forall s a. STM s a -> forall r. (a -> StmA s r) -> StmA s r
unSTM (a -> STM s b
f a
m) b -> StmA s r
k)
{-# INLINE (>>) #-}
>> :: forall a b. STM s a -> STM s b -> STM s b
(>>) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
#if !(MIN_VERSION_base(4,13,0))
fail = Fail.fail
#endif
instance Fail.MonadFail (STM s) where
fail :: forall a. String -> STM s a
fail String
msg = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> StmA s r
_ -> forall s a. SomeException -> StmA s a
ThrowStm (forall e. Exception e => e -> SomeException
toException (String -> ErrorCall
ErrorCall String
msg))
instance Alternative (STM s) where
empty :: forall a. STM s a
empty = forall (m :: * -> *) a. MonadSTM m => STM m a
MonadSTM.retry
<|> :: forall a. STM s a -> STM s a -> STM s a
(<|>) = forall (m :: * -> *) a. MonadSTM m => STM m a -> STM m a -> STM m a
MonadSTM.orElse
instance MonadPlus (STM s) where
instance MonadFix (STM s) where
mfix :: forall a. (a -> STM s a) -> STM s a
mfix a -> STM s a
f = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> StmA s r
k -> forall a s r. (a -> STM s a) -> (a -> StmA s r) -> StmA s r
FixStm a -> STM s a
f a -> StmA s r
k
instance MonadSay (IOSim s) where
say :: String -> IOSim s ()
say String
msg = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s b. String -> SimA s b -> SimA s b
Say String
msg (() -> SimA s r
k ())
instance MonadThrow (IOSim s) where
throwIO :: forall e a. Exception e => e -> IOSim s a
throwIO e
e = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> SimA s r
_ -> forall s a. SomeException -> SimA s a
Throw (forall e. Exception e => e -> SomeException
toException e
e)
instance MonadEvaluate (IOSim s) where
evaluate :: forall a. a -> IOSim s a
evaluate a
a = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> SimA s r
k -> forall a s b. a -> (a -> SimA s b) -> SimA s b
Evaluate a
a a -> SimA s r
k
instance NoThunks (IOSim s a) where
showTypeOf :: Proxy (IOSim s a) -> String
showTypeOf Proxy (IOSim s a)
_ = String
"IOSim"
wNoThunks :: Context -> IOSim s a -> IO (Maybe ThunkInfo)
wNoThunks Context
_ctxt IOSim s a
_act = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
instance Exceptions.MonadThrow (IOSim s) where
throwM :: forall e a. Exception e => e -> IOSim s a
throwM = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
MonadThrow.throwIO
instance MonadThrow (STM s) where
throwIO :: forall e a. Exception e => e -> STM s a
throwIO e
e = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> StmA s r
_ -> forall s a. SomeException -> StmA s a
ThrowStm (forall e. Exception e => e -> SomeException
toException e
e)
bracket :: forall a b c.
STM s a -> (a -> STM s b) -> (a -> STM s c) -> STM s c
bracket STM s a
before a -> STM s b
after a -> STM s c
thing = do
a
a <- STM s a
before
c
r <- a -> STM s c
thing a
a
b
_ <- a -> STM s b
after a
a
forall (m :: * -> *) a. Monad m => a -> m a
return c
r
finally :: forall a b. STM s a -> STM s b -> STM s a
finally STM s a
thing STM s b
after = do
a
r <- STM s a
thing
b
_ <- STM s b
after
forall (m :: * -> *) a. Monad m => a -> m a
return a
r
instance Exceptions.MonadThrow (STM s) where
throwM :: forall e a. Exception e => e -> STM s a
throwM = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
MonadThrow.throwIO
instance MonadCatch (STM s) where
catch :: forall e a. Exception e => STM s a -> (e -> STM s a) -> STM s a
catch STM s a
action e -> STM s a
handler = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> StmA s r
k -> forall s a b.
StmA s a
-> (SomeException -> StmA s a) -> (a -> StmA s b) -> StmA s b
CatchStm (forall s a. STM s a -> StmA s a
runSTM STM s a
action) (forall s a. STM s a -> StmA s a
runSTM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e s a.
Exception e =>
(e -> STM s a) -> SomeException -> STM s a
fromHandler e -> STM s a
handler) a -> StmA s r
k
where
fromHandler :: Exception e => (e -> STM s a) -> SomeException -> STM s a
fromHandler :: forall e s a.
Exception e =>
(e -> STM s a) -> SomeException -> STM s a
fromHandler e -> STM s a
h SomeException
e = case forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e of
Maybe e
Nothing -> forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO SomeException
e
Just e
e' -> e -> STM s a
h e
e'
generalBracket :: forall a b c.
STM s a
-> (a -> ExitCase b -> STM s c) -> (a -> STM s b) -> STM s (b, c)
generalBracket STM s a
acquire a -> ExitCase b -> STM s c
release a -> STM s b
use = do
a
resource <- STM s a
acquire
b
b <- a -> STM s b
use a
resource forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
`catch` \SomeException
e -> do
c
_ <- a -> ExitCase b -> STM s c
release a
resource (forall a. SomeException -> ExitCase a
ExitCaseException SomeException
e)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO SomeException
e
c
c <- a -> ExitCase b -> STM s c
release a
resource (forall a. a -> ExitCase a
ExitCaseSuccess b
b)
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, c
c)
instance Exceptions.MonadCatch (STM s) where
catch :: forall e a. Exception e => STM s a -> (e -> STM s a) -> STM s a
catch = forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
MonadThrow.catch
instance MonadCatch (IOSim s) where
catch :: forall e a.
Exception e =>
IOSim s a -> (e -> IOSim s a) -> IOSim s a
catch IOSim s a
action e -> IOSim s a
handler =
forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> SimA s r
k -> forall a s a b.
Exception a =>
SimA s a -> (a -> SimA s a) -> (a -> SimA s b) -> SimA s b
Catch (forall s a. IOSim s a -> SimA s a
runIOSim IOSim s a
action) (forall s a. IOSim s a -> SimA s a
runIOSim forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> IOSim s a
handler) a -> SimA s r
k
instance Exceptions.MonadCatch (IOSim s) where
catch :: forall e a.
Exception e =>
IOSim s a -> (e -> IOSim s a) -> IOSim s a
catch = forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
MonadThrow.catch
instance MonadMask (IOSim s) where
mask :: forall b.
((forall a. IOSim s a -> IOSim s a) -> IOSim s b) -> IOSim s b
mask (forall a. IOSim s a -> IOSim s a) -> IOSim s b
action = do
MaskingState
b <- forall s. IOSim s MaskingState
getMaskingStateImpl
case MaskingState
b of
MaskingState
Unmasked -> forall s a. IOSim s a -> IOSim s a
block forall a b. (a -> b) -> a -> b
$ (forall a. IOSim s a -> IOSim s a) -> IOSim s b
action forall s a. IOSim s a -> IOSim s a
unblock
MaskingState
MaskedInterruptible -> (forall a. IOSim s a -> IOSim s a) -> IOSim s b
action forall s a. IOSim s a -> IOSim s a
block
MaskingState
MaskedUninterruptible -> (forall a. IOSim s a -> IOSim s a) -> IOSim s b
action forall s a. IOSim s a -> IOSim s a
blockUninterruptible
uninterruptibleMask :: forall b.
((forall a. IOSim s a -> IOSim s a) -> IOSim s b) -> IOSim s b
uninterruptibleMask (forall a. IOSim s a -> IOSim s a) -> IOSim s b
action = do
MaskingState
b <- forall s. IOSim s MaskingState
getMaskingStateImpl
case MaskingState
b of
MaskingState
Unmasked -> forall s a. IOSim s a -> IOSim s a
blockUninterruptible forall a b. (a -> b) -> a -> b
$ (forall a. IOSim s a -> IOSim s a) -> IOSim s b
action forall s a. IOSim s a -> IOSim s a
unblock
MaskingState
MaskedInterruptible -> forall s a. IOSim s a -> IOSim s a
blockUninterruptible forall a b. (a -> b) -> a -> b
$ (forall a. IOSim s a -> IOSim s a) -> IOSim s b
action forall s a. IOSim s a -> IOSim s a
block
MaskingState
MaskedUninterruptible -> (forall a. IOSim s a -> IOSim s a) -> IOSim s b
action forall s a. IOSim s a -> IOSim s a
blockUninterruptible
instance MonadMaskingState (IOSim s) where
getMaskingState :: IOSim s MaskingState
getMaskingState = forall s. IOSim s MaskingState
getMaskingStateImpl
interruptible :: forall a. IOSim s a -> IOSim s a
interruptible IOSim s a
action = do
MaskingState
b <- forall s. IOSim s MaskingState
getMaskingStateImpl
case MaskingState
b of
MaskingState
Unmasked -> IOSim s a
action
MaskingState
MaskedInterruptible -> forall s a. IOSim s a -> IOSim s a
unblock IOSim s a
action
MaskingState
MaskedUninterruptible -> IOSim s a
action
instance Exceptions.MonadMask (IOSim s) where
mask :: forall b.
((forall a. IOSim s a -> IOSim s a) -> IOSim s b) -> IOSim s b
mask = forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
MonadThrow.mask
uninterruptibleMask :: forall b.
((forall a. IOSim s a -> IOSim s a) -> IOSim s b) -> IOSim s b
uninterruptibleMask = forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
MonadThrow.uninterruptibleMask
generalBracket :: forall a b c.
IOSim s a
-> (a -> ExitCase b -> IOSim s c)
-> (a -> IOSim s b)
-> IOSim s (b, c)
generalBracket IOSim s a
acquire a -> ExitCase b -> IOSim s c
release a -> IOSim s b
use =
forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
mask forall a b. (a -> b) -> a -> b
$ \forall a. IOSim s a -> IOSim s a
unmasked -> do
a
resource <- IOSim s a
acquire
b
b <- forall a. IOSim s a -> IOSim s a
unmasked (a -> IOSim s b
use a
resource) forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
`catch` \SomeException
e -> do
c
_ <- a -> ExitCase b -> IOSim s c
release a
resource (forall a. SomeException -> ExitCase a
Exceptions.ExitCaseException SomeException
e)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwIO SomeException
e
c
c <- a -> ExitCase b -> IOSim s c
release a
resource (forall a. a -> ExitCase a
Exceptions.ExitCaseSuccess b
b)
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, c
c)
instance NoThunks a => NoThunks (StrictTVar (IOSim s) a) where
showTypeOf :: Proxy (StrictTVar (IOSim s) a) -> String
showTypeOf Proxy (StrictTVar (IOSim s) a)
_ = String
"StrictTVar IOSim"
wNoThunks :: Context -> StrictTVar (IOSim s) a -> IO (Maybe ThunkInfo)
wNoThunks Context
ctxt StrictTVar (IOSim s) a
tvar = do
a
a <- forall s a. ST s a -> IO a
unsafeSTToIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. ST s a -> ST s a
lazyToStrictST forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. TVar s a -> ST s a
execReadTVar forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StrictTVar m a -> LazyTVar m a
StrictTVar.toLazyTVar
forall a b. (a -> b) -> a -> b
$ StrictTVar (IOSim s) a
tvar
forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo)
noThunks Context
ctxt a
a
execReadTVar :: TVar s a -> ST s a
execReadTVar :: forall s a. TVar s a -> ST s a
execReadTVar TVar{STRef s a
tvarCurrent :: forall s a. TVar s a -> STRef s a
tvarCurrent :: STRef s a
tvarCurrent} = forall s a. STRef s a -> ST s a
readSTRef STRef s a
tvarCurrent
{-# INLINE execReadTVar #-}
getMaskingStateImpl :: IOSim s MaskingState
unblock, block, blockUninterruptible :: IOSim s a -> IOSim s a
getMaskingStateImpl :: forall s. IOSim s MaskingState
getMaskingStateImpl = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall s b. (MaskingState -> SimA s b) -> SimA s b
GetMaskState
unblock :: forall s a. IOSim s a -> IOSim s a
unblock IOSim s a
a = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim (forall s a b.
MaskingState -> IOSim s a -> (a -> SimA s b) -> SimA s b
SetMaskState MaskingState
Unmasked IOSim s a
a)
block :: forall s a. IOSim s a -> IOSim s a
block IOSim s a
a = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim (forall s a b.
MaskingState -> IOSim s a -> (a -> SimA s b) -> SimA s b
SetMaskState MaskingState
MaskedInterruptible IOSim s a
a)
blockUninterruptible :: forall s a. IOSim s a -> IOSim s a
blockUninterruptible IOSim s a
a = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim (forall s a b.
MaskingState -> IOSim s a -> (a -> SimA s b) -> SimA s b
SetMaskState MaskingState
MaskedUninterruptible IOSim s a
a)
instance MonadThread (IOSim s) where
type ThreadId (IOSim s) = ThreadId
myThreadId :: IOSim s (ThreadId (IOSim s))
myThreadId = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \ThreadId (IOSim s) -> SimA s r
k -> forall s b. (ThreadId -> SimA s b) -> SimA s b
GetThreadId ThreadId (IOSim s) -> SimA s r
k
labelThread :: ThreadId (IOSim s) -> String -> IOSim s ()
labelThread ThreadId (IOSim s)
t String
l = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s b. ThreadId -> String -> SimA s b -> SimA s b
LabelThread ThreadId (IOSim s)
t String
l (() -> SimA s r
k ())
instance MonadFork (IOSim s) where
forkIO :: IOSim s () -> IOSim s (ThreadId (IOSim s))
forkIO IOSim s ()
task = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \ThreadId (IOSim s) -> SimA s r
k -> forall s b. IOSim s () -> (ThreadId -> SimA s b) -> SimA s b
Fork IOSim s ()
task ThreadId (IOSim s) -> SimA s r
k
forkOn :: Int -> IOSim s () -> IOSim s (ThreadId (IOSim s))
forkOn Int
_ IOSim s ()
task = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \ThreadId (IOSim s) -> SimA s r
k -> forall s b. IOSim s () -> (ThreadId -> SimA s b) -> SimA s b
Fork IOSim s ()
task ThreadId (IOSim s) -> SimA s r
k
forkIOWithUnmask :: ((forall a. IOSim s a -> IOSim s a) -> IOSim s ())
-> IOSim s (ThreadId (IOSim s))
forkIOWithUnmask (forall a. IOSim s a -> IOSim s a) -> IOSim s ()
f = forall (m :: * -> *). MonadFork m => m () -> m (ThreadId m)
forkIO ((forall a. IOSim s a -> IOSim s a) -> IOSim s ()
f forall s a. IOSim s a -> IOSim s a
unblock)
throwTo :: forall e. Exception e => ThreadId (IOSim s) -> e -> IOSim s ()
throwTo ThreadId (IOSim s)
tid e
e = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s a. SomeException -> ThreadId -> SimA s a -> SimA s a
ThrowTo (forall e. Exception e => e -> SomeException
toException e
e) ThreadId (IOSim s)
tid (() -> SimA s r
k ())
yield :: IOSim s ()
yield = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s a. SimA s a -> SimA s a
YieldSim (() -> SimA s r
k ())
instance MonadTest (IOSim s) where
exploreRaces :: IOSim s ()
exploreRaces = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s a. SimA s a -> SimA s a
ExploreRaces (() -> SimA s r
k ())
instance MonadSay (STMSim s) where
say :: String -> STMSim s ()
say String
msg = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> StmA s r
k -> forall s b. String -> StmA s b -> StmA s b
SayStm String
msg (() -> StmA s r
k ())
instance MonadLabelledSTM (IOSim s) where
labelTVar :: forall a. TVar (IOSim s) a -> String -> STM (IOSim s) ()
labelTVar TVar (IOSim s) a
tvar String
label = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ \() -> StmA s r
k -> forall s a b. String -> TVar s a -> StmA s b -> StmA s b
LabelTVar String
label TVar (IOSim s) a
tvar (() -> StmA s r
k ())
labelTQueue :: forall a. TQueue (IOSim s) a -> String -> STM (IOSim s) ()
labelTQueue = forall (m :: * -> *) a.
MonadLabelledSTM m =>
TQueueDefault m a -> String -> STM m ()
labelTQueueDefault
labelTBQueue :: forall a. TBQueue (IOSim s) a -> String -> STM (IOSim s) ()
labelTBQueue = forall (m :: * -> *) a.
MonadLabelledSTM m =>
TBQueueDefault m a -> String -> STM m ()
labelTBQueueDefault
instance MonadSTM (IOSim s) where
type STM (IOSim s) = STM s
type TVar (IOSim s) = TVar s
type TMVar (IOSim s) = TMVarDefault (IOSim s)
type TQueue (IOSim s) = TQueueDefault (IOSim s)
type TBQueue (IOSim s) = TBQueueDefault (IOSim s)
type TArray (IOSim s) = TArrayDefault (IOSim s)
type TSem (IOSim s) = TSemDefault (IOSim s)
type TChan (IOSim s) = TChanDefault (IOSim s)
atomically :: forall a. HasCallStack => STM (IOSim s) a -> IOSim s a
atomically STM (IOSim s) a
action = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> SimA s r
k -> forall s a b. STM s a -> (a -> SimA s b) -> SimA s b
Atomically STM (IOSim s) a
action a -> SimA s r
k
newTVar :: forall a. a -> STM (IOSim s) (TVar (IOSim s) a)
newTVar a
x = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \TVar s a -> StmA s r
k -> forall a s b.
Maybe String -> a -> (TVar s a -> StmA s b) -> StmA s b
NewTVar forall a. Maybe a
Nothing a
x TVar s a -> StmA s r
k
readTVar :: forall a. TVar (IOSim s) a -> STM (IOSim s) a
readTVar TVar (IOSim s) a
tvar = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> StmA s r
k -> forall s a b. TVar s a -> (a -> StmA s b) -> StmA s b
ReadTVar TVar (IOSim s) a
tvar a -> StmA s r
k
writeTVar :: forall a. TVar (IOSim s) a -> a -> STM (IOSim s) ()
writeTVar TVar (IOSim s) a
tvar a
x = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> StmA s r
k -> forall s a b. TVar s a -> a -> StmA s b -> StmA s b
WriteTVar TVar (IOSim s) a
tvar a
x (() -> StmA s r
k ())
retry :: forall a. STM (IOSim s) a
retry = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> StmA s r
_ -> forall s b. StmA s b
Retry
orElse :: forall a. STM (IOSim s) a -> STM (IOSim s) a -> STM (IOSim s) a
orElse STM (IOSim s) a
a STM (IOSim s) a
b = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> StmA s r
k -> forall s a b. StmA s a -> StmA s a -> (a -> StmA s b) -> StmA s b
OrElse (forall s a. STM s a -> StmA s a
runSTM STM (IOSim s) a
a) (forall s a. STM s a -> StmA s a
runSTM STM (IOSim s) a
b) a -> StmA s r
k
newTMVar :: forall a. a -> STM (IOSim s) (TMVar (IOSim s) a)
newTMVar = forall (m :: * -> *) a. MonadSTM m => a -> STM m (TMVarDefault m a)
MonadSTM.newTMVarDefault
newEmptyTMVar :: forall a. STM (IOSim s) (TMVar (IOSim s) a)
newEmptyTMVar = forall (m :: * -> *) a. MonadSTM m => STM m (TMVarDefault m a)
MonadSTM.newEmptyTMVarDefault
takeTMVar :: forall a. TMVar (IOSim s) a -> STM (IOSim s) a
takeTMVar = forall (m :: * -> *) a. MonadSTM m => TMVarDefault m a -> STM m a
MonadSTM.takeTMVarDefault
tryTakeTMVar :: forall a. TMVar (IOSim s) a -> STM (IOSim s) (Maybe a)
tryTakeTMVar = forall (m :: * -> *) a.
MonadSTM m =>
TMVarDefault m a -> STM m (Maybe a)
MonadSTM.tryTakeTMVarDefault
putTMVar :: forall a. TMVar (IOSim s) a -> a -> STM (IOSim s) ()
putTMVar = forall (m :: * -> *) a.
MonadSTM m =>
TMVarDefault m a -> a -> STM m ()
MonadSTM.putTMVarDefault
tryPutTMVar :: forall a. TMVar (IOSim s) a -> a -> STM (IOSim s) Bool
tryPutTMVar = forall (m :: * -> *) a.
MonadSTM m =>
TMVarDefault m a -> a -> STM m Bool
MonadSTM.tryPutTMVarDefault
readTMVar :: forall a. TMVar (IOSim s) a -> STM (IOSim s) a
readTMVar = forall (m :: * -> *) a. MonadSTM m => TMVarDefault m a -> STM m a
MonadSTM.readTMVarDefault
tryReadTMVar :: forall a. TMVar (IOSim s) a -> STM (IOSim s) (Maybe a)
tryReadTMVar = forall (m :: * -> *) a.
MonadSTM m =>
TMVarDefault m a -> STM m (Maybe a)
MonadSTM.tryReadTMVarDefault
swapTMVar :: forall a. TMVar (IOSim s) a -> a -> STM (IOSim s) a
swapTMVar = forall (m :: * -> *) a.
MonadSTM m =>
TMVarDefault m a -> a -> STM m a
MonadSTM.swapTMVarDefault
isEmptyTMVar :: forall a. TMVar (IOSim s) a -> STM (IOSim s) Bool
isEmptyTMVar = forall (m :: * -> *) a.
MonadSTM m =>
TMVarDefault m a -> STM m Bool
MonadSTM.isEmptyTMVarDefault
newTQueue :: forall a. STM (IOSim s) (TQueue (IOSim s) a)
newTQueue = forall (m :: * -> *) a. MonadSTM m => STM m (TQueueDefault m a)
newTQueueDefault
readTQueue :: forall a. TQueue (IOSim s) a -> STM (IOSim s) a
readTQueue = forall (m :: * -> *) a. MonadSTM m => TQueueDefault m a -> STM m a
readTQueueDefault
tryReadTQueue :: forall a. TQueue (IOSim s) a -> STM (IOSim s) (Maybe a)
tryReadTQueue = forall (m :: * -> *) a.
MonadSTM m =>
TQueueDefault m a -> STM m (Maybe a)
tryReadTQueueDefault
peekTQueue :: forall a. TQueue (IOSim s) a -> STM (IOSim s) a
peekTQueue = forall (m :: * -> *) a. MonadSTM m => TQueueDefault m a -> STM m a
peekTQueueDefault
tryPeekTQueue :: forall a. TQueue (IOSim s) a -> STM (IOSim s) (Maybe a)
tryPeekTQueue = forall (m :: * -> *) a.
MonadSTM m =>
TQueueDefault m a -> STM m (Maybe a)
tryPeekTQueueDefault
flushTQueue :: forall a. TQueue (IOSim s) a -> STM (IOSim s) [a]
flushTQueue = forall (m :: * -> *) a.
MonadSTM m =>
TQueueDefault m a -> STM m [a]
flushTQueueDefault
writeTQueue :: forall a. TQueue (IOSim s) a -> a -> STM (IOSim s) ()
writeTQueue = forall (m :: * -> *) a.
MonadSTM m =>
TQueueDefault m a -> a -> STM m ()
writeTQueueDefault
isEmptyTQueue :: forall a. TQueue (IOSim s) a -> STM (IOSim s) Bool
isEmptyTQueue = forall (m :: * -> *) a.
MonadSTM m =>
TQueueDefault m a -> STM m Bool
isEmptyTQueueDefault
unGetTQueue :: forall a. TQueue (IOSim s) a -> a -> STM (IOSim s) ()
unGetTQueue = forall (m :: * -> *) a.
MonadSTM m =>
TQueueDefault m a -> a -> STM m ()
unGetTQueueDefault
newTBQueue :: forall a. Natural -> STM (IOSim s) (TBQueue (IOSim s) a)
newTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
Natural -> STM m (TBQueueDefault m a)
newTBQueueDefault
readTBQueue :: forall a. TBQueue (IOSim s) a -> STM (IOSim s) a
readTBQueue = forall (m :: * -> *) a. MonadSTM m => TBQueueDefault m a -> STM m a
readTBQueueDefault
tryReadTBQueue :: forall a. TBQueue (IOSim s) a -> STM (IOSim s) (Maybe a)
tryReadTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueueDefault m a -> STM m (Maybe a)
tryReadTBQueueDefault
peekTBQueue :: forall a. TBQueue (IOSim s) a -> STM (IOSim s) a
peekTBQueue = forall (m :: * -> *) a. MonadSTM m => TBQueueDefault m a -> STM m a
peekTBQueueDefault
tryPeekTBQueue :: forall a. TBQueue (IOSim s) a -> STM (IOSim s) (Maybe a)
tryPeekTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueueDefault m a -> STM m (Maybe a)
tryPeekTBQueueDefault
flushTBQueue :: forall a. TBQueue (IOSim s) a -> STM (IOSim s) [a]
flushTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueueDefault m a -> STM m [a]
flushTBQueueDefault
writeTBQueue :: forall a. TBQueue (IOSim s) a -> a -> STM (IOSim s) ()
writeTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueueDefault m a -> a -> STM m ()
writeTBQueueDefault
lengthTBQueue :: forall a. TBQueue (IOSim s) a -> STM (IOSim s) Natural
lengthTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueueDefault m a -> STM m Natural
lengthTBQueueDefault
isEmptyTBQueue :: forall a. TBQueue (IOSim s) a -> STM (IOSim s) Bool
isEmptyTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueueDefault m a -> STM m Bool
isEmptyTBQueueDefault
isFullTBQueue :: forall a. TBQueue (IOSim s) a -> STM (IOSim s) Bool
isFullTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueueDefault m a -> STM m Bool
isFullTBQueueDefault
unGetTBQueue :: forall a. TBQueue (IOSim s) a -> a -> STM (IOSim s) ()
unGetTBQueue = forall (m :: * -> *) a.
MonadSTM m =>
TBQueueDefault m a -> a -> STM m ()
unGetTBQueueDefault
newTSem :: Integer -> STM (IOSim s) (TSem (IOSim s))
newTSem = forall (m :: * -> *).
MonadSTM m =>
Integer -> STM m (TSemDefault m)
MonadSTM.newTSemDefault
waitTSem :: TSem (IOSim s) -> STM (IOSim s) ()
waitTSem = forall (m :: * -> *). MonadSTM m => TSemDefault m -> STM m ()
MonadSTM.waitTSemDefault
signalTSem :: TSem (IOSim s) -> STM (IOSim s) ()
signalTSem = forall (m :: * -> *). MonadSTM m => TSemDefault m -> STM m ()
MonadSTM.signalTSemDefault
signalTSemN :: Natural -> TSem (IOSim s) -> STM (IOSim s) ()
signalTSemN = forall (m :: * -> *).
MonadSTM m =>
Natural -> TSemDefault m -> STM m ()
MonadSTM.signalTSemNDefault
newTChan :: forall a. STM (IOSim s) (TChan (IOSim s) a)
newTChan = forall (m :: * -> *) a. MonadSTM m => STM m (TChanDefault m a)
MonadSTM.newTChanDefault
newBroadcastTChan :: forall a. STM (IOSim s) (TChan (IOSim s) a)
newBroadcastTChan = forall (m :: * -> *) a. MonadSTM m => STM m (TChanDefault m a)
MonadSTM.newBroadcastTChanDefault
writeTChan :: forall a. TChan (IOSim s) a -> a -> STM (IOSim s) ()
writeTChan = forall (m :: * -> *) a.
MonadSTM m =>
TChanDefault m a -> a -> STM m ()
MonadSTM.writeTChanDefault
readTChan :: forall a. TChan (IOSim s) a -> STM (IOSim s) a
readTChan = forall (m :: * -> *) a. MonadSTM m => TChanDefault m a -> STM m a
MonadSTM.readTChanDefault
tryReadTChan :: forall a. TChan (IOSim s) a -> STM (IOSim s) (Maybe a)
tryReadTChan = forall (m :: * -> *) a.
MonadSTM m =>
TChanDefault m a -> STM m (Maybe a)
MonadSTM.tryReadTChanDefault
peekTChan :: forall a. TChan (IOSim s) a -> STM (IOSim s) a
peekTChan = forall (m :: * -> *) a. MonadSTM m => TChanDefault m a -> STM m a
MonadSTM.peekTChanDefault
tryPeekTChan :: forall a. TChan (IOSim s) a -> STM (IOSim s) (Maybe a)
tryPeekTChan = forall (m :: * -> *) a.
MonadSTM m =>
TChanDefault m a -> STM m (Maybe a)
MonadSTM.tryPeekTChanDefault
dupTChan :: forall a. TChan (IOSim s) a -> STM (IOSim s) (TChan (IOSim s) a)
dupTChan = forall (m :: * -> *) a.
MonadSTM m =>
TChanDefault m a -> STM m (TChanDefault m a)
MonadSTM.dupTChanDefault
unGetTChan :: forall a. TChan (IOSim s) a -> a -> STM (IOSim s) ()
unGetTChan = forall (m :: * -> *) a.
MonadSTM m =>
TChanDefault m a -> a -> STM m ()
MonadSTM.unGetTChanDefault
isEmptyTChan :: forall a. TChan (IOSim s) a -> STM (IOSim s) Bool
isEmptyTChan = forall (m :: * -> *) a.
MonadSTM m =>
TChanDefault m a -> STM m Bool
MonadSTM.isEmptyTChanDefault
cloneTChan :: forall a. TChan (IOSim s) a -> STM (IOSim s) (TChan (IOSim s) a)
cloneTChan = forall (m :: * -> *) a.
MonadSTM m =>
TChanDefault m a -> STM m (TChanDefault m a)
MonadSTM.cloneTChanDefault
instance MonadInspectSTM (IOSim s) where
type InspectMonad (IOSim s) = ST s
inspectTVar :: forall (proxy :: (* -> *) -> *) a.
proxy (IOSim s) -> TVar (IOSim s) a -> InspectMonad (IOSim s) a
inspectTVar proxy (IOSim s)
_ TVar { STRef s a
tvarCurrent :: STRef s a
tvarCurrent :: forall s a. TVar s a -> STRef s a
tvarCurrent } = forall s a. STRef s a -> ST s a
readSTRef STRef s a
tvarCurrent
inspectTMVar :: forall (proxy :: (* -> *) -> *) a.
proxy (IOSim s)
-> TMVar (IOSim s) a -> InspectMonad (IOSim s) (Maybe a)
inspectTMVar proxy (IOSim s)
_ (MonadSTM.TMVar TVar { STRef s (Maybe a)
tvarCurrent :: STRef s (Maybe a)
tvarCurrent :: forall s a. TVar s a -> STRef s a
tvarCurrent }) = forall s a. STRef s a -> ST s a
readSTRef STRef s (Maybe a)
tvarCurrent
instance MonadTraceSTM (IOSim s) where
traceTVar :: forall (proxy :: (* -> *) -> *) a.
proxy (IOSim s)
-> TVar (IOSim s) a
-> (Maybe a -> a -> InspectMonad (IOSim s) TraceValue)
-> STM (IOSim s) ()
traceTVar proxy (IOSim s)
_ TVar (IOSim s) a
tvar Maybe a -> a -> InspectMonad (IOSim s) TraceValue
f = forall s a. (forall r. (a -> StmA s r) -> StmA s r) -> STM s a
STM forall a b. (a -> b) -> a -> b
$ \() -> StmA s r
k -> forall s a b.
TVar s a
-> (Maybe a -> a -> ST s TraceValue) -> StmA s b -> StmA s b
TraceTVar TVar (IOSim s) a
tvar Maybe a -> a -> InspectMonad (IOSim s) TraceValue
f (() -> StmA s r
k ())
traceTQueue :: forall (proxy :: (* -> *) -> *) a.
proxy (IOSim s)
-> TQueue (IOSim s) a
-> (Maybe [a] -> [a] -> InspectMonad (IOSim s) TraceValue)
-> STM (IOSim s) ()
traceTQueue = forall (m :: * -> *) (proxy :: (* -> *) -> *) a.
MonadTraceSTM m =>
proxy m
-> TQueueDefault m a
-> (Maybe [a] -> [a] -> InspectMonad m TraceValue)
-> STM m ()
traceTQueueDefault
traceTBQueue :: forall (proxy :: (* -> *) -> *) a.
proxy (IOSim s)
-> TBQueue (IOSim s) a
-> (Maybe [a] -> [a] -> InspectMonad (IOSim s) TraceValue)
-> STM (IOSim s) ()
traceTBQueue = forall (m :: * -> *) (proxy :: (* -> *) -> *) a.
MonadTraceSTM m =>
proxy m
-> TBQueueDefault m a
-> (Maybe [a] -> [a] -> InspectMonad m TraceValue)
-> STM m ()
traceTBQueueDefault
instance MonadMVar (IOSim s) where
type MVar (IOSim s) = MVarDefault (IOSim s)
newEmptyMVar :: forall a. IOSim s (MVar (IOSim s) a)
newEmptyMVar = forall (m :: * -> *) a. MonadSTM m => m (MVarDefault m a)
newEmptyMVarDefault
newMVar :: forall a. a -> IOSim s (MVar (IOSim s) a)
newMVar = forall (m :: * -> *) a. MonadSTM m => a -> m (MVarDefault m a)
newMVarDefault
takeMVar :: forall a. MVar (IOSim s) a -> IOSim s a
takeMVar = forall (m :: * -> *) a.
(MonadMask m, MonadSTM m,
forall x tvar. (tvar ~ TVar m x) => Eq tvar) =>
MVarDefault m a -> m a
takeMVarDefault
putMVar :: forall a. MVar (IOSim s) a -> a -> IOSim s ()
putMVar = forall (m :: * -> *) a.
(MonadMask m, MonadSTM m,
forall x tvar. (tvar ~ TVar m x) => Eq tvar) =>
MVarDefault m a -> a -> m ()
putMVarDefault
tryTakeMVar :: forall a. MVar (IOSim s) a -> IOSim s (Maybe a)
tryTakeMVar = forall (m :: * -> *) a.
MonadSTM m =>
MVarDefault m a -> m (Maybe a)
tryTakeMVarDefault
tryPutMVar :: forall a. MVar (IOSim s) a -> a -> IOSim s Bool
tryPutMVar = forall (m :: * -> *) a.
MonadSTM m =>
MVarDefault m a -> a -> m Bool
tryPutMVarDefault
readMVar :: forall a. MVar (IOSim s) a -> IOSim s a
readMVar = forall (m :: * -> *) a.
(MonadSTM m, MonadMask m,
forall x tvar. (tvar ~ TVar m x) => Eq tvar) =>
MVarDefault m a -> m a
readMVarDefault
tryReadMVar :: forall a. MVar (IOSim s) a -> IOSim s (Maybe a)
tryReadMVar = forall (m :: * -> *) a.
MonadSTM m =>
MVarDefault m a -> m (Maybe a)
tryReadMVarDefault
isEmptyMVar :: forall a. MVar (IOSim s) a -> IOSim s Bool
isEmptyMVar = forall (m :: * -> *) a. MonadSTM m => MVarDefault m a -> m Bool
isEmptyMVarDefault
data Async s a = Async !ThreadId (STM s (Either SomeException a))
instance Eq (Async s a) where
Async ThreadId
tid STM s (Either SomeException a)
_ == :: Async s a -> Async s a -> Bool
== Async ThreadId
tid' STM s (Either SomeException a)
_ = ThreadId
tid forall a. Eq a => a -> a -> Bool
== ThreadId
tid'
instance Ord (Async s a) where
compare :: Async s a -> Async s a -> Ordering
compare (Async ThreadId
tid STM s (Either SomeException a)
_) (Async ThreadId
tid' STM s (Either SomeException a)
_) = forall a. Ord a => a -> a -> Ordering
compare ThreadId
tid ThreadId
tid'
instance Functor (Async s) where
fmap :: forall a b. (a -> b) -> Async s a -> Async s b
fmap a -> b
f (Async ThreadId
tid STM s (Either SomeException a)
a) = forall s a. ThreadId -> STM s (Either SomeException a) -> Async s a
Async ThreadId
tid (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM s (Either SomeException a)
a)
instance MonadAsync (IOSim s) where
type Async (IOSim s) = Async s
async :: forall a. IOSim s a -> IOSim s (Async (IOSim s) a)
async IOSim s a
action = do
TMVarDefault (IOSim s) (Either SomeException a)
var <- forall (m :: * -> *) a. MonadSTM m => m (TMVar m a)
MonadSTM.newEmptyTMVarIO
ThreadId
tid <- forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
mask forall a b. (a -> b) -> a -> b
$ \forall b. IOSim s b -> IOSim s b
restore ->
forall (m :: * -> *). MonadFork m => m () -> m (ThreadId m)
forkIO forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> m (Either e a)
try (forall b. IOSim s b -> IOSim s b
restore IOSim s a
action)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(MonadSTM m, HasCallStack) =>
STM m a -> m a
MonadSTM.atomically forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadSTM m => TMVar m a -> a -> STM m ()
MonadSTM.putTMVar TMVarDefault (IOSim s) (Either SomeException a)
var
forall (m :: * -> *) a.
MonadLabelledSTM m =>
TMVar m a -> String -> m ()
MonadSTM.labelTMVarIO TMVarDefault (IOSim s) (Either SomeException a)
var (String
"async-" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show ThreadId
tid)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall s a. ThreadId -> STM s (Either SomeException a) -> Async s a
Async ThreadId
tid (forall (m :: * -> *) a. MonadSTM m => TMVar m a -> STM m a
MonadSTM.readTMVar TMVarDefault (IOSim s) (Either SomeException a)
var))
asyncOn :: forall a. Int -> IOSim s a -> IOSim s (Async (IOSim s) a)
asyncOn Int
_ = forall (m :: * -> *) a. MonadAsync m => m a -> m (Async m a)
async
asyncBound :: forall a. IOSim s a -> IOSim s (Async (IOSim s) a)
asyncBound = forall (m :: * -> *) a. MonadAsync m => m a -> m (Async m a)
async
asyncThreadId :: forall a. Async (IOSim s) a -> ThreadId (IOSim s)
asyncThreadId (Async ThreadId
tid STM s (Either SomeException a)
_) = ThreadId
tid
waitCatchSTM :: forall a.
Async (IOSim s) a -> STM (IOSim s) (Either SomeException a)
waitCatchSTM (Async ThreadId
_ STM s (Either SomeException a)
w) = STM s (Either SomeException a)
w
pollSTM :: forall a.
Async (IOSim s) a -> STM (IOSim s) (Maybe (Either SomeException a))
pollSTM (Async ThreadId
_ STM s (Either SomeException a)
w) = (forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM s (Either SomeException a)
w) forall (m :: * -> *) a. MonadSTM m => STM m a -> STM m a -> STM m a
`MonadSTM.orElse` forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
cancel :: forall a. Async (IOSim s) a -> IOSim s ()
cancel a :: Async (IOSim s) a
a@(Async ThreadId
tid STM s (Either SomeException a)
_) = forall (m :: * -> *) e.
(MonadFork m, Exception e) =>
ThreadId m -> e -> m ()
throwTo ThreadId
tid AsyncCancelled
AsyncCancelled forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) a.
MonadAsync m =>
Async m a -> m (Either SomeException a)
waitCatch Async (IOSim s) a
a
cancelWith :: forall e a. Exception e => Async (IOSim s) a -> e -> IOSim s ()
cancelWith a :: Async (IOSim s) a
a@(Async ThreadId
tid STM s (Either SomeException a)
_) e
e = forall (m :: * -> *) e.
(MonadFork m, Exception e) =>
ThreadId m -> e -> m ()
throwTo ThreadId
tid e
e forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) a.
MonadAsync m =>
Async m a -> m (Either SomeException a)
waitCatch Async (IOSim s) a
a
asyncWithUnmask :: forall a.
((forall b. IOSim s b -> IOSim s b) -> IOSim s a)
-> IOSim s (Async (IOSim s) a)
asyncWithUnmask (forall b. IOSim s b -> IOSim s b) -> IOSim s a
k = forall (m :: * -> *) a. MonadAsync m => m a -> m (Async m a)
async ((forall b. IOSim s b -> IOSim s b) -> IOSim s a
k forall s a. IOSim s a -> IOSim s a
unblock)
asyncOnWithUnmask :: forall a.
Int
-> ((forall b. IOSim s b -> IOSim s b) -> IOSim s a)
-> IOSim s (Async (IOSim s) a)
asyncOnWithUnmask Int
_ (forall b. IOSim s b -> IOSim s b) -> IOSim s a
k = forall (m :: * -> *) a. MonadAsync m => m a -> m (Async m a)
async ((forall b. IOSim s b -> IOSim s b) -> IOSim s a
k forall s a. IOSim s a -> IOSim s a
unblock)
instance MonadST (IOSim s) where
withLiftST :: forall b. (forall s. (forall a. ST s a -> IOSim s a) -> b) -> b
withLiftST forall s. (forall a. ST s a -> IOSim s a) -> b
f = forall s. (forall a. ST s a -> IOSim s a) -> b
f forall s a. ST s a -> IOSim s a
liftST
liftST :: StrictST.ST s a -> IOSim s a
liftST :: forall s a. ST s a -> IOSim s a
liftST ST s a
action = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \a -> SimA s r
k -> forall s a b. ST s a -> (a -> SimA s b) -> SimA s b
LiftST ST s a
action a -> SimA s r
k
instance MonadMonotonicTimeNSec (IOSim s) where
getMonotonicTimeNSec :: IOSim s Word64
getMonotonicTimeNSec = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \Word64 -> SimA s r
k -> forall s b. (Time -> SimA s b) -> SimA s b
GetMonoTime (Word64 -> SimA s r
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. Time -> Word64
conv)
where
conv :: Time -> Word64
conv :: Time -> Word64
conv (Time DiffTime
d) = forall a b. (Integral a, Num b) => a -> b
fromIntegral (DiffTime -> Integer
diffTimeToPicoseconds DiffTime
d forall a. Integral a => a -> a -> a
`div` Integer
1_000)
instance MonadMonotonicTime (IOSim s) where
getMonotonicTime :: IOSim s Time
getMonotonicTime = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \Time -> SimA s r
k -> forall s b. (Time -> SimA s b) -> SimA s b
GetMonoTime Time -> SimA s r
k
instance MonadTime (IOSim s) where
getCurrentTime :: IOSim s UTCTime
getCurrentTime = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \UTCTime -> SimA s r
k -> forall s b. (UTCTime -> SimA s b) -> SimA s b
GetWallTime UTCTime -> SimA s r
k
setCurrentTime :: UTCTime -> IOSim s ()
setCurrentTime :: forall s. UTCTime -> IOSim s ()
setCurrentTime UTCTime
t = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s b. UTCTime -> SimA s b -> SimA s b
SetWallTime UTCTime
t (() -> SimA s r
k ())
unshareClock :: IOSim s ()
unshareClock :: forall s. IOSim s ()
unshareClock = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s a. SimA s a -> SimA s a
UnshareClock (() -> SimA s r
k ())
instance MonadDelay (IOSim s) where
threadDelay :: Int -> IOSim s ()
threadDelay Int
d =
forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s b. DiffTime -> SimA s b -> SimA s b
ThreadDelay (Int -> DiffTime
SI.microsecondsAsIntToDiffTime Int
d)
(() -> SimA s r
k ())
instance SI.MonadDelay (IOSim s) where
threadDelay :: DiffTime -> IOSim s ()
threadDelay DiffTime
d =
forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s b. DiffTime -> SimA s b -> SimA s b
ThreadDelay DiffTime
d (() -> SimA s r
k ())
data Timeout s = Timeout !(TVar s TimeoutState) !TimeoutId
| NegativeTimeout !TimeoutId
newTimeout :: DiffTime -> IOSim s (Timeout s)
newTimeout :: forall s. DiffTime -> IOSim s (Timeout s)
newTimeout DiffTime
d = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \Timeout s -> SimA s r
k -> forall s b. DiffTime -> (Timeout s -> SimA s b) -> SimA s b
NewTimeout DiffTime
d Timeout s -> SimA s r
k
readTimeout :: Timeout s -> STM s TimeoutState
readTimeout :: forall s. Timeout s -> STM s TimeoutState
readTimeout (Timeout TVar s TimeoutState
var TimeoutId
_key) = forall (m :: * -> *) a. MonadSTM m => TVar m a -> STM m a
MonadSTM.readTVar TVar s TimeoutState
var
readTimeout (NegativeTimeout TimeoutId
_key) = forall (f :: * -> *) a. Applicative f => a -> f a
pure TimeoutState
TimeoutCancelled
cancelTimeout :: Timeout s -> IOSim s ()
cancelTimeout :: forall s. Timeout s -> IOSim s ()
cancelTimeout Timeout s
t = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \() -> SimA s r
k -> forall s b. Timeout s -> SimA s b -> SimA s b
CancelTimeout Timeout s
t (() -> SimA s r
k ())
awaitTimeout :: Timeout s -> STM s Bool
awaitTimeout :: forall s. Timeout s -> STM s Bool
awaitTimeout Timeout s
t = do TimeoutState
s <- forall s. Timeout s -> STM s TimeoutState
readTimeout Timeout s
t
case TimeoutState
s of
TimeoutState
TimeoutPending -> forall (m :: * -> *) a. MonadSTM m => STM m a
retry
TimeoutState
TimeoutFired -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
TimeoutState
TimeoutCancelled -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
instance MonadTimer (IOSim s) where
timeout :: forall a. Int -> IOSim s a -> IOSim s (Maybe a)
timeout Int
d IOSim s a
action
| Int
d forall a. Ord a => a -> a -> Bool
< Int
0 = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IOSim s a
action
| Int
d forall a. Eq a => a -> a -> Bool
== Int
0 = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
| Bool
otherwise = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \Maybe a -> SimA s r
k -> forall s a b.
DiffTime -> SimA s a -> (Maybe a -> SimA s b) -> SimA s b
StartTimeout DiffTime
d' (forall s a. IOSim s a -> SimA s a
runIOSim IOSim s a
action) Maybe a -> SimA s r
k
where
d' :: DiffTime
d' = Int -> DiffTime
SI.microsecondsAsIntToDiffTime Int
d
registerDelay :: Int -> IOSim s (TVar (IOSim s) Bool)
registerDelay Int
d = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \TVar (IOSim s) Bool -> SimA s r
k -> forall s b. DiffTime -> (TVar s Bool -> SimA s b) -> SimA s b
RegisterDelay DiffTime
d' TVar (IOSim s) Bool -> SimA s r
k
where
d' :: DiffTime
d' = Int -> DiffTime
SI.microsecondsAsIntToDiffTime Int
d
instance SI.MonadTimer (IOSim s) where
timeout :: forall a. DiffTime -> IOSim s a -> IOSim s (Maybe a)
timeout DiffTime
d IOSim s a
action
| DiffTime
d forall a. Ord a => a -> a -> Bool
< DiffTime
0 = forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IOSim s a
action
| DiffTime
d forall a. Eq a => a -> a -> Bool
== DiffTime
0 = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
| Bool
otherwise = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \Maybe a -> SimA s r
k -> forall s a b.
DiffTime -> SimA s a -> (Maybe a -> SimA s b) -> SimA s b
StartTimeout DiffTime
d (forall s a. IOSim s a -> SimA s a
runIOSim IOSim s a
action) Maybe a -> SimA s r
k
registerDelay :: DiffTime -> IOSim s (TVar (IOSim s) Bool)
registerDelay DiffTime
d = forall s a. (forall r. (a -> SimA s r) -> SimA s r) -> IOSim s a
IOSim forall a b. (a -> b) -> a -> b
$ oneShot :: forall a b. (a -> b) -> a -> b
oneShot forall a b. (a -> b) -> a -> b
$ \TVar (IOSim s) Bool -> SimA s r
k -> forall s b. DiffTime -> (TVar s Bool -> SimA s b) -> SimA s b
RegisterDelay DiffTime
d TVar (IOSim s) Bool -> SimA s r
k
registerDelayCancellable :: DiffTime -> IOSim s (STM (IOSim s) TimeoutState, IOSim s ())
registerDelayCancellable DiffTime
d = do
Timeout s
t <- forall s. DiffTime -> IOSim s (Timeout s)
newTimeout DiffTime
d
forall (m :: * -> *) a. Monad m => a -> m a
return (forall s. Timeout s -> STM s TimeoutState
readTimeout Timeout s
t, forall s. Timeout s -> IOSim s ()
cancelTimeout Timeout s
t)
newtype TimeoutException = TimeoutException TimeoutId deriving TimeoutException -> TimeoutException -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimeoutException -> TimeoutException -> Bool
$c/= :: TimeoutException -> TimeoutException -> Bool
== :: TimeoutException -> TimeoutException -> Bool
$c== :: TimeoutException -> TimeoutException -> Bool
Eq
instance Show TimeoutException where
show :: TimeoutException -> String
show (TimeoutException TimeoutId
tmid) = String
"<<timeout " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show TimeoutId
tmid forall a. [a] -> [a] -> [a]
++ String
" >>"
instance Exception TimeoutException where
toException :: TimeoutException -> SomeException
toException = forall e. Exception e => e -> SomeException
asyncExceptionToException
fromException :: SomeException -> Maybe TimeoutException
fromException = forall e. Exception e => SomeException -> Maybe e
asyncExceptionFromException
newtype EventlogEvent = EventlogEvent String
newtype EventlogMarker = EventlogMarker String
instance MonadEventlog (IOSim s) where
traceEventIO :: String -> IOSim s ()
traceEventIO = forall a s. Typeable a => a -> IOSim s ()
traceM forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> EventlogEvent
EventlogEvent
traceMarkerIO :: String -> IOSim s ()
traceMarkerIO = forall a s. Typeable a => a -> IOSim s ()
traceM forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> EventlogMarker
EventlogMarker
data SimEvent
= SimEvent {
SimEvent -> Time
seTime :: !Time,
SimEvent -> ThreadId
seThreadId :: !ThreadId,
SimEvent -> Maybe String
seThreadLabel :: !(Maybe ThreadLabel),
SimEvent -> SimEventType
seType :: !SimEventType
}
| SimPOREvent {
seTime :: !Time,
seThreadId :: !ThreadId,
SimEvent -> Int
seStep :: !Int,
seThreadLabel :: !(Maybe ThreadLabel),
seType :: !SimEventType
}
| SimRacesFound [ScheduleControl]
deriving forall x. Rep SimEvent x -> SimEvent
forall x. SimEvent -> Rep SimEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SimEvent x -> SimEvent
$cfrom :: forall x. SimEvent -> Rep SimEvent x
Generic
deriving Int -> SimEvent -> String -> String
[SimEvent] -> String -> String
SimEvent -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [SimEvent] -> String -> String
$cshowList :: [SimEvent] -> String -> String
show :: SimEvent -> String
$cshow :: SimEvent -> String
showsPrec :: Int -> SimEvent -> String -> String
$cshowsPrec :: Int -> SimEvent -> String -> String
Show via Quiet SimEvent
ppSimEvent :: Int
-> Int
-> Int
-> SimEvent
-> String
ppSimEvent :: Int -> Int -> Int -> SimEvent -> String
ppSimEvent Int
timeWidth Int
tidWidth Int
tLabelWidth SimEvent {Time
seTime :: Time
seTime :: SimEvent -> Time
seTime, ThreadId
seThreadId :: ThreadId
seThreadId :: SimEvent -> ThreadId
seThreadId, Maybe String
seThreadLabel :: Maybe String
seThreadLabel :: SimEvent -> Maybe String
seThreadLabel, SimEventType
seType :: SimEventType
seType :: SimEvent -> SimEventType
seType} =
forall r. PrintfType r => String -> r
printf String
"%-*s - %-*s %-*s - %s"
Int
timeWidth
(forall a. Show a => a -> String
show Time
seTime)
Int
tidWidth
(forall a. Show a => a -> String
show ThreadId
seThreadId)
Int
tLabelWidth
String
threadLabel
(forall a. Show a => a -> String
show SimEventType
seType)
where
threadLabel :: String
threadLabel = forall a. a -> Maybe a -> a
fromMaybe String
"" Maybe String
seThreadLabel
ppSimEvent Int
timeWidth Int
tidWidth Int
tLableWidth SimPOREvent {Time
seTime :: Time
seTime :: SimEvent -> Time
seTime, ThreadId
seThreadId :: ThreadId
seThreadId :: SimEvent -> ThreadId
seThreadId, Int
seStep :: Int
seStep :: SimEvent -> Int
seStep, Maybe String
seThreadLabel :: Maybe String
seThreadLabel :: SimEvent -> Maybe String
seThreadLabel, SimEventType
seType :: SimEventType
seType :: SimEvent -> SimEventType
seType} =
forall r. PrintfType r => String -> r
printf String
"%-*s - %-*s %-*s - %s"
Int
timeWidth
(forall a. Show a => a -> String
show Time
seTime)
Int
tidWidth
(forall a. Show a => a -> String
show (ThreadId
seThreadId, Int
seStep))
Int
tLableWidth
String
threadLabel
(forall a. Show a => a -> String
show SimEventType
seType)
where
threadLabel :: String
threadLabel = forall a. a -> Maybe a -> a
fromMaybe String
"" Maybe String
seThreadLabel
ppSimEvent Int
_ Int
_ Int
_ (SimRacesFound [ScheduleControl]
controls) =
String
"RacesFound "forall a. [a] -> [a] -> [a]
++forall a. Show a => a -> String
show [ScheduleControl]
controls
data SimResult a
= MainReturn !Time a ![Labelled ThreadId]
| MainException !Time SomeException ![Labelled ThreadId]
| Deadlock !Time ![Labelled ThreadId]
| Loop
deriving (Int -> SimResult a -> String -> String
forall a. Show a => Int -> SimResult a -> String -> String
forall a. Show a => [SimResult a] -> String -> String
forall a. Show a => SimResult a -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [SimResult a] -> String -> String
$cshowList :: forall a. Show a => [SimResult a] -> String -> String
show :: SimResult a -> String
$cshow :: forall a. Show a => SimResult a -> String
showsPrec :: Int -> SimResult a -> String -> String
$cshowsPrec :: forall a. Show a => Int -> SimResult a -> String -> String
Show, forall a b. a -> SimResult b -> SimResult a
forall a b. (a -> b) -> SimResult a -> SimResult b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> SimResult b -> SimResult a
$c<$ :: forall a b. a -> SimResult b -> SimResult a
fmap :: forall a b. (a -> b) -> SimResult a -> SimResult b
$cfmap :: forall a b. (a -> b) -> SimResult a -> SimResult b
Functor)
type SimTrace a = Trace.Trace (SimResult a) SimEvent
ppTrace :: Show a => SimTrace a -> String
ppTrace :: forall a. Show a => SimTrace a -> String
ppTrace SimTrace a
tr = forall a b. (a -> String) -> (b -> String) -> Trace a b -> String
Trace.ppTrace
forall a. Show a => a -> String
show
(Int -> Int -> Int -> SimEvent -> String
ppSimEvent Int
timeWidth Int
tidWith Int
labelWidth)
SimTrace a
tr
where
(Max Int
timeWidth, Max Int
tidWith, Max Int
labelWidth) =
forall (t :: * -> * -> *) a. (Bifoldable t, Ord a) => t a a -> a
bimaximum
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (forall a b. a -> b -> a
const (forall a. a -> Max a
Max Int
0, forall a. a -> Max a
Max Int
0, forall a. a -> Max a
Max Int
0))
(\SimEvent
a -> case SimEvent
a of
SimEvent {Time
seTime :: Time
seTime :: SimEvent -> Time
seTime, ThreadId
seThreadId :: ThreadId
seThreadId :: SimEvent -> ThreadId
seThreadId, Maybe String
seThreadLabel :: Maybe String
seThreadLabel :: SimEvent -> Maybe String
seThreadLabel} ->
( forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Show a => a -> String
show Time
seTime))
, forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Show a => a -> String
show (ThreadId
seThreadId)))
, forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length Maybe String
seThreadLabel)
)
SimPOREvent {Time
seTime :: Time
seTime :: SimEvent -> Time
seTime, ThreadId
seThreadId :: ThreadId
seThreadId :: SimEvent -> ThreadId
seThreadId, Maybe String
seThreadLabel :: Maybe String
seThreadLabel :: SimEvent -> Maybe String
seThreadLabel} ->
( forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Show a => a -> String
show Time
seTime))
, forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Show a => a -> String
show (ThreadId
seThreadId)))
, forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length Maybe String
seThreadLabel)
)
SimRacesFound {} ->
(forall a. a -> Max a
Max Int
0, forall a. a -> Max a
Max Int
0, forall a. a -> Max a
Max Int
0)
)
forall a b. (a -> b) -> a -> b
$ SimTrace a
tr
ppTrace_ :: SimTrace a -> String
ppTrace_ :: forall a. SimTrace a -> String
ppTrace_ SimTrace a
tr = forall a b. (a -> String) -> (b -> String) -> Trace a b -> String
Trace.ppTrace
(forall a b. a -> b -> a
const String
"")
(Int -> Int -> Int -> SimEvent -> String
ppSimEvent Int
timeWidth Int
tidWith Int
labelWidth)
SimTrace a
tr
where
(Max Int
timeWidth, Max Int
tidWith, Max Int
labelWidth) =
forall (t :: * -> * -> *) a. (Bifoldable t, Ord a) => t a a -> a
bimaximum
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (forall a b. a -> b -> a
const (forall a. a -> Max a
Max Int
0, forall a. a -> Max a
Max Int
0, forall a. a -> Max a
Max Int
0))
(\SimEvent
a -> case SimEvent
a of
SimEvent {Time
seTime :: Time
seTime :: SimEvent -> Time
seTime, ThreadId
seThreadId :: ThreadId
seThreadId :: SimEvent -> ThreadId
seThreadId, Maybe String
seThreadLabel :: Maybe String
seThreadLabel :: SimEvent -> Maybe String
seThreadLabel} ->
( forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Show a => a -> String
show Time
seTime))
, forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Show a => a -> String
show (ThreadId
seThreadId)))
, forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length Maybe String
seThreadLabel)
)
SimPOREvent {Time
seTime :: Time
seTime :: SimEvent -> Time
seTime, ThreadId
seThreadId :: ThreadId
seThreadId :: SimEvent -> ThreadId
seThreadId, Maybe String
seThreadLabel :: Maybe String
seThreadLabel :: SimEvent -> Maybe String
seThreadLabel} ->
( forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Show a => a -> String
show Time
seTime))
, forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. Show a => a -> String
show (ThreadId
seThreadId)))
, forall a. a -> Max a
Max (forall (t :: * -> *) a. Foldable t => t a -> Int
length Maybe String
seThreadLabel)
)
SimRacesFound {} ->
(forall a. a -> Max a
Max Int
0, forall a. a -> Max a
Max Int
0, forall a. a -> Max a
Max Int
0)
)
forall a b. (a -> b) -> a -> b
$ SimTrace a
tr
ppDebug :: SimTrace a -> x -> x
ppDebug :: forall a x. SimTrace a -> x -> x
ppDebug = forall a. Endo a -> a -> a
appEndo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a. (a -> a) -> Endo a
Endo forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. String -> a -> a
Debug.trace forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Trace a b -> [b]
Trace.toList
pattern SimTrace :: Time -> ThreadId -> Maybe ThreadLabel -> SimEventType -> SimTrace a
-> SimTrace a
pattern $bSimTrace :: forall a.
Time
-> ThreadId
-> Maybe String
-> SimEventType
-> SimTrace a
-> SimTrace a
$mSimTrace :: forall {r} {a}.
SimTrace a
-> (Time
-> ThreadId -> Maybe String -> SimEventType -> SimTrace a -> r)
-> ((# #) -> r)
-> r
SimTrace time threadId threadLabel traceEvent trace =
Trace.Cons (SimEvent time threadId threadLabel traceEvent)
trace
pattern SimPORTrace :: Time -> ThreadId -> Int -> Maybe ThreadLabel -> SimEventType -> SimTrace a
-> SimTrace a
pattern $bSimPORTrace :: forall a.
Time
-> ThreadId
-> Int
-> Maybe String
-> SimEventType
-> SimTrace a
-> SimTrace a
$mSimPORTrace :: forall {r} {a}.
SimTrace a
-> (Time
-> ThreadId
-> Int
-> Maybe String
-> SimEventType
-> SimTrace a
-> r)
-> ((# #) -> r)
-> r
SimPORTrace time threadId step threadLabel traceEvent trace =
Trace.Cons (SimPOREvent time threadId step threadLabel traceEvent)
trace
pattern TraceRacesFound :: [ScheduleControl] -> SimTrace a
-> SimTrace a
pattern $bTraceRacesFound :: forall a. [ScheduleControl] -> SimTrace a -> SimTrace a
$mTraceRacesFound :: forall {r} {a}.
SimTrace a
-> ([ScheduleControl] -> SimTrace a -> r) -> ((# #) -> r) -> r
TraceRacesFound controls trace =
Trace.Cons (SimRacesFound controls)
trace
pattern TraceMainReturn :: Time -> a -> [Labelled ThreadId]
-> SimTrace a
pattern $bTraceMainReturn :: forall a. Time -> a -> [Labelled ThreadId] -> SimTrace a
$mTraceMainReturn :: forall {r} {a}.
SimTrace a
-> (Time -> a -> [Labelled ThreadId] -> r) -> ((# #) -> r) -> r
TraceMainReturn time a threads = Trace.Nil (MainReturn time a threads)
pattern TraceMainException :: Time -> SomeException -> [Labelled ThreadId]
-> SimTrace a
pattern $bTraceMainException :: forall a.
Time -> SomeException -> [Labelled ThreadId] -> SimTrace a
$mTraceMainException :: forall {r} {a}.
SimTrace a
-> (Time -> SomeException -> [Labelled ThreadId] -> r)
-> ((# #) -> r)
-> r
TraceMainException time err threads = Trace.Nil (MainException time err threads)
pattern TraceDeadlock :: Time -> [Labelled ThreadId]
-> SimTrace a
pattern $bTraceDeadlock :: forall a. Time -> [Labelled ThreadId] -> SimTrace a
$mTraceDeadlock :: forall {r} {a}.
SimTrace a
-> (Time -> [Labelled ThreadId] -> r) -> ((# #) -> r) -> r
TraceDeadlock time threads = Trace.Nil (Deadlock time threads)
pattern TraceLoop :: SimTrace a
pattern $bTraceLoop :: forall a. SimTrace a
$mTraceLoop :: forall {r} {a}. SimTrace a -> ((# #) -> r) -> ((# #) -> r) -> r
TraceLoop = Trace.Nil Loop
{-# COMPLETE SimTrace, SimPORTrace, TraceMainReturn, TraceMainException, TraceDeadlock, TraceLoop #-}
data SimEventType
= EventSay String
| EventLog Dynamic
| EventMask MaskingState
| EventThrow SomeException
| EventThrowTo SomeException ThreadId
| EventThrowToBlocked
| EventThrowToWakeup
| EventThrowToUnmasked (Labelled ThreadId)
| EventThreadForked ThreadId
| EventThreadFinished
| EventThreadUnhandled SomeException
| EventTxCommitted [Labelled TVarId]
[Labelled TVarId]
(Maybe Effect)
| EventTxAborted (Maybe Effect)
| EventTxBlocked [Labelled TVarId]
(Maybe Effect)
| EventTxWakeup [Labelled TVarId]
| EventUnblocked [ThreadId]
| EventThreadDelay TimeoutId Time
| EventThreadDelayFired TimeoutId
| EventTimeoutCreated TimeoutId ThreadId Time
| EventTimeoutFired TimeoutId
| EventRegisterDelayCreated TimeoutId TVarId Time
| EventRegisterDelayFired TimeoutId
| EventTimerCreated TimeoutId TVarId Time
| EventTimerUpdated TimeoutId Time
| EventTimerCancelled TimeoutId
| EventTimerFired TimeoutId
| EventThreadStatus ThreadId
ThreadId
| EventSimStart ScheduleControl
| EventThreadSleep
| EventThreadWake
| EventDeschedule Deschedule
| EventFollowControl ScheduleControl
| EventAwaitControl StepId ScheduleControl
| EventPerformAction StepId
| EventReschedule ScheduleControl
deriving Int -> SimEventType -> String -> String
[SimEventType] -> String -> String
SimEventType -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [SimEventType] -> String -> String
$cshowList :: [SimEventType] -> String -> String
show :: SimEventType -> String
$cshow :: SimEventType -> String
showsPrec :: Int -> SimEventType -> String -> String
$cshowsPrec :: Int -> SimEventType -> String -> String
Show
data Labelled a = Labelled {
forall a. Labelled a -> a
l_labelled :: !a,
forall a. Labelled a -> Maybe String
l_label :: !(Maybe String)
}
deriving (Labelled a -> Labelled a -> Bool
forall a. Eq a => Labelled a -> Labelled a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Labelled a -> Labelled a -> Bool
$c/= :: forall a. Eq a => Labelled a -> Labelled a -> Bool
== :: Labelled a -> Labelled a -> Bool
$c== :: forall a. Eq a => Labelled a -> Labelled a -> Bool
Eq, Labelled a -> Labelled a -> Bool
Labelled a -> Labelled a -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Labelled a)
forall a. Ord a => Labelled a -> Labelled a -> Bool
forall a. Ord a => Labelled a -> Labelled a -> Ordering
forall a. Ord a => Labelled a -> Labelled a -> Labelled a
min :: Labelled a -> Labelled a -> Labelled a
$cmin :: forall a. Ord a => Labelled a -> Labelled a -> Labelled a
max :: Labelled a -> Labelled a -> Labelled a
$cmax :: forall a. Ord a => Labelled a -> Labelled a -> Labelled a
>= :: Labelled a -> Labelled a -> Bool
$c>= :: forall a. Ord a => Labelled a -> Labelled a -> Bool
> :: Labelled a -> Labelled a -> Bool
$c> :: forall a. Ord a => Labelled a -> Labelled a -> Bool
<= :: Labelled a -> Labelled a -> Bool
$c<= :: forall a. Ord a => Labelled a -> Labelled a -> Bool
< :: Labelled a -> Labelled a -> Bool
$c< :: forall a. Ord a => Labelled a -> Labelled a -> Bool
compare :: Labelled a -> Labelled a -> Ordering
$ccompare :: forall a. Ord a => Labelled a -> Labelled a -> Ordering
Ord, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Labelled a) x -> Labelled a
forall a x. Labelled a -> Rep (Labelled a) x
$cto :: forall a x. Rep (Labelled a) x -> Labelled a
$cfrom :: forall a x. Labelled a -> Rep (Labelled a) x
Generic)
deriving Int -> Labelled a -> String -> String
[Labelled a] -> String -> String
Labelled a -> String
forall a. Show a => Int -> Labelled a -> String -> String
forall a. Show a => [Labelled a] -> String -> String
forall a. Show a => Labelled a -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [Labelled a] -> String -> String
$cshowList :: forall a. Show a => [Labelled a] -> String -> String
show :: Labelled a -> String
$cshow :: forall a. Show a => Labelled a -> String
showsPrec :: Int -> Labelled a -> String -> String
$cshowsPrec :: forall a. Show a => Int -> Labelled a -> String -> String
Show via Quiet (Labelled a)
data StmTxResult s a =
StmTxCommitted a [SomeTVar s]
[SomeTVar s]
[SomeTVar s]
[Dynamic]
[String]
TVarId
| StmTxBlocked [SomeTVar s]
| StmTxAborted [SomeTVar s] SomeException
data BranchStmA s a =
OrElseStmA (StmA s a)
| CatchStmA (SomeException -> StmA s a)
| NoOpStmA
data StmStack s b a where
AtomicallyFrame :: StmStack s a a
BranchFrame :: !(BranchStmA s a)
-> (a -> StmA s b)
-> Map TVarId (SomeTVar s)
-> [SomeTVar s]
-> [SomeTVar s]
-> StmStack s b c
-> StmStack s a c
data ScheduleControl = ControlDefault
| ControlAwait [ScheduleMod]
| ControlFollow [StepId] [ScheduleMod]
deriving (ScheduleControl -> ScheduleControl -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScheduleControl -> ScheduleControl -> Bool
$c/= :: ScheduleControl -> ScheduleControl -> Bool
== :: ScheduleControl -> ScheduleControl -> Bool
$c== :: ScheduleControl -> ScheduleControl -> Bool
Eq, Eq ScheduleControl
ScheduleControl -> ScheduleControl -> Bool
ScheduleControl -> ScheduleControl -> Ordering
ScheduleControl -> ScheduleControl -> ScheduleControl
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ScheduleControl -> ScheduleControl -> ScheduleControl
$cmin :: ScheduleControl -> ScheduleControl -> ScheduleControl
max :: ScheduleControl -> ScheduleControl -> ScheduleControl
$cmax :: ScheduleControl -> ScheduleControl -> ScheduleControl
>= :: ScheduleControl -> ScheduleControl -> Bool
$c>= :: ScheduleControl -> ScheduleControl -> Bool
> :: ScheduleControl -> ScheduleControl -> Bool
$c> :: ScheduleControl -> ScheduleControl -> Bool
<= :: ScheduleControl -> ScheduleControl -> Bool
$c<= :: ScheduleControl -> ScheduleControl -> Bool
< :: ScheduleControl -> ScheduleControl -> Bool
$c< :: ScheduleControl -> ScheduleControl -> Bool
compare :: ScheduleControl -> ScheduleControl -> Ordering
$ccompare :: ScheduleControl -> ScheduleControl -> Ordering
Ord, Int -> ScheduleControl -> String -> String
[ScheduleControl] -> String -> String
ScheduleControl -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [ScheduleControl] -> String -> String
$cshowList :: [ScheduleControl] -> String -> String
show :: ScheduleControl -> String
$cshow :: ScheduleControl -> String
showsPrec :: Int -> ScheduleControl -> String -> String
$cshowsPrec :: Int -> ScheduleControl -> String -> String
Show)
data ScheduleMod = ScheduleMod{
ScheduleMod -> (ThreadId, Int)
scheduleModTarget :: StepId,
ScheduleMod -> ScheduleControl
scheduleModControl :: ScheduleControl,
ScheduleMod -> [(ThreadId, Int)]
scheduleModInsertion :: [StepId]
}
deriving (ScheduleMod -> ScheduleMod -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScheduleMod -> ScheduleMod -> Bool
$c/= :: ScheduleMod -> ScheduleMod -> Bool
== :: ScheduleMod -> ScheduleMod -> Bool
$c== :: ScheduleMod -> ScheduleMod -> Bool
Eq, Eq ScheduleMod
ScheduleMod -> ScheduleMod -> Bool
ScheduleMod -> ScheduleMod -> Ordering
ScheduleMod -> ScheduleMod -> ScheduleMod
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ScheduleMod -> ScheduleMod -> ScheduleMod
$cmin :: ScheduleMod -> ScheduleMod -> ScheduleMod
max :: ScheduleMod -> ScheduleMod -> ScheduleMod
$cmax :: ScheduleMod -> ScheduleMod -> ScheduleMod
>= :: ScheduleMod -> ScheduleMod -> Bool
$c>= :: ScheduleMod -> ScheduleMod -> Bool
> :: ScheduleMod -> ScheduleMod -> Bool
$c> :: ScheduleMod -> ScheduleMod -> Bool
<= :: ScheduleMod -> ScheduleMod -> Bool
$c<= :: ScheduleMod -> ScheduleMod -> Bool
< :: ScheduleMod -> ScheduleMod -> Bool
$c< :: ScheduleMod -> ScheduleMod -> Bool
compare :: ScheduleMod -> ScheduleMod -> Ordering
$ccompare :: ScheduleMod -> ScheduleMod -> Ordering
Ord)
type StepId = (ThreadId, Int)
instance Show ScheduleMod where
showsPrec :: Int -> ScheduleMod -> String -> String
showsPrec Int
d (ScheduleMod (ThreadId, Int)
tgt ScheduleControl
ctrl [(ThreadId, Int)]
insertion) =
Bool -> (String -> String) -> String -> String
showParen (Int
dforall a. Ord a => a -> a -> Bool
>Int
10) forall a b. (a -> b) -> a -> b
$
String -> String -> String
showString String
"ScheduleMod " forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. Show a => Int -> a -> String -> String
showsPrec Int
11 (ThreadId, Int)
tgt forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> String -> String
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. Show a => Int -> a -> String -> String
showsPrec Int
11 ScheduleControl
ctrl forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> String -> String
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. Show a => Int -> a -> String -> String
showsPrec Int
11 [(ThreadId, Int)]
insertion
data ExplorationOptions = ExplorationOptions{
ExplorationOptions -> Int
explorationScheduleBound :: Int,
ExplorationOptions -> Int
explorationBranching :: Int,
ExplorationOptions -> Maybe Int
explorationStepTimelimit :: Maybe Int,
ExplorationOptions -> Maybe ScheduleControl
explorationReplay :: Maybe ScheduleControl
}
deriving Int -> ExplorationOptions -> String -> String
[ExplorationOptions] -> String -> String
ExplorationOptions -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [ExplorationOptions] -> String -> String
$cshowList :: [ExplorationOptions] -> String -> String
show :: ExplorationOptions -> String
$cshow :: ExplorationOptions -> String
showsPrec :: Int -> ExplorationOptions -> String -> String
$cshowsPrec :: Int -> ExplorationOptions -> String -> String
Show
stdExplorationOptions :: ExplorationOptions
stdExplorationOptions :: ExplorationOptions
stdExplorationOptions = ExplorationOptions{
explorationScheduleBound :: Int
explorationScheduleBound = Int
100,
explorationBranching :: Int
explorationBranching = Int
3,
explorationStepTimelimit :: Maybe Int
explorationStepTimelimit = forall a. Maybe a
Nothing,
explorationReplay :: Maybe ScheduleControl
explorationReplay = forall a. Maybe a
Nothing
}
type ExplorationSpec = ExplorationOptions -> ExplorationOptions
withScheduleBound :: Int -> ExplorationSpec
withScheduleBound :: Int -> ExplorationSpec
withScheduleBound Int
n ExplorationOptions
e = ExplorationOptions
e{explorationScheduleBound :: Int
explorationScheduleBound = Int
n}
withBranching :: Int -> ExplorationSpec
withBranching :: Int -> ExplorationSpec
withBranching Int
n ExplorationOptions
e = ExplorationOptions
e{explorationBranching :: Int
explorationBranching = Int
n}
withStepTimelimit :: Int -> ExplorationSpec
withStepTimelimit :: Int -> ExplorationSpec
withStepTimelimit Int
n ExplorationOptions
e = ExplorationOptions
e{explorationStepTimelimit :: Maybe Int
explorationStepTimelimit = forall a. a -> Maybe a
Just Int
n}
withReplay :: ScheduleControl -> ExplorationSpec
withReplay :: ScheduleControl -> ExplorationSpec
withReplay ScheduleControl
r ExplorationOptions
e = ExplorationOptions
e{explorationReplay :: Maybe ScheduleControl
explorationReplay = forall a. a -> Maybe a
Just ScheduleControl
r}