11{-# LANGUAGE BangPatterns #-}
22{-# LANGUAGE CPP #-}
3- {-# LANGUAGE DeriveGeneric #-}
4- {-# LANGUAGE DerivingStrategies #-}
53{-# LANGUAGE DerivingVia #-}
64{-# LANGUAGE ExistentialQuantification #-}
75{-# LANGUAGE FlexibleInstances #-}
86{-# LANGUAGE GADTSyntax #-}
9- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
10- {-# LANGUAGE LambdaCase #-}
117{-# LANGUAGE MultiParamTypeClasses #-}
128{-# LANGUAGE NamedFieldPuns #-}
13- {-# LANGUAGE PatternSynonyms #-}
149{-# LANGUAGE RankNTypes #-}
1510{-# LANGUAGE ScopedTypeVariables #-}
1611{-# LANGUAGE TypeFamilies #-}
@@ -161,22 +156,22 @@ initialState =
161156 where
162157 epoch1970 = UTCTime (fromGregorian 1970 1 1 ) 0
163158
164- invariant :: Maybe (Thread s a ) -> SimState s a -> Bool
159+ invariant :: Maybe (Thread s a ) -> SimState s a -> x -> x
165160
166161invariant (Just running) simstate@ SimState {runqueue,threads,clocks} =
167- not (threadBlocked running)
168- && threadId running `Map.notMember` threads
169- && threadId running `List.notElem` toList runqueue
170- && threadClockId running `Map.member` clocks
171- && invariant Nothing simstate
162+ assert ( not (threadBlocked running) )
163+ . assert ( threadId running `Map.notMember` threads)
164+ . assert ( threadId running `List.notElem` runqueue)
165+ . assert ( threadClockId running `Map.member` clocks)
166+ . invariant Nothing simstate
172167
173168invariant Nothing SimState {runqueue,threads,clocks} =
174- all (`Map.member` threads) runqueue
175- && and [ threadBlocked t == (threadId t `notElem` runqueue)
176- | t <- Map. elems threads ]
177- && toList runqueue == List. nub (toList runqueue)
178- && and [ threadClockId t `Map.member` clocks
179- | t <- Map. elems threads ]
169+ assert ( all (`Map.member` threads) runqueue)
170+ . assert ( and [ threadBlocked t == (threadId t `notElem` runqueue)
171+ | t <- Map. elems threads ])
172+ . assert ( toList runqueue == List. nub (toList runqueue) )
173+ . assert ( and [ threadClockId t `Map.member` clocks
174+ | t <- Map. elems threads ])
180175
181176-- | Interpret the simulation monotonic time as a 'NominalDiffTime' since
182177-- the start.
@@ -202,7 +197,7 @@ schedule !thread@Thread{
202197 nextVid, nextTmid,
203198 curTime = time
204199 } =
205- assert ( invariant (Just thread) simstate) $
200+ invariant (Just thread) simstate $
206201 case action of
207202
208203 Return x -> {-# SCC "schedule.Return" #-}
@@ -423,7 +418,7 @@ schedule !thread@Thread{
423418 return (SimTrace time tid tlbl (EventTimeoutCreated nextTmid tid expiry) trace)
424419
425420 RegisterDelay d k | d < 0 ->
426- {-# SCC "schedule.NewRegisterDelay" #-} do
421+ {-# SCC "schedule.NewRegisterDelay.1 " #-} do
427422 ! tvar <- execNewTVar nextVid
428423 (Just $ " <<timeout " ++ show (unTimeoutId nextTmid) ++ " >>" )
429424 True
@@ -435,7 +430,7 @@ schedule !thread@Thread{
435430 trace)
436431
437432 RegisterDelay d k ->
438- {-# SCC "schedule.NewRegisterDelay" #-} do
433+ {-# SCC "schedule.NewRegisterDelay.2 " #-} do
439434 ! tvar <- execNewTVar nextVid
440435 (Just $ " <<timeout " ++ show (unTimeoutId nextTmid) ++ " >>" )
441436 False
@@ -809,7 +804,7 @@ reschedule :: SimState s a -> ST s (SimTrace a)
809804reschedule ! simstate@ SimState { runqueue, threads }
810805 | Just (! tid, runqueue') <- Deque. uncons runqueue =
811806 {-# SCC "reschedule.Just" #-}
812- assert ( invariant Nothing simstate) $
807+ invariant Nothing simstate $
813808
814809 let thread = threads Map. ! tid in
815810 schedule thread simstate { runqueue = runqueue'
@@ -819,7 +814,7 @@ reschedule !simstate@SimState{ runqueue, threads }
819814-- timer event, or stop.
820815reschedule ! simstate@ SimState { threads, timers, curTime = time } =
821816 {-# SCC "reschedule.Nothing" #-}
822- assert ( invariant Nothing simstate) $
817+ invariant Nothing simstate $
823818
824819 -- important to get all events that expire at this time
825820 case removeMinimums timers of
0 commit comments