{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}

module Distribution.Types.Benchmark (
    Benchmark(..),
    emptyBenchmark,
    benchmarkType,
    benchmarkModules,
    benchmarkModulesAutogen
) where

import Prelude ()
import Distribution.Compat.Prelude

import Distribution.Types.BuildInfo
import Distribution.Types.BenchmarkType
import Distribution.Types.BenchmarkInterface
import Distribution.Types.UnqualComponentName

import Distribution.ModuleName

import qualified Distribution.Types.BuildInfo.Lens as L

-- | A \"benchmark\" stanza in a cabal file.
--
data Benchmark = Benchmark {
        Benchmark -> UnqualComponentName
benchmarkName      :: UnqualComponentName,
        Benchmark -> BenchmarkInterface
benchmarkInterface :: BenchmarkInterface,
        Benchmark -> BuildInfo
benchmarkBuildInfo :: BuildInfo
    }
    deriving ((forall x. Benchmark -> Rep Benchmark x)
-> (forall x. Rep Benchmark x -> Benchmark) -> Generic Benchmark
forall x. Rep Benchmark x -> Benchmark
forall x. Benchmark -> Rep Benchmark x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Benchmark x -> Benchmark
$cfrom :: forall x. Benchmark -> Rep Benchmark x
Generic, Int -> Benchmark -> ShowS
[Benchmark] -> ShowS
Benchmark -> String
(Int -> Benchmark -> ShowS)
-> (Benchmark -> String)
-> ([Benchmark] -> ShowS)
-> Show Benchmark
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Benchmark] -> ShowS
$cshowList :: [Benchmark] -> ShowS
show :: Benchmark -> String
$cshow :: Benchmark -> String
showsPrec :: Int -> Benchmark -> ShowS
$cshowsPrec :: Int -> Benchmark -> ShowS
Show, ReadPrec [Benchmark]
ReadPrec Benchmark
Int -> ReadS Benchmark
ReadS [Benchmark]
(Int -> ReadS Benchmark)
-> ReadS [Benchmark]
-> ReadPrec Benchmark
-> ReadPrec [Benchmark]
-> Read Benchmark
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Benchmark]
$creadListPrec :: ReadPrec [Benchmark]
readPrec :: ReadPrec Benchmark
$creadPrec :: ReadPrec Benchmark
readList :: ReadS [Benchmark]
$creadList :: ReadS [Benchmark]
readsPrec :: Int -> ReadS Benchmark
$creadsPrec :: Int -> ReadS Benchmark
Read, Benchmark -> Benchmark -> Bool
(Benchmark -> Benchmark -> Bool)
-> (Benchmark -> Benchmark -> Bool) -> Eq Benchmark
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Benchmark -> Benchmark -> Bool
$c/= :: Benchmark -> Benchmark -> Bool
== :: Benchmark -> Benchmark -> Bool
$c== :: Benchmark -> Benchmark -> Bool
Eq, Typeable, Typeable Benchmark
DataType
Constr
Typeable Benchmark
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Benchmark -> c Benchmark)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Benchmark)
-> (Benchmark -> Constr)
-> (Benchmark -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Benchmark))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Benchmark))
-> ((forall b. Data b => b -> b) -> Benchmark -> Benchmark)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Benchmark -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Benchmark -> r)
-> (forall u. (forall d. Data d => d -> u) -> Benchmark -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Benchmark -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Benchmark -> m Benchmark)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Benchmark -> m Benchmark)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Benchmark -> m Benchmark)
-> Data Benchmark
Benchmark -> DataType
Benchmark -> Constr
(forall b. Data b => b -> b) -> Benchmark -> Benchmark
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Benchmark -> c Benchmark
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Benchmark
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Benchmark -> u
forall u. (forall d. Data d => d -> u) -> Benchmark -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Benchmark -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Benchmark -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Benchmark
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Benchmark -> c Benchmark
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Benchmark)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Benchmark)
$cBenchmark :: Constr
$tBenchmark :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
gmapMp :: (forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
gmapM :: (forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
gmapQi :: Int -> (forall d. Data d => d -> u) -> Benchmark -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Benchmark -> u
gmapQ :: (forall d. Data d => d -> u) -> Benchmark -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Benchmark -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Benchmark -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Benchmark -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Benchmark -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Benchmark -> r
gmapT :: (forall b. Data b => b -> b) -> Benchmark -> Benchmark
$cgmapT :: (forall b. Data b => b -> b) -> Benchmark -> Benchmark
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Benchmark)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Benchmark)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Benchmark)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Benchmark)
dataTypeOf :: Benchmark -> DataType
$cdataTypeOf :: Benchmark -> DataType
toConstr :: Benchmark -> Constr
$ctoConstr :: Benchmark -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Benchmark
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Benchmark
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Benchmark -> c Benchmark
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Benchmark -> c Benchmark
$cp1Data :: Typeable Benchmark
Data)

instance Binary Benchmark

instance NFData Benchmark where rnf :: Benchmark -> ()
rnf = Benchmark -> ()
forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

instance L.HasBuildInfo Benchmark where
    buildInfo :: LensLike f Benchmark Benchmark BuildInfo BuildInfo
