Skip to content

Commit 83412f7

Browse files
committed
fixup! io-sim: Add support for unique symbol generation
1 parent 325538a commit 83412f7

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ ppLabelled pp Labelled { l_labelled = a, l_label = Nothing } = pp a
205205
ppLabelled pp Labelled { l_labelled = a, l_label = Just lbl } = concat ["Labelled ", pp a, " ", lbl]
206206

207207
-- | Abstract unique symbols à la "Data.Unique".
208-
type role IOSimUnique nominal
209208
newtype IOSimUnique s = MkUnique{ unMkUnique :: Integer }
210209
deriving stock (Eq, Ord)
211210
deriving newtype (Hashable, NFData)
211+
type role IOSimUnique nominal
212212

213213
--
214214
-- Utils

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,10 @@ schedule !thread@Thread{
635635

636636
NewUnique k -> do
637637
let thread' = thread{ threadControl = ThreadControl (k nextUniq) ctl }
638-
simstate' = simstate{ nextUniq = MkUnique (unMkUnique nextUniq + 1) }
639-
schedule thread' simstate'
638+
n = unMkUnique nextUniq
639+
simstate' = simstate{ nextUniq = MkUnique (n + 1) }
640+
SimTrace time tid tlbl (EventUniqueCreated n)
641+
<$> schedule thread' simstate'
640642

641643

642644
threadInterruptible :: Thread s a -> Bool

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,9 @@ data SimEventType
10641064
| EventThreadUnhandled SomeException
10651065
-- ^ thread terminated by an unhandled exception
10661066

1067+
| EventUniqueCreated Integer
1068+
-- ^ created the n-th 'IOSimUnique'
1069+
10671070
--
10681071
-- STM events
10691072
--
@@ -1171,6 +1174,7 @@ ppSimEventType = \case
11711174
EventThreadFinished -> "ThreadFinished"
11721175
EventThreadUnhandled a ->
11731176
"ThreadUnhandled " ++ show a
1177+
EventUniqueCreated n -> "UniqueCreated " ++ show n
11741178
EventTxCommitted written created mbEff ->
11751179
concat [ "TxCommitted ",
11761180
ppList (ppLabelled show) written, " ",

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,10 @@ schedule thread@Thread{
818818

819819
NewUnique k -> do
820820
let thread' = thread{ threadControl = ThreadControl (k nextUniq) ctl }
821-
simstate' = simstate{ nextUniq = MkUnique (unMkUnique nextUniq + 1) }
822-
schedule thread' simstate'
821+
n = unMkUnique nextUniq
822+
simstate' = simstate{ nextUniq = MkUnique (n + 1) }
823+
SimPORTrace time tid tstep tlbl (EventUniqueCreated n)
824+
<$> schedule thread' simstate'
823825

824826

825827
threadInterruptible :: Thread s a -> Bool

0 commit comments

Comments
 (0)