-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Builtins] Polish handling of integral types #6036
Merged
effectfully
merged 13 commits into
master
from
effectfully/builtins/polish-handling-of-integral-types
May 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d39992e
[Builtins] Polish handling of integral types
effectfully a76d1ac
Merge branch 'master' of https://github.com/input-output-hk/plutus in…
effectfully f202ac1
Put 'EvaluationError' inside of 'UnliftingError'
effectfully 8d136bb
Progress
effectfully 5a639ab
Make it work
effectfully 4f963a6
Fix naming
effectfully aca4446
Polishing
effectfully 8637022
Fix '_EvaluationError' loop
effectfully b17f92e
'throw*' to 'throwing _*'
effectfully ba20422
More polishing
effectfully 12aed03
Realizing that I'm wrong
effectfully 9c442b3
Tweaking
effectfully b61cce8
Add a changelog entry
effectfully File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Put 'EvaluationError' inside of 'UnliftingError'
- Loading branch information
commit f202ac1c7c1a7ae91eb7e3b509a10b1874eb8c3b
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
plutus-core/plutus-core/src/PlutusCore/Evaluation/Error.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
-- editorconfig-checker-disable-file | ||
-- | The exceptions that an abstract machine can throw. | ||
|
||
-- appears in the generated instances | ||
{-# OPTIONS_GHC -Wno-overlapping-patterns #-} | ||
|
||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE FunctionalDependencies #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
module PlutusCore.Evaluation.Error | ||
( EvaluationError (..) | ||
, AsEvaluationError (..) | ||
) where | ||
|
||
import PlutusPrelude | ||
|
||
import PlutusCore.Evaluation.Result | ||
|
||
import Control.Lens | ||
|
||
{- | 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) | ||
|
||
mtraverse makeClassyPrisms | ||
[ ''EvaluationError | ||
] | ||
|
||
instance AsEvaluationFailure operational => | ||
AsEvaluationFailure (EvaluationError operational structural) where | ||
_EvaluationFailure = _OperationalEvaluationError . _EvaluationFailure | ||
|
||
instance | ||
( HasPrettyDefaults config ~ 'True | ||
, Pretty operational, PrettyBy config structural | ||
) => PrettyBy config (EvaluationError operational structural) where | ||
prettyBy _ (OperationalEvaluationError operational) = pretty operational | ||
prettyBy config (StructuralEvaluationError structural) = prettyBy config structural | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's kinda weird that operational errors aren't pretty-printed configurably, but this all is old code and I'm not gonna bother fixing it here. |
||
|
||
instance (Pretty operational, Pretty structural) => | ||
Pretty (EvaluationError operational structural) where | ||
pretty (OperationalEvaluationError operational) = pretty operational | ||
pretty (StructuralEvaluationError structural) = pretty structural |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all the same stuff as in the recent PR about operational vs structural errors, I just it moved it to its own module.