-- editorconfig-checker-disable-file
{-# LANGUAGE ConstraintKinds      #-}
{-# LANGUAGE DataKinds            #-}
{-# LANGUAGE DeriveAnyClass       #-}
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeFamilies         #-}
{-# LANGUAGE UndecidableInstances #-}

{-# LANGUAGE StrictData           #-}
-- So that we don't spend a lot of time optimizing loads of Core whose performance doesn't matter.
{-# OPTIONS_GHC -O0               #-}

module PlutusCore.Evaluation.Machine.BuiltinCostModel
    ( BuiltinCostModel
    , BuiltinCostModelBase(..)
    , CostingFun(..)
    , UnimplementedCostingFun(..)
    , Intercept(..)
    , Slope(..)
    , Coefficient0(..)
    , Coefficient1(..)
    , Coefficient2(..)
    , Coefficient00(..)
    , Coefficient10(..)
    , Coefficient01(..)
    , Coefficient20(..)
    , Coefficient11(..)
    , Coefficient02(..)
    , OneVariableLinearFunction(..)
    , OneVariableQuadraticFunction(..)
    , TwoVariableLinearFunction(..)
    , TwoVariableQuadraticFunction(..)
    , ModelSubtractedSizes(..)
    , ModelConstantOrOneArgument(..)
    , ModelConstantOrTwoArguments(..)
    , ModelConstantOrLinear(..)  -- Deprecated: see Note [Backward compatibility for costing functions]
    , ModelOneArgument(..)
    , ModelTwoArguments(..)
    , ModelThreeArguments(..)
    , ModelFourArguments(..)
    , ModelFiveArguments(..)
    , ModelSixArguments(..)
    , runCostingFunOneArgument
    , runCostingFunTwoArguments
    , runCostingFunThreeArguments
    , runCostingFunFourArguments
    , runCostingFunFiveArguments
    , runCostingFunSixArguments
    , Hashable
    , MCostingFun (..)
    )
where

import PlutusPrelude hiding (toList)

import PlutusCore.Evaluation.Machine.CostingFun.Core
import PlutusCore.Evaluation.Machine.CostingFun.JSON ()
import PlutusCore.Evaluation.Machine.ExBudget

import Barbies
import Data.Aeson
import Data.Kind qualified as Kind
import Data.Monoid
import Deriving.Aeson
import Language.Haskell.TH.Syntax hiding (Name, newName)

type BuiltinCostModel = BuiltinCostModelBase CostingFun

-- See  Note [Budgeting units] in ExBudgeting.hs

-- If the types here change there may be difficulties compiling this file
-- because it doesn't match builtinCostModel.json (which is parsed during
-- compilation).  In that case, manually change the JSON to match or do what it
-- says in Note [Modifying the cost model] in ExBudgetingDefaults.hs.

-- | The main model which contains all data required to predict the cost of
-- builtin functions. See 'CostModelGeneration.md' for how this is
-- generated. Calibrated for the CEK machine.

data BuiltinCostModelBase f =
    BuiltinCostModelBase
    {
      -- Integers
      forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramAddInteger                      :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramSubtractInteger                 :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramMultiplyInteger                 :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramDivideInteger                   :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramQuotientInteger                 :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramRemainderInteger                :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramModInteger                      :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramEqualsInteger                   :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramLessThanInteger                 :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramLessThanEqualsInteger           :: f ModelTwoArguments
    -- Bytestrings
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramAppendByteString                :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramConsByteString                  :: f ModelTwoArguments
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramSliceByteString                 :: f ModelThreeArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramLengthOfByteString              :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramIndexByteString                 :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramEqualsByteString                :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramLessThanByteString              :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramLessThanEqualsByteString        :: f ModelTwoArguments
    -- Cryptography and hashes
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramSha2_256                        :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramSha3_256                        :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramBlake2b_256                     :: f ModelOneArgument
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramVerifyEd25519Signature          :: f ModelThreeArguments
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramVerifyEcdsaSecp256k1Signature   :: f ModelThreeArguments
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramVerifySchnorrSecp256k1Signature :: f ModelThreeArguments
    -- Strings
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramAppendString                    :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramEqualsString                    :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramEncodeUtf8                      :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramDecodeUtf8                      :: f ModelOneArgument
    -- Bool
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramIfThenElse                      :: f ModelThreeArguments
    -- Unit
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramChooseUnit                      :: f ModelTwoArguments
    -- Tracing
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramTrace                           :: f ModelTwoArguments
    -- Pairs
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramFstPair                         :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramSndPair                         :: f ModelOneArgument
    -- Lists
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramChooseList                      :: f ModelThreeArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramMkCons                          :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramHeadList                        :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramTailList                        :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramNullList                        :: f ModelOneArgument
    -- Data
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelSixArguments
paramChooseData                      :: f ModelSixArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramConstrData                      :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramMapData                         :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramListData                        :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramIData                           :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramBData                           :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramUnConstrData                    :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramUnMapData                       :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramUnListData                      :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramUnIData                         :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramUnBData                         :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramEqualsData                      :: f ModelTwoArguments
    -- Misc constructors
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramMkPairData                      :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramMkNilData                       :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramMkNilPairData                   :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramSerialiseData                   :: f ModelOneArgument
    -- BLS12-381
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_G1_add                :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramBls12_381_G1_neg                :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_G1_scalarMul          :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_G1_equal              :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramBls12_381_G1_compress           :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramBls12_381_G1_uncompress         :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_G1_hashToGroup        :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_G2_add                :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramBls12_381_G2_neg                :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_G2_scalarMul          :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_G2_equal              :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramBls12_381_G2_compress           :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramBls12_381_G2_uncompress         :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_G2_hashToGroup        :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_millerLoop            :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_mulMlResult           :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramBls12_381_finalVerify           :: f ModelTwoArguments
    -- Keccak_256, Blake2b_224
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramKeccak_256                      :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramBlake2b_224                     :: f ModelOneArgument
    -- Bitwise operations
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramIntegerToByteString             :: f ModelThreeArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramByteStringToInteger             :: f ModelTwoArguments
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramAndByteString                   :: f ModelThreeArguments
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramOrByteString                    :: f ModelThreeArguments
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramXorByteString                   :: f ModelThreeArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramComplementByteString            :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramReadBit                         :: f ModelTwoArguments
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramWriteBits                       :: f ModelThreeArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramReplicateByte                   :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramShiftByteString                 :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelTwoArguments
paramRotateByteString                :: f ModelTwoArguments
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramCountSetBits                    :: f ModelOneArgument
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramFindFirstSetBit                 :: f ModelOneArgument
    -- Ripemd_160
    , forall (f :: * -> *). BuiltinCostModelBase f -> f ModelOneArgument
paramRipemd_160                      :: f ModelOneArgument
    , forall (f :: * -> *).
BuiltinCostModelBase f -> f ModelThreeArguments
paramExpModInteger                   :: f ModelThreeArguments
    }
    deriving stock ((forall x.
 BuiltinCostModelBase f -> Rep (BuiltinCostModelBase f) x)
-> (forall x.
    Rep (BuiltinCostModelBase f) x -> BuiltinCostModelBase f)
-> Generic (BuiltinCostModelBase f)
forall x. Rep (BuiltinCostModelBase f) x -> BuiltinCostModelBase f
forall x. BuiltinCostModelBase f -> Rep (BuiltinCostModelBase f) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (f :: * -> *) x.
Rep (BuiltinCostModelBase f) x -> BuiltinCostModelBase f
forall (f :: * -> *) x.
BuiltinCostModelBase f -> Rep (BuiltinCostModelBase f) x
$cfrom :: forall (f :: * -> *) x.
BuiltinCostModelBase f -> Rep (BuiltinCostModelBase f) x
from :: forall x. BuiltinCostModelBase f -> Rep (BuiltinCostModelBase f) x
$cto :: forall (f :: * -> *) x.
Rep (BuiltinCostModelBase f) x -> BuiltinCostModelBase f
to :: forall x. Rep (BuiltinCostModelBase f) x -> BuiltinCostModelBase f
Generic)
    deriving anyclass ((forall (f :: * -> *) (g :: * -> *).
 (forall a. f a -> g a)
 -> BuiltinCostModelBase f -> BuiltinCostModelBase g)
-> FunctorB BuiltinCostModelBase
forall k (b :: (k -> *) -> *).
(forall (f :: k -> *) (g :: k -> *).
 (forall (a :: k). f a -> g a) -> b f -> b g)
-> FunctorB b
forall (f :: * -> *) (g :: * -> *).
(forall a. f a -> g a)
-> BuiltinCostModelBase f -> BuiltinCostModelBase g
$cbmap :: forall (f :: * -> *) (g :: * -> *).
(forall a. f a -> g a)
-> BuiltinCostModelBase f -> BuiltinCostModelBase g
bmap :: forall (f :: * -> *) (g :: * -> *).
(forall a. f a -> g a)
-> BuiltinCostModelBase f -> BuiltinCostModelBase g
FunctorB, FunctorB BuiltinCostModelBase
FunctorB BuiltinCostModelBase =>
(forall (e :: * -> *) (f :: * -> *) (g :: * -> *).
 Applicative e =>
 (forall a. f a -> e (g a))
 -> BuiltinCostModelBase f -> e (BuiltinCostModelBase g))
-> TraversableB BuiltinCostModelBase
forall k (b :: (k -> *) -> *).
FunctorB b =>
(forall (e :: * -> *) (f :: k -> *) (g :: k -> *).
 Applicative e =>
 (forall (a :: k). f a -> e (g a)) -> b f -> e (b g))
-> TraversableB b
forall (e :: * -> *) (f :: * -> *) (g :: * -> *).
Applicative e =>
(forall a. f a -> e (g a))
-> BuiltinCostModelBase f -> e (BuiltinCostModelBase g)
$cbtraverse :: forall (e :: * -> *) (f :: * -> *) (g :: * -> *).
Applicative e =>
(forall a. f a -> e (g a))
-> BuiltinCostModelBase f -> e (BuiltinCostModelBase g)
btraverse :: forall (e :: * -> *) (f :: * -> *) (g :: * -> *).
Applicative e =>
(forall a. f a -> e (g a))
-> BuiltinCostModelBase f -> e (BuiltinCostModelBase g)
TraversableB, FunctorB BuiltinCostModelBase
FunctorB BuiltinCostModelBase =>
(forall (c :: * -> Constraint) (f :: * -> *).
 AllB c BuiltinCostModelBase =>
 BuiltinCostModelBase f
 -> BuiltinCostModelBase (Product (Dict c) f))
-> ConstraintsB BuiltinCostModelBase
forall k (b :: (k -> *) -> *).
FunctorB b =>
(forall (c :: k -> Constraint) (f :: k -> *).
 AllB c b =>
 b f -> b (Product (Dict c) f))
-> ConstraintsB b
forall (c :: * -> Constraint) (f :: * -> *).
AllB c BuiltinCostModelBase =>
BuiltinCostModelBase f -> BuiltinCostModelBase (Product (Dict c) f)
$cbaddDicts :: forall (c :: * -> Constraint) (f :: * -> *).
AllB c BuiltinCostModelBase =>
BuiltinCostModelBase f -> BuiltinCostModelBase (Product (Dict c) f)
baddDicts :: forall (c :: * -> Constraint) (f :: * -> *).
AllB c BuiltinCostModelBase =>
BuiltinCostModelBase f -> BuiltinCostModelBase (Product (Dict c) f)
ConstraintsB)

deriving via CustomJSON '[FieldLabelModifier (StripPrefix "param", LowerInitialCharacter)]
             (BuiltinCostModelBase CostingFun) instance ToJSON (BuiltinCostModelBase CostingFun)
deriving via CustomJSON '[FieldLabelModifier (StripPrefix "param", LowerInitialCharacter)]
             (BuiltinCostModelBase CostingFun) instance FromJSON (BuiltinCostModelBase CostingFun)

-- | Same as 'CostingFun' but maybe missing.
-- We could use 'Compose Maybe CostinFun' instead but we would then need an orphan ToJSON instance.
newtype MCostingFun a = MCostingFun (Maybe (CostingFun a))
    deriving newtype ([MCostingFun a] -> Encoding
[MCostingFun a] -> Value
MCostingFun a -> Bool
MCostingFun a -> Encoding
MCostingFun a -> Value
(MCostingFun a -> Value)
-> (MCostingFun a -> Encoding)
-> ([MCostingFun a] -> Value)
-> ([MCostingFun a] -> Encoding)
-> (MCostingFun a -> Bool)
-> ToJSON (MCostingFun a)
forall a. ToJSON a => [MCostingFun a] -> Encoding
forall a. ToJSON a => [MCostingFun a] -> Value
forall a. ToJSON a => MCostingFun a -> Bool
forall a. ToJSON a => MCostingFun a -> Encoding
forall a. ToJSON a => MCostingFun a -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: forall a. ToJSON a => MCostingFun a -> Value
toJSON :: MCostingFun a -> Value
$ctoEncoding :: forall a. ToJSON a => MCostingFun a -> Encoding
toEncoding :: MCostingFun a -> Encoding
$ctoJSONList :: forall a. ToJSON a => [MCostingFun a] -> Value
toJSONList :: [MCostingFun a] -> Value
$ctoEncodingList :: forall a. ToJSON a => [MCostingFun a] -> Encoding
toEncodingList :: [MCostingFun a] -> Encoding
$comitField :: forall a. ToJSON a => MCostingFun a -> Bool
omitField :: MCostingFun a -> Bool
ToJSON)
    deriving (NonEmpty (MCostingFun a) -> MCostingFun a
MCostingFun a -> MCostingFun a -> MCostingFun a
(MCostingFun a -> MCostingFun a -> MCostingFun a)
-> (NonEmpty (MCostingFun a) -> MCostingFun a)
-> (forall b. Integral b => b -> MCostingFun a -> MCostingFun a)
-> Semigroup (MCostingFun a)
forall b. Integral b => b -> MCostingFun a -> MCostingFun a
forall a. NonEmpty (MCostingFun a) -> MCostingFun a
forall a. MCostingFun a -> MCostingFun a -> MCostingFun a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a b. Integral b => b -> MCostingFun a -> MCostingFun a
$c<> :: forall a. MCostingFun a -> MCostingFun a -> MCostingFun a
<> :: MCostingFun a -> MCostingFun a -> MCostingFun a
$csconcat :: forall a. NonEmpty (MCostingFun a) -> MCostingFun a
sconcat :: NonEmpty (MCostingFun a) -> MCostingFun a
$cstimes :: forall a b. Integral b => b -> MCostingFun a -> MCostingFun a
stimes :: forall b. Integral b => b -> MCostingFun a -> MCostingFun a
Semigroup, Semigroup (MCostingFun a)
MCostingFun a
Semigroup (MCostingFun a) =>
MCostingFun a
-> (MCostingFun a -> MCostingFun a -> MCostingFun a)
-> ([MCostingFun a] -> MCostingFun a)
-> Monoid (MCostingFun a)
[MCostingFun a] -> MCostingFun a
MCostingFun a -> MCostingFun a -> MCostingFun a
forall a. Semigroup (MCostingFun a)
forall a. MCostingFun a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. [MCostingFun a] -> MCostingFun a
forall a. MCostingFun a -> MCostingFun a -> MCostingFun a
$cmempty :: forall a. MCostingFun a
mempty :: MCostingFun a
$cmappend :: forall a. MCostingFun a -> MCostingFun a -> MCostingFun a
mappend :: MCostingFun a -> MCostingFun a -> MCostingFun a
$cmconcat :: forall a. [MCostingFun a] -> MCostingFun a
mconcat :: [MCostingFun a] -> MCostingFun a
Monoid) via (Alt Maybe (CostingFun a)) -- for mempty == MCostingFun Nothing

-- Omit generating JSON for any costing functions that have not been set (are missing).
deriving via CustomJSON '[OmitNothingFields, FieldLabelModifier (StripPrefix "param", LowerInitialCharacter)]
             (BuiltinCostModelBase MCostingFun) instance ToJSON (BuiltinCostModelBase MCostingFun)

-- Needed to help derive various instances for BuiltinCostModelBase
type AllArgumentModels (constraint :: Kind.Type -> Kind.Constraint) f =
    ( constraint (f ModelOneArgument)
    , constraint (f ModelTwoArguments)
    , constraint (f ModelThreeArguments)
    , constraint (f ModelFourArguments)
    , constraint (f ModelFiveArguments)
    , constraint (f ModelSixArguments))

-- HLS doesn't like the AllBF from Barbies.
deriving anyclass instance AllArgumentModels NFData  f => NFData  (BuiltinCostModelBase f)
deriving anyclass instance AllArgumentModels Default f => Default (BuiltinCostModelBase f)
deriving stock instance AllArgumentModels Lift    f => Lift    (BuiltinCostModelBase f)
deriving stock instance AllArgumentModels Show    f => Show    (BuiltinCostModelBase f)
deriving stock instance AllArgumentModels Eq      f => Eq      (BuiltinCostModelBase f)