Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two IntMap-related improvements #390

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions core/Test/Tasty/Ingredients/ConsoleReporter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import Test.Tasty.Runners.Reducers
import Test.Tasty.Runners.Utils
import Text.Printf
import qualified Data.IntMap as IntMap
import qualified Data.IntSet as IntSet
import Data.Char
#ifdef USE_WCWIDTH
import Foreign.C.Types (CInt(..), CWchar(..))
Expand Down Expand Up @@ -433,8 +434,8 @@ statusMapResult lookahead0 smap
where
f :: Int
-> TVar Status
-> (IntMap.IntMap () -> Int -> STM (IO Bool))
-> (IntMap.IntMap () -> Int -> STM (IO Bool))
-> (IntSet.IntSet -> Int -> STM (IO Bool))
-> (IntSet.IntSet -> Int -> STM (IO Bool))
-- ok_tests is a set of tests that completed successfully
-- lookahead is the number of unfinished tests that we are allowed to
-- look at
Expand All @@ -447,23 +448,23 @@ statusMapResult lookahead0 smap
case this_status of
Done r ->
if resultSuccessful r
then k (IntMap.insert key () ok_tests) lookahead
then k (IntSet.insert key ok_tests) lookahead
else return $ return False
_ -> k ok_tests (lookahead-1)

-- next_iter is called when we end the current iteration,
-- either because we reached the end of the test tree
-- or because we exhausted the lookahead
next_iter :: IntMap.IntMap () -> STM (IO Bool)
next_iter :: IntSet.IntSet -> STM (IO Bool)
next_iter ok_tests =
-- If we made no progress at all, wait until at least some tests
-- complete.
-- Otherwise, reduce the set of tests we are looking at.
if IntMap.null ok_tests
if IntSet.null ok_tests
then retry
else return $ statusMapResult lookahead0 (IntMap.difference smap ok_tests)
else return $ statusMapResult lookahead0 (IntMap.withoutKeys smap ok_tests)

finish :: IntMap.IntMap () -> Int -> STM (IO Bool)
finish :: IntSet.IntSet -> Int -> STM (IO Bool)
finish ok_tests _ = next_iter ok_tests

-- }}}
Expand Down
4 changes: 2 additions & 2 deletions core/Test/Tasty/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Test.Tasty.Run
, DependencyException(..)
) where

import qualified Data.IntMap as IntMap
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Sequence as Seq
import qualified Data.Foldable as F
import Data.Int (Int64)
Expand Down Expand Up @@ -607,7 +607,7 @@ launchTestTree opts tree k0 = do
let NumThreads numTheads = lookupOption opts
(t,k1) <- timed $ do
abortTests <- runInParallel numTheads (testAction <$> testActions)
(do let smap = IntMap.fromList $ zip [0..] (testStatus <$> testActions)
(do let smap = IntMap.fromDistinctAscList $ zip [0..] (testStatus <$> testActions)
k0 smap)
`finallyRestore` \restore -> do
-- Tell all running tests to wrap up.
Expand Down
2 changes: 1 addition & 1 deletion core/tasty.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ library
build-depends:
base >= 4.9 && < 5,
stm >= 2.3 && < 2.6,
containers < 0.7,
containers >= 0.5.8 && < 0.7,
andreasabel marked this conversation as resolved.
Show resolved Hide resolved
transformers >= 0.5 && < 0.7,
tagged >= 0.5 && < 0.9,
optparse-applicative >= 0.14 && < 0.19,
Expand Down