16
16
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
17
17
{-# OPTIONS_GHC -Wno-partial-fields #-}
18
18
19
- module Control.Monad.IOSim.Types where
19
+ module Control.Monad.IOSim.Types
20
+ ( IOSim (.. )
21
+ , runIOSim
22
+ , traceM
23
+ , traceSTM
24
+ , liftST
25
+ , SimA (.. )
26
+ , StepId
27
+ , STMSim
28
+ , STM (.. )
29
+ , runSTM
30
+ , StmA (.. )
31
+ , StmTxResult (.. )
32
+ , StmStack (.. )
33
+ , Timeout (.. )
34
+ , TimeoutException (.. )
35
+
36
+ , setCurrentTime
37
+ , unshareClock
38
+
39
+ , ScheduleControl (.. )
40
+ , ScheduleMod (.. )
41
+ , ExplorationOptions (.. )
42
+ , ExplorationSpec
43
+ , withScheduleBound
44
+ , withBranching
45
+ , withStepTimelimit
46
+ , withReplay
47
+ , stdExplorationOptions
48
+
49
+ , EventlogEvent (.. )
50
+ , EventlogMarker (.. )
51
+
52
+ , SimEventType (.. )
53
+ , SimEvent (.. )
54
+ , SimResult (.. )
55
+ , SimTrace
56
+ , Trace. Trace (Trace , SimTrace , TraceMainReturn , TraceMainException ,
57
+ TraceDeadlock , TraceRacesFound , TraceLoop )
58
+ , ppTrace
59
+ , ppTrace_
60
+ , ppSimEvent
61
+ , TraceEvent
62
+ , Labelled (.. )
63
+
64
+ , module Control.Monad.IOSim.CommonTypes
65
+ , SimM
66
+ , SimSTM
67
+ ) where
20
68
21
69
import Control.Exception (ErrorCall (.. ), asyncExceptionFromException , asyncExceptionToException )
22
70
import Control.Applicative
@@ -47,18 +95,20 @@ import Data.Bifoldable
47
95
import Data.Bifunctor (bimap )
48
96
import Data.Map.Strict (Map )
49
97
import Data.Maybe (fromMaybe )
50
- import Data.Set ( Set )
98
+ import Data.Monoid ( Endo ( .. ) )
51
99
import Data.Dynamic (Dynamic , toDyn )
52
- import Data.Function (on )
53
100
import Data.Typeable
54
101
import Data.STRef.Lazy
55
102
import qualified Data.List.Trace as Trace
103
+ import qualified Debug.Trace as Debug
56
104
import Text.Printf
57
105
58
106
import GHC.Generics (Generic )
59
107
import Quiet (Quiet (.. ))
60
108
109
+ import Control.Monad.IOSim.CommonTypes
61
110
import Control.Monad.IOSim.STM
111
+ import Control.Monad.IOSimPOR.Types
62
112
63
113
64
114
import qualified System.IO.Error as IO.Error (userError )
@@ -630,8 +680,10 @@ data SimEventType
630
680
631
681
| EventTxCommitted [Labelled TVarId ] -- tx wrote to these
632
682
[TVarId ] -- and created these
633
- | EventTxAborted
683
+ (Maybe Effect ) -- effect performed (only for `IOSimPOR`)
684
+ | EventTxAborted (Maybe Effect ) -- effect performed (only for `IOSimPOR`)
634
685
| EventTxBlocked [Labelled TVarId ] -- tx blocked reading these
686
+ (Maybe Effect ) -- effect performed (only for `IOSimPOR`)
635
687
| EventTxWakeup [Labelled TVarId ] -- changed vars causing retry
636
688
637
689
| EventTimerCreated TimeoutId TVarId Time
@@ -644,35 +696,16 @@ data SimEventType
644
696
| EventThreadSleep -- the labelling thread was runnable,
645
697
-- but its execution was delayed
646
698
| EventThreadWake -- until this point
699
+ | EventDeschedule Deschedule
700
+ | EventFollowControl ScheduleControl
701
+ | EventAwaitControl StepId ScheduleControl
702
+ | EventPerformAction StepId
703
+ | EventReschedule ScheduleControl
647
704
deriving Show
648
705
649
706
type TraceEvent = SimEventType
650
707
{-# DEPRECATED TraceEvent "Use 'SimEventType' instead." #-}
651
708
652
- data ThreadId = RacyThreadId [Int ]
653
- | ThreadId [Int ] -- non racy threads have higher priority
654
- deriving (Eq , Ord , Show )
655
-
656
- childThreadId :: ThreadId -> Int -> ThreadId
657
- childThreadId (RacyThreadId is) i = RacyThreadId (is ++ [i])
658
- childThreadId (ThreadId is) i = ThreadId (is ++ [i])
659
-
660
- setRacyThread :: ThreadId -> ThreadId
661
- setRacyThread (ThreadId is) = RacyThreadId is
662
- setRacyThread tid@ RacyThreadId {} = tid
663
-
664
- newtype TVarId = TVarId Int deriving (Eq , Ord , Enum , Show )
665
- newtype TimeoutId = TimeoutId Int deriving (Eq , Ord , Enum , Show )
666
- newtype ClockId = ClockId [Int ] deriving (Eq , Ord , Show )
667
- newtype VectorClock = VectorClock { getVectorClock :: Map ThreadId Int }
668
- deriving Show
669
-
670
- unTimeoutId :: TimeoutId -> Int
671
- unTimeoutId (TimeoutId a) = a
672
-
673
- type ThreadLabel = String
674
- type TVarLabel = String
675
-
676
709
data Labelled a = Labelled {
677
710
l_labelled :: ! a ,
678
711
l_label :: ! (Maybe String )
@@ -684,49 +717,6 @@ data Labelled a = Labelled {
684
717
-- Executing STM Transactions
685
718
--
686
719
687
- data MkTVarTrace s a where
688
- MkTVarTrace :: forall s a tr . Typeable tr => (Maybe a -> a -> ST s tr )
689
- -> MkTVarTrace s a
690
-
691
-
692
- data TVar s a = TVar {
693
-
694
- -- | The identifier of this var.
695
- --
696
- tvarId :: ! TVarId ,
697
-
698
- -- | Label.
699
- tvarLabel :: ! (STRef s (Maybe TVarLabel )),
700
-
701
- -- | The var's current value
702
- --
703
- tvarCurrent :: ! (STRef s a ),
704
-
705
- -- | A stack of undo values. This is only used while executing a
706
- -- transaction.
707
- --
708
- tvarUndo :: ! (STRef s [a ]),
709
-
710
- -- | Thread Ids of threads blocked on a read of this var. It is
711
- -- represented in reverse order of thread wakeup, without duplicates.
712
- --
713
- -- To avoid duplicates efficiently, the operations rely on a copy of the
714
- -- thread Ids represented as a set.
715
- --
716
- tvarBlocked :: ! (STRef s ([ThreadId ], Set ThreadId )),
717
-
718
- -- | The vector clock of the current value.
719
- --
720
- tvarVClock :: ! (STRef s VectorClock ),
721
-
722
- -- | Callback to construct a trace which will be attached to the dynamic
723
- -- trace.
724
- tvarTrace :: ! (STRef s (Maybe (MkTVarTrace s a )))
725
- }
726
-
727
- instance Eq (TVar s a ) where
728
- (==) = on (==) tvarId
729
-
730
720
data StmTxResult s a =
731
721
-- | A committed transaction reports the vars that were written (in order
732
722
-- of first write) so that the scheduler can unblock other threads that
@@ -756,9 +746,6 @@ data StmTxResult s a =
756
746
--
757
747
| StmTxAborted [SomeTVar s ] SomeException
758
748
759
- data SomeTVar s where
760
- SomeTVar :: ! (TVar s a ) -> SomeTVar s
761
-
762
749
data StmStack s b a where
763
750
-- | Executing in the context of a top level 'atomically'.
764
751
AtomicallyFrame :: StmStack s a a
0 commit comments