buildInfo BuildInfo -> f BuildInfo
f (Benchmark UnqualComponentName
x1 BenchmarkInterface
x2 BuildInfo
x3) = (BuildInfo -> Benchmark) -> f BuildInfo -> f Benchmark
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\BuildInfo
y1 -> UnqualComponentName -> BenchmarkInterface -> BuildInfo -> Benchmark
Benchmark UnqualComponentName
x1 BenchmarkInterface
x2 BuildInfo
y1) (BuildInfo -> f BuildInfo
f BuildInfo
x3)

instance Monoid Benchmark where
    mempty :: Benchmark
mempty = Benchmark :: UnqualComponentName -> BenchmarkInterface -> BuildInfo -> Benchmark
Benchmark {
        benchmarkName :: UnqualComponentName
benchmarkName      = UnqualComponentName
forall a. Monoid a => a
mempty,
        benchmarkInterface :: BenchmarkInterface
benchmarkInterface = BenchmarkInterface
forall a. Monoid a => a
mempty,
        benchmarkBuildInfo :: BuildInfo
benchmarkBuildInfo = BuildInfo
forall a. Monoid a => a
mempty
    }
    mappend :: Benchmark -> Benchmark -> Benchmark
mappend = Benchmark -> Benchmark -> Benchmark
forall a. Semigroup a => a -> a -> a
(<>)

instance Semigroup Benchmark where
    Benchmark
a <> :: Benchmark -> Benchmark -> Benchmark
<> Benchmark
b = Benchmark :: UnqualComponentName -> BenchmarkInterface -> BuildInfo -> Benchmark
Benchmark {
        benchmarkName :: UnqualComponentName
benchmarkName      = (Benchmark -> UnqualComponentName) -> UnqualComponentName
combine' Benchmark -> UnqualComponentName
benchmarkName,
        benchmarkInterface :: BenchmarkInterface
benchmarkInterface = (Benchmark -> BenchmarkInterface) -> BenchmarkInterface
forall a. Monoid a => (Benchmark -> a) -> a
combine  Benchmark -> BenchmarkInterface
benchmarkInterface,
        benchmarkBuildInfo :: BuildInfo
benchmarkBuildInfo = (Benchmark -> BuildInfo) -> BuildInfo
forall a. Monoid a => (Benchmark -> a) -> a
combine  Benchmark -> BuildInfo
benchmarkBuildInfo
    }
        where combine :: (Benchmark -> a) -> a
combine  Benchmark -> a
field = Benchmark -> a
field Benchmark
a a -> a -> a
forall a. Monoid a => a -> a -> a
`mappend` Benchmark -> a
field Benchmark
b
              combine' :: (Benchmark -> UnqualComponentName) -> UnqualComponentName
combine' Benchmark -> UnqualComponentName
field = case ( UnqualComponentName -> String
unUnqualComponentName (UnqualComponentName -> String) -> UnqualComponentName -> String
forall a b. (a -> b) -> a -> b
$ Benchmark -> UnqualComponentName
field Benchmark
a
                                    , UnqualComponentName -> String
unUnqualComponentName (UnqualComponentName -> String) -> UnqualComponentName -> String
forall a b. (a -> b) -> a -> b
$ Benchmark -> UnqualComponentName
field Benchmark
b) of
                        (String
"", String
_) -> Benchmark -> UnqualComponentName
field Benchmark
b
                        (String
_, String
"") -> Benchmark -> UnqualComponentName
field Benchmark
a
                        (String
x, String
y) -> String -> UnqualComponentName
forall a. HasCallStack => String -> a
error (String -> UnqualComponentName) -> String -> UnqualComponentName
forall a b. (a -> b) -> a -> b
$ String
"Ambiguous values for test field: '"
                            String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"' and '" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
y String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"'"

emptyBenchmark :: Benchmark
emptyBenchmark :: Benchmark
emptyBenchmark = Benchmark
forall a. Monoid a => a
mempty

benchmarkType :: Benchmark -> BenchmarkType
benchmarkType :: Benchmark -> BenchmarkType
benchmarkType Benchmark
benchmark = case Benchmark -> BenchmarkInterface
benchmarkInterface Benchmark
benchmark of
  BenchmarkExeV10 Version
ver String
_              -> Version -> BenchmarkType
BenchmarkTypeExe Version
ver
  BenchmarkUnsupported BenchmarkType
benchmarktype -> BenchmarkType
benchmarktype

-- | Get all the module names from a benchmark.
benchmarkModules :: Benchmark -> [ModuleName]
benchmarkModules :: Benchmark -> [ModuleName]
benchmarkModules Benchmark
benchmark = BuildInfo -> [ModuleName]
otherModules (Benchmark -> BuildInfo
benchmarkBuildInfo Benchmark
benchmark)

-- | Get all the auto generated module names from a benchmark.
-- This are a subset of 'benchmarkModules'.
benchmarkModulesAutogen :: Benchmark -> [ModuleName]
benchmarkModulesAutogen :: Benchmark -> [ModuleName]
benchmarkModulesAutogen Benchmark
benchmark = BuildInfo -> [ModuleName]
autogenModules (Benchmark -> BuildInfo
benchmarkBuildInfo Benchmark
benchmark)