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

module Distribution.Types.BenchmarkType
  ( BenchmarkType (..)
  , knownBenchmarkTypes
  , benchmarkTypeExe
  ) where

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.Parsec
import Distribution.Pretty
import Distribution.Version
import Text.PrettyPrint (char, text)

-- | The \"benchmark-type\" field in the benchmark stanza.
data BenchmarkType
  = -- | \"type: exitcode-stdio-x.y\"
    BenchmarkTypeExe Version
  | -- | Some unknown benchmark type e.g. \"type: foo\"
    BenchmarkTypeUnknown String Version
  deriving ((forall x. BenchmarkType -> Rep BenchmarkType x)
-> (forall x. Rep BenchmarkType x -> BenchmarkType)
-> Generic BenchmarkType
forall x. Rep BenchmarkType x -> BenchmarkType
forall x. BenchmarkType -> Rep BenchmarkType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BenchmarkType -> Rep BenchmarkType x
from :: forall x. BenchmarkType -> Rep BenchmarkType x
$cto :: forall x. Rep BenchmarkType x -> BenchmarkType
to :: forall x. Rep BenchmarkType x -> BenchmarkType
Generic, Int -> BenchmarkType -> ShowS
[BenchmarkType] -> ShowS
BenchmarkType -> String
(Int -> BenchmarkType -> ShowS)
-> (BenchmarkType -> String)
-> ([BenchmarkType] -> ShowS)
-> Show BenchmarkType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BenchmarkType -> ShowS
showsPrec :: Int -> BenchmarkType -> ShowS
$cshow :: BenchmarkType -> String
show :: BenchmarkType -> String
$cshowList :: [BenchmarkType] -> ShowS
showList :: [BenchmarkType] -> ShowS
Show, ReadPrec [BenchmarkType]
ReadPrec BenchmarkType
Int -> ReadS BenchmarkType
ReadS [BenchmarkType]
(Int -> ReadS BenchmarkType)
-> ReadS [BenchmarkType]
-> ReadPrec BenchmarkType
-> ReadPrec [BenchmarkType]
-> Read BenchmarkType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS BenchmarkType
readsPrec :: Int -> ReadS BenchmarkType
$creadList :: ReadS [BenchmarkType]
readList :: ReadS [BenchmarkType]
$creadPrec :: ReadPrec BenchmarkType
readPrec :: ReadPrec BenchmarkType
$creadListPrec :: ReadPrec [BenchmarkType]
readListPrec :: ReadPrec [BenchmarkType]
Read, BenchmarkType -> BenchmarkType -> Bool
(BenchmarkType -> BenchmarkType -> Bool)
-> (BenchmarkType -> BenchmarkType -> Bool) -> Eq BenchmarkType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BenchmarkType -> BenchmarkType -> Bool
== :: BenchmarkType -> BenchmarkType -> Bool
$c/= :: BenchmarkType -> BenchmarkType -> Bool
/= :: BenchmarkType -> BenchmarkType -> Bool
Eq, Eq BenchmarkType
Eq BenchmarkType =>
(BenchmarkType -> BenchmarkType -> Ordering)
-> (BenchmarkType -> BenchmarkType -> Bool)
-> (BenchmarkType -> BenchmarkType -> Bool)
-> (BenchmarkType -> BenchmarkType -> Bool)
-> (BenchmarkType -> BenchmarkType -> Bool)
-> (BenchmarkType -> BenchmarkType -> BenchmarkType)
-> (BenchmarkType -> BenchmarkType -> BenchmarkType)
-> Ord BenchmarkType
BenchmarkType -> BenchmarkType -> Bool
BenchmarkType -> BenchmarkType -> Ordering
BenchmarkType -> BenchmarkType -> BenchmarkType
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 :: BenchmarkType -> BenchmarkType -> Ordering
compare :: BenchmarkType -> BenchmarkType -> Ordering
$c< :: BenchmarkType -> BenchmarkType -> Bool
< :: BenchmarkType -> BenchmarkType -> Bool
$c<= :: BenchmarkType -> BenchmarkType -> Bool
<= :: BenchmarkType -> BenchmarkType -> Bool
$c> :: BenchmarkType -> BenchmarkType -> Bool
> :: BenchmarkType -> BenchmarkType -> Bool
$c>= :: BenchmarkType -> BenchmarkType -> Bool
>= :: BenchmarkType -> BenchmarkType -> Bool
$cmax :: BenchmarkType -> BenchmarkType -> BenchmarkType
max :: BenchmarkType -> BenchmarkType -> BenchmarkType
$cmin :: BenchmarkType -> BenchmarkType -> BenchmarkType
min :: BenchmarkType -> BenchmarkType -> BenchmarkType
Ord, Typeable, Typeable BenchmarkType
Typeable BenchmarkType =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> BenchmarkType -> c BenchmarkType)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c BenchmarkType)
-> (BenchmarkType -> Constr)
-> (BenchmarkType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c BenchmarkType))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c BenchmarkType))
-> ((forall b. Data b => b -> b) -> BenchmarkType -> BenchmarkType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> BenchmarkType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> BenchmarkType -> r)
-> (forall u. (forall d. Data d => d -> u) -> BenchmarkType -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BenchmarkType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType)
-> Data BenchmarkType
BenchmarkType -> Constr
BenchmarkType -> DataType
(forall b. Data b => b -> b) -> BenchmarkType -> BenchmarkType
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) -> BenchmarkType -> u
forall u. (forall d. Data d => d -> u) -> BenchmarkType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BenchmarkType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BenchmarkType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BenchmarkType
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BenchmarkType -> c BenchmarkType
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BenchmarkType)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BenchmarkType)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BenchmarkType -> c BenchmarkType
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BenchmarkType -> c BenchmarkType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BenchmarkType
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BenchmarkType
$ctoConstr :: BenchmarkType -> Constr
toConstr :: BenchmarkType -> Constr
$cdataTypeOf :: BenchmarkType -> DataType
dataTypeOf :: BenchmarkType -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BenchmarkType)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BenchmarkType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BenchmarkType)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BenchmarkType)
$cgmapT :: (forall b. Data b => b -> b) -> BenchmarkType -> BenchmarkType
gmapT :: (forall b. Data b => b -> b) -> BenchmarkType -> BenchmarkType
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BenchmarkType -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BenchmarkType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BenchmarkType -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BenchmarkType -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BenchmarkType -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BenchmarkType -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BenchmarkType -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BenchmarkType -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BenchmarkType -> m BenchmarkType
Data)

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

