Skip to content

Commit 53eb05a

Browse files
committed
io-sim-por: code style & comments
1 parent 4534b6e commit 53eb05a

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ runSimOrThrow mainAction =
362362

363363
-- | Like 'runSim' but fail when the main thread terminates if there are other
364364
-- threads still running or blocked. If one is trying to follow a strict thread
365-
-- cleanup policy then this helps testing for that.
365+
-- clean-up policy then this helps testing for that.
366366
--
367367
runSimStrictShutdown :: forall a. (forall s. IOSim s a) -> Either Failure a
368368
runSimStrictShutdown mainAction = traceResult True (runSimTrace mainAction)
@@ -451,8 +451,8 @@ runSimTrace mainAction = runST (runSimTraceST mainAction)
451451
-- slot. In /IOSim/ and /IOSimPOR/ time only moves explicitly through timer
452452
-- events, e.g. things like `Control.Monad.Class.MonadTimer.SI.threadDelay`,
453453
-- `Control.Monad.Class.MonadTimer.SI.registerDelay` or the
454-
-- `Control.Monad.Class.MonadTimer.NonStandard.MonadTimeout` api. The usual
455-
-- quickcheck techniques can help explore different schedules of
454+
-- `Control.Monad.Class.MonadTimer.NonStandard.MonadTimeout` API. The usual
455+
-- QuickCheck techniques can help explore different schedules of
456456
-- threads too.
457457

458458
-- | Execute a simulation, discover & revert races. Note that this will execute

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ schedule !thread@Thread{
424424
let !expiry = d `addTime` time
425425
!timers' = PSQ.insert nextTmid expiry (TimerThreadDelay tid nextTmid) timers
426426
!thread' = thread { threadControl = ThreadControl (Return ()) (DelayFrame nextTmid k ctl) }
427-
!trace <- deschedule (Blocked BlockedOnOther) thread' simstate { timers = timers'
427+
!trace <- deschedule (Blocked BlockedOnDelay) thread' simstate { timers = timers'
428428
, nextTmid = succ nextTmid }
429429
return (SimTrace time tid tlbl (EventThreadDelay nextTmid expiry) trace)
430430

@@ -609,10 +609,10 @@ schedule !thread@Thread{
609609
-- exception and the source thread id to the pending async exceptions.
610610
let adjustTarget t = t { threadThrowTo = (e, Labelled tid tlbl) : threadThrowTo t }
611611
threads' = Map.adjust adjustTarget tid' threads
612-
!trace <- deschedule (Blocked BlockedOnOther) thread' simstate { threads = threads' }
612+
!trace <- deschedule (Blocked BlockedOnThrowTo) thread' simstate { threads = threads' }
613613
return $ SimTrace time tid tlbl (EventThrowTo e tid')
614614
$ SimTrace time tid tlbl EventThrowToBlocked
615-
$ SimTrace time tid tlbl (EventDeschedule (Blocked BlockedOnOther))
615+
$ SimTrace time tid tlbl (EventDeschedule (Blocked BlockedOnThrowTo))
616616
$ trace
617617
else do
618618
-- The target thread has async exceptions unmasked, or is masked but

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ data TimerCompletionInfo s =
175175
-- ^ `timeout` timer run by `ThreadId` which was assigned the given
176176
-- `TimeoutId` (only used to report in a trace).
177177

178-
type RunQueue = OrdPSQ (Down ThreadId) (Down ThreadId) ()
178+
type RunQueue = OrdPSQ (Down ThreadId) (Down ThreadId) ()
179179
type Timeouts s = OrdPSQ TimeoutId Time (TimerCompletionInfo s)
180180

181181
-- | Internal state.
@@ -601,7 +601,7 @@ schedule thread@Thread{
601601
thread'' = Thread { threadId = tid'
602602
, threadControl = ThreadControl (runIOSim a)
603603
ForkFrame
604-
, threadStatus = ThreadRunning
604+
, threadStatus = ThreadRunning
605605
, threadMasking = threadMasking thread
606606
, threadThrowTo = []
607607
, threadClockId = threadClockId thread
@@ -1023,7 +1023,7 @@ reschedule simstate@SimState{ threads, timers, curTime = time, races } =
10231023
TimeoutFired -> error "MonadTimer(Sim): invariant violation"
10241024
TimeoutCancelled -> return ()
10251025
timeoutAction (TimerRegisterDelay var) = writeTVar var True
1026-
timeoutAction (TimerThreadDelay _ _) = return ()
1026+
timeoutAction (TimerThreadDelay _ _) = return ()
10271027
timeoutAction (TimerTimeout _ _ _) = return ()
10281028

10291029
unblockThreads :: forall s a.
@@ -1105,7 +1105,7 @@ forkTimeoutInterruptThreads timeoutExpired simState =
11051105
where
11061106
-- we launch a thread responsible for throwing an AsyncCancelled exception
11071107
-- to the thread which timeout expired
1108-
throwToThread :: [(Thread s a, TMVar (IOSim s) ThreadId)]
1108+
throwToThread :: [(Thread s a, TMVar (IOSim s) ThreadId)]
11091109

11101110
(simState', throwToThread) = List.mapAccumR fn simState timeoutExpired
11111111
where
@@ -1143,7 +1143,7 @@ forkTimeoutInterruptThreads timeoutExpired simState =
11431143
, lock
11441144
)
11451145
)
1146-
1146+
11471147

11481148
-- | Iterate through the control stack to find an enclosing exception handler
11491149
-- of the right type, or unwind all the way to the top level for the thread.
@@ -1249,10 +1249,10 @@ runSimTraceST mainAction = controlSimTraceST Nothing ControlDefault mainAction
12491249
controlSimTraceST :: Maybe Int -> ScheduleControl -> IOSim s a -> ST s (SimTrace a)
12501250
controlSimTraceST limit control mainAction =
12511251
SimPORTrace (curTime initialState)
1252-
(threadId mainThread)
1253-
0
1254-
(threadLabel mainThread)
1255-
(EventSimStart control)
1252+
(threadId mainThread)
1253+
0
1254+
(threadLabel mainThread)
1255+
(EventSimStart control)
12561256
<$> schedule mainThread initialState { control = control,
12571257
control0 = control,
12581258
perStepTimeLimit = limit
@@ -1662,6 +1662,7 @@ racingSteps s s' =
16621662
)
16631663
where throwsTo s1 s2 =
16641664
stepThreadId s2 `elem` effectThrows (stepEffect s1)
1665+
-- `throwTo` races with any other effect
16651666
&& stepEffect s2 /= mempty
16661667

16671668
currentStep :: Thread s a -> Step
@@ -1822,7 +1823,7 @@ updateRaces newStep@Step{ stepThreadId = tid, stepEffect = newEffect }
18221823
}
18231824

18241825
activeRaces' :: [StepInfo]
1825-
!activeRaces' =
1826+
!activeRaces' =
18261827
case newStepInfo of
18271828
Nothing -> updateStepInfo <$> activeRaces
18281829
Just si -> si : (updateStepInfo <$> activeRaces)

0 commit comments

Comments
 (0)