plutus-core-1.60.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

UntypedPlutusCore.Evaluation.Machine.Cek

Description

The API to the CEK machine.

Synopsis}
  • cekResultToEither :: CekResult name uni fun -> Either (CekEvaluationException name uni fun) (Term name uni fun ())
  • data CekValue uni fun ann
  • data DischargeResult uni fun
  • dischargeResultToTerm :: DischargeResult uni fun -> NTerm uni fun ()
  • readKnownCek :: (ThrowableBuiltins uni fun, ReadKnown (Term Name uni fun ()) a) => MachineParameters CekMachineCosts fun (CekValue uni fun ann) -> Term Name uni fun ann -> Either (CekEvaluationException Name uni fun) a
  • class Eq a => Hashable a
  • type ThrowableBuiltins uni fun = (PrettyUni uni, Pretty fun, Typeable uni, Typeable fun)
  • Running the machine

    runCek :: ThrowableBuiltins uni fun => MachineParameters CekMachineCosts fun (CekValue uni fun ann) -> ExBudgetMode cost uni fun -> EmitterMode uni fun -> Term Name uni fun ann -> CekReport cost Name uni fun #

    Evaluate a term using the CEK machine with logging enabled and keep track of costing. A wrapper around the internal runCek to debruijn input and undebruijn output. *THIS FUNCTION IS PARTIAL if the input term contains free variables*

    runCekDeBruijn :: ThrowableBuiltins uni fun => MachineParameters CekMachineCosts fun (CekValue uni fun ann) -> ExBudgetMode cost uni fun -> EmitterMode uni fun -> NTerm uni fun ann -> CekReport cost NamedDeBruijn uni fun #

    Evaluate a term using the CEK machine and keep track of costing, logging is optional.

    runCekNoEmit :: ThrowableBuiltins uni fun => MachineParameters CekMachineCosts fun (CekValue uni fun ann) -> ExBudgetMode cost uni fun -> Term Name uni fun ann -> (Either (CekEvaluationException Name uni fun) (Term Name uni fun ()), cost) #

    Evaluate a term using the CEK machine with logging disabled and keep track of costing. *THIS FUNCTION IS PARTIAL if the input term contains free variables*

    evaluateCek :: ThrowableBuiltins uni fun => EmitterMode uni fun -> MachineParameters CekMachineCosts fun (CekValue uni fun ann) -> Term Name uni fun ann -> (Text]) #

    Evaluate a term using the CEK machine with logging enabled. *THIS FUNCTION IS PARTIAL if the input term contains free variables*

    evaluateCekNoEmit :: ThrowableBuiltins uni fun => MachineParameters CekMachineCosts fun (CekValue uni fun ann) -> Term Name uni fun ann -> Either (CekEvaluationException Name uni fun) (Term Name uni fun ()) #

    Evaluate a term using the CEK machine with logging disabled. *THIS FUNCTION IS PARTIAL if the input term contains free variables*

    data EvaluationResult a #

    The parameterized type of results various evaluation engines return.

    Instances

    Instances details
    Some TyNameRep] #

    Methods

    typeAst :: Type0 tyname uni () #

    (TypeError ('Text "Use \8216BuiltinResult\8217 instead of \8216EvaluationResult\8217") :: Constraint, uni ~ UniOf val) => MakeKnownIn uni val (EvaluationResult a) # 
    Instance details

    Defined in PlutusCore.Builtin.KnownType

    (TypeError ('Text "Use \8216BuiltinResult\8217 instead of \8216EvaluationResult\8217") :: Constraint, uni ~ UniOf val) => ReadKnownIn uni val (EvaluationResult a) # 
    Instance details

    Defined in PlutusCore.Builtin.KnownType

    Methods

    readKnown :: val -> ReadKnownM (EvaluationResult a) #

    PrettyBy config a => PrettyBy config (EvaluationResult a) # 
    Instance details

    Defined in PlutusCore.Evaluation.Result

    Methods

    prettyBy :: config -> EvaluationResult a -> Doc ann #

    prettyListBy :: config -> [EvaluationResult a] -> Doc ann #

    Generic (EvaluationResult a) # 
    Instance details

    Defined in PlutusCore.Evaluation.Result

    Associated Types

    type Rep (EvaluationResult a) :: Type -> Type #

    Show a => Show (EvaluationResult a) # 
    Instance details

    Defined in PlutusCore.Evaluation.Result

    NFData a => NFData (EvaluationResult a) # 
    Instance details

    Defined in PlutusCore.Evaluation.Result

    Methods

    rnf :: EvaluationResult a -> () #

    Eq a => Eq (EvaluationResult a) # 
    Instance details

    Defined in PlutusCore.Evaluation.Result

    PrettyClassic a => Pretty (EvaluationResult a) # 
    Instance details

    Defined in PlutusCore.Evaluation.Result

    Methods

    pretty :: EvaluationResult a -> Doc ann #

    prettyList :: [EvaluationResult a] -> Doc ann #

    type ToBinds uni acc (EvaluationResult a :: Type) # 
    Instance details

    Defined in PlutusCore.Builtin.KnownTypeAst

    type ToBinds uni acc (EvaluationResult a :: Type) = ToBinds uni acc a
    type ToHoles uni _1 (EvaluationResult a :: Type) # 
    Instance details

    Defined in PlutusCore.Builtin.KnownTypeAst

    type ToHoles uni _1 (EvaluationResult a :: Type) = '[TypeHole a :: Hole]
    type IsBuiltin uni (EvaluationResult a :: Type) # 
    Instance details

    Defined in PlutusCore.Builtin.KnownTypeAst

    type Rep (EvaluationResult a) # 
    Instance details

    Defined in PlutusCore.Evaluation.Result

    type Rep (EvaluationResult a) = D1 ('MetaData "EvaluationResult" "PlutusCore.Evaluation.Result" "plutus-core-1.60.0.0-inplace" 'False) (C1 ('MetaCons "EvaluationSuccess" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)) :+: C1 ('MetaCons "EvaluationFailure" 'PrefixI 'False) (U1 :: Type -> Type))

    splitStructuralOperational :: Either (EvaluationException structural operational term) a -> Either (ErrorWithCause structural term) (EvaluationResult a) #

    Preserve the contents of an StructuralError as a Left and turn an OperationalError into a Right EvaluationFailure (thus erasing the content of the error in the latter case).

    unsafeSplitStructuralOperational :: (PrettyPlc structural, PrettyPlc term, Typeable structural, Typeable term) => Either (EvaluationException structural operational term) a -> EvaluationResult a #

    Throw on a StructuralError and turn an OperationalError into an EvaluationFailure (thus erasing the content of the error in the latter case).

    Errors

    data ErrorWithCause err cause #

    An error and (optionally) what caused it.

    Constructors

    ErrorWithCause 

    Fields

    Instances

    Instances details
    Bifunctor ErrorWithCause # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Methods

    bimap :: (a -> b) -> (c -> d) -> ErrorWithCause a c -> ErrorWithCause b d #

    first :: (a -> b) -> ErrorWithCause a c -> ErrorWithCause b c #

    second :: (b -> c) -> ErrorWithCause a b -> ErrorWithCause a c #

    (PrettyBy config cause, PrettyBy config err) => PrettyBy config (ErrorWithCause err cause) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Methods

    prettyBy :: config -> ErrorWithCause err cause -> Doc ann #

    prettyListBy :: config -> [ErrorWithCause err cause] -> Doc ann #

    Foldable (ErrorWithCause err) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Methods

    fold :: Monoid m => ErrorWithCause err m -> m #

    foldMap :: Monoid m => (a -> m) -> ErrorWithCause err a -> m #

    foldMap' :: Monoid m => (a -> m) -> ErrorWithCause err a -> m #

    foldr :: (a -> b -> b) -> b -> ErrorWithCause err a -> b #

    foldr' :: (a -> b -> b) -> b -> ErrorWithCause err a -> b #

    foldl :: (b -> a -> b) -> b -> ErrorWithCause err a -> b #

    foldl' :: (b -> a -> b) -> b -> ErrorWithCause err a -> b #

    foldr1 :: (a -> a -> a) -> ErrorWithCause err a -> a #

    foldl1 :: (a -> a -> a) -> ErrorWithCause err a -> a #

    toList :: ErrorWithCause err a -> [a] #

    null :: ErrorWithCause err a -> Bool #

    length :: ErrorWithCause err a -> Int #

    elem :: Eq a => a -> ErrorWithCause err a -> Bool #

    maximum :: Ord a => ErrorWithCause err a -> a #

    minimum :: Ord a => ErrorWithCause err a -> a #

    sum :: Num a => ErrorWithCause err a -> a #

    product :: Num a => ErrorWithCause err a -> a #

    Traversable (ErrorWithCause err) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Methods

    traverse :: Applicative f => (a -> f b) -> ErrorWithCause err a -> f (ErrorWithCause err b) #

    sequenceA :: Applicative f => ErrorWithCause err (f a) -> f (ErrorWithCause err a) #

    mapM :: Monad m => (a -> m b) -> ErrorWithCause err a -> m (ErrorWithCause err b) #

    sequence :: Monad m => ErrorWithCause err (m a) -> m (ErrorWithCause err a) #

    Functor (ErrorWithCause err) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Methods

    fmap :: (a -> b) -> ErrorWithCause err a -> ErrorWithCause err b #

    (<$) :: a -> ErrorWithCause err b -> ErrorWithCause err a #

    (PrettyPlc cause, PrettyPlc err, Typeable cause, Typeable err) => Exception (ErrorWithCause err cause) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Generic (ErrorWithCause err cause) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Associated Types

    type Rep (ErrorWithCause err cause) :: Type -> Type #

    Methods

    from :: ErrorWithCause err cause -> Rep (ErrorWithCause err cause) x #

    to :: Rep (ErrorWithCause err cause) x -> ErrorWithCause err cause #

    (PrettyPlc cause, PrettyPlc err) => Show (ErrorWithCause err cause) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Methods

    showsPrec :: Int -> ErrorWithCause err cause -> ShowS #

    show :: ErrorWithCause err cause -> String #

    showList :: [ErrorWithCause err cause] -> ShowS #

    (NFData err, NFData cause) => NFData (ErrorWithCause err cause) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Methods

    rnf :: ErrorWithCause err cause -> () #

    (Eq err, Eq cause) => Eq (ErrorWithCause err cause) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Methods

    (==) :: ErrorWithCause err cause -> ErrorWithCause err cause -> Bool #

    (/=) :: ErrorWithCause err cause -> ErrorWithCause err cause -> Bool #

    (Pretty err, Pretty cause) => Pretty (ErrorWithCause err cause) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    Methods

    pretty :: ErrorWithCause err cause -> Doc ann #

    prettyList :: [ErrorWithCause err cause] -> Doc ann #

    ThrowableBuiltins uni fun => MonadError (CekEvaluationException NamedDeBruijn uni fun) (CekM uni fun s) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    throwError :: CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a #

    catchError :: CekM uni fun s a -> (CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a) -> CekM uni fun s a #

    type Rep (ErrorWithCause err cause) # 
    Instance details

    Defined in PlutusCore.Evaluation.ErrorWithCause

    type Rep (ErrorWithCause err cause) = D1 ('MetaData "ErrorWithCause" "PlutusCore.Evaluation.ErrorWithCause" "plutus-core-1.60.0.0-inplace" 'False) (C1 ('MetaCons "ErrorWithCause" 'PrefixI 'True) (S1 ('MetaSel ('Just "_ewcError") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 err) :*: S1 ('MetaSel ('Just "_ewcCause") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe cause))))

    type CekEvaluationException name uni fun = EvaluationException (MachineError fun) CekUserError (Term name uni fun ()) #

    The CEK machine-specific EvaluationException.

    data EvaluationError structural operational #

    The type of errors that can occur during evaluation. There are two kinds of errors:

    1. Structural ones -- these are errors that are indicative of the _structure_ of the program being wrong. For example, a free variable was encountered during evaluation, a non-function was applied to an argument or tailList was applied to a non-list.
    2. Operational ones -- these are errors that are indicative of the _logic_ of the program being wrong. For example, error was executed, tailList was applied to an empty list or evaluation ran out of gas.

    On the chain both of these are just regular failures and we don't distinguish between them there: if a script fails, it fails, it doesn't matter what the reason was. However in the tests it does matter why the failure occurred: a structural error may indicate that the test was written incorrectly while an operational error may be entirely expected.

    In other words, structural errors are "runtime type errors" and operational errors are regular runtime errors. Which means that evaluating an (erased) well-typed program should never produce a structural error, only an operational one. This creates a sort of "runtime type system" for UPLC and it would be great to stick to it and enforce in tests etc, but we currently don't.

    Constructors

    StructuralError !structural 
    OperationalError !operational 

    Instances

    Instances details
    Bifoldable EvaluationError # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Methods

    bifold :: Monoid m => EvaluationError m m -> m #

    bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> EvaluationError a b -> m #

    bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> EvaluationError a b -> c #

    bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> EvaluationError a b -> c #

    Bifunctor EvaluationError # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Methods

    bimap :: (a -> b) -> (c -> d) -> EvaluationError a c -> EvaluationError b d #

    first :: (a -> b) -> EvaluationError a c -> EvaluationError b c #

    second :: (b -> c) -> EvaluationError a b -> EvaluationError a c #

    Bitraversable EvaluationError # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Methods

    bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> EvaluationError a b -> f (EvaluationError c d) #

    (HasPrettyDefaults config ~ 'True, PrettyBy config structural, Pretty operational) => PrettyBy config (EvaluationError structural operational) # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Methods

    prettyBy :: config -> EvaluationError structural operational -> Doc ann #

    prettyListBy :: config -> [EvaluationError structural operational] -> Doc ann #

    Functor (EvaluationError structural) # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Methods

    fmap :: (a -> b) -> EvaluationError structural a -> EvaluationError structural b #

    (<$) :: a -> EvaluationError structural b -> EvaluationError structural a #

    Generic (EvaluationError structural operational) # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Associated Types

    type Rep (EvaluationError structural operational) :: Type -> Type #

    Methods

    from :: EvaluationError structural operational -> Rep (EvaluationError structural operational) x #

    to :: Rep (EvaluationError structural operational) x -> EvaluationError structural operational #

    (Show structural, Show operational) => Show (EvaluationError structural operational) # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Methods

    showsPrec :: Int -> EvaluationError structural operational -> ShowS #

    show :: EvaluationError structural operational -> String #

    showList :: [EvaluationError structural operational] -> ShowS #

    (NFData structural, NFData operational) => NFData (EvaluationError structural operational) # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Methods

    rnf :: EvaluationError structural operational -> () #

    (Eq structural, Eq operational) => Eq (EvaluationError structural operational) # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Methods

    (==) :: EvaluationError structural operational -> EvaluationError structural operational -> Bool #

    (/=) :: EvaluationError structural operational -> EvaluationError structural operational -> Bool #

    (Pretty structural, Pretty operational) => Pretty (EvaluationError structural operational) # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    Methods

    pretty :: EvaluationError structural operational -> Doc ann #

    prettyList :: [EvaluationError structural operational] -> Doc ann #

    ThrowableBuiltins uni fun => MonadError (CekEvaluationException NamedDeBruijn uni fun) (CekM uni fun s) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    throwError :: CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a #

    catchError :: CekM uni fun s a -> (CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a) -> CekM uni fun s a #

    type Rep (EvaluationError structural operational) # 
    Instance details

    Defined in PlutusCore.Evaluation.Error

    type Rep (EvaluationError structural operational) = D1 ('MetaData "EvaluationError" "PlutusCore.Evaluation.Error" "plutus-core-1.60.0.0-inplace" 'False) (C1 ('MetaCons "StructuralError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 structural)) :+: C1 ('MetaCons "OperationalError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 operational)))

    Costing

    data ExBudgetCategory fun #

    Constructors

    BStep StepKind 
    BBuiltinApp fun 
    BStartup 

    Instances

    Instances details
    ExBudgetBuiltin fun (ExBudgetCategory fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    exBudgetBuiltin :: fun -> ExBudgetCategory fun #

    Generic (ExBudgetCategory fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Associated Types

    type Rep (ExBudgetCategory fun) :: Type -> Type #

    Show fun => Show (ExBudgetCategory fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    NFData fun => NFData (ExBudgetCategory fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    rnf :: ExBudgetCategory fun -> () #

    Eq fun => Eq (ExBudgetCategory fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Ord fun => Ord (ExBudgetCategory fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Hashable fun => Hashable (ExBudgetCategory fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Show fun => Pretty (ExBudgetCategory fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    pretty :: ExBudgetCategory fun -> Doc ann #

    prettyList :: [ExBudgetCategory fun] -> Doc ann #

    type Rep (ExBudgetCategory fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    type Rep (ExBudgetCategory fun) = D1 ('MetaData "ExBudgetCategory" "UntypedPlutusCore.Evaluation.Machine.Cek.Internal" "plutus-core-1.60.0.0-inplace" 'False) (C1 ('MetaCons "BStep" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 StepKind)) :+: (C1 ('MetaCons "BBuiltinApp" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 fun)) :+: C1 ('MetaCons "BStartup" 'PrefixI 'False) (U1 :: Type -> Type)))

    newtype CekBudgetSpender uni fun s #

    The CEK machine is parameterized over a spendBudget function. This makes the budgeting machinery extensible and allows us to separate budgeting logic from evaluation logic and avoid branching on the union of all possible budgeting state types during evaluation.

    Constructors

    CekBudgetSpender 

    Fields

    newtype ExBudgetMode cost uni fun #

    A budgeting mode to execute the CEK machine in.

    Constructors

    ExBudgetMode 

    Fields

    data StepKind #

    Instances

    Instances details
    Bounded StepKind # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Enum StepKind # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Generic StepKind # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Associated Types

    type Rep StepKind :: Type -> Type #

    Methods

    from :: StepKind -> Rep StepKind x #

    to :: Rep StepKind x -> StepKind #

    Show StepKind # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    NFData StepKind # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    rnf :: StepKind -> () #

    Eq StepKind # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Ord StepKind # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Hashable StepKind # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    hashWithSalt :: Int -> StepKind -> Int #

    hash :: StepKind -> Int #

    type Rep StepKind # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    type Rep StepKind = D1 ('MetaData "StepKind" "UntypedPlutusCore.Evaluation.Machine.Cek.Internal" "plutus-core-1.60.0.0-inplace" 'False) (((C1 ('MetaCons "BConst" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BVar" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "BLamAbs" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BApply" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "BDelay" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BForce" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "BBuiltin" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "BConstr" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "BCase" 'PrefixI 'False) (U1 :: Type -> Type)))))

    newtype CekExTally fun #

    For a detailed report on what costs how much + the same overall budget that Counting gives. The (derived) MonoidalHashMap (ExBudgetCategory fun) ExBudget))))

    newtype CountingSt #

    For calculating the cost of execution by counting up using the Monoid instance of ExBudget.

    Constructors

    CountingSt ExBudget 

    data TallyingSt fun #

    Constructors

    TallyingSt (CekExTally fun) ExBudget 

    Instances

    Instances details
    (Show fun, Ord fun) => PrettyBy config (TallyingSt fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    prettyBy :: config -> TallyingSt fun -> Doc ann #

    prettyListBy :: config -> [TallyingSt fun] -> Doc ann #

    Hashable fun => Monoid (TallyingSt fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    mempty :: TallyingSt fun #

    mappend :: TallyingSt fun -> TallyingSt fun -> TallyingSt fun #

    mconcat :: [TallyingSt fun] -> TallyingSt fun #

    Hashable fun => Semigroup (TallyingSt fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    (<>) :: TallyingSt fun -> TallyingSt fun -> TallyingSt fun #

    sconcat :: NonEmpty (TallyingSt fun) -> TallyingSt fun #

    stimes :: Integral b => b -> TallyingSt fun -> TallyingSt fun #

    Generic (TallyingSt fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Associated Types

    type Rep (TallyingSt fun) :: Type -> Type #

    Methods

    from :: TallyingSt fun -> Rep (TallyingSt fun) x #

    to :: Rep (TallyingSt fun) x -> TallyingSt fun #

    Show fun => Show (TallyingSt fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    showsPrec :: Int -> TallyingSt fun -> ShowS #

    show :: TallyingSt fun -> String #

    showList :: [TallyingSt fun] -> ShowS #

    NFData fun => NFData (TallyingSt fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    rnf :: TallyingSt fun -> () #

    Eq fun => Eq (TallyingSt fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    (==) :: TallyingSt fun -> TallyingSt fun -> Bool #

    (/=) :: TallyingSt fun -> TallyingSt fun -> Bool #

    (Show fun, Ord fun) => Pretty (TallyingSt fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    pretty :: TallyingSt fun -> Doc ann #

    prettyList :: [TallyingSt fun] -> Doc ann #

    type Rep (TallyingSt fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    type Rep (TallyingSt fun) = D1 ('MetaData "TallyingSt" "UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode" "plutus-core-1.60.0.0-inplace" 'False) (C1 ('MetaCons "TallyingSt" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (CekExTally fun)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ExBudget)))

    newtype RestrictingSt #

    Instances

    Instances details
    Monoid RestrictingSt # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Semigroup RestrictingSt # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Show RestrictingSt # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    NFData RestrictingSt # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    rnf :: RestrictingSt -> () #

    Eq RestrictingSt # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Pretty RestrictingSt # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    pretty :: RestrictingSt -> Doc ann #

    prettyList :: [RestrictingSt] -> Doc ann #

    PrettyBy config RestrictingSt # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode

    Methods

    prettyBy :: config -> RestrictingSt -> Doc ann #

    prettyListBy :: config -> [RestrictingSt] -> Doc ann #

    type CekMachineCosts = CekMachineCostsBase Identity #

    Costs for evaluating AST nodes. Times should be specified in picoseconds, memory sizes in bytes.

    Costing modes

    monoidalBudgeting :: Monoid cost => (ExBudgetCategory fun -> ExBudget -> cost) -> ExBudgetMode cost uni fun #

    Construct an ExBudgetMode out of a function returning a value of the budgeting state type. The value then gets added to the current state via (<>).

    counting :: ExBudgetMode CountingSt uni fun #

    For calculating the cost of execution.

    tallying :: Hashable fun => ExBudgetMode (TallyingSt fun) uni fun #

    For a detailed report on what costs how much + the same overall budget that Counting gives.

    restricting :: ThrowableBuiltins uni fun => ExRestrictingBudget -> ExBudgetMode RestrictingSt uni fun #

    For execution, to avoid overruns.

    enormousBudget :: ExRestrictingBudget #

    When we want to just evaluate the program we use the Restricting mode with an enormous budget, so that evaluation costs of on-chain budgeting are reflected accurately in benchmarks.

    Emitter modes

    noEmitter :: EmitterMode uni fun #

    No emitter.

    logEmitter :: EmitterMode uni fun #

    Emits log only.

    logWithTimeEmitter :: EmitterMode uni fun #

    Emits log with timestamp.

    logWithBudgetEmitter :: EmitterMode uni fun #

    Emits log with the budget.

    logWithCallTraceEmitter :: EmitterMode uni fun #

    Emits log and, when script evaluation fails, call trace.

    This requires script to be compiled with `PlutusTx.Plugin:profile-all` turned on because this relies on compiler-generated trace calls that notifies entrance and exit of a function call. These traces that mark entrance and exit are ordinary traces like "-> rob:Example.hs:3:1-3:15" and "<- bob:Example.hs:1:1-1:13" with "->" and "<-" prefixies, where "bob" and "rob" is the name of the function with source span. If regular script with no entrance/exit marker is given, this emitter will behave identically to logEmitter.

    When script evaluation fails, this emitter will give call trace of the functions that led to the evaluation failure. This is useful for pin-pointing specific area of the codebase that caused failure when debugging a script. When script evaluation passes, every trace message generated by `profile-all` flag will be removed, and this emitter will behave identically to logEmitter.

    Misc

    data BuiltinsRuntime fun val #

    A data wrapper around a function returning the BuiltinRuntime of a built-in function.

    In order for lookups to be efficient the BuiltinRuntimes need to be cached, i.e. pulled out of the function statically. See makeBuiltinMeaning for how we achieve that.

    Constructors

    BuiltinsRuntime 

    Fields

    Instances

    Instances details
    (Text]

    Logs emitted during evaluation.

    cekResultToEither :: CekResult name uni fun -> Either (CekEvaluationException name uni fun) (Term name uni fun ()) #

    Convert the given CekResult into an Either. This is useful, because in the ledger API we care whether the result is a constant or not, but in tests, executables etc we don't and so handling an either-error-or-term is more natural.

    data CekValue uni fun ann #

    Constructors

    VCon !(Some (ValueOf uni)) 
    VDelay !(NTerm uni fun ann) !(CekValEnv uni fun ann) 
    VLamAbs !NamedDeBruijn !(NTerm uni fun ann) !(CekValEnv uni fun ann) 
    VBuiltin

    A partial builtin application, accumulating arguments for eventual full application. We don't need a CekValEnv here unlike in the other constructors, because VBuiltin values always store their corresponding Terms fully discharged, see the comments at the call sites (search for VBuiltin).

    Fields

    • !fun

      So that we know, for what builtin we're calculating the cost. We can sneak this into BuiltinRuntime, so that we don't need to store it here, but somehow doing so was consistently slowing evaluation down by half a percent. Might be noise, might be not, but at least we know that removing this fun is not helpful anyway. See this commit reversing the change: https://github.com/IntersectMBO/plutus/pull/4778/commits/86a3e24ca3c671cc27c6f4344da2bcd14f961706

    • (NTerm uni fun ())

      This must be lazy. It represents the fully discharged partial application of the builtin function that we're going to run when it's fully saturated. We need the Term to be able to return it in case full saturation is never achieved and a partial application needs to be returned in the result. The laziness is important, because the arguments are discharged values and discharging is expensive, so we don't want to do it unless we really have to. Making this field strict resulted in a 3-4.5% slowdown at the time of writing.

    • !(BuiltinRuntime (CekValue uni fun ann))

      The partial application and its costing function. Check the docs of BuiltinRuntime for details. | A constructor value, including fully computed arguments and the tag.

    VConstr !Word64 !(EmptyOrMultiStack uni fun ann) 

    Instances

    Instances details
    (PrettyUni uni, Pretty fun) => PrettyBy PrettyConfigPlc (CekValue uni fun ann) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    prettyBy :: PrettyConfigPlc -> CekValue uni fun ann -> Doc ann0 #

    prettyListBy :: PrettyConfigPlc -> [CekValue uni fun ann] -> Doc ann0 #

    Show (BuiltinRuntime (CekValue uni fun ann)) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    showsPrec :: Int -> BuiltinRuntime (CekValue uni fun ann) -> ShowS #

    show :: BuiltinRuntime (CekValue uni fun ann) -> String #

    showList :: [BuiltinRuntime (CekValue uni fun ann)] -> ShowS #

    (GShow uni, Everywhere uni Show, Show fun, Show ann, Closed uni) => Show (CekValue uni fun ann) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    showsPrec :: Int -> CekValue uni fun ann -> ShowS #

    show :: CekValue uni fun ann -> String #

    showList :: [CekValue uni fun ann] -> ShowS #

    HasConstant (CekValue uni fun ann) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    asConstant :: CekValue uni fun ann -> Either BuiltinError (Some (ValueOf (UniOf (CekValue uni fun ann)))) #

    fromConstant :: Some (ValueOf (UniOf (CekValue uni fun ann))) -> CekValue uni fun ann #

    (Closed uni, Everywhere uni ExMemoryUsage) => ExMemoryUsage (CekValue uni fun ann) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    memoryUsage :: CekValue uni fun ann -> CostRose #

    type UniOf (CekValue uni fun ann) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    type UniOf (CekValue uni fun ann) = uni

    data DischargeResult uni fun #

    The result of dischargeCekValue.

    Constructors

    DischargeConstant (Some (ValueOf uni)) 
    DischargeNonConstant (NTerm uni fun ()) 

    Instances

    Instances details
    (PrettyUni uni, Pretty fun) => PrettyBy PrettyConfigPlc (DischargeResult uni fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    prettyBy :: PrettyConfigPlc -> DischargeResult uni fun -> Doc ann #

    prettyListBy :: PrettyConfigPlc -> [DischargeResult uni fun] -> Doc ann #

    (GShow uni, Everywhere uni Show, Show fun, Closed uni) => Show (DischargeResult uni fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    showsPrec :: Int -> DischargeResult uni fun -> ShowS #

    show :: DischargeResult uni fun -> String #

    showList :: [DischargeResult uni fun] -> ShowS #

    (GEq uni, Everywhere uni Eq, Eq fun, Closed uni) => Eq (DischargeResult uni fun) # 
    Instance details

    Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

    Methods

    (==) :: DischargeResult uni fun -> DischargeResult uni fun -> Bool #

    (/=) :: DischargeResult uni fun -> DischargeResult uni fun -> Bool #

    dischargeResultToTerm :: DischargeResult uni fun -> NTerm uni fun () #

    readKnownCek :: (ThrowableBuiltins uni fun, ReadKnown (Term Name uni fun ()) a) => MachineParameters CekMachineCosts fun (CekValue uni fun ann) -> Term Name uni fun ann -> Either (CekEvaluationException Name uni fun) a #

    Unlift a value using the CEK machine. *THIS FUNCTION IS PARTIAL if the input term contains free variables*

    class hashWithSalt.

    Hashable is intended exclusively for use in in-memory data structures. . Hashable does not have a fixed standard. This allows it to improve over time. . Because it does not have a fixed standard, different computers or computers on different versions of the code will observe different hash values. As such, Hashable is not recommended for use other than in-memory datastructures. Specifically, Hashable is not intended for network use or in applications which persist hashed values. For stable hashing use named hashes: sha256, crc32, xxhash etc.

    If you are looking for Hashable instance in time package, check time-compat

    Instances

    Instances details
    Hashable Key 
    Instance details

    Defined in Data.Aeson.Key

    Methods

    hashWithSalt :: Text -> Data.Hashable.Class

    Methods

    hashWithSalt :: Int -> (a1, a2, a3, a4, a5, a6, a7) -> Int #

    hash :: (a1, a2, a3, a4, a5, a6, a7) -> Int #

    type ThrowableBuiltins uni fun = (PrettyUni uni, Pretty fun, Typeable uni, Typeable fun) #

    The set of constraints we need to be able to throw exceptions with things with built-in types and functions in them.