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

UntypedPlutusCore.Evaluation.Machine.SteppableCek.Internal

Description

The CEK machine. The CEK machine relies on variables having non-equal Uniques whenever they have non-equal string names. I.e. Uniques are used instead of string names. This is for efficiency reasons. The CEK machines handles name capture by design.

Synopsis

lenContext :: Context uni fun ann -> Word #

cekStateContext :: Traversal' (CekState uni fun ann) (Context uni fun ann) #

cekStateAnn :: CekState uni fun ann -> Maybe ann #

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 #

computeCek :: forall uni fun ann s. (ThrowableBuiltins uni fun, GivenCekReqs uni fun ann s) => Context uni fun ann -> CekValEnv uni fun ann -> NTerm uni fun ann -> CekM uni fun s (CekState uni fun ann) #

returnCek :: forall uni fun ann s. (ThrowableBuiltins uni fun, GivenCekReqs uni fun ann s) => Context uni fun ann -> CekValue uni fun ann -> CekM uni fun s (CekState uni fun ann) #

mkCekTrans :: forall cost uni fun ann m s. (ThrowableBuiltins uni fun, PrimMonad m, s ~ PrimState m) => MachineParameters CekMachineCosts fun (CekValue uni fun ann) -> ExBudgetMode cost uni fun -> EmitterMode uni fun -> Slippage -> m (CekTrans uni fun ann s, ExBudgetInfo cost uni fun s) #

Based on the supplied arguments, initialize the CEK environment and construct a state transition function. Returns the constructed transition function paired with the methods to live access the running budget.

type CekTrans uni fun ann s = Trans (CekM uni fun s) (CekState uni fun ann) #

nilSlippage :: Slippage #

A CEK parameter that turns the slippage optimization *off*.

This is needed in the case of the debugger, where the accounting/budgeting costs must be *live* updated.

data EvaluationResult a #

The parameterized type of results various evaluation engines return.

Constructors

EvaluationSuccess !a 
EvaluationFailure 

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))

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)))

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 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.

data CekUserError #

Constructors

CekCaseBuiltinError Text)) :+: (C1 ('MetaCons "CekOutOfExError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ExRestrictingBudget)) :+: C1 ('MetaCons "CekEvaluationFailure" 'PrefixI 'False) (U1 :: Type -> Type)))

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

The CEK machine-specific EvaluationException.

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 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 #

newtype EmitterMode uni fun #

An emitting mode to execute the CEK machine in, similar to ExBudgetMode.

Constructors

EmitterMode 

Fields

data ArgStack uni fun ann #

A LIFO stack of CekValues, used to record multiple arguments that need to be pushed onto the context in reverse order. Currently used by FrameConstr for collecting the elements of a Constr as it is cheap to prepend new elements in ArgStack.

Constructors

NilStack 
ConsStack !(CekValue uni fun ann) !(ArgStack uni fun ann) 

Instances

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

Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

Methods

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

show :: ArgStack uni fun ann -> String #

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

data EmptyOrMultiStack uni fun ann #

An alternative version of ArgStack that uses ArgNonEmptyStack when non-empty. Used in VConstr. Once all evaluated elements of Constr is collecting to ArgStack in FrameConstr, the collected elements gets reversed and put into VConstr as EmptyOrMultiStack. VConstr using EmptyOrMultiStack is more efficient than ArgStack when casing, since FrameAwaitFunValueN can be dispatched with a single pattern match.

Constructors

EmptyStack 
MultiStack !(ArgStackNonEmpty uni fun ann) 

Instances

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

Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

Methods

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

show :: EmptyOrMultiStack uni fun ann -> String #

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

data ArgStackNonEmpty uni fun ann #

A non-empty variant of ArgStack, used in FrameAwaitFunValueN to store arguments that will be applied to a term. More efficient than ArgStack, since this saves one evaluation cycle by ensuring there is no NilStack.

Constructors

LastStackNonEmpty !(CekValue uni fun ann) 
ConsStackNonEmpty !(CekValue uni fun ann) !(ArgStackNonEmpty uni fun ann) 

Instances

Instances details
(GShow uni, Everywhere uni RAList (CekValue uni fun ann) #

type GivenCekReqs uni fun ann s = (GivenCekRuntime uni fun ann, GivenCekCaserBuiltin uni, GivenCekEmitter uni fun s, GivenCekSpender uni fun s, GivenCekSlippage, GivenCekStepCounter s, GivenCekCosts) #

Constraint requiring all of the machine's implicit parameters.

type GivenCekSpender uni fun s = ?cekBudgetSpender :: CekBudgetSpender uni fun s #

Implicit parameter for budget spender.

data StepCounter (n :: Nat) s #

A set of Word8 counters that is used in the CEK machine to count steps.

type NumberOfStepCounters = CountConstructorsEnum (Rep StepKind) #

The number of step counters that we need, should be the same as the number of constructors of StepKind.

type CounterSize = NumberOfStepCounters + 1 #

The total number of counters that we need, one extra for the total counter. See Note [Structure of the step counter]

type TotalCountIndex = NumberOfStepCounters #

The index at which the total step counter is kept. See Note [Structure of the step counter]

type NTerm uni fun = Term NamedDeBruijn uni fun #

The Terms that CEK can execute must have DeBruijn binders Name is not necessary but we leave it here for simplicity and debuggability.

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).

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.

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

mapTermCekResult :: (Term name uni fun () -> Term name' uni fun ()) -> CekResult name uni fun -> CekResult name' uni fun #

Apply the given function to the Term (if any) stored in the given CekResult.

dischargeCekValue :: forall uni fun ann. CekValue uni fun ann -> DischargeResult uni fun #

Convert a CekValue into a Term by replacing all bound variables with the terms they're bound to (which themselves have to be obtained by recursively discharging values).

defaultSlippage :: Slippage #

The default number of slippage (in machine steps) to allow.

runCekM :: forall cost uni fun ann. ThrowableBuiltins uni fun => MachineParameters CekMachineCosts fun (CekValue uni fun ann) -> ExBudgetMode cost uni fun -> EmitterMode uni fun -> (forall s. GivenCekReqs uni fun ann s => CekM uni fun s (DischargeResult uni fun)) -> CekReport cost NamedDeBruijn uni fun #