dejafu-0.3.0.0: Overloadable primitives for testable, potentially non-deterministic, concurrency.

Safe HaskellNone
LanguageHaskell2010

Test.DejaFu.STM.Internal

Contents

Description

MonadSTM testing implementation, internal types and definitions.

Synopsis

Documentation

type M n r a = Cont (STMAction n r) a Source

The underlying monad is based on continuations over primitive actions.

type Fixed n r = Ref n r (Cont (STMAction n r)) Source

Dict of methods for implementations to override.

Primitive actions

data STMAction n r Source

STM transactions are represented as a sequence of primitive actions.

Constructors

forall a e . Exception e => SCatch (e -> M n r a) (M n r a) (a -> STMAction n r) 
forall a . SRead (TVar r a) (a -> STMAction n r) 
forall a . SWrite (TVar r a) a (STMAction n r) 
forall a . SOrElse (M n r a) (M n r a) (a -> STMAction n r) 
forall a . SNew String a (TVar r a -> STMAction n r) 
SLift (n (STMAction n r)) 
forall e . Exception e => SThrow e 
SRetry 
SStop 

TVars

newtype TVar r a Source

A TVar is a tuple of a unique ID and the value contained. The ID is so that blocked transactions can be re-run when a TVar they depend on has changed.

Constructors

TVar (TVarId, r a) 

Output

data Result a Source

The result of an STM transaction, along with which TVars it touched whilst executing.

Constructors

Success [TVarId] [TVarId] a

The transaction completed successfully, reading the first list TVars and writing to the second.

Retry [TVarId]

The transaction aborted by calling retry, and read the returned TVars. It should be retried when at least one of the TVars has been mutated.

Exception SomeException

The transaction aborted by throwing an exception.

Execution

doTransaction :: Monad n => Fixed n r -> M n r a -> IdSource -> n (Result a, n (), IdSource, TTrace) Source

Run a STM transaction, returning an action to undo its effects.

stepTrans :: Monad n => Fixed n r -> STMAction n r -> IdSource -> n (STMAction n r, n (), IdSource, [TVarId], [TVarId], TAction) Source

Run a transaction for one step.