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

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

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.Types.BenchmarkInterface
import Distribution.Types.BenchmarkType
import Distribution.Types.BuildInfo
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
$cfrom :: forall x. Benchmark -> Rep Benchmark x
from :: forall x. Benchmark -> Rep Benchmark x
$cto :: forall x. Rep Benchmark x -> Benchmark
to :: forall x. Rep Benchmark x -> Benchmark
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
$cshowsPrec :: Int -> Benchmark -> ShowS
showsPrec :: Int -> Benchmark -> ShowS
$cshow :: Benchmark -> String
show :: Benchmark -> String
$cshowList :: [Benchmark] -> ShowS
showList :: [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
$creadsPrec :: Int -> ReadS Benchmark
readsPrec :: Int -> ReadS Benchmark
$creadList :: ReadS [Benchmark]
readList :: ReadS [Benchmark]
$creadPrec :: ReadPrec Benchmark
readPrec :: ReadPrec Benchmark
$creadListPrec :: ReadPrec [Benchmark]
readListPrec :: ReadPrec [Benchmark]
Read, Benchmark -> Benchmark -> Bool
(Benchmark -> Benchmark -> Bool)
-> (Benchmark -> Benchmark -> Bool) -> Eq Benchmark
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Benchmark -> Benchmark -> Bool
== :: Benchmark -> Benchmark -> Bool
$c/= :: Benchmark -> Benchmark -> Bool
/= :: Benchmark -> Benchmark -> Bool
Eq, Eq Benchmark
Eq Benchmark =>
(Benchmark -> Benchmark -> Ordering)
-> (Benchmark -> Benchmark -> Bool)
-> (Benchmark -> Benchmark -> Bool)
-> (Benchmark -> Benchmark -> Bool)
-> (Benchmark -> Benchmark -> Bool)
-> (Benchmark -> Benchmark -> Benchmark)
-> (Benchmark -> Benchmark -> Benchmark)
-> Ord 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
$ccompare :: Benchmark -> Benchmark -> Ordering
compare :: Benchmark -> Benchmark -> Ordering
$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
>= :: Benchmark -> Benchmark -> Bool
$cmax :: Benchmark -> Benchmark -> Benchmark
max :: Benchmark -> Benchmark -> Benchmark
$cmin :: Benchmark -> Benchmark -> Benchmark
min :: Benchmark -> Benchmark -> Benchmark
Ord, Typeable, Typeable Benchmark
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 -> Constr
Benchmark -> DataType
(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)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Benchmark -> c Benchmark
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Benchmark -> c Benchmark
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Benchmark
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Benchmark
$ctoConstr :: Benchmark -> Constr
toConstr :: Benchmark -> Constr
$cdataTypeOf :: Benchmark -> DataType
dataTypeOf :: Benchmark -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Benchmark)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Benchmark)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Benchmark)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Benchmark)
$cgmapT :: (forall b. Data b => b -> b) -> Benchmark -> Benchmark
gmapT :: (forall b. Data b => b -> b) -> Benchmark -> Benchmark
$cgmapQl :: 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
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Benchmark -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Benchmark -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Benchmark -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Benchmark -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Benchmark -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Benchmark -> u
$cgmapM :: forall (m :: * -> *).
Monad 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
$cgmapMp :: 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
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Benchmark -> m Benchmark
Data)

instance Binary Benchmark
instance Structured Benchmark
instance NFData Benchmark where rnf :: Benchmark -> ()
rnf = Benchmark -> ()
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) = (BuildInfo -> Benchmark) -> f BuildInfo -> f Benchmark
forall a b. (a -> b) -> f a -> f b
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 = 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
      { benchmarkName :: UnqualComponentName
benchmarkName = Benchmark
-> Benchmark
-> (Benchmark -> UnqualComponentName)
-> String
-> UnqualComponentName
forall b a.
(Monoid b, Eq b, Show b) =>
a -> a -> (a -> b) -> String -> b
combineNames Benchmark
a Benchmark
b Benchmark -> UnqualComponentName
benchmarkName String
"benchmark"
      , 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

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)