Skip to content

Commit 6700050

Browse files
committed
io-sim-por: Moved types to Control.Monad.IOSimPOR.Types
1 parent 9b47268 commit 6700050

File tree

3 files changed

+126
-96
lines changed

3 files changed

+126
-96
lines changed

io-sim/src/Control/Monad/IOSim/Types.hs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,63 +1107,6 @@ data StmStack s b a where
11071107
-> StmStack s b c
11081108
-> StmStack s a c
11091109

1110-
1111-
---
1112-
--- Schedules
1113-
---
1114-
1115-
-- | Modified execution schedule.
1116-
--
1117-
data ScheduleControl = ControlDefault
1118-
-- ^ default scheduling mode
1119-
| ControlAwait [ScheduleMod]
1120-
-- ^ if the current control is 'ControlAwait', the normal
1121-
-- scheduling will proceed, until the thread found in the
1122-
-- first 'ScheduleMod' reaches the given step. At this
1123-
-- point the thread is put to sleep, until after all the
1124-
-- steps are followed.
1125-
| ControlFollow [StepId] [ScheduleMod]
1126-
-- ^ follow the steps then continue with schedule
1127-
-- modifications. This control is set by 'followControl'
1128-
-- when 'controlTargets' returns true.
1129-
deriving (Eq, Ord, Show)
1130-
1131-
1132-
isDefaultSchedule :: ScheduleControl -> Bool
1133-
isDefaultSchedule ControlDefault = True
1134-
isDefaultSchedule (ControlFollow [] []) = True
1135-
isDefaultSchedule _ = False
1136-
1137-
-- | A schedule modification inserted at given execution step.
1138-
--
1139-
data ScheduleMod = ScheduleMod{
1140-
-- | Step at which the 'ScheduleMod' is activated.
1141-
scheduleModTarget :: StepId,
1142-
-- | 'ScheduleControl' at the activation step. It is needed by
1143-
-- 'extendScheduleControl' when combining the discovered schedule with the
1144-
-- initial one.
1145-
scheduleModControl :: ScheduleControl,
1146-
-- | Series of steps which are executed at the target step. This *includes*
1147-
-- the target step, not necessarily as the last step.
1148-
scheduleModInsertion :: [StepId]
1149-
}
1150-
deriving (Eq, Ord)
1151-
1152-
-- | Execution step is identified by the thread id and a monotonically
1153-
-- increasing number (thread specific).
1154-
--
1155-
type StepId = (ThreadId, Int)
1156-
1157-
instance Show ScheduleMod where
1158-
showsPrec d (ScheduleMod tgt ctrl insertion) =
1159-
showParen (d>10) $
1160-
showString "ScheduleMod " .
1161-
showsPrec 11 tgt .
1162-
showString " " .
1163-
showsPrec 11 ctrl .
1164-
showString " " .
1165-
showsPrec 11 insertion
1166-
11671110
---
11681111
--- Exploration options
11691112
---

io-sim/src/Control/Monad/IOSimPOR/Internal.hs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,14 +1664,6 @@ ordNub = go Set.empty
16641664
-- Steps
16651665
--
16661666

1667-
data Step = Step {
1668-
stepThreadId :: !ThreadId,
1669-
stepStep :: !Int,
1670-
stepEffect :: !Effect,
1671-
stepVClock :: !VectorClock
1672-
}
1673-
deriving Show
1674-
16751667
-- | Check if two steps can be reordered with a possibly different outcome.
16761668
--
16771669
racingSteps :: Step -- ^ an earlier step
@@ -1714,36 +1706,6 @@ stepThread thread@Thread { threadId = tid,
17141706
threadEffect thread
17151707
)
17161708

1717-
1718-
-- As we run a simulation, we collect info about each previous step
1719-
data StepInfo = StepInfo {
1720-
stepInfoStep :: !Step,
1721-
-- Control information when we reached this step
1722-
stepInfoControl :: !ScheduleControl,
1723-
-- threads that are still concurrent with this step
1724-
stepInfoConcurrent :: !(Set ThreadId),
1725-
-- steps following this one that did not happen after it
1726-
-- (in reverse order)
1727-
stepInfoNonDep :: ![Step],
1728-
-- later steps that race with this one
1729-
stepInfoRaces :: ![Step]
1730-
}
1731-
deriving Show
1732-
1733-
--
1734-
-- Races
1735-
--
1736-
1737-
data Races = Races { -- These steps may still race with future steps
1738-
activeRaces :: ![StepInfo],
1739-
-- These steps cannot be concurrent with future steps
1740-
completeRaces :: ![StepInfo]
1741-
}
1742-
deriving Show
1743-
1744-
noRaces :: Races
1745-
noRaces = Races [] []
1746-
17471709
-- | 'updateRaces' turns a current 'Step' into 'StepInfo', and updates all
17481710
-- 'activeRaces'.
17491711
--

