{-# 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. 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
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]
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
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, Eq Benchmark
Benchmark -> Benchmark -> Bool
Benchmark -> Benchmark -> Ordering
Benchmark -> Benchmark -> Benchmark
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Benchmark -> Benchmark -> Benchmark
$cmin :: Benchmark -> Benchmark -> Benchmark
max :: Benchmark -> Benchmark -> Benchmark
$cmax :: Benchmark -> Benchmark -> Benchmark
>= :: Benchmark -> Benchmark -> Bool
$c>= :: Benchmark -> Benchmark -> Bool
> :: Benchmark -> Benchmark -> Bool
$c> :: Benchmark -> Benchmark -> Bool
<= :: Benchmark -> Benchmark -> Bool
$c<= :: Benchmark -> Benchmark -> Bool
< :: Benchmark -> Benchmark -> Bool
$c< :: Benchmark -> Benchmark -> Bool
compare :: Benchmark -> Benchmark -> Ordering
$ccompare :: Benchmark -> Benchmark -> Ordering
Ord, Typeable, Typeable Benchmark
Benchmark -> DataType
Benchmark -> Constr
(forall b. Data b => b -> b) -> Benchmark -> 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)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(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 (m :: * -> *).
MonadPlus m =>
(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 (m :: * -> *).
Monad m =>
(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 :: forall u. Int -> (forall d. Data d => d -> u) -> Benchmark -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Benchmark -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Benchmark -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Benchmark -> [u]
gmapQr :: forall r r'.
(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 :: forall r r'.
(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 (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(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 (t :: * -> *) (c :: * -> *).
Typeable t =>
(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 (c :: * -> *).
(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 (c :: * -> *).
(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
Data)

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

instance L.HasBuildInfo Benchmark where
    buildInfo :: Lens' Benchmark BuildInfo
buildInfo BuildInfo -> f BuildInfo
f (Benchmark UnqualComponentName
x1 BenchmarkInterface
x2 BuildInfo
x3) = 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 {
        benchmarkName :: UnqualComponentName
benchmarkName      = forall a. Monoid a => a
mempty,
        benchmarkInterface :: BenchmarkInterface
benchmarkInterface = forall a. Monoid a => a
mempty,
        benchmarkBuildInfo :: BuildInfo
benchmarkBuildInfo = forall a. Monoid a => a
mempty
    }
    mappend :: Benchmark -> Benchmark -> Benchmark
mappend = forall a. Semigroup a => a -> a -> a
(<>)

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

emptyBenchmark :: Benchmark
emptyBenchmark :: Benchmark
emptyBenchmark = 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)