knownBenchmarkTypes :: [BenchmarkType]
knownBenchmarkTypes :: [BenchmarkType]
knownBenchmarkTypes = [BenchmarkType
benchmarkTypeExe]

benchmarkTypeExe :: BenchmarkType
benchmarkTypeExe :: BenchmarkType
benchmarkTypeExe = Version -> BenchmarkType
BenchmarkTypeExe ([Int] -> Version
mkVersion [Int
1, Int
0])

instance Pretty BenchmarkType where
  pretty :: BenchmarkType -> Doc
pretty (BenchmarkTypeExe Version
ver) = String -> Doc
text String
"exitcode-stdio-" Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
ver
  pretty (BenchmarkTypeUnknown String
name Version
ver) = String -> Doc
text String
name Doc -> Doc -> Doc
<<>> Char -> Doc
char Char
'-' Doc -> Doc -> Doc
<<>> Version -> Doc
forall a. Pretty a => a -> Doc
pretty Version
ver

instance Parsec BenchmarkType where
  parsec :: forall (m :: * -> *). CabalParsing m => m BenchmarkType
parsec = (Version -> String -> BenchmarkType) -> m BenchmarkType
forall (m :: * -> *) ver a.
(CabalParsing m, Parsec ver) =>
(ver -> String -> a) -> m a
parsecStandard ((Version -> String -> BenchmarkType) -> m BenchmarkType)
-> (Version -> String -> BenchmarkType) -> m BenchmarkType
forall a b. (a -> b) -> a -> b
$ \Version
ver String
name -> case String
name of
    String
"exitcode-stdio" -> Version -> BenchmarkType
BenchmarkTypeExe Version
ver
    String
_ -> String -> Version -> BenchmarkType
BenchmarkTypeUnknown String
name Version
ver