| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
PlutusCore.Builtin.Result
Synopsis
- data EvaluationError structural operational
- = StructuralError !structural
- | OperationalError !operational
- newtype UnliftingError = MkUnliftingError {}
- newtype UnliftingEvaluationError = MkUnliftingEvaluationError {}
- data BuiltinError
- data BuiltinResult a
- notAConstant ∷ BuiltinError
- underTypeError ∷ BuiltinError
- operationalUnliftingError ∷ Text → BuiltinError
- structuralUnliftingError ∷ Text → BuiltinError
- emit ∷ Text → BuiltinResult ()
- withLogs ∷ DList Text → BuiltinResult a → BuiltinResult a
- throwing ∷ MonadError e m ⇒ AReview e t → t → m x
- throwing_ ∷ MonadError e m ⇒ AReview e () → m x
- builtinResultFailure ∷ BuiltinResult a
Documentation
data EvaluationError structural operational Source #
The type of errors that can occur during evaluation. There are two kinds of errors:
- 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
tailListwas applied to a non-list. - Operational ones -- these are errors that are indicative of the _logic_ of the program being
wrong. For example,
errorwas executed,tailListwas 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
newtype UnliftingError Source #
The error message part of an UnliftingEvaluationError.
Constructors
| MkUnliftingError | |
Fields | |
Instances
| IsString UnliftingError Source # | |
Defined in PlutusCore.Builtin.Result Methods | |
| Monoid UnliftingError Source # | |
Defined in PlutusCore.Builtin.Result Methods mempty ∷ UnliftingError Source # mappend ∷ UnliftingError → UnliftingError → UnliftingError Source # | |
| Semigroup UnliftingError Source # | |
Defined in PlutusCore.Builtin.Result Methods (<>) ∷ UnliftingError → UnliftingError → UnliftingError Source # sconcat ∷ NonEmpty UnliftingError → UnliftingError Source # stimes ∷ Integral b ⇒ b → UnliftingError → UnliftingError Source # | |
| Show UnliftingError Source # | |
Defined in PlutusCore.Builtin.Result | |
| NFData UnliftingError Source # | |
Defined in PlutusCore.Builtin.Result Methods rnf ∷ UnliftingError → () Source # | |
| Eq UnliftingError Source # | |
Defined in PlutusCore.Builtin.Result Methods (==) ∷ UnliftingError → UnliftingError → Bool Source # (/=) ∷ UnliftingError → UnliftingError → Bool Source # | |
| Pretty UnliftingError Source # | |
Defined in PlutusCore.Builtin.Result | |
newtype UnliftingEvaluationError Source #
When unlifting of a PLC term into a Haskell value fails, this error is thrown.
Constructors
| MkUnliftingEvaluationError | |
Instances
| Show UnliftingEvaluationError Source # | |
Defined in PlutusCore.Builtin.Result | |
| NFData UnliftingEvaluationError Source # | |
Defined in PlutusCore.Builtin.Result Methods rnf ∷ UnliftingEvaluationError → () Source # | |
| Eq UnliftingEvaluationError Source # | |
Defined in PlutusCore.Builtin.Result | |
| Pretty UnliftingEvaluationError Source # | |
Defined in PlutusCore.Builtin.Result Methods pretty ∷ UnliftingEvaluationError → Doc ann Source # prettyList ∷ [UnliftingEvaluationError] → Doc ann Source # | |
data BuiltinError Source #
The type of errors that readKnown and makeKnown can return.
Instances
| Show BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result | |
| Eq BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result Methods (==) ∷ BuiltinError → BuiltinError → Bool Source # (/=) ∷ BuiltinError → BuiltinError → Bool Source # | |
| Pretty BuiltinError Source # | |
Defined in PlutusCore.Builtin.Result | |
| MonadError BuiltinError BuiltinResult Source # |
|
Defined in PlutusCore.Builtin.Result Methods throwError ∷ BuiltinError → BuiltinResult a Source # catchError ∷ BuiltinResult a → (BuiltinError → BuiltinResult a) → BuiltinResult a Source # | |
data BuiltinResult a Source #
The monad that makeKnown runs in.
Equivalent to ExceptT BuiltinError (Writer (DList Text)), except optimized in two ways:
- everything is strict
- has the
BuiltinSuccessconstructor that is used for returning a value with no logs attached, which is the most common case for us, so it helps a lot not to construct and deconstruct a redundant tuple
Moving from ExceptT BuiltinError (Writer (DList Text)) to this data type gave us a speedup of
8% of total evaluation time.
Logs are represented as a DList, because we don't particularly care about the efficiency of
logging, since there's no logging on the chain and builtins don't emit much anyway. Otherwise
we'd have to use text-builder or text-builder-linear or something of this sort.
Constructors
| BuiltinSuccess a | |
| BuiltinSuccessWithLogs (DList Text) a | |
| BuiltinFailure (DList Text) BuiltinError |
Instances
operationalUnliftingError ∷ Text → BuiltinError Source #
Construct a prism focusing on the *EvaluationFailure part of err by taking
that *EvaluationFailure and
- pretty-printing and embedding it into an
UnliftingErrorfor the setter part of the prism - returning it directly for the opposite direction (there's no other way to convert an
UnliftingErrorto an evaluation failure, since the latter doesn't carry any content)
This is useful for providing AsUnliftingError instances for types such as CkUserError and
CekUserError.
emit ∷ Text → BuiltinResult () Source #
Add a log line to the logs.
withLogs ∷ DList Text → BuiltinResult a → BuiltinResult a Source #
Prepend logs to a BuiltinResult computation.
throwing ∷ MonadError e m ⇒ AReview e t → t → m x #
throwing_ ∷ MonadError e m ⇒ AReview e () → m x #