-- editorconfig-checker-disable-file
{-# LANGUAGE DataKinds       #-}
{-# LANGUAGE LambdaCase      #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies    #-}

module PlutusCore.Evaluation.Machine.ExBudgetingDefaults
    ( defaultBuiltinsRuntimeForSemanticsVariant
    , defaultCekParametersForVariant
    , defaultCostModelParamsForVariant
    , cekCostModelForVariant
    , defaultBuiltinsRuntimeForTesting
    , defaultCekParametersForTesting
    , defaultCekMachineCostsForTesting
    , defaultCostModelParamsForTesting
    , defaultBuiltinCostModelForTesting
    , defaultCekCostModelForTesting
    , defaultCekCostModelForTestingB
    , unitCekMachineCosts
    , unitCekParameters
    )

where

import PlutusCore.Builtin

import PlutusCore.DataFilePaths qualified as DFP
import PlutusCore.Default
import PlutusCore.Evaluation.Machine.BuiltinCostModel
import PlutusCore.Evaluation.Machine.CostModelInterface
import PlutusCore.Evaluation.Machine.MachineParameters

import UntypedPlutusCore.Evaluation.Machine.Cek.CekMachineCosts
import UntypedPlutusCore.Evaluation.Machine.Cek.Internal

import Data.Aeson.THReader
-- Not using 'noinline' from "GHC.Exts", because our CI was unable to find it there, somehow.
import GHC.Magic (noinline)
import PlutusPrelude

{- Note [Modifying the cost model]
   When the Haskell representation of the cost model is changed, for example by
   adding a new builtin or changing the name of an existing one,
   readJSONFromFile will fail when it tries to read a JSON file generated using
   the previous version.  When this happens, uncomment the three lines below (and
   comment out the three above) then rerun

      cabal run plutus-core:generate-cost-model

   (You may also need to add 'data-default' to the 'build-depends' for the
   library in plutus-core.cabal). This will generate a new JSON file filled with
   default values.  After that, restore this file to its previous state and then
   run "generate-cost-model" again to fill in the JSON file with the correct
   values (assuming that suitable benchmarking data is in benching.csv and that
   models.R contains R code to generate cost models for any new functions).

   Alternatively, modify the appropriate 'builtinCostModelX.json' by hand so
   that it matches the new format.
 -}

-- import           Data.Default
-- defaultBuiltinCostModel :: BuiltinCostModel
-- defaultBuiltinCostModel = def

-- | The default cost model for built-in functions (variant A)
builtinCostModelVariantA :: BuiltinCostModel
builtinCostModelVariantA :: BuiltinCostModel
builtinCostModelVariantA =
    $$(readJSONFromFile DFP.builtinCostModelFileA)
-- This is a huge record, inlining it is wasteful.
{-# OPAQUE builtinCostModelVariantA #-}

{- Note [No inlining for CekMachineCosts]
We don't want this to get inlined, as otherwise the default 'CekMachineCosts'
appears faster than 'CekMachineCosts' that we get in production after applying
the costing parameters provided by the ledger. -}
-- | Default costs for CEK machine instructions (variant A)
cekMachineCostsVariantA :: CekMachineCosts
cekMachineCostsVariantA :: CekMachineCosts
cekMachineCostsVariantA =
  $$(readJSONFromFile DFP.cekMachineCostsFileA)
{-# OPAQUE cekMachineCostsVariantA #-}

{-| The default cost model, including both builtin costs and machine step costs.
    Note that this is not necessarily the cost model in use on the chain at any
    given time.  The definitive values used for calculating on-chain costs are
    protocol parameters which are part of the state of the chain; in practice
    these will usually have been obtained from the contents of the JSON files at
    some point in the past, but we do not guarantee this.  During on-chain
    evaluation the ledger passes a cost model to the Plutus Core evaluator using
    the `mkEvaluationContext` functions in PlutusLedgerApi.
-}
cekCostModelVariantA :: CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantA :: CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantA = CekMachineCosts
-> BuiltinCostModel -> CostModel CekMachineCosts BuiltinCostModel
forall machinecosts builtincosts.
machinecosts -> builtincosts -> CostModel machinecosts builtincosts
CostModel CekMachineCosts
cekMachineCostsVariantA BuiltinCostModel
builtinCostModelVariantA

builtinCostModelVariantB :: BuiltinCostModel
builtinCostModelVariantB :: BuiltinCostModel
builtinCostModelVariantB =
    $$(readJSONFromFile DFP.builtinCostModelFileB)
{-# OPAQUE builtinCostModelVariantB #-}

-- See Note [No inlining for CekMachineCosts]
cekMachineCostsVariantB :: CekMachineCosts
cekMachineCostsVariantB :: CekMachineCosts
cekMachineCostsVariantB =
  $$(readJSONFromFile DFP.cekMachineCostsFileB)
{-# OPAQUE cekMachineCostsVariantB #-}

cekCostModelVariantB :: CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantB :: CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantB = CekMachineCosts
-> BuiltinCostModel -> CostModel CekMachineCosts BuiltinCostModel
forall machinecosts builtincosts.
machinecosts -> builtincosts -> CostModel machinecosts builtincosts
CostModel CekMachineCosts
cekMachineCostsVariantB BuiltinCostModel
builtinCostModelVariantB

builtinCostModelVariantC :: BuiltinCostModel
builtinCostModelVariantC :: BuiltinCostModel
builtinCostModelVariantC =
    $$(readJSONFromFile DFP.builtinCostModelFileC)
{-# OPAQUE builtinCostModelVariantC #-}

-- See Note [No inlining for CekMachineCosts]
cekMachineCostsVariantC :: CekMachineCosts
cekMachineCostsVariantC :: CekMachineCosts
cekMachineCostsVariantC =
  $$(readJSONFromFile DFP.cekMachineCostsFileC)
{-# OPAQUE cekMachineCostsVariantC #-}

cekCostModelVariantC :: CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantC :: CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantC = CekMachineCosts
-> BuiltinCostModel -> CostModel CekMachineCosts BuiltinCostModel
forall machinecosts builtincosts.
machinecosts -> builtincosts -> CostModel machinecosts builtincosts
CostModel CekMachineCosts
cekMachineCostsVariantC BuiltinCostModel
builtinCostModelVariantC

-- | Return the 'CostModel' corresponding to the given semantics variant. The dependency on the
-- semantics variant is what makes cost models configurable.
cekCostModelForVariant :: BuiltinSemanticsVariant DefaultFun -> CostModel CekMachineCosts BuiltinCostModel
cekCostModelForVariant :: BuiltinSemanticsVariant DefaultFun
-> CostModel CekMachineCosts BuiltinCostModel
cekCostModelForVariant BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantA = CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantA
cekCostModelForVariant BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantB = CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantB
cekCostModelForVariant BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantC = CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantC

-- | The default cost model data.  This is exposed to the ledger, so let's not
-- confuse anybody by mentioning the CEK machine
defaultCostModelParamsA :: Maybe CostModelParams
defaultCostModelParamsA :: Maybe CostModelParams
defaultCostModelParamsA = CostModel CekMachineCosts BuiltinCostModel -> Maybe CostModelParams
forall machinecosts builtincosts.
(ToJSON machinecosts, ToJSON builtincosts) =>
CostModel machinecosts builtincosts -> Maybe CostModelParams
extractCostModelParams CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantA

defaultCostModelParamsB :: Maybe CostModelParams
defaultCostModelParamsB :: Maybe CostModelParams
defaultCostModelParamsB = CostModel CekMachineCosts BuiltinCostModel -> Maybe CostModelParams
forall machinecosts builtincosts.
(ToJSON machinecosts, ToJSON builtincosts) =>
CostModel machinecosts builtincosts -> Maybe CostModelParams
extractCostModelParams CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantB

defaultCostModelParamsC :: Maybe CostModelParams
defaultCostModelParamsC :: Maybe CostModelParams
defaultCostModelParamsC = CostModel CekMachineCosts BuiltinCostModel -> Maybe CostModelParams
forall machinecosts builtincosts.
(ToJSON machinecosts, ToJSON builtincosts) =>
CostModel machinecosts builtincosts -> Maybe CostModelParams
extractCostModelParams CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantC

defaultCostModelParamsForVariant :: BuiltinSemanticsVariant DefaultFun -> Maybe CostModelParams
defaultCostModelParamsForVariant :: BuiltinSemanticsVariant DefaultFun -> Maybe CostModelParams
defaultCostModelParamsForVariant = \case
  BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantA -> Maybe CostModelParams
defaultCostModelParamsA
  BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantB -> Maybe CostModelParams
defaultCostModelParamsB
  BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantC -> Maybe CostModelParams
defaultCostModelParamsC

{- Note [No inlining for MachineParameters]
We don't want this to get inlined in order for this definition not to appear
faster than the used in production. Also see Note [noinline for saving on
ticks]. -}
defaultCekParametersA :: Typeable ann => MachineParameters CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersA :: forall ann.
Typeable ann =>
MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersA =
    (BuiltinSemanticsVariant DefaultFun
 -> CostModel CekMachineCosts BuiltinCostModel
 -> MachineParameters
      CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann))
-> BuiltinSemanticsVariant DefaultFun
-> CostModel CekMachineCosts BuiltinCostModel
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall a. a -> a
noinline BuiltinSemanticsVariant DefaultFun
-> CostModel CekMachineCosts BuiltinCostModel
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall (uni :: * -> *) fun builtincosts val machinecosts.
(CostingPart uni fun ~ builtincosts, HasMeaningIn uni val,
 ToBuiltinMeaning uni fun) =>
BuiltinSemanticsVariant fun
-> CostModel machinecosts builtincosts
-> MachineParameters machinecosts fun val
mkMachineParameters BuiltinSemanticsVariant DefaultFun
DefaultFunSemanticsVariantA CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantA

-- See Note [No inlining for MachineParameters]
defaultCekParametersB :: Typeable ann => MachineParameters CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersB :: forall ann.
Typeable ann =>
MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersB =
    (BuiltinSemanticsVariant DefaultFun
 -> CostModel CekMachineCosts BuiltinCostModel
 -> MachineParameters
      CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann))
-> BuiltinSemanticsVariant DefaultFun
-> CostModel CekMachineCosts BuiltinCostModel
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall a. a -> a
noinline BuiltinSemanticsVariant DefaultFun
-> CostModel CekMachineCosts BuiltinCostModel
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall (uni :: * -> *) fun builtincosts val machinecosts.
(CostingPart uni fun ~ builtincosts, HasMeaningIn uni val,
 ToBuiltinMeaning uni fun) =>
BuiltinSemanticsVariant fun
-> CostModel machinecosts builtincosts
-> MachineParameters machinecosts fun val
mkMachineParameters BuiltinSemanticsVariant DefaultFun
DefaultFunSemanticsVariantB CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantB

-- See Note [No inlining for MachineParameters]
defaultCekParametersC :: Typeable ann => MachineParameters CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersC :: forall ann.
Typeable ann =>
MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersC =
    (BuiltinSemanticsVariant DefaultFun
 -> CostModel CekMachineCosts BuiltinCostModel
 -> MachineParameters
      CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann))
-> BuiltinSemanticsVariant DefaultFun
-> CostModel CekMachineCosts BuiltinCostModel
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall a. a -> a
noinline BuiltinSemanticsVariant DefaultFun
-> CostModel CekMachineCosts BuiltinCostModel
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall (uni :: * -> *) fun builtincosts val machinecosts.
(CostingPart uni fun ~ builtincosts, HasMeaningIn uni val,
 ToBuiltinMeaning uni fun) =>
BuiltinSemanticsVariant fun
-> CostModel machinecosts builtincosts
-> MachineParameters machinecosts fun val
mkMachineParameters BuiltinSemanticsVariant DefaultFun
DefaultFunSemanticsVariantC CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantC

{- Note [noinline for saving on ticks]
We use 'noinline' purely for saving on simplifier ticks for definitions, whose performance doesn't
matter. Otherwise compilation for this module is slower and GHC may end up exhausting simplifier
ticks leading to a compilation error.
-}
defaultBuiltinsRuntimeForSemanticsVariant
    :: HasMeaningIn DefaultUni term
    => BuiltinSemanticsVariant DefaultFun
    -> BuiltinsRuntime DefaultFun term
-- See Note [noinline for saving on ticks].
defaultBuiltinsRuntimeForSemanticsVariant :: forall term.
HasMeaningIn DefaultUni term =>
BuiltinSemanticsVariant DefaultFun
-> BuiltinsRuntime DefaultFun term
defaultBuiltinsRuntimeForSemanticsVariant BuiltinSemanticsVariant DefaultFun
semvar =
  (BuiltinSemanticsVariant DefaultFun
 -> BuiltinCostModel -> BuiltinsRuntime DefaultFun term)
-> BuiltinSemanticsVariant DefaultFun
-> BuiltinCostModel
-> BuiltinsRuntime DefaultFun term
forall a. a -> a
noinline BuiltinSemanticsVariant DefaultFun
-> BuiltinCostModel -> BuiltinsRuntime DefaultFun term
forall cost (uni :: * -> *) fun val.
(cost ~ CostingPart uni fun, ToBuiltinMeaning uni fun,
 HasMeaningIn uni val) =>
BuiltinSemanticsVariant fun -> cost -> BuiltinsRuntime fun val
toBuiltinsRuntime BuiltinSemanticsVariant DefaultFun
semvar (BuiltinCostModel -> BuiltinsRuntime DefaultFun term)
-> BuiltinCostModel -> BuiltinsRuntime DefaultFun term
forall a b. (a -> b) -> a -> b
$ BuiltinSemanticsVariant DefaultFun -> BuiltinCostModel
builtinCostModelFor BuiltinSemanticsVariant DefaultFun
semvar
  where builtinCostModelFor :: BuiltinSemanticsVariant DefaultFun -> BuiltinCostModel
builtinCostModelFor = \case
          BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantA -> BuiltinCostModel
builtinCostModelVariantA
          BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantB -> BuiltinCostModel
builtinCostModelVariantB
          BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantC -> BuiltinCostModel
builtinCostModelVariantC

defaultCekParametersForVariant
  :: Typeable ann
  => BuiltinSemanticsVariant DefaultFun
  -> MachineParameters CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersForVariant :: forall ann.
Typeable ann =>
BuiltinSemanticsVariant DefaultFun
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersForVariant = \case
  BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantA -> MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall ann.
Typeable ann =>
MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersA
  BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantB -> MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall ann.
Typeable ann =>
MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersB
  BuiltinSemanticsVariant DefaultFun
R:BuiltinSemanticsVariantDefaultFun
DefaultFunSemanticsVariantC -> MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall ann.
Typeable ann =>
MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersC


-- *** THE FOLLOWING SHOULD ONLY BE USED FOR TESTING ***
{- We export a number of objects which are used in tests in a number of places in
   the codebase. For the time being we'll just use the most recent cost model
   for all of these.  In fact we may want tests for each variant in some cases
   TODO:
      * Maybe export fewer things and extract the required component at the use site.
      * Make the names more sensible: does "default" refer to the variant
        or the set of builtins?
      * Perhaps export functions like `defaultBuiltinCostModelForVariant
        and then apply those to `def` where they're used.
-}
defaultBuiltinsRuntimeForTesting
    :: HasMeaningIn DefaultUni term
    => BuiltinsRuntime DefaultFun term
-- See Note [noinline for saving on ticks].
defaultBuiltinsRuntimeForTesting :: forall term.
HasMeaningIn DefaultUni term =>
BuiltinsRuntime DefaultFun term
defaultBuiltinsRuntimeForTesting = BuiltinSemanticsVariant DefaultFun
-> BuiltinsRuntime DefaultFun term
forall term.
HasMeaningIn DefaultUni term =>
BuiltinSemanticsVariant DefaultFun
-> BuiltinsRuntime DefaultFun term
defaultBuiltinsRuntimeForSemanticsVariant BuiltinSemanticsVariant DefaultFun
DefaultFunSemanticsVariantC

defaultCekParametersForTesting :: Typeable ann => MachineParameters CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersForTesting :: forall ann.
Typeable ann =>
MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersForTesting = MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall ann.
Typeable ann =>
MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
defaultCekParametersC

defaultCekMachineCostsForTesting :: CekMachineCosts
defaultCekMachineCostsForTesting :: CekMachineCosts
defaultCekMachineCostsForTesting = CekMachineCosts
cekMachineCostsVariantC

defaultBuiltinCostModelForTesting :: BuiltinCostModel
defaultBuiltinCostModelForTesting :: BuiltinCostModel
defaultBuiltinCostModelForTesting = BuiltinCostModel
builtinCostModelVariantC

defaultCostModelParamsForTesting :: Maybe CostModelParams
defaultCostModelParamsForTesting :: Maybe CostModelParams
defaultCostModelParamsForTesting = Maybe CostModelParams
defaultCostModelParamsC

defaultCekCostModelForTesting :: CostModel CekMachineCosts BuiltinCostModel
defaultCekCostModelForTesting :: CostModel CekMachineCosts BuiltinCostModel
defaultCekCostModelForTesting = CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantC

defaultCekCostModelForTestingB :: CostModel CekMachineCosts BuiltinCostModel
defaultCekCostModelForTestingB :: CostModel CekMachineCosts BuiltinCostModel
defaultCekCostModelForTestingB = CostModel CekMachineCosts BuiltinCostModel
cekCostModelVariantB

{- A cost model with unit costs, so we can count how often each builtin is called.
  This currently works for all semantics variants because to date we have only
  ever added new builtins and never removed any. -}
unitCostOneArgument :: CostingFun ModelOneArgument
unitCostOneArgument :: CostingFun ModelOneArgument
unitCostOneArgument =  ModelOneArgument -> ModelOneArgument -> CostingFun ModelOneArgument
forall model. model -> model -> CostingFun model
CostingFun (CostingInteger -> ModelOneArgument
ModelOneArgumentConstantCost CostingInteger
1) (CostingInteger -> ModelOneArgument
ModelOneArgumentConstantCost CostingInteger
0)

unitCostTwoArguments :: CostingFun ModelTwoArguments
unitCostTwoArguments :: CostingFun ModelTwoArguments
unitCostTwoArguments   =  ModelTwoArguments
-> ModelTwoArguments -> CostingFun ModelTwoArguments
forall model. model -> model -> CostingFun model
CostingFun (CostingInteger -> ModelTwoArguments
ModelTwoArgumentsConstantCost CostingInteger
1) (CostingInteger -> ModelTwoArguments
ModelTwoArgumentsConstantCost CostingInteger
0)

unitCostThreeArguments :: CostingFun ModelThreeArguments
unitCostThreeArguments :: CostingFun ModelThreeArguments
unitCostThreeArguments =  ModelThreeArguments
-> ModelThreeArguments -> CostingFun ModelThreeArguments
forall model. model -> model -> CostingFun model
CostingFun (CostingInteger -> ModelThreeArguments
ModelThreeArgumentsConstantCost CostingInteger
1) (CostingInteger -> ModelThreeArguments
ModelThreeArgumentsConstantCost CostingInteger
0)

unitCostSixArguments :: CostingFun ModelSixArguments
unitCostSixArguments :: CostingFun ModelSixArguments
unitCostSixArguments   =  ModelSixArguments
-> ModelSixArguments -> CostingFun ModelSixArguments
forall model. model -> model -> CostingFun model
CostingFun (CostingInteger -> ModelSixArguments
ModelSixArgumentsConstantCost CostingInteger
1) (CostingInteger -> ModelSixArguments
ModelSixArgumentsConstantCost CostingInteger
0)

unitCostBuiltinCostModel :: BuiltinCostModel
unitCostBuiltinCostModel :: BuiltinCostModel
unitCostBuiltinCostModel = BuiltinCostModelBase
    {
     -- Integers
      paramAddInteger :: CostingFun ModelTwoArguments
paramAddInteger                      = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramSubtractInteger :: CostingFun ModelTwoArguments
paramSubtractInteger                 = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramMultiplyInteger :: CostingFun ModelTwoArguments
paramMultiplyInteger                 = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramDivideInteger :: CostingFun ModelTwoArguments
paramDivideInteger                   = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramQuotientInteger :: CostingFun ModelTwoArguments
paramQuotientInteger                 = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramRemainderInteger :: CostingFun ModelTwoArguments
paramRemainderInteger                = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramModInteger :: CostingFun ModelTwoArguments
paramModInteger                      = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramEqualsInteger :: CostingFun ModelTwoArguments
paramEqualsInteger                   = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramLessThanInteger :: CostingFun ModelTwoArguments
paramLessThanInteger                 = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramLessThanEqualsInteger :: CostingFun ModelTwoArguments
paramLessThanEqualsInteger           = CostingFun ModelTwoArguments
unitCostTwoArguments
    -- Bytestrings
    , paramAppendByteString :: CostingFun ModelTwoArguments
paramAppendByteString                = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramConsByteString :: CostingFun ModelTwoArguments
paramConsByteString                  = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramSliceByteString :: CostingFun ModelThreeArguments
paramSliceByteString                 = CostingFun ModelThreeArguments
unitCostThreeArguments
    , paramLengthOfByteString :: CostingFun ModelOneArgument
paramLengthOfByteString              = CostingFun ModelOneArgument
unitCostOneArgument
    , paramIndexByteString :: CostingFun ModelTwoArguments
paramIndexByteString                 = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramEqualsByteString :: CostingFun ModelTwoArguments
paramEqualsByteString                = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramLessThanByteString :: CostingFun ModelTwoArguments
paramLessThanByteString              = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramLessThanEqualsByteString :: CostingFun ModelTwoArguments
paramLessThanEqualsByteString        = CostingFun ModelTwoArguments
unitCostTwoArguments
    -- Cryptography and hashes
    , paramSha2_256 :: CostingFun ModelOneArgument
paramSha2_256                        = CostingFun ModelOneArgument
unitCostOneArgument
    , paramSha3_256 :: CostingFun ModelOneArgument
paramSha3_256                        = CostingFun ModelOneArgument
unitCostOneArgument
    , paramBlake2b_256 :: CostingFun ModelOneArgument
paramBlake2b_256                     = CostingFun ModelOneArgument
unitCostOneArgument
    , paramVerifyEd25519Signature :: CostingFun ModelThreeArguments
paramVerifyEd25519Signature          = CostingFun ModelThreeArguments
unitCostThreeArguments
    , paramVerifyEcdsaSecp256k1Signature :: CostingFun ModelThreeArguments
paramVerifyEcdsaSecp256k1Signature   = CostingFun ModelThreeArguments
unitCostThreeArguments
    , paramVerifySchnorrSecp256k1Signature :: CostingFun ModelThreeArguments
paramVerifySchnorrSecp256k1Signature = CostingFun ModelThreeArguments
unitCostThreeArguments
    -- Strings
    , paramAppendString :: CostingFun ModelTwoArguments
paramAppendString                    = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramEqualsString :: CostingFun ModelTwoArguments
paramEqualsString                    = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramEncodeUtf8 :: CostingFun ModelOneArgument
paramEncodeUtf8                      = CostingFun ModelOneArgument
unitCostOneArgument
    , paramDecodeUtf8 :: CostingFun ModelOneArgument
paramDecodeUtf8                      = CostingFun ModelOneArgument
unitCostOneArgument
    -- Bool
    , paramIfThenElse :: CostingFun ModelThreeArguments
paramIfThenElse                      = CostingFun ModelThreeArguments
unitCostThreeArguments
    -- Unit
    , paramChooseUnit :: CostingFun ModelTwoArguments
paramChooseUnit                      = CostingFun ModelTwoArguments
unitCostTwoArguments
    -- Tracing
    , paramTrace :: CostingFun ModelTwoArguments
paramTrace                           = CostingFun ModelTwoArguments
unitCostTwoArguments
    -- Pairs
    , paramFstPair :: CostingFun ModelOneArgument
paramFstPair                         = CostingFun ModelOneArgument
unitCostOneArgument
    , paramSndPair :: CostingFun ModelOneArgument
paramSndPair                         = CostingFun ModelOneArgument
unitCostOneArgument
    -- Lists
    , paramChooseList :: CostingFun ModelThreeArguments
paramChooseList                      = CostingFun ModelThreeArguments
unitCostThreeArguments
    , paramMkCons :: CostingFun ModelTwoArguments
paramMkCons                          = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramHeadList :: CostingFun ModelOneArgument
paramHeadList                        = CostingFun ModelOneArgument
unitCostOneArgument
    , paramTailList :: CostingFun ModelOneArgument
paramTailList                        = CostingFun ModelOneArgument
unitCostOneArgument
    , paramNullList :: CostingFun ModelOneArgument
paramNullList                        = CostingFun ModelOneArgument
unitCostOneArgument
    -- Data
    , paramChooseData :: CostingFun ModelSixArguments
paramChooseData                      = CostingFun ModelSixArguments
unitCostSixArguments
    , paramConstrData :: CostingFun ModelTwoArguments
paramConstrData                      = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramMapData :: CostingFun ModelOneArgument
paramMapData                         = CostingFun ModelOneArgument
unitCostOneArgument
    , paramListData :: CostingFun ModelOneArgument
paramListData                        = CostingFun ModelOneArgument
unitCostOneArgument
    , paramIData :: CostingFun ModelOneArgument
paramIData                           = CostingFun ModelOneArgument
unitCostOneArgument
    , paramBData :: CostingFun ModelOneArgument
paramBData                           = CostingFun ModelOneArgument
unitCostOneArgument
    , paramUnConstrData :: CostingFun ModelOneArgument
paramUnConstrData                    = CostingFun ModelOneArgument
unitCostOneArgument
    , paramUnMapData :: CostingFun ModelOneArgument
paramUnMapData                       = CostingFun ModelOneArgument
unitCostOneArgument
    , paramUnListData :: CostingFun ModelOneArgument
paramUnListData                      = CostingFun ModelOneArgument
unitCostOneArgument
    , paramUnIData :: CostingFun ModelOneArgument
paramUnIData                         = CostingFun ModelOneArgument
unitCostOneArgument
    , paramUnBData :: CostingFun ModelOneArgument
paramUnBData                         = CostingFun ModelOneArgument
unitCostOneArgument
    , paramEqualsData :: CostingFun ModelTwoArguments
paramEqualsData                      = CostingFun ModelTwoArguments
unitCostTwoArguments
    -- Misc constructors
    , paramMkPairData :: CostingFun ModelTwoArguments
paramMkPairData                      = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramMkNilData :: CostingFun ModelOneArgument
paramMkNilData                       = CostingFun ModelOneArgument
unitCostOneArgument
    , paramMkNilPairData :: CostingFun ModelOneArgument
paramMkNilPairData                   = CostingFun ModelOneArgument
unitCostOneArgument
    , paramSerialiseData :: CostingFun ModelOneArgument
paramSerialiseData                   = CostingFun ModelOneArgument
unitCostOneArgument
    -- BLS12-381 operations
    , paramBls12_381_G1_add :: CostingFun ModelTwoArguments
paramBls12_381_G1_add                = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_G1_neg :: CostingFun ModelOneArgument
paramBls12_381_G1_neg                = CostingFun ModelOneArgument
unitCostOneArgument
    , paramBls12_381_G1_scalarMul :: CostingFun ModelTwoArguments
paramBls12_381_G1_scalarMul          = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_G1_equal :: CostingFun ModelTwoArguments
paramBls12_381_G1_equal              = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_G1_compress :: CostingFun ModelOneArgument
paramBls12_381_G1_compress           = CostingFun ModelOneArgument
unitCostOneArgument
    , paramBls12_381_G1_uncompress :: CostingFun ModelOneArgument
paramBls12_381_G1_uncompress         = CostingFun ModelOneArgument
unitCostOneArgument
    , paramBls12_381_G1_hashToGroup :: CostingFun ModelTwoArguments
paramBls12_381_G1_hashToGroup        = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_G2_add :: CostingFun ModelTwoArguments
paramBls12_381_G2_add                = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_G2_neg :: CostingFun ModelOneArgument
paramBls12_381_G2_neg                = CostingFun ModelOneArgument
unitCostOneArgument
    , paramBls12_381_G2_scalarMul :: CostingFun ModelTwoArguments
paramBls12_381_G2_scalarMul          = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_G2_equal :: CostingFun ModelTwoArguments
paramBls12_381_G2_equal              = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_G2_compress :: CostingFun ModelOneArgument
paramBls12_381_G2_compress           = CostingFun ModelOneArgument
unitCostOneArgument
    , paramBls12_381_G2_uncompress :: CostingFun ModelOneArgument
paramBls12_381_G2_uncompress         = CostingFun ModelOneArgument
unitCostOneArgument
    , paramBls12_381_G2_hashToGroup :: CostingFun ModelTwoArguments
paramBls12_381_G2_hashToGroup        = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_millerLoop :: CostingFun ModelTwoArguments
paramBls12_381_millerLoop            = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_mulMlResult :: CostingFun ModelTwoArguments
paramBls12_381_mulMlResult           = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramBls12_381_finalVerify :: CostingFun ModelTwoArguments
paramBls12_381_finalVerify           = CostingFun ModelTwoArguments
unitCostTwoArguments
    -- Keccak_256, Blake2b_224
    , paramKeccak_256 :: CostingFun ModelOneArgument
paramKeccak_256                      = CostingFun ModelOneArgument
unitCostOneArgument
    , paramBlake2b_224 :: CostingFun ModelOneArgument
paramBlake2b_224                     = CostingFun ModelOneArgument
unitCostOneArgument
    -- Bitwise operations
    , paramIntegerToByteString :: CostingFun ModelThreeArguments
paramIntegerToByteString             = CostingFun ModelThreeArguments
unitCostThreeArguments
    , paramByteStringToInteger :: CostingFun ModelTwoArguments
paramByteStringToInteger             = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramAndByteString :: CostingFun ModelThreeArguments
paramAndByteString                   = CostingFun ModelThreeArguments
unitCostThreeArguments
    , paramOrByteString :: CostingFun ModelThreeArguments
paramOrByteString                    = CostingFun ModelThreeArguments
unitCostThreeArguments
    , paramXorByteString :: CostingFun ModelThreeArguments
paramXorByteString                   = CostingFun ModelThreeArguments
unitCostThreeArguments
    , paramComplementByteString :: CostingFun ModelOneArgument
paramComplementByteString            = CostingFun ModelOneArgument
unitCostOneArgument
    , paramReadBit :: CostingFun ModelTwoArguments
paramReadBit                         = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramWriteBits :: CostingFun ModelThreeArguments
paramWriteBits                       = CostingFun ModelThreeArguments
unitCostThreeArguments
    , paramReplicateByte :: CostingFun ModelTwoArguments
paramReplicateByte                   = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramShiftByteString :: CostingFun ModelTwoArguments
paramShiftByteString                 = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramRotateByteString :: CostingFun ModelTwoArguments
paramRotateByteString                = CostingFun ModelTwoArguments
unitCostTwoArguments
    , paramCountSetBits :: CostingFun ModelOneArgument
paramCountSetBits                    = CostingFun ModelOneArgument
unitCostOneArgument
    , paramFindFirstSetBit :: CostingFun ModelOneArgument
paramFindFirstSetBit                 = CostingFun ModelOneArgument
unitCostOneArgument
    -- Ripemd_160
    , paramRipemd_160 :: CostingFun ModelOneArgument
paramRipemd_160                      = CostingFun ModelOneArgument
unitCostOneArgument
    , paramExpModInteger :: CostingFun ModelThreeArguments
paramExpModInteger                   = CostingFun ModelThreeArguments
unitCostThreeArguments
    }

unitCekParameters :: Typeable ann => MachineParameters CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
unitCekParameters :: forall ann.
Typeable ann =>
MachineParameters
  CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
unitCekParameters =
    -- See Note [noinline for saving on ticks].
    (BuiltinSemanticsVariant DefaultFun
 -> CostModel CekMachineCosts BuiltinCostModel
 -> MachineParameters
      CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann))
-> BuiltinSemanticsVariant DefaultFun
-> CostModel CekMachineCosts BuiltinCostModel
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall a. a -> a
noinline BuiltinSemanticsVariant DefaultFun
-> CostModel CekMachineCosts BuiltinCostModel
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall (uni :: * -> *) fun builtincosts val machinecosts.
(CostingPart uni fun ~ builtincosts, HasMeaningIn uni val,
 ToBuiltinMeaning uni fun) =>
BuiltinSemanticsVariant fun
-> CostModel machinecosts builtincosts
-> MachineParameters machinecosts fun val
mkMachineParameters BuiltinSemanticsVariant DefaultFun
forall a. Default a => a
def (CostModel CekMachineCosts BuiltinCostModel
 -> MachineParameters
      CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann))
-> CostModel CekMachineCosts BuiltinCostModel
-> MachineParameters
     CekMachineCosts DefaultFun (CekValue DefaultUni DefaultFun ann)
forall a b. (a -> b) -> a -> b
$
        CekMachineCosts
-> BuiltinCostModel -> CostModel CekMachineCosts BuiltinCostModel
forall machinecosts builtincosts.
machinecosts -> builtincosts -> CostModel machinecosts builtincosts
CostModel CekMachineCosts
unitCekMachineCosts BuiltinCostModel
unitCostBuiltinCostModel