diff --git a/doc/notes/plutus-core/cek-budgeting-profiling/CostingDetails.md b/doc/notes/plutus-core/cek-budgeting-profiling/CostingDetails.md index 173dccdf2de..73af0aaba22 100644 --- a/doc/notes/plutus-core/cek-budgeting-profiling/CostingDetails.md +++ b/doc/notes/plutus-core/cek-budgeting-profiling/CostingDetails.md @@ -70,7 +70,7 @@ instance (Eq fun, Hashable fun, ToExMemory term) => Restricting resb -> when (exceedsBudget resb newBudget) $ throwingWithCause _EvaluationError - (UserEvaluationError $ CekOutOfExError resb newBudget) + (OperationalEvaluationError $ CekOutOfExError resb newBudget) Nothing -- No value available for error ``` @@ -96,7 +96,7 @@ to the current mode: newBudget <- exBudgetStateBudget <%= (<> budget) when (exceedsBudget resb newBudget) $ throwingWithCause _EvaluationError - (UserEvaluationError $ CekOutOfExError resb newBudget) + (OperationalEvaluationError $ CekOutOfExError resb newBudget) Nothing ``` @@ -114,7 +114,7 @@ of memory very quickly. Changing the code to Restricting resb -> when (exceedsBudget resb newBudget) $ throwingWithCause _EvaluationError - (UserEvaluationError $ CekOutOfExError resb newBudget) + (OperationalEvaluationError $ CekOutOfExError resb newBudget) Nothing ``` diff --git a/plutus-benchmark/nofib/exe/Main.hs b/plutus-benchmark/nofib/exe/Main.hs index ca88a42c653..c2dd8e7e9c3 100644 --- a/plutus-benchmark/nofib/exe/Main.hs +++ b/plutus-benchmark/nofib/exe/Main.hs @@ -202,7 +202,7 @@ options = hsubparser ---------------- Evaluation ---------------- evaluateWithCek :: UPLC.Term UPLC.NamedDeBruijn DefaultUni DefaultFun () -> UPLC.EvaluationResult (UPLC.Term UPLC.NamedDeBruijn DefaultUni DefaultFun ()) -evaluateWithCek = UPLC.unsafeExtractEvaluationResult . (\(fstT,_,_) -> fstT) . UPLC.runCekDeBruijn PLC.defaultCekParameters UPLC.restrictingEnormous UPLC.noEmitter +evaluateWithCek = UPLC.unsafeToEvaluationResult . (\(fstT,_,_) -> fstT) . UPLC.runCekDeBruijn PLC.defaultCekParameters UPLC.restrictingEnormous UPLC.noEmitter writeFlatNamed :: UPLC.Program UPLC.NamedDeBruijn DefaultUni DefaultFun () -> IO () writeFlatNamed prog = BS.putStr . Flat.flat . UPLC.UnrestrictedProgram $ prog diff --git a/plutus-core/changelog.d/20240517_191403_effectfully_polish_evaluation_errors.md b/plutus-core/changelog.d/20240517_191403_effectfully_polish_evaluation_errors.md new file mode 100644 index 00000000000..fb19345a29b --- /dev/null +++ b/plutus-core/changelog.d/20240517_191403_effectfully_polish_evaluation_errors.md @@ -0,0 +1,7 @@ +### Removed + +- `unsafeRunCekNoEmit` and all `unsafeEvaluate*` functions in #6043. To replace e.g. `unsafeEvaluateCek` you can use `evaluateCek` in combination with `unsafeToEvaluationResult`. + +### Changed + +- Renamed `unsafeExtractEvaluationResult` to `unsafeToEvaluationResult`. diff --git a/plutus-core/cost-model/budgeting-bench/Common.hs b/plutus-core/cost-model/budgeting-bench/Common.hs index a314102ffda..617307cf454 100644 --- a/plutus-core/cost-model/budgeting-bench/Common.hs +++ b/plutus-core/cost-model/budgeting-bench/Common.hs @@ -78,13 +78,11 @@ benchWith -> String -> PlainTerm DefaultUni fun -> Benchmark -benchWith params name term = bench name $ whnf (unsafeEvaluateCekNoEmit params) term -{- ^ Note that to get sensible results with whnf, we must use an evaluation - function that looks at the result, so eg unsafeEvaluateCek won't work - properly because it returns a pair whose components won't be evaluated by - whnf. We can't use nf because it does too much work: for instance if it gets - back a 'Data' value it'll traverse all of it. --} +-- Note that to get sensible results with 'whnf', we must use an evaluation function that looks at +-- the result, so e.g. 'evaluateCek' won't work properly because it returns a pair whose components +-- won't be evaluated by 'whnf'. We can't use 'nf' because it does too much work: for instance if it +-- gets back a 'Data' value it'll traverse all of it. +benchWith params name term = bench name $ whnf (evaluateCekNoEmit params) term benchDefault :: String -> PlainTerm DefaultUni DefaultFun -> Benchmark benchDefault = benchWith defaultCekParameters diff --git a/plutus-core/plutus-core/src/PlutusCore/Evaluation/ErrorWithCause.hs b/plutus-core/plutus-core/src/PlutusCore/Evaluation/ErrorWithCause.hs index 15d3123338e..32bdc30d797 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/ErrorWithCause.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/ErrorWithCause.hs @@ -37,11 +37,14 @@ instance (Pretty err, Pretty cause) => Pretty (ErrorWithCause err cause) where instance (PrettyBy config cause, PrettyBy config err) => PrettyBy config (ErrorWithCause err cause) where - prettyBy config (ErrorWithCause err mayCause) = - "An error has occurred: " <+> prettyBy config err <> - case mayCause of - Nothing -> mempty - Just cause -> hardline <> "Caused by:" <+> prettyBy config cause + prettyBy config (ErrorWithCause err mayCause) = fold + [ "An error has occurred:" + , hardline + , prettyBy config err + , case mayCause of + Nothing -> mempty + Just cause -> hardline <> "Caused by:" <+> prettyBy config cause + ] instance (PrettyPlc cause, PrettyPlc err) => Show (ErrorWithCause err cause) where diff --git a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/Ck.hs b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/Ck.hs index e188b2cfa73..d1b7abab36f 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/Ck.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/Ck.hs @@ -17,12 +17,11 @@ module PlutusCore.Evaluation.Machine.Ck , CkEvaluationException , CkM , CkValue - , extractEvaluationResult , runCk + , extractEvaluationResult + , unsafeToEvaluationResult , evaluateCk , evaluateCkNoEmit - , unsafeEvaluateCk - , unsafeEvaluateCkNoEmit , readKnownCk ) where @@ -195,7 +194,7 @@ stack |> Constr _ ty i es = case es of t : ts -> FrameConstr ty i ts [] : stack |> t stack |> Case _ _ arg cs = FrameCase cs : stack |> arg _ |> Error{} = - throwingWithCause _EvaluationError (UserEvaluationError CkEvaluationFailure) Nothing + throwingWithCause _EvaluationError (OperationalEvaluationError CkEvaluationFailure) Nothing _ |> var@Var{} = throwingWithCause _MachineError OpenTermEvaluatedMachineError $ Just var @@ -312,22 +311,6 @@ evaluateCkNoEmit -> Either (CkEvaluationException uni fun) (Term TyName Name uni fun ()) evaluateCkNoEmit runtime = fst . runCk runtime False --- | Evaluate a term using the CK machine with logging enabled. May throw a 'CkEvaluationException'. -unsafeEvaluateCk - :: ThrowableBuiltins uni fun - => BuiltinsRuntime fun (CkValue uni fun) - -> Term TyName Name uni fun () - -> (EvaluationResult (Term TyName Name uni fun ()), [Text]) -unsafeEvaluateCk runtime = first unsafeExtractEvaluationResult . evaluateCk runtime - --- | Evaluate a term using the CK machine with logging disabled. May throw a 'CkEvaluationException'. -unsafeEvaluateCkNoEmit - :: ThrowableBuiltins uni fun - => BuiltinsRuntime fun (CkValue uni fun) - -> Term TyName Name uni fun () - -> EvaluationResult (Term TyName Name uni fun ()) -unsafeEvaluateCkNoEmit runtime = unsafeExtractEvaluationResult . evaluateCkNoEmit runtime - -- | Unlift a value using the CK machine. readKnownCk :: ReadKnown (Term TyName Name uni fun ()) a diff --git a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/Exception.hs b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/Exception.hs index 354750cc82c..bd10f0267fe 100644 --- a/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/Exception.hs +++ b/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/Exception.hs @@ -29,7 +29,7 @@ module PlutusCore.Evaluation.Machine.Exception , throwing_ , throwingWithCause , extractEvaluationResult - , unsafeExtractEvaluationResult + , unsafeToEvaluationResult ) where import PlutusPrelude @@ -55,9 +55,9 @@ data MachineError fun | OpenTermEvaluatedMachineError -- ^ An attempt to evaluate an open term. | UnliftingMachineError UnliftingError - -- ^ An attempt to compute a constant application resulted in 'ConstAppError'. + -- ^ An attempt to compute a constant application resulted in 'UnliftingError'. | BuiltinTermArgumentExpectedMachineError - -- ^ A builtin expected a term argument, but something else was received + -- ^ A builtin expected a term argument, but something else was received. | UnexpectedBuiltinTermArgumentMachineError -- ^ A builtin received a term argument when something else was expected | NonConstrScrutinized @@ -65,13 +65,31 @@ data MachineError fun deriving stock (Show, Eq, Functor, Generic) deriving anyclass (NFData) --- | The type of errors (all of them) which can occur during evaluation --- (some are used-caused, some are internal). -data EvaluationError user internal - = InternalEvaluationError !internal - -- ^ Indicates bugs. - | UserEvaluationError !user - -- ^ Indicates user errors. +{- | The type of errors that can occur during evaluation. There are two kinds of errors: + +1. 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. +2. 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, or a non-function was + applied to an argument. + +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, operational errors are regular runtime errors and structural errors are \"runtime +type 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. For example, +a built-in function expecting a list but getting something else should throw a structural error, +but currently it'll throw an operational one. This is something that we plan to improve upon in +future. +-} +data EvaluationError operational structural + = OperationalEvaluationError !operational + | StructuralEvaluationError !structural deriving stock (Show, Eq, Functor, Generic) deriving anyclass (NFData) @@ -80,47 +98,50 @@ mtraverse makeClassyPrisms , ''EvaluationError ] -instance internal ~ MachineError fun => AsMachineError (EvaluationError user internal) fun where - _MachineError = _InternalEvaluationError -instance AsUnliftingError internal => AsUnliftingError (EvaluationError user internal) where - _UnliftingError = _InternalEvaluationError . _UnliftingError +instance structural ~ MachineError fun => + AsMachineError (EvaluationError operational structural) fun where + _MachineError = _StructuralEvaluationError +instance AsUnliftingError structural => + AsUnliftingError (EvaluationError operational structural) where + _UnliftingError = _StructuralEvaluationError . _UnliftingError instance AsUnliftingError (MachineError fun) where _UnliftingError = _UnliftingMachineError -instance AsEvaluationFailure user => AsEvaluationFailure (EvaluationError user internal) where - _EvaluationFailure = _UserEvaluationError . _EvaluationFailure - -type EvaluationException user internal = - ErrorWithCause (EvaluationError user internal) - -{- Note [Ignoring context in UserEvaluationError] -The UserEvaluationError error has a term argument, but -extractEvaluationResult just discards this and returns -EvaluationFailure. This means that, for example, if we use the `plc` -command to execute a program containing a division by zero, plc exits -silently without reporting that anything has gone wrong (but returning -a non-zero exit code to the shell via `exitFailure`). This is because -UserEvaluationError is used in cases when a PLC program itself goes -wrong (for example, a failure due to `(error)`, a failure during -builtin evaluation, or exceeding the gas limit). This is used to -signal unsuccessful in validation and so is not regarded as a real -error; in contrast, machine errors, typechecking failures, -and so on are genuine errors and we report their context if available. - -} - --- | Turn any 'UserEvaluationError' into an 'EvaluationFailure'. +instance AsEvaluationFailure operational => + AsEvaluationFailure (EvaluationError operational structural) where + _EvaluationFailure = _OperationalEvaluationError . _EvaluationFailure + +type EvaluationException operational structural = + ErrorWithCause (EvaluationError operational structural) + +{- Note [Ignoring context in OperationalEvaluationError] +The 'OperationalEvaluationError' error has a term argument, but 'extractEvaluationResult' just +discards this and returns 'EvaluationFailure'. This means that, for example, if we use the @plc@ +command to execute a program containing a division by zero, @plc@ exits silently without reporting +that anything has gone wrong (but returning a non-zero exit code to the shell via 'exitFailure'). +This is because 'OperationalEvaluationError' is used in cases when a PLC program itself goes wrong +(see the Haddocks of 'EvaluationError'). This is used to signal unsuccessful validation and so is +not regarded as a real error; in contrast structural errors are genuine errors and we report their +context if available. +-} + +-- See Note [Ignoring context in OperationalEvaluationError]. +-- | Preserve the contents of an 'StructuralEvaluationError' as a 'Left' and turn an +-- 'OperationalEvaluationError' into a @Right EvaluationFailure@. extractEvaluationResult - :: Either (EvaluationException user internal term) a - -> Either (ErrorWithCause internal term) (EvaluationResult a) + :: Either (EvaluationException operational structural term) a + -> Either (ErrorWithCause structural term) (EvaluationResult a) extractEvaluationResult (Right term) = Right $ EvaluationSuccess term extractEvaluationResult (Left (ErrorWithCause evalErr cause)) = case evalErr of - InternalEvaluationError err -> Left $ ErrorWithCause err cause - UserEvaluationError _ -> Right $ EvaluationFailure + StructuralEvaluationError err -> Left $ ErrorWithCause err cause + OperationalEvaluationError _ -> Right $ EvaluationFailure -unsafeExtractEvaluationResult +-- | Throw on a 'StructuralEvaluationError' and turn an 'OperationalEvaluationError' into an +-- 'EvaluationFailure'. +unsafeToEvaluationResult :: (PrettyPlc internal, PrettyPlc term, Typeable internal, Typeable term) => Either (EvaluationException user internal term) a -> EvaluationResult a -unsafeExtractEvaluationResult = unsafeFromEither . extractEvaluationResult +unsafeToEvaluationResult = unsafeFromEither . extractEvaluationResult instance (HasPrettyDefaults config ~ 'True, Pretty fun) => PrettyBy config (MachineError fun) where @@ -145,13 +166,7 @@ instance (HasPrettyDefaults config ~ 'True, Pretty fun) => instance ( HasPrettyDefaults config ~ 'True - , PrettyBy config internal, Pretty user - ) => PrettyBy config (EvaluationError user internal) where - prettyBy config (InternalEvaluationError err) = fold - [ "error:", hardline - , prettyBy config err - ] - prettyBy _ (UserEvaluationError err) = fold - [ "User error:", hardline - , pretty err - ] + , Pretty operational, PrettyBy config structural + ) => PrettyBy config (EvaluationError operational structural) where + prettyBy _ (OperationalEvaluationError operational) = pretty operational + prettyBy config (StructuralEvaluationError structural) = prettyBy config structural diff --git a/plutus-core/plutus-core/src/PlutusCore/TypeCheck.hs b/plutus-core/plutus-core/src/PlutusCore/TypeCheck.hs index b71f193d2db..995f944c372 100644 --- a/plutus-core/plutus-core/src/PlutusCore/TypeCheck.hs +++ b/plutus-core/plutus-core/src/PlutusCore/TypeCheck.hs @@ -36,9 +36,9 @@ import PlutusCore.Quote import PlutusCore.Rename import PlutusCore.TypeCheck.Internal --- | The constraint for built-in types/functions are kind/type-checkable. +-- | The constraint for built-in types\/functions are kind\/type-checkable. -- --- We keep this separate from 'MonadKindCheck'/'MonadTypeCheck', because those mainly constrain the +-- We keep this separate from 'MonadKindCheck'\/'MonadTypeCheck', because those mainly constrain the -- monad and 'Typecheckable' constraints only the builtins. In particular useful when the monad gets -- instantiated and builtins don't. Another reason is that 'Typecheckable' is not required during -- type checking, since it's only needed for computing 'BuiltinTypes', which is passed as a regular diff --git a/plutus-core/plutus-core/test/Evaluation/Machines.hs b/plutus-core/plutus-core/test/Evaluation/Machines.hs index 0d662124ce3..e47c3aceeee 100644 --- a/plutus-core/plutus-core/test/Evaluation/Machines.hs +++ b/plutus-core/plutus-core/test/Evaluation/Machines.hs @@ -20,10 +20,12 @@ import Test.Tasty import Test.Tasty.Hedgehog testMachine - :: (uni ~ DefaultUni, fun ~ DefaultFun, PrettyPlc internal) + :: (uni ~ DefaultUni, fun ~ DefaultFun, PrettyPlc structural) => String -> (Term TyName Name uni fun () -> - Either (EvaluationException user internal (Term TyName Name uni fun ())) (Term TyName Name uni fun ())) + Either + (EvaluationException operational structural (Term TyName Name uni fun ())) + (Term TyName Name uni fun ())) -> TestTree testMachine machine eval = testGroup machine $ fromInterestingTermGens $ \name -> diff --git a/plutus-core/plutus-ir/test/PlutusIR/Compiler/Recursion/errorBinding.golden b/plutus-core/plutus-ir/test/PlutusIR/Compiler/Recursion/errorBinding.golden index 26a2b45bb82..4efbe91da20 100644 --- a/plutus-core/plutus-ir/test/PlutusIR/Compiler/Recursion/errorBinding.golden +++ b/plutus-core/plutus-ir/test/PlutusIR/Compiler/Recursion/errorBinding.golden @@ -1,4 +1,4 @@ -An error has occurred: User error: +An error has occurred: The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. Final budget: ({cpu: 100 | mem: 100}) diff --git a/plutus-core/plutus-ir/test/PlutusIR/Transform/StrictLetRec/Tests/Lib.hs b/plutus-core/plutus-ir/test/PlutusIR/Transform/StrictLetRec/Tests/Lib.hs index f07c3210a2c..3421d896f9e 100644 --- a/plutus-core/plutus-ir/test/PlutusIR/Transform/StrictLetRec/Tests/Lib.hs +++ b/plutus-core/plutus-ir/test/PlutusIR/Transform/StrictLetRec/Tests/Lib.hs @@ -29,8 +29,8 @@ import PlutusIR.Compiler qualified as PIR import PlutusIR.Core qualified as PIR import PlutusIR.Parser (pTerm) import UntypedPlutusCore.Core qualified as UPLC -import UntypedPlutusCore.Evaluation.Machine.Cek (CekValue, EvaluationResult (..), logEmitter, - unsafeEvaluateCek) +import UntypedPlutusCore.Evaluation.Machine.Cek (CekValue, EvaluationResult (..), evaluateCek, + logEmitter, unsafeToEvaluationResult) import UntypedPlutusCore.Evaluation.Machine.Cek.CekMachineCosts (CekMachineCosts) pirTermFromFile @@ -66,7 +66,7 @@ compilePirProgramOrFail pirProgram = do & runExceptT >>= \case Left (er :: PIR.Error DefaultUni DefaultFun (Provenance ())) -> fail $ show er - Right p -> pure (void p) + Right p -> pure (void p) compileTplcProgramOrFail :: (MonadFail m) @@ -83,7 +83,8 @@ evaluateUplcProgramWithTraces :: UPLC.Program Name DefaultUni DefaultFun () -> (EvaluationResult (UPLC.Term Name DefaultUni DefaultFun ()), [Text]) evaluateUplcProgramWithTraces uplcProg = - unsafeEvaluateCek logEmitter machineParameters (uplcProg ^. UPLC.progTerm) + first unsafeToEvaluationResult $ + evaluateCek logEmitter machineParameters (uplcProg ^. UPLC.progTerm) where costModel :: CostModel CekMachineCosts BuiltinCostModel = CostModel defaultCekMachineCosts defaultBuiltinCostModel @@ -102,5 +103,5 @@ defaultCompilationCtx = do handlePirErrorByFailing :: (Pretty ann, MonadFail m) => Either (PIR.Error DefaultUni DefaultFun ann) a -> m a handlePirErrorByFailing = \case - Left e -> fail $ show e + Left e -> fail $ show e Right x -> pure x diff --git a/plutus-core/testlib/PlutusCore/Generators/Hedgehog/Test.hs b/plutus-core/testlib/PlutusCore/Generators/Hedgehog/Test.hs index 3c6921b1780..ab045c191d2 100644 --- a/plutus-core/testlib/PlutusCore/Generators/Hedgehog/Test.hs +++ b/plutus-core/testlib/PlutusCore/Generators/Hedgehog/Test.hs @@ -95,11 +95,11 @@ sampleProgramValueGolden folder name genTerm = do propEvaluate :: ( uni ~ DefaultUni, fun ~ DefaultFun , KnownTypeAst TyName uni a, MakeKnown (Term TyName Name uni fun ()) a - , PrettyPlc internal + , PrettyPlc structural ) => (Term TyName Name uni fun () -> Either - (EvaluationException user internal (Term TyName Name uni fun ())) + (EvaluationException operational structural (Term TyName Name uni fun ())) (Term TyName Name uni fun ())) -- ^ An evaluator. -> TermGen a -- ^ A term/value generator. diff --git a/plutus-core/testlib/PlutusCore/Generators/Hedgehog/TypeEvalCheck.hs b/plutus-core/testlib/PlutusCore/Generators/Hedgehog/TypeEvalCheck.hs index 45d585448d6..c005bd7a963 100644 --- a/plutus-core/testlib/PlutusCore/Generators/Hedgehog/TypeEvalCheck.hs +++ b/plutus-core/testlib/PlutusCore/Generators/Hedgehog/TypeEvalCheck.hs @@ -94,11 +94,11 @@ type TypeEvalCheckM uni fun = Either (TypeEvalCheckError uni fun) typeEvalCheckBy :: ( uni ~ DefaultUni, fun ~ DefaultFun , KnownTypeAst TyName uni a, MakeKnown (Term TyName Name uni fun ()) a - , PrettyPlc internal + , PrettyPlc structural ) => (Term TyName Name uni fun () -> Either - (EvaluationException user internal (Term TyName Name uni fun ())) + (EvaluationException operational structural (Term TyName Name uni fun ())) (Term TyName Name uni fun ())) -- ^ An evaluator. -> TermOf (Term TyName Name uni fun ()) a diff --git a/plutus-core/testlib/PlutusCore/Generators/NEAT/Spec.hs b/plutus-core/testlib/PlutusCore/Generators/NEAT/Spec.hs index e3fc6fb1e6a..a66684842c3 100644 --- a/plutus-core/testlib/PlutusCore/Generators/NEAT/Spec.hs +++ b/plutus-core/testlib/PlutusCore/Generators/NEAT/Spec.hs @@ -111,21 +111,21 @@ not exploited. -- handle a user error and turn it back into an error term handleError :: Type TyName DefaultUni () - -> U.ErrorWithCause (U.EvaluationError user internal) term - -> Either (U.ErrorWithCause (U.EvaluationError user internal) term) + -> U.ErrorWithCause (U.EvaluationError operational structural) term + -> Either (U.ErrorWithCause (U.EvaluationError operational structural) term) (Term TyName Name DefaultUni DefaultFun ()) handleError ty e = case U._ewcError e of - U.UserEvaluationError _ -> return (Error () ty) - U.InternalEvaluationError _ -> throwError e + U.OperationalEvaluationError _ -> return (Error () ty) + U.StructuralEvaluationError _ -> throwError e -- untyped version of `handleError` handleUError :: - U.ErrorWithCause (U.EvaluationError user internal) term - -> Either (U.ErrorWithCause (U.EvaluationError user internal) term) + U.ErrorWithCause (U.EvaluationError operational structural) term + -> Either (U.ErrorWithCause (U.EvaluationError operational structural) term) (U.Term Name DefaultUni DefaultFun ()) handleUError e = case U._ewcError e of - U.UserEvaluationError _ -> return (U.Error ()) - U.InternalEvaluationError _ -> throwError e + U.OperationalEvaluationError _ -> return (U.Error ()) + U.StructuralEvaluationError _ -> throwError e -- |Property: check if the type is preserved by evaluation. -- diff --git a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek.hs b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek.hs index ee43e07dc11..8593d87c31e 100644 --- a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek.hs +++ b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek.hs @@ -7,14 +7,11 @@ module UntypedPlutusCore.Evaluation.Machine.Cek runCek , runCekDeBruijn , runCekNoEmit - , unsafeRunCekNoEmit , evaluateCek , evaluateCekNoEmit - , unsafeEvaluateCek - , unsafeEvaluateCekNoEmit , EvaluationResult(..) , extractEvaluationResult - , unsafeExtractEvaluationResult + , unsafeToEvaluationResult -- * Errors , CekUserError(..) , ErrorWithCause(..) @@ -59,7 +56,6 @@ import UntypedPlutusCore.Evaluation.Machine.Cek.Internal import UntypedPlutusCore.Evaluation.Machine.CommonAPI qualified as Common import PlutusCore.Builtin -import PlutusCore.Evaluation.Machine.Exception import PlutusCore.Evaluation.Machine.MachineParameters import PlutusCore.Name.Unique @@ -88,18 +84,6 @@ runCekNoEmit -> (Either (CekEvaluationException Name uni fun) (Term Name uni fun ()), cost) runCekNoEmit = Common.runCekNoEmit runCekDeBruijn -{-| Unsafely evaluate a term using the CEK machine with logging disabled and keep track of costing. -May throw a 'CekMachineException'. -*THIS FUNCTION IS PARTIAL if the input term contains free variables* --} -unsafeRunCekNoEmit - :: ThrowableBuiltins uni fun - => MachineParameters CekMachineCosts fun (CekValue uni fun ann) - -> ExBudgetMode cost uni fun - -> Term Name uni fun ann - -> (EvaluationResult (Term Name uni fun ()), cost) -unsafeRunCekNoEmit = Common.unsafeRunCekNoEmit runCekDeBruijn - -- | Evaluate a term using the CEK machine with logging enabled. -- *THIS FUNCTION IS PARTIAL if the input term contains free variables* evaluateCek @@ -119,25 +103,6 @@ evaluateCekNoEmit -> Either (CekEvaluationException Name uni fun) (Term Name uni fun ()) evaluateCekNoEmit = Common.evaluateCekNoEmit runCekDeBruijn --- | Evaluate a term using the CEK machine with logging enabled. May throw a 'CekMachineException'. --- *THIS FUNCTION IS PARTIAL if the input term contains free variables* -unsafeEvaluateCek - :: ThrowableBuiltins uni fun - => EmitterMode uni fun - -> MachineParameters CekMachineCosts fun (CekValue uni fun ann) - -> Term Name uni fun ann - -> (EvaluationResult (Term Name uni fun ()), [Text]) -unsafeEvaluateCek = Common.unsafeEvaluateCek runCekDeBruijn - --- | Evaluate a term using the CEK machine with logging disabled. May throw a 'CekMachineException'. --- *THIS FUNCTION IS PARTIAL if the input term contains free variables* -unsafeEvaluateCekNoEmit - :: ThrowableBuiltins uni fun - => MachineParameters CekMachineCosts fun (CekValue uni fun ann) - -> Term Name uni fun ann - -> EvaluationResult (Term Name uni fun ()) -unsafeEvaluateCekNoEmit = Common.unsafeEvaluateCekNoEmit runCekDeBruijn - -- | Unlift a value using the CEK machine. -- *THIS FUNCTION IS PARTIAL if the input term contains free variables* readKnownCek diff --git a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/ExBudgetMode.hs b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/ExBudgetMode.hs index 0d376a47b02..a2f15197f96 100644 --- a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/ExBudgetMode.hs +++ b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/ExBudgetMode.hs @@ -144,7 +144,7 @@ restricting (ExRestrictingBudget initB@(ExBudget cpuInit memInit)) = ExBudgetMod when (cpuLeft' < 0 || memLeft' < 0) $ do let budgetLeft = ExBudget cpuLeft' memLeft' throwingWithCause _EvaluationError - (UserEvaluationError . CekOutOfExError $ ExRestrictingBudget budgetLeft) + (OperationalEvaluationError . CekOutOfExError $ ExRestrictingBudget budgetLeft) Nothing spender = CekBudgetSpender spend remaining = ExBudget <$> readCpu <*> readMem diff --git a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/Internal.hs b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/Internal.hs index fc755a41f2c..113abb8699a 100644 --- a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/Internal.hs +++ b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/Internal.hs @@ -48,6 +48,7 @@ module UntypedPlutusCore.Evaluation.Machine.Cek.Internal , StepKind(..) , ThrowableBuiltins , extractEvaluationResult + , unsafeToEvaluationResult , spendBudgetStreamCek , runCekDeBruijn , dischargeCekValue diff --git a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/CommonAPI.hs b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/CommonAPI.hs index fa24c961b5c..a9c2bf023f8 100644 --- a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/CommonAPI.hs +++ b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/CommonAPI.hs @@ -11,14 +11,11 @@ module UntypedPlutusCore.Evaluation.Machine.CommonAPI runCek , runCekDeBruijn , runCekNoEmit - , unsafeRunCekNoEmit , evaluateCek , evaluateCekNoEmit - , unsafeEvaluateCek - , unsafeEvaluateCekNoEmit , EvaluationResult(..) , extractEvaluationResult - , unsafeExtractEvaluationResult + , unsafeToEvaluationResult -- * Errors , CekUserError(..) , ErrorWithCause(..) @@ -63,7 +60,6 @@ import UntypedPlutusCore.Evaluation.Machine.Cek.ExBudgetMode import UntypedPlutusCore.Evaluation.Machine.Cek.Internal import PlutusCore.Builtin -import PlutusCore.Evaluation.Machine.Exception import PlutusCore.Evaluation.Machine.MachineParameters import PlutusCore.Name.Unique import PlutusCore.Quote @@ -137,21 +133,6 @@ runCekNoEmit runner params mode = -- throw away the logs (\(res, cost, _logs) -> (res, cost)) . runCek runner params mode noEmitter -{-| Unsafely evaluate a term a machine with logging disabled and keep track of costing. -May throw a 'CekMachineException'. -*THIS FUNCTION IS PARTIAL if the input term contains free variables* --} -unsafeRunCekNoEmit - :: ThrowableBuiltins uni fun - => MachineRunner cost uni fun ann - -> MachineParameters CekMachineCosts fun (CekValue uni fun ann) - -> ExBudgetMode cost uni fun - -> Term Name uni fun ann - -> (EvaluationResult (Term Name uni fun ()), cost) -unsafeRunCekNoEmit runner params mode = - -- Don't use 'first': https://github.com/IntersectMBO/plutus/issues/3876 - (\(e, l) -> (unsafeExtractEvaluationResult e, l)) . runCekNoEmit runner params mode - -- | Evaluate a term using a machine with logging enabled. -- *THIS FUNCTION IS PARTIAL if the input term contains free variables* evaluateCek @@ -175,29 +156,6 @@ evaluateCekNoEmit -> Either (CekEvaluationException Name uni fun) (Term Name uni fun ()) evaluateCekNoEmit runner params = fst . runCekNoEmit runner params restrictingEnormous --- | Evaluate a term using a machine with logging enabled. May throw a 'CekMachineException'. --- *THIS FUNCTION IS PARTIAL if the input term contains free variables* -unsafeEvaluateCek - :: ThrowableBuiltins uni fun - => MachineRunner RestrictingSt uni fun ann - -> EmitterMode uni fun - -> MachineParameters CekMachineCosts fun (CekValue uni fun ann) - -> Term Name uni fun ann - -> (EvaluationResult (Term Name uni fun ()), [Text]) -unsafeEvaluateCek runner emitTime params = - -- Don't use 'first': https://github.com/IntersectMBO/plutus/issues/3876 - (\(e, l) -> (unsafeExtractEvaluationResult e, l)) . evaluateCek runner emitTime params - --- | Evaluate a term using a machine with logging disabled. May throw a 'CekMachineException'. --- *THIS FUNCTION IS PARTIAL if the input term contains free variables* -unsafeEvaluateCekNoEmit - :: ThrowableBuiltins uni fun - => MachineRunner RestrictingSt uni fun ann - -> MachineParameters CekMachineCosts fun (CekValue uni fun ann) - -> Term Name uni fun ann - -> EvaluationResult (Term Name uni fun ()) -unsafeEvaluateCekNoEmit runner params = unsafeExtractEvaluationResult . evaluateCekNoEmit runner params - -- | Unlift a value using a machine. -- *THIS FUNCTION IS PARTIAL if the input term contains free variables* readKnownCek diff --git a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/SteppableCek.hs b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/SteppableCek.hs index e81bf9ac973..9caacf82789 100644 --- a/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/SteppableCek.hs +++ b/plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/SteppableCek.hs @@ -7,14 +7,11 @@ module UntypedPlutusCore.Evaluation.Machine.SteppableCek runCek , runCekDeBruijn , runCekNoEmit - , unsafeRunCekNoEmit , evaluateCek , evaluateCekNoEmit - , unsafeEvaluateCek - , unsafeEvaluateCekNoEmit , EvaluationResult(..) , extractEvaluationResult - , unsafeExtractEvaluationResult + , unsafeToEvaluationResult -- * Errors , CekUserError(..) , ErrorWithCause(..) @@ -57,7 +54,6 @@ import UntypedPlutusCore.Evaluation.Machine.CommonAPI qualified as Common import UntypedPlutusCore.Evaluation.Machine.SteppableCek.Internal as S import PlutusCore.Builtin -import PlutusCore.Evaluation.Machine.Exception import PlutusCore.Evaluation.Machine.MachineParameters import PlutusCore.Name.Unique @@ -87,19 +83,6 @@ runCekNoEmit -> (Either (CekEvaluationException Name uni fun) (Term Name uni fun ()), cost) runCekNoEmit = Common.runCekNoEmit S.runCekDeBruijn -{-| Unsafely evaluate a term using the Steppable CEK machine with logging disabled --- and keep track of costing. -May throw a 'CekMachineException'. -*THIS FUNCTION IS PARTIAL if the input term contains free variables* --} -unsafeRunCekNoEmit - :: ThrowableBuiltins uni fun - => MachineParameters CekMachineCosts fun (CekValue uni fun ann) - -> ExBudgetMode cost uni fun - -> Term Name uni fun ann - -> (EvaluationResult (Term Name uni fun ()), cost) -unsafeRunCekNoEmit = Common.unsafeRunCekNoEmit S.runCekDeBruijn - -- | Evaluate a term using the Steppable CEK machine with logging enabled. -- *THIS FUNCTION IS PARTIAL if the input term contains free variables* evaluateCek @@ -119,27 +102,6 @@ evaluateCekNoEmit -> Either (CekEvaluationException Name uni fun) (Term Name uni fun ()) evaluateCekNoEmit = Common.evaluateCekNoEmit S.runCekDeBruijn --- | Evaluate a term using the Steppable CEK machine with logging enabled. --- May throw a 'CekMachineException'. --- *THIS FUNCTION IS PARTIAL if the input term contains free variables* -unsafeEvaluateCek - :: ThrowableBuiltins uni fun - => EmitterMode uni fun - -> MachineParameters CekMachineCosts fun (CekValue uni fun ann) - -> Term Name uni fun ann - -> (EvaluationResult (Term Name uni fun ()), [Text]) -unsafeEvaluateCek = Common.unsafeEvaluateCek S.runCekDeBruijn - --- | Evaluate a term using the Steppable CEK machine with logging disabled. --- May throw a 'CekMachineException'. --- *THIS FUNCTION IS PARTIAL if the input term contains free variables* -unsafeEvaluateCekNoEmit - :: ThrowableBuiltins uni fun - => MachineParameters CekMachineCosts fun (CekValue uni fun ann) - -> Term Name uni fun ann - -> EvaluationResult (Term Name uni fun ()) -unsafeEvaluateCekNoEmit = Common.unsafeEvaluateCekNoEmit S.runCekDeBruijn - -- | Unlift a value using the Steppable CEK machine. -- *THIS FUNCTION IS PARTIAL if the input term contains free variables* readKnownCek diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Common.hs b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Common.hs index 285059ed8f2..46700d430ac 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Common.hs +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Common.hs @@ -3,8 +3,9 @@ {-# LANGUAGE TypeOperators #-} module Evaluation.Builtins.Common - ( unsafeEvaluateCek - , unsafeEvaluateCekNoEmit + ( unsafeToEvaluationResult + , evaluateCek + , evaluateCekNoEmit , readKnownCek , typecheckAnd , typecheckEvaluateCek @@ -27,6 +28,7 @@ import UntypedPlutusCore qualified as UPLC import UntypedPlutusCore.Evaluation.Machine.Cek import Control.Monad.Except +import Data.Bifunctor import Data.Text (Text) -- | Type check and evaluate a term. @@ -39,14 +41,12 @@ typecheckAnd UPLC.Term Name uni fun () -> a) -> CostingPart uni fun -> TPLC.Term TyName Name uni fun () -> m a typecheckAnd semvar action costingPart term = TPLC.runQuoteT $ do - -- Here we don't use `getDefTypeCheckConfig`, to cover the absurd case where - -- builtins can change their type according to their BuiltinSemanticsVariant + -- Here we don't use 'getDefTypeCheckConfig', to cover the absurd case where + -- builtins can change their type according to their 'BuiltinSemanticsVariant'. tcConfig <- TypeCheckConfig defKindCheckConfig <$> builtinMeaningsToTypes semvar () _ <- TPLC.inferType tcConfig term + let runtime = mkMachineParameters semvar $ CostModel defaultCekMachineCosts costingPart return . action runtime $ TPLC.eraseTerm term - where - runtime = mkMachineParameters semvar $ - CostModel defaultCekMachineCosts costingPart -- | Type check and evaluate a term, logging enabled. typecheckEvaluateCek @@ -57,7 +57,9 @@ typecheckEvaluateCek -> CostingPart uni fun -> TPLC.Term TyName Name uni fun () -> m (EvaluationResult (UPLC.Term Name uni fun ()), [Text]) -typecheckEvaluateCek semvar = typecheckAnd semvar $ unsafeEvaluateCek logEmitter +typecheckEvaluateCek semvar = + typecheckAnd semvar $ \params -> + first unsafeToEvaluationResult . evaluateCek logEmitter params -- | Type check and evaluate a term, logging disabled. typecheckEvaluateCekNoEmit @@ -68,7 +70,9 @@ typecheckEvaluateCekNoEmit -> CostingPart uni fun -> TPLC.Term TyName Name uni fun () -> m (EvaluationResult (UPLC.Term Name uni fun ())) -typecheckEvaluateCekNoEmit semvar = typecheckAnd semvar unsafeEvaluateCekNoEmit +typecheckEvaluateCekNoEmit semvar = + typecheckAnd semvar $ \params -> + unsafeToEvaluationResult . evaluateCekNoEmit params -- | Type check and convert a Plutus Core term to a Haskell value. typecheckReadKnownCek @@ -80,4 +84,5 @@ typecheckReadKnownCek -> CostingPart uni fun -> TPLC.Term TyName Name uni fun () -> m (Either (CekEvaluationException Name uni fun) a) -typecheckReadKnownCek semvar = typecheckAnd semvar readKnownCek +typecheckReadKnownCek semvar = + typecheckAnd semvar readKnownCek diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs index c7d6eb915e8..25ccd044ea2 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs @@ -89,8 +89,10 @@ test_Const = tB = mkConstant () b text = toTypeAst @_ @_ @DefaultUni @Text Proxy runConst con = mkIterAppNoAnn (mkIterInstNoAnn con [text, bool]) [tC, tB] - lhs = typecheckReadKnownCek def defaultBuiltinCostModelExt $ runConst $ builtin () (Right Const) - rhs = typecheckReadKnownCek def defaultBuiltinCostModelExt $ runConst $ mapFun @DefaultFun Left Plc.const + lhs = typecheckReadKnownCek def defaultBuiltinCostModelExt $ + runConst $ builtin () (Right Const) + rhs = typecheckReadKnownCek def defaultBuiltinCostModelExt $ + runConst $ mapFun @DefaultFun Left Plc.const lhs === Right (Right c) lhs === rhs @@ -125,7 +127,8 @@ test_Id = . LamAbs () i integer . LamAbs () j integer $ Var () i - typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= Right (EvaluationSuccess oneU) + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= + Right (EvaluationSuccess oneU) -- | Test that a polymorphic built-in function can have a higher-kinded type variable in its -- signature. @@ -140,7 +143,8 @@ test_IdFInteger = = apply () (mapFun Left Scott.sum) . apply () (tyInst () (builtin () $ Right IdFInteger) Scott.listTy) $ mkIterAppNoAnn (mapFun Left Scott.enumFromTo) [one, ten] - typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= Right (EvaluationSuccess res) + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= + Right (EvaluationSuccess res) test_IdList :: TestTree test_IdList = @@ -158,7 +162,8 @@ test_IdList = . apply () (tyInst () (builtin () $ Right IdList) integer) $ mkIterAppNoAnn (mapFun Left Scott.enumFromTo) [one, ten] tyAct @?= tyExp - typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= Right (EvaluationSuccess res) + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= + Right (EvaluationSuccess res) {- Note [Higher-rank built-in functions] We can't unlift a monomorphic function passed to a built-in function, let alone unlift a polymorphic @@ -194,7 +199,8 @@ test_IdRank2 = = apply () (mapFun Left Scott.sum) . tyInst () (apply () (tyInst () (builtin () $ Right IdRank2) Scott.listTy) Scott.nil) $ integer - typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= Right (EvaluationSuccess res) + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= + Right (EvaluationSuccess res) -- | Test that a builtin can be applied to a non-constant term. test_ScottToMetaUnit :: TestTree @@ -207,7 +213,8 @@ test_ScottToMetaUnit = let runtime = mkMachineParameters def $ CostModel defaultCekMachineCosts () -- @scottToMetaUnit Scott.map@ is ill-typed, but still runs successfully, since the builtin -- doesn't look at the argument. - unsafeEvaluateCekNoEmit runtime (eraseTerm $ applyTerm Scott.map) @?= res + unsafeToEvaluationResult (evaluateCekNoEmit runtime (eraseTerm $ applyTerm Scott.map)) @?= + res -- | Test that an exception thrown in the builtin application code does not get caught in the CEK -- machine and blows in the caller face instead. Uses a one-argument built-in function. @@ -218,8 +225,10 @@ test_FailingSucc = apply () (builtin () $ Right FailingSucc) $ mkConstant @Integer @DefaultUni @DefaultFunExt () 0 typeErrOrEvalExcOrRes :: Either _ (Either BuiltinErrorCall _) <- - -- Here we rely on 'typecheckAnd' lazily running the action after type checking the term. - traverse (try . evaluate) $ typecheckEvaluateCek def defaultBuiltinCostModelExt term + -- Here we rely on 'typecheckAnd' lazily running the action after type checking the + -- term. + traverse (try . evaluate) $ + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term typeErrOrEvalExcOrRes @?= Right (Left BuiltinErrorCall) -- | Test that evaluating a PLC builtin application that is expensive enough to exceed the budget @@ -232,7 +241,8 @@ test_ExpensiveSucc = apply () (builtin () $ Right ExpensiveSucc) $ mkConstant @Integer @DefaultUni @DefaultFunExt () 0 typeErrOrEvalExcOrRes :: Either _ (Either BuiltinErrorCall _) <- - traverse (try . evaluate) $ typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term + traverse (try . evaluate) $ + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term typeErrOrEvalExcOrRes @?= Right (Right EvaluationFailure) -- | Test that an exception thrown in the builtin application code does not get caught in the CEK @@ -246,8 +256,10 @@ test_FailingPlus = , mkConstant @Integer @DefaultUni () 1 ] typeErrOrEvalExcOrRes :: Either _ (Either BuiltinErrorCall _) <- - -- Here we rely on 'typecheckAnd' lazily running the action after type checking the term. - traverse (try . evaluate) $ typecheckEvaluateCek def defaultBuiltinCostModelExt term + -- Here we rely on 'typecheckAnd' lazily running the action after type checking the + -- term. + traverse (try . evaluate) $ + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term typeErrOrEvalExcOrRes @?= Right (Left BuiltinErrorCall) -- | Test that evaluating a PLC builtin application that is expensive enough to exceed the budget @@ -262,7 +274,8 @@ test_ExpensivePlus = , mkConstant @Integer @DefaultUni () 1 ] typeErrOrEvalExcOrRes :: Either _ (Either BuiltinErrorCall _) <- - traverse (try . evaluate) $ typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term + traverse (try . evaluate) $ + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term typeErrOrEvalExcOrRes @?= Right (Right EvaluationFailure) -- | Test that @Null@, @Head@ and @Tail@ are enough to get pattern matching on built-in lists. @@ -277,7 +290,8 @@ test_BuiltinList = , mkConstant @Integer () 0 , mkConstant @[Integer] () xs ] - typecheckEvaluateCekNoEmit def defaultBuiltinCostModel term @?= Right (EvaluationSuccess res) + typecheckEvaluateCekNoEmit def defaultBuiltinCostModel term @?= + Right (EvaluationSuccess res) -- | Test that right-folding a built-in list with built-in 'Cons' recreates that list. test_IdBuiltinList :: TestTree @@ -287,12 +301,14 @@ test_IdBuiltinList = xsTerm = mkConstant @[Integer] () [1..10] listOfInteger = mkTyBuiltin @_ @[Integer] () term - = mkIterAppNoAnn (mkIterInstNoAnn (mapFun Left Builtin.foldrList) [integer, listOfInteger]) + = mkIterAppNoAnn + (mkIterInstNoAnn (mapFun Left Builtin.foldrList) [integer, listOfInteger]) [ tyInst () (builtin () $ Left MkCons) integer , mkConstant @[Integer] () [] , xsTerm ] - typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= Right (EvaluationSuccess xsTerm) + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= + Right (EvaluationSuccess xsTerm) test_BuiltinPair :: TestTree test_BuiltinPair = @@ -343,7 +359,8 @@ test_SwapEls = , mkConstant @Integer () 0 , mkConstant () xs ] - typecheckEvaluateCekNoEmit def defaultBuiltinCostModel term @?= Right (EvaluationSuccess res) + typecheckEvaluateCekNoEmit def defaultBuiltinCostModel term @?= + Right (EvaluationSuccess res) -- | Test that right-folding a built-in 'Data' with the constructors of 'Data' recreates the -- original value. @@ -361,7 +378,8 @@ test_IdBuiltinData = , emb BData , dTerm ] - typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= Right (EvaluationSuccess dTerm) + typecheckEvaluateCekNoEmit def defaultBuiltinCostModelExt term @?= + Right (EvaluationSuccess dTerm) -- | For testing how an evaluator instantiated at a particular 'ExBudgetMode' handles the -- 'TrackCosts' builtin. @@ -425,7 +443,7 @@ test_SerialiseDataImpossible = dataLoop = Apply () (Builtin () SerialiseData) $ mkConstant () loop where loop = List [loop] budgetMode = restricting . ExRestrictingBudget $ ExBudget 10000000000 10000000 - evalRestricting params = fst . unsafeRunCekNoEmit params budgetMode + evalRestricting params = unsafeToEvaluationResult . fst . runCekNoEmit params budgetMode typecheckAnd def evalRestricting defaultBuiltinCostModel dataLoop @?= Right EvaluationFailure diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Debug/ex3.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Debug/ex3.golden index bd65974e19d..569eea1d5ad 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Debug/ex3.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Debug/ex3.golden @@ -7,5 +7,5 @@ OldState: Computing NewState: Returning Driver is going to do a single step OldState: Returning NewState: Computing Driver is going to do a single step -OldState: Computing NewState is Error: An error has occurred: User error: +OldState: Computing NewState is Error: An error has occurred: The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Debug/ex4.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Debug/ex4.golden index 79a5ab7f1cf..a3e13d2a057 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Debug/ex4.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Debug/ex4.golden @@ -1,5 +1,5 @@ Driver is going to do a single step OldState: Starting NewState: Computing Driver is going to do a single step -OldState: Computing NewState is Error: An error has occurred: User error: +OldState: Computing NewState is Error: An error has occurred: The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNoBranch.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNoBranch.plc.golden index 1436661e809..e229d959ca8 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNoBranch.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNoBranch.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: Case expression missing the branch required by the scrutinee tag: 0 Caused by: (constr 0 (con integer 1))) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNoBranch.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNoBranch.uplc.golden index 1436661e809..e229d959ca8 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNoBranch.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNoBranch.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: Case expression missing the branch required by the scrutinee tag: 0 Caused by: (constr 0 (con integer 1))) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNonTag.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNonTag.plc.golden index f48798f54d0..1bd7d1fbdda 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNonTag.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNonTag.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A non-constructor value was scrutinized in a case expression Caused by: (con integer 1)) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNonTag.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNonTag.uplc.golden index f48798f54d0..1bd7d1fbdda 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNonTag.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/caseNonTag.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A non-constructor value was scrutinized in a case expression Caused by: (con integer 1)) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/diFullyApplied.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/diFullyApplied.plc.golden index f177b6623f1..7f60668f62e 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/diFullyApplied.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/diFullyApplied.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: User error: +(Left An error has occurred: The provided Plutus code called 'error'. Caused by: [ [ (builtin divideInteger) (con integer 1) ] (con integer 0) ]) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/diFullyApplied.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/diFullyApplied.uplc.golden index 6ef7aa04f30..6388d69ceea 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/diFullyApplied.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/diFullyApplied.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: User error: +(Left An error has occurred: The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. Caused by: [ [ (builtin divideInteger) (con integer 1) ] (con integer 0) ]) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerAtInteger.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerAtInteger.plc.golden index d3afe69b18d..8c9074010e3 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerAtInteger.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerAtInteger.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin expected a term argument, but something else was received Caused by: (force (force (builtin ifThenElse)))) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerAtInteger.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerAtInteger.uplc.golden index d3afe69b18d..8c9074010e3 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerAtInteger.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerAtInteger.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin expected a term argument, but something else was received Caused by: (force (force (builtin ifThenElse)))) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerWrongCondTypeSat.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerWrongCondTypeSat.plc.golden index 0baa2734b4e..9cb5f80b598 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerWrongCondTypeSat.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerWrongCondTypeSat.plc.golden @@ -1,4 +1,4 @@ -(Left An error has occurred: error: +(Left An error has occurred: Could not unlift a value: Type mismatch: expected: bool; actual: string Caused by: [ diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerWrongCondTypeSat.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerWrongCondTypeSat.uplc.golden index 0baa2734b4e..9cb5f80b598 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerWrongCondTypeSat.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteAtIntegerWrongCondTypeSat.uplc.golden @@ -1,4 +1,4 @@ -(Left An error has occurred: error: +(Left An error has occurred: Could not unlift a value: Type mismatch: expected: bool; actual: string Caused by: [ diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteTypeTermType.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteTypeTermType.plc.golden index 1aeab826898..5db27720294 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteTypeTermType.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteTypeTermType.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin expected a term argument, but something else was received Caused by: (force [ (force (builtin ifThenElse)) (con bool True) ])) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteTypeTermType.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteTypeTermType.uplc.golden index 1aeab826898..5db27720294 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteTypeTermType.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteTypeTermType.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin expected a term argument, but something else was received Caused by: (force [ (force (builtin ifThenElse)) (con bool True) ])) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedFullyApplied.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedFullyApplied.plc.golden index 8672ef77c8e..984aefc089d 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedFullyApplied.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedFullyApplied.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin received a term argument when something else was expected Caused by: [ (builtin ifThenElse) (con bool True) ]) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedFullyApplied.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedFullyApplied.uplc.golden index 8672ef77c8e..984aefc089d 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedFullyApplied.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedFullyApplied.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin received a term argument when something else was expected Caused by: [ (builtin ifThenElse) (con bool True) ]) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedWithCond.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedWithCond.plc.golden index 8672ef77c8e..984aefc089d 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedWithCond.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedWithCond.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin received a term argument when something else was expected Caused by: [ (builtin ifThenElse) (con bool True) ]) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedWithCond.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedWithCond.uplc.golden index 8672ef77c8e..984aefc089d 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedWithCond.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/iteUninstantiatedWithCond.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin received a term argument when something else was expected Caused by: [ (builtin ifThenElse) (con bool True) ]) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError1.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError1.plc.golden index cbb14ee9289..c9322a9f0b0 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError1.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError1.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin expected a term argument, but something else was received Caused by: (force (builtin multiplyInteger))) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError1.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError1.uplc.golden index cbb14ee9289..c9322a9f0b0 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError1.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError1.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin expected a term argument, but something else was received Caused by: (force (builtin multiplyInteger))) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError2.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError2.plc.golden index 5591ce3bdb2..e68a5566eed 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError2.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError2.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin expected a term argument, but something else was received Caused by: (force [ (builtin multiplyInteger) (con integer 11) ])) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError2.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError2.uplc.golden index 5591ce3bdb2..e68a5566eed 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError2.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError2.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: A builtin expected a term argument, but something else was received Caused by: (force [ (builtin multiplyInteger) (con integer 11) ])) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError3.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError3.plc.golden index 2f90b39bb7f..bec5ef97c9d 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError3.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError3.plc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: Attempted to instantiate a non-polymorphic term. Caused by: (con integer 242)) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError3.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError3.uplc.golden index 2f90b39bb7f..bec5ef97c9d 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError3.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/mulInstError3.uplc.golden @@ -1,3 +1,3 @@ -(Left An error has occurred: error: +(Left An error has occurred: Attempted to instantiate a non-polymorphic term. Caused by: (con integer 242)) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/polyErrorInst.plc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/polyErrorInst.plc.golden index d9c90ef72de..faaf84c1554 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/polyErrorInst.plc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/polyErrorInst.plc.golden @@ -1,2 +1,2 @@ -(Left An error has occurred: User error: +(Left An error has occurred: The provided Plutus code called 'error'.) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/polyErrorInst.uplc.golden b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/polyErrorInst.uplc.golden index fccaddb46c4..cc268b310d6 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Golden/polyErrorInst.uplc.golden +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Golden/polyErrorInst.uplc.golden @@ -1,2 +1,2 @@ -(Left An error has occurred: User error: +(Left An error has occurred: The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.) \ No newline at end of file diff --git a/plutus-core/untyped-plutus-core/test/Evaluation/Machines.hs b/plutus-core/untyped-plutus-core/test/Evaluation/Machines.hs index f2d25e512bc..750c104f777 100644 --- a/plutus-core/untyped-plutus-core/test/Evaluation/Machines.hs +++ b/plutus-core/untyped-plutus-core/test/Evaluation/Machines.hs @@ -5,7 +5,6 @@ module Evaluation.Machines ( test_machines - --, test_memory , test_budget , test_tallying ) where @@ -41,16 +40,20 @@ import Test.Tasty.Golden import Test.Tasty.Hedgehog testMachine - :: (uni ~ DefaultUni, fun ~ DefaultFun, PrettyPlc internal) + :: (uni ~ DefaultUni, fun ~ DefaultFun, PrettyPlc structural) => String -> (Term Name uni fun () -> - Either (EvaluationException user internal (Term Name uni fun ())) (Term Name uni fun ())) + Either + (EvaluationException operational structural (Term Name uni fun ())) + (Term Name uni fun ())) -> TestTree testMachine machine eval = testGroup machine $ fromInterestingTermGens $ \name genTermOfTbv -> testPropertyNamed name (fromString name) . withTests 200 . property $ do TermOf term val <- forAllWith mempty genTermOfTbv - let resExp = eraseTerm <$> makeKnownOrFail @_ @(Plc.Term TyName Name DefaultUni DefaultFun ()) val + let resExp = + eraseTerm <$> + makeKnownOrFail @_ @(Plc.Term TyName Name DefaultUni DefaultFun ()) val case extractEvaluationResult . eval $ eraseTerm term of Left err -> fail $ show err Right resAct -> resAct === resExp diff --git a/plutus-core/untyped-plutus-core/test/Transform/CaseOfCase/Test.hs b/plutus-core/untyped-plutus-core/test/Transform/CaseOfCase/Test.hs index 21ba8f2f45b..30862d0f4d6 100644 --- a/plutus-core/untyped-plutus-core/test/Transform/CaseOfCase/Test.hs +++ b/plutus-core/untyped-plutus-core/test/Transform/CaseOfCase/Test.hs @@ -23,7 +23,7 @@ import Test.Tasty.HUnit (testCase, (@?=)) import UntypedPlutusCore (DefaultFun, DefaultUni, Name, Term (..)) import UntypedPlutusCore.Core qualified as UPLC import UntypedPlutusCore.Evaluation.Machine.Cek (CekMachineCosts, CekValue, EvaluationResult (..), - noEmitter, unsafeEvaluateCek) + evaluateCek, noEmitter, unsafeToEvaluationResult) import UntypedPlutusCore.Transform.CaseOfCase (caseOfCase) test_caseOfCase :: TestTree @@ -119,7 +119,7 @@ testCaseOfCaseWithError = evaluateUplc :: UPLC.Term Name DefaultUni DefaultFun () -> EvaluationResult (UPLC.Term Name DefaultUni DefaultFun ()) -evaluateUplc = fst <$> unsafeEvaluateCek noEmitter machineParameters +evaluateUplc = unsafeToEvaluationResult . fst <$> evaluateCek noEmitter machineParameters where costModel :: CostModel CekMachineCosts BuiltinCostModel = CostModel defaultCekMachineCosts defaultBuiltinCostModel diff --git a/plutus-tx-plugin/test/Plugin/Basic/9.6/ifOptEval.eval.golden b/plutus-tx-plugin/test/Plugin/Basic/9.6/ifOptEval.eval.golden index 64d9a1489c9..5104d4035fc 100644 --- a/plutus-tx-plugin/test/Plugin/Basic/9.6/ifOptEval.eval.golden +++ b/plutus-tx-plugin/test/Plugin/Basic/9.6/ifOptEval.eval.golden @@ -1,4 +1,4 @@ -An error has occurred: User error: +An error has occurred: The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. Caused by: (divideInteger 1 0) Final budget: ({cpu: 453560 diff --git a/plutus-tx-plugin/test/Strictness/9.6/lambda-default.eval.golden b/plutus-tx-plugin/test/Strictness/9.6/lambda-default.eval.golden index 1d4b8b27224..f2c04fe10eb 100644 --- a/plutus-tx-plugin/test/Strictness/9.6/lambda-default.eval.golden +++ b/plutus-tx-plugin/test/Strictness/9.6/lambda-default.eval.golden @@ -1,2 +1,2 @@ -An error has occurred: User error: +An error has occurred: The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. \ No newline at end of file diff --git a/plutus-tx-plugin/test/Strictness/9.6/lambda-nonstrict.eval.golden b/plutus-tx-plugin/test/Strictness/9.6/lambda-nonstrict.eval.golden index 1d4b8b27224..f2c04fe10eb 100644 --- a/plutus-tx-plugin/test/Strictness/9.6/lambda-nonstrict.eval.golden +++ b/plutus-tx-plugin/test/Strictness/9.6/lambda-nonstrict.eval.golden @@ -1,2 +1,2 @@ -An error has occurred: User error: +An error has occurred: The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. \ No newline at end of file diff --git a/plutus-tx-plugin/test/Strictness/9.6/lambda-strict.eval.golden b/plutus-tx-plugin/test/Strictness/9.6/lambda-strict.eval.golden index 1d4b8b27224..f2c04fe10eb 100644 --- a/plutus-tx-plugin/test/Strictness/9.6/lambda-strict.eval.golden +++ b/plutus-tx-plugin/test/Strictness/9.6/lambda-strict.eval.golden @@ -1,2 +1,2 @@ -An error has occurred: User error: +An error has occurred: The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'. \ No newline at end of file diff --git a/plutus-tx-test-util/testlib/PlutusTx/Test/Util/Compiled.hs b/plutus-tx-test-util/testlib/PlutusTx/Test/Util/Compiled.hs index 1fc7673a871..f5804bca453 100644 --- a/plutus-tx-test-util/testlib/PlutusTx/Test/Util/Compiled.hs +++ b/plutus-tx-test-util/testlib/PlutusTx/Test/Util/Compiled.hs @@ -65,7 +65,7 @@ haskellValueToTerm = compiledCodeToTerm . Tx.liftCodeDef {- | Just run a term to obtain an `EvaluationResult` (used for tests etc.) -} unsafeRunTermCek :: Term -> EvaluationResult Term unsafeRunTermCek = - unsafeExtractEvaluationResult + unsafeToEvaluationResult . (\(res, _, _) -> res) . runCekDeBruijn PLC.defaultCekParameters Cek.restrictingEnormous Cek.noEmitter