-
Notifications
You must be signed in to change notification settings - Fork 157
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
Only evaluate Plutus scripts in static checks. #2767
Merged
Changes from all commits
Commits
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
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -45,6 +45,7 @@ module Control.State.Transition.Extended | |||||
SingEP (..), | ||||||
EventPolicy (..), | ||||||
EventReturnType, | ||||||
labeled, | ||||||
labeledPred, | ||||||
labeledPredE, | ||||||
ifFailureFree, | ||||||
|
@@ -314,12 +315,18 @@ data Clause sts (rtype :: RuleType) a where | |||||
a -> | ||||||
Clause sts rtype a | ||||||
Predicate :: | ||||||
[Label] -> | ||||||
Validation (NonEmpty e) a -> | ||||||
-- Type of failure to return if the predicate fails | ||||||
(e -> PredicateFailure sts) -> | ||||||
a -> | ||||||
Clause sts rtype a | ||||||
-- | Label part of a rule. The interpreter may be configured to only run parts | ||||||
-- of rules governed by (or by the lack of) certain labels. | ||||||
Label :: | ||||||
NonEmpty Label -> | ||||||
Rule sts rtype a -> | ||||||
a -> | ||||||
Clause sts rtype a | ||||||
IfFailureFree :: Rule sts rtype a -> Rule sts rtype a -> Clause sts rtype a | ||||||
|
||||||
deriving instance Functor (Clause sts rtype) | ||||||
|
@@ -341,26 +348,28 @@ validateTrans :: | |||||
(e -> PredicateFailure sts) -> | ||||||
Validation (NonEmpty e) () -> | ||||||
Rule sts ctx () | ||||||
validateTrans t v = liftF $ Predicate [] v t () | ||||||
validateTrans t v = liftF $ Predicate v t () | ||||||
|
||||||
-- | Same as `validation`, except with ability to translate opaque failures | ||||||
-- into `PredicateFailure`s with a help of supplied function. | ||||||
validateTransLabeled :: | ||||||
-- | Transformation function for all errors | ||||||
(e -> PredicateFailure sts) -> | ||||||
-- | Supply a list of labels to be used as filters when STS is executed | ||||||
[Label] -> | ||||||
NonEmpty Label -> | ||||||
-- | Actual validations to be executed | ||||||
Validation (NonEmpty e) () -> | ||||||
Rule sts ctx () | ||||||
validateTransLabeled t labels v = liftF $ Predicate labels v t () | ||||||
validateTransLabeled t labels v = liftF $ Label labels (liftF $ Predicate v t ()) () | ||||||
|
||||||
-- | Oh noes! | ||||||
-- | ||||||
-- This takes a condition (a boolean expression) and a failure and results in | ||||||
-- a clause which will throw that failure if the condition fails. | ||||||
(?!) :: Bool -> PredicateFailure sts -> Rule sts ctx () | ||||||
(?!) = labeledPred [] | ||||||
(?!) cond onFail = | ||||||
liftF $ | ||||||
Predicate (if cond then Success () else Failure (() :| [])) (const onFail) () | ||||||
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. Just one minor optional suggestion, which doesn't change the semantics, but might make it easier to read the code:
Suggested change
|
||||||
|
||||||
infix 1 ?! | ||||||
|
||||||
|
@@ -371,27 +380,27 @@ failBecause = (False ?!) | |||||
-- | ||||||
-- We interpret this as "What?" "No!" "Because:" | ||||||
(?!:) :: Either e () -> (e -> PredicateFailure sts) -> Rule sts ctx () | ||||||
(?!:) = labeledPredE [] | ||||||
(?!:) cond onFail = | ||||||
liftF $ | ||||||
Predicate (eitherToValidation $ first pure cond) onFail () | ||||||
|
||||||
-- | Labeled predicate. This may be used to control which predicates are run | ||||||
-- using 'ValidateSuchThat'. | ||||||
labeledPred :: [Label] -> Bool -> PredicateFailure sts -> Rule sts ctx () | ||||||
labeledPred lbls cond orElse = | ||||||
liftF $ | ||||||
Predicate | ||||||
lbls | ||||||
(if cond then Success () else Failure (() :| [])) | ||||||
(const orElse) | ||||||
() | ||||||
labeledPred :: NonEmpty Label -> Bool -> PredicateFailure sts -> Rule sts ctx () | ||||||
labeledPred lbls cond orElse = labeled lbls (cond ?! orElse) | ||||||
|
||||||
-- | Labeled predicate with an explanation | ||||||
labeledPredE :: | ||||||
[Label] -> | ||||||
NonEmpty Label -> | ||||||
Either e () -> | ||||||
(e -> PredicateFailure sts) -> | ||||||
Rule sts ctx () | ||||||
labeledPredE lbls cond orElse = | ||||||
liftF $ Predicate lbls (eitherToValidation $ first pure cond) orElse () | ||||||
labeledPredE lbls cond orElse = labeled lbls (cond ?!: orElse) | ||||||
|
||||||
-- | Labeled clause. This will only be executed if the interpreter is set to | ||||||
-- execute clauses with this label. | ||||||
labeled :: NonEmpty Label -> Rule sts ctx () -> Rule sts ctx () | ||||||
labeled lbls subrule = liftF $ Label lbls subrule () | ||||||
|
||||||
trans :: | ||||||
Embed sub super => RuleContext rtype sub -> Rule super rtype (State sub) | ||||||
|
@@ -582,11 +591,13 @@ applyRuleInternal ep vp goSTS jc r = do | |||||
if failureFree | ||||||
then foldF runClause yesrule | ||||||
else foldF runClause norule | ||||||
runClause (Predicate lbls cond orElse val) = | ||||||
if validateIf lbls | ||||||
then case cond of | ||||||
Success x -> pure x | ||||||
Failure errs -> modify (first (map orElse (reverse (NE.toList errs)) <>)) >> pure val | ||||||
runClause (Predicate cond orElse val) = | ||||||
case cond of | ||||||
Success x -> pure x | ||||||
Failure errs -> modify (first (map orElse (reverse (NE.toList errs)) <>)) >> pure val | ||||||
runClause (Label lbls subrule val) = | ||||||
if validateIf (NE.toList lbls) | ||||||
then foldF runClause subrule | ||||||
else pure val | ||||||
runClause (SubTrans (subCtx :: RuleContext _rtype sub) next) = do | ||||||
s <- lift $ goSTS subCtx | ||||||
|
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.
How about some comment here, explaining exactly what is going on here, and some discussion about the correct use of this function. One might also explain what NE.:| does. It looks like a constructor function?
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.
@TimSheard It is a type constructor for
NonEmpty
, it comes frombase
: https://downloads.haskell.org/~ghc/8.10.7/docs/html/libraries/base-4.14.3.0/Data-List-NonEmpty.html#t:NonEmpty