@@ -133,6 +133,7 @@ import Control.Monad.IOSimPOR.Types
133
133
134
134
135
135
import qualified System.IO.Error as IO.Error (userError )
136
+ import Data.List (intercalate )
136
137
137
138
{-# ANN module "HLint: ignore Use readTVarIO" #-}
138
139
newtype IOSim s a = IOSim { unIOSim :: forall r . (a -> SimA s r ) -> SimA s r }
@@ -807,9 +808,9 @@ ppSimEvent _ _ _ (SimRacesFound controls) =
807
808
808
809
-- | A result type of a simulation.
809
810
data SimResult a
810
- = MainReturn ! Time a ! [Labelled IOSimThreadId ]
811
+ = MainReturn ! Time ! ( Labelled IOSimThreadId ) a ! [Labelled IOSimThreadId ]
811
812
-- ^ Return value of the main thread.
812
- | MainException ! Time SomeException ! [Labelled IOSimThreadId ]
813
+ | MainException ! Time ! ( Labelled IOSimThreadId ) SomeException ! [Labelled IOSimThreadId ]
813
814
-- ^ Exception thrown by the main thread.
814
815
| Deadlock ! Time ! [Labelled IOSimThreadId ]
815
816
-- ^ Deadlock discovered in the simulation. Deadlocks are discovered if
@@ -821,6 +822,47 @@ data SimResult a
821
822
| InternalError String
822
823
deriving (Show , Functor )
823
824
825
+ ppSimResult :: Show a
826
+ => Int
827
+ -> Int
828
+ -> Int
829
+ -> SimResult a
830
+ -> String
831
+ ppSimResult timeWidth tidWidth thLabelWidth r = case r of
832
+ MainReturn (Time time) tid a tids ->
833
+ printf " %-*s - %-*s %-*s - %s %s"
834
+ timeWidth
835
+ (show time)
836
+ tidWidth
837
+ (ppIOSimThreadId (l_labelled tid))
838
+ thLabelWidth
839
+ (fromMaybe " " $ l_label tid)
840
+ (" MainReturn " ++ show a)
841
+ (" [" ++ intercalate " ," (ppLabelled ppIOSimThreadId `map` tids) ++ " ]" )
842
+ MainException (Time time) tid e tids ->
843
+ printf " %-*s - %-*s %-*s - %s %s"
844
+ timeWidth
845
+ (show time)
846
+ tidWidth
847
+ (ppIOSimThreadId (l_labelled tid))
848
+ thLabelWidth
849
+ (fromMaybe " " $ l_label tid)
850
+ (" MainException " ++ show e)
851
+ (" [" ++ intercalate " ," (ppLabelled ppIOSimThreadId `map` tids) ++ " ]" )
852
+ Deadlock (Time time) tids ->
853
+ printf " %-*s - %-*s %-*s - %s %s"
854
+ timeWidth
855
+ (show time)
856
+ tidWidth
857
+ " "
858
+ thLabelWidth
859
+ " "
860
+ " Deadlock"
861
+ (" [" ++ intercalate " ," (ppLabelled ppIOSimThreadId `map` tids) ++ " ]" )
862
+ Loop -> " <<io-sim-por: step execution exceded explorationStepTimelimit>>"
863
+ InternalError e -> " <<io-sim internal error: " ++ show e ++ " >>"
864
+
865
+
824
866
-- | A type alias for 'IOSim' simulation trace. It comes with useful pattern
825
867
-- synonyms.
826
868
--
@@ -830,21 +872,21 @@ type SimTrace a = Trace.Trace (SimResult a) SimEvent
830
872
--
831
873
ppTrace :: Show a => SimTrace a -> String
832
874
ppTrace tr = Trace. ppTrace
833
- show
834
- (ppSimEvent timeWidth tidWith labelWidth)
875
+ (ppSimResult timeWidth tidWidth labelWidth)
876
+ (ppSimEvent timeWidth tidWidth labelWidth)
835
877
tr
836
878
where
837
- (Max timeWidth, Max tidWith , Max labelWidth) =
879
+ (Max timeWidth, Max tidWidth , Max labelWidth) =
838
880
bimaximum
839
881
. bimap (const (Max 0 , Max 0 , Max 0 ))
840
882
(\ a -> case a of
841
- SimEvent {seTime, seThreadId, seThreadLabel} ->
842
- ( Max (length (show seTime ))
883
+ SimEvent {seTime = Time time , seThreadId, seThreadLabel} ->
884
+ ( Max (length (show time ))
843
885
, Max (length (show (seThreadId)))
844
886
, Max (length seThreadLabel)
845
887
)
846
- SimPOREvent {seTime, seThreadId, seThreadLabel} ->
847
- ( Max (length (show seTime ))
888
+ SimPOREvent {seTime = Time time , seThreadId, seThreadLabel} ->
889
+ ( Max (length (show time ))
848
890
, Max (length (show (seThreadId)))
849
891
, Max (length seThreadLabel)
850
892
)
@@ -859,10 +901,10 @@ ppTrace tr = Trace.ppTrace
859
901
ppTrace_ :: SimTrace a -> String
860
902
ppTrace_ tr = Trace. ppTrace
861
903
(const " " )
862
- (ppSimEvent timeWidth tidWith labelWidth)
904
+ (ppSimEvent timeWidth tidWidth labelWidth)
863
905
tr
864
906
where
865
- (Max timeWidth, Max tidWith , Max labelWidth) =
907
+ (Max timeWidth, Max tidWidth , Max labelWidth) =
866
908
bimaximum
867
909
. bimap (const (Max 0 , Max 0 , Max 0 ))
868
910
(\ a -> case a of
@@ -910,13 +952,13 @@ pattern TraceRacesFound controls trace =
910
952
Trace. Cons (SimRacesFound controls)
911
953
trace
912
954
913
- pattern TraceMainReturn :: Time -> a -> [Labelled IOSimThreadId ]
955
+ pattern TraceMainReturn :: Time -> Labelled IOSimThreadId -> a -> [Labelled IOSimThreadId ]
914
956
-> SimTrace a
915
- pattern TraceMainReturn time a threads = Trace. Nil (MainReturn time a threads)
957
+ pattern TraceMainReturn time tid a threads = Trace. Nil (MainReturn time tid a threads)
916
958
917
- pattern TraceMainException :: Time -> SomeException -> [Labelled IOSimThreadId ]
959
+ pattern TraceMainException :: Time -> Labelled IOSimThreadId -> SomeException -> [Labelled IOSimThreadId ]
918
960
-> SimTrace a
919
- pattern TraceMainException time err threads = Trace. Nil (MainException time err threads)
961
+ pattern TraceMainException time tid err threads = Trace. Nil (MainException time tid err threads)
920
962
921
963
pattern TraceDeadlock :: Time -> [Labelled IOSimThreadId ]
922
964
-> SimTrace a
@@ -1132,7 +1174,7 @@ ppSimEventType = \case
1132
1174
concat [ " Effect " ,
1133
1175
ppVectorClock clock, " " ,
1134
1176
ppEffect eff ]
1135
- EventRaces a -> " Races " ++ show a
1177
+ EventRaces a -> show a
1136
1178
1137
1179
-- | A labelled value.
1138
1180
--
0 commit comments