Skip to content

Commit

Permalink
Merge pull request #202 from input-output-hk/coot/ppTrace_
Browse files Browse the repository at this point in the history
io-sim: more general ppTrace_ type signature
  • Loading branch information
coot authored Jan 8, 2025
2 parents 573aa8d + c035dea commit 10c1bec
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
- name: Install LLVM (macOS)
if: runner.os == 'macOS' && matrix.ghc == '8.10'
run: |
brew install llvm@13
echo "LLVM_CONFIG=$(brew --prefix llvm@13)/bin/llvm-config" >> $GITHUB_ENV
echo "$(brew --prefix llvm@13)/bin" >> $GITHUB_PATH
brew install llvm@14
echo "LLVM_CONFIG=$(brew --prefix llvm@14)/bin/llvm-config" >> $GITHUB_ENV
echo "$(brew --prefix llvm@14)/bin" >> $GITHUB_PATH
- name: Verify LLVM installation
if: runner.os == 'macOS' && matrix.ghc == '8.10'
Expand Down
2 changes: 0 additions & 2 deletions io-classes/mtl/Control/Monad/Class/MonadSTM/Trans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ instance ( MonadSTM m, MArray e a (STM m) ) => MArray e a (ContTSTM r m) where
getNumElements = ContTSTM . getNumElements
unsafeRead arr = ContTSTM . unsafeRead arr
unsafeWrite arr i = ContTSTM . unsafeWrite arr i
#if __GLASGOW_HASKELL__ >= 910
newArray idxs = ContTSTM . newArray idxs
#endif


-- note: this (and the following) instance requires 'UndecidableInstances'
Expand Down
1 change: 1 addition & 0 deletions io-sim/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- `selectTraceEventsSayWithTime'`
is more general. These functions now accepts trace with any result, rather
than one that finishes with `SimResult`.
- More polymorphic `ppTrace_` type signature.

## 1.6.0.0

Expand Down
2 changes: 1 addition & 1 deletion io-sim/src/Control/Monad/IOSim/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ ppTrace tr = Trace.ppTrace

-- | Like 'ppTrace' but does not show the result value.
--
ppTrace_ :: SimTrace a -> String
ppTrace_ :: Trace.Trace a SimEvent -> String
ppTrace_ tr = Trace.ppTrace
(const "")
(ppSimEvent timeWidth tidWidth labelWidth)
Expand Down
30 changes: 23 additions & 7 deletions io-sim/test/Test/Control/Monad/IOSimPOR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,31 @@ doit n = do
threadDelay 1
readTVarIO r


traceNoDuplicates :: (Testable prop1, Show a1) => ((a1 -> a2 -> a2) -> prop1) -> Property
traceNoDuplicates k = r `pseq` (k addTrace .&&. maximum (traceCounts ()) == 1)
traceNoDuplicates :: forall a b.
(Show a)
=> ((a -> b -> b) -> Property)
-> Property
-- this NOINLINE pragma is useful for debugging if `r` didn't flow outside of
-- `traceNoDuplicate`.
{-# NOINLINE traceNoDuplicates #-}
traceNoDuplicates k = unsafePerformIO $ do
r <- newIORef (Map.empty :: Map String Int)
return $ r `pseq`
(k (addTrace r) .&&. counterexample "trace counts" (maximum (Map.elems (traceCounts r)) === 1))
where
r = unsafePerformIO $ newIORef (Map.empty :: Map String Int)
addTrace t x = unsafePerformIO $ do
atomicModifyIORef r (\m->(Map.insertWith (+) (show t) 1 m,()))
addTrace :: IORef (Map String Int) -> a -> b -> b
addTrace r t x = unsafePerformIO $ do
let s = show t
atomicModifyIORef r
(\m->
let m' = Map.insertWith (+) s 1 m
in (m', ())
)
return x
traceCounts () = unsafePerformIO $ Map.elems <$> readIORef r

traceCounts :: IORef (Map String Int) -> Map String Int
traceCounts r = unsafePerformIO $ readIORef r


-- | Checks that IOSimPOR is capable of analysing an infinite simulation
-- lazily.
Expand Down

0 comments on commit 10c1bec

Please sign in to comment.