io-sim/src/Control/Monad/IOSimPOR/Types.hs

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
{-# LANGUAGE NamedFieldPuns #-}
2-
module Control.Monad.IOSimPOR.Types where
2+
module Control.Monad.IOSimPOR.Types
3+
( -- * Effects
4+
Effect (..)
5+
, readEffects
6+
, writeEffects
7+
, forkEffect
8+
, throwToEffect
9+
, wakeupEffects
10+
, onlyReadEffect
11+
, racingEffects
12+
-- * Schedules
13+
, ScheduleControl (..)
14+
, isDefaultSchedule
15+
, ScheduleMod (..)
16+
-- * Steps
17+
, StepId
18+
, Step (..)
19+
, StepInfo (..)
20+
-- * Races
21+
, Races (..)
22+
, noRaces
23+
) where
324

425
import qualified Data.List as List
526
import Data.Set (Set)
@@ -99,3 +120,107 @@ racingEffects e e' =
99120

100121
intersectsL :: Eq a => [a] -> [a] -> Bool
101122
intersectsL a b = not $ null $ a `List.intersect` b
123+
124+
125+
---
126+
--- Schedules
127+
---
128+
129+
-- | Modified execution schedule.
130+
--
131+
data ScheduleControl = ControlDefault
132+
-- ^ default scheduling mode
133+
| ControlAwait [ScheduleMod]
134+
-- ^ if the current control is 'ControlAwait', the normal
135+
-- scheduling will proceed, until the thread found in the
136+
-- first 'ScheduleMod' reaches the given step. At this
137+
-- point the thread is put to sleep, until after all the
138+
-- steps are followed.
139+
| ControlFollow [StepId] [ScheduleMod]
140+
-- ^ follow the steps then continue with schedule
141+
-- modifications. This control is set by 'followControl'
142+
-- when 'controlTargets' returns true.
143+
deriving (Eq, Ord, Show)
144+
145+
146+
isDefaultSchedule :: ScheduleControl -> Bool
147+
isDefaultSchedule ControlDefault = True
148+
isDefaultSchedule (ControlFollow [] []) = True
149+
isDefaultSchedule _ = False
150+
151+
-- | A schedule modification inserted at given execution step.
152+
--
153+
data ScheduleMod = ScheduleMod{
154+
-- | Step at which the 'ScheduleMod' is activated.
155+
scheduleModTarget :: StepId,
156+
-- | 'ScheduleControl' at the activation step. It is needed by
157+
-- 'extendScheduleControl' when combining the discovered schedule with the
158+
-- initial one.
159+
scheduleModControl :: ScheduleControl,
160+
-- | Series of steps which are executed at the target step. This *includes*
161+
-- the target step, not necessarily as the last step.
162+
scheduleModInsertion :: [StepId]
163+
}
164+
deriving (Eq, Ord)
165+
166+
167+
-- | Execution step is identified by the thread id and a monotonically
168+
-- increasing number (thread specific).
169+
--
170+
type StepId = (ThreadId, Int)
171+
172+
instance Show ScheduleMod where
173+
showsPrec d (ScheduleMod tgt ctrl insertion) =
174+
showParen (d>10) $
175+
showString "ScheduleMod " .
176+
showsPrec 11 tgt .
177+
showString " " .
178+
showsPrec 11 ctrl .
179+
showString " " .
180+
showsPrec 11 insertion
181+
182+
--
183+
-- Steps
184+
--
185+
186+
data Step = Step {
187+
stepThreadId :: !ThreadId,
188+
stepStep :: !Int,
189+
stepEffect :: !Effect,
190+
stepVClock :: !VectorClock
191+
}
192+
deriving Show
193+
194+
195+
--
196+
-- StepInfo
197+
--
198+
199+
-- As we run a simulation, we collect info about each previous step
200+
data StepInfo = StepInfo {
201+
stepInfoStep :: !Step,
202+
-- Control information when we reached this step
203+
stepInfoControl :: !ScheduleControl,
204+
-- threads that are still concurrent with this step
205+
stepInfoConcurrent :: !(Set ThreadId),
206+
-- steps following this one that did not happen after it
207+
-- (in reverse order)
208+
stepInfoNonDep :: ![Step],
209+
-- later steps that race with this one
210+
stepInfoRaces :: ![Step]
211+
}
212+
deriving Show
213+
214+
--
215+
-- Races
216+
--
217+
218+
data Races = Races { -- These steps may still race with future steps
219+
activeRaces :: ![StepInfo],
220+
-- These steps cannot be concurrent with future steps
221+
completeRaces :: ![StepInfo]
222+
}
223+
deriving Show
224+
225+
noRaces :: Races
226+
noRaces = Races [] []

0 commit comments

Comments
 (0)