Skip to content

Commit 4c83fac

Browse files
committed
Tweaks & Cleanup
1 parent ba63c4c commit 4c83fac

File tree

9 files changed

+28
-37
lines changed

9 files changed

+28
-37
lines changed

io-classes/src/Control/Monad/Class/MonadAsync.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
{-# LANGUAGE QuantifiedConstraints #-}
88
{-# LANGUAGE RankNTypes #-}
99
{-# LANGUAGE ScopedTypeVariables #-}
10-
{-# LANGUAGE TypeApplications #-}
11-
{-# LANGUAGE TypeFamilies #-}
1210
{-# LANGUAGE TypeFamilyDependencies #-}
1311
-- MonadAsync's ReaderT instance is undecidable.
1412
{-# LANGUAGE UndecidableInstances #-}

io-classes/src/Control/Monad/Class/MonadSTM.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
-- | This module corresponds to `Control.Monad.STM` in "stm" package
22
--
3+
{-# LANGUAGE DataKinds #-}
4+
{-# LANGUAGE DerivingStrategies #-}
5+
{-# LANGUAGE FlexibleContexts #-}
6+
{-# LANGUAGE GADTs #-}
7+
{-# LANGUAGE MultiParamTypeClasses #-}
8+
{-# LANGUAGE RankNTypes #-}
9+
{-# LANGUAGE ScopedTypeVariables #-}
10+
-- undecidable instances needed for 'WrappedSTM' instances of 'MonadThrow' and
11+
-- 'MonadCatch' type classes.
12+
{-# LANGUAGE UndecidableInstances #-}
313
module Control.Monad.Class.MonadSTM
414
( MonadSTM (STM, atomically, retry, orElse, check)
515
, throwSTM

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{-# LANGUAGE GADTs #-}
22
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
33
{-# LANGUAGE ScopedTypeVariables #-}
4-
{-# LANGUAGE StandaloneDeriving #-}
54

65
-- | Common types shared between `IOSim` and `IOSimPOR`.
76
--

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

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
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

166161
invariant (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

173168
invariant 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)
809804
reschedule !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.
820815
reschedule !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

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE GADTs #-}
2-
{-# LANGUAGE StandaloneDeriving #-}
32
{-# LANGUAGE RankNTypes #-}
43
{-# LANGUAGE ScopedTypeVariables #-}
54

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ newtype TQueueDefault m a = TQueue (TVar m ([a], [a]))
2323
labelTQueueDefault
2424
:: MonadLabelledSTM m
2525
=> TQueueDefault m a -> String -> STM m ()
26-
labelTQueueDefault (TQueue queue) label = labelTVar queue label
26+
labelTQueueDefault (TQueue queue) label = labelTVar queue label
2727

2828
traceTQueueDefault
2929
:: MonadTraceSTM m

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE DeriveFunctor #-}
33
{-# LANGUAGE DeriveGeneric #-}
4-
{-# LANGUAGE DerivingStrategies #-}
54
{-# LANGUAGE DerivingVia #-}
65
{-# LANGUAGE ExistentialQuantification #-}
76
{-# LANGUAGE FlexibleInstances #-}
87
{-# LANGUAGE GADTSyntax #-}
9-
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
108
{-# LANGUAGE MultiParamTypeClasses #-}
119
{-# LANGUAGE NamedFieldPuns #-}
1210
{-# LANGUAGE PatternSynonyms #-}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
{-# LANGUAGE BangPatterns #-}
22
{-# LANGUAGE CPP #-}
3-
{-# LANGUAGE DeriveGeneric #-}
4-
{-# LANGUAGE DerivingStrategies #-}
53
{-# LANGUAGE DerivingVia #-}
64
{-# LANGUAGE ExistentialQuantification #-}
75
{-# LANGUAGE FlexibleContexts #-}
86
{-# LANGUAGE FlexibleInstances #-}
97
{-# LANGUAGE GADTSyntax #-}
10-
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
11-
{-# LANGUAGE LambdaCase #-}
128
{-# LANGUAGE MultiParamTypeClasses #-}
139
{-# LANGUAGE NamedFieldPuns #-}
1410
{-# LANGUAGE RankNTypes #-}
1511
{-# LANGUAGE ScopedTypeVariables #-}
16-
{-# LANGUAGE StandaloneDeriving #-}
17-
{-# LANGUAGE TypeApplications #-}
1812
{-# LANGUAGE TypeFamilies #-}
19-
{-# LANGUAGE StandaloneDeriving #-}
2013

2114
{-# OPTIONS_GHC -Wno-orphans #-}
2215
-- incomplete uni patterns in 'schedule' (when interpreting 'StmTxCommitted')

io-sim/test/Test/STM.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{-# LANGUAGE FlexibleContexts #-}
44
{-# LANGUAGE GADTs #-}
55
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6-
{-# LANGUAGE KindSignatures #-}
76
{-# LANGUAGE NamedFieldPuns #-}
87
{-# LANGUAGE RankNTypes #-}
98
{-# LANGUAGE ScopedTypeVariables #-}

0 commit comments

Comments
 (0)