-
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
Tests for the preserve-logging
flag.
#6162
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,10 @@ evaluateBuiltinsPass :: (PLC.Typecheckable uni fun, PLC.GEq uni, Applicative m) | |
-> BuiltinsInfo uni fun | ||
-> CostingPart uni fun | ||
-> Pass m TyName Name uni fun a | ||
evaluateBuiltinsPass tcconfig conservative binfo costModel = | ||
evaluateBuiltinsPass tcconfig preserveLogging binfo costModel = | ||
NamedPass "evaluate builtins" $ | ||
Pass | ||
(pure . evaluateBuiltins conservative binfo costModel) | ||
(pure . evaluateBuiltins preserveLogging binfo costModel) | ||
[Typechecks tcconfig] | ||
[ConstCondition (Typechecks tcconfig)] | ||
|
||
|
@@ -46,7 +46,7 @@ evaluateBuiltins | |
-> CostingPart uni fun | ||
-> Term tyname name uni fun a | ||
-> Term tyname name uni fun a | ||
evaluateBuiltins conservative binfo costModel = transformOf termSubterms processTerm | ||
evaluateBuiltins preserveLogging binfo costModel = transformOf termSubterms processTerm | ||
where | ||
-- Nothing means "leave the original term as it was" | ||
eval | ||
|
@@ -55,18 +55,18 @@ evaluateBuiltins conservative binfo costModel = transformOf termSubterms process | |
-> Maybe (Term tyname name uni fun ()) | ||
eval (BuiltinCostedResult _ getX) AppContextEnd = | ||
case getX of | ||
BuiltinSuccess v -> Just v | ||
BuiltinSuccess term -> Just term | ||
-- Evaluates successfully, but does logging. If we're being conservative | ||
-- then we should leave these in, so we don't remove people's logging! | ||
-- Otherwise `trace "hello" x` is a prime candidate for evaluation! | ||
BuiltinSuccessWithLogs _ v -> if conservative then Nothing else Just v | ||
BuiltinSuccessWithLogs _ term -> if preserveLogging then Nothing else Just term | ||
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 perhaps should be 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. The thing is that at the preserveLogging <- view (ccOpts . coPreserveLogging)
... $ EvaluateBuiltins.evaluateBuiltinsPass tcconfig preserveLogging binfo costModel 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. Fair enough, but I think it's the |
||
-- Evaluation failure. This can mean that the evaluation legitimately | ||
-- failed (e.g. `divideInteger 1 0`), or that it failed because the | ||
-- argument terms are not currently in the right form (because they're | ||
-- not evaluated, we're in the middle of a term here!). Since we can't | ||
-- distinguish these, we have to assume it's the latter case and just leave | ||
-- things alone. | ||
BuiltinFailure{} -> Nothing | ||
BuiltinFailure{} -> Nothing | ||
eval (BuiltinExpectArgument toRuntime) (TermAppContext arg _ ctx) = | ||
-- Builtin evaluation does not work with annotations, so we have to throw | ||
-- the argument annotation away here | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# OPTIONS_GHC -fplugin PlutusTx.Plugin #-} | ||
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:no-conservative-optimisation #-} | ||
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:preserve-logging #-} | ||
|
||
module Plugin.NoTrace.WithPreservedLogging where | ||
|
||
import Data.Proxy (Proxy (..)) | ||
import Plugin.NoTrace.Lib qualified as Lib | ||
import PlutusTx.Bool (Bool) | ||
import PlutusTx.Builtins (BuiltinString, Integer) | ||
import PlutusTx.Code (CompiledCode) | ||
import PlutusTx.Plugin (plc) | ||
|
||
traceArgument :: CompiledCode (BuiltinString -> ()) | ||
traceArgument = plc (Proxy @"traceArgument") Lib.traceArgument | ||
|
||
traceShow :: CompiledCode () | ||
traceShow = plc (Proxy @"traceShow") Lib.traceShow | ||
|
||
traceDirect :: CompiledCode () | ||
traceDirect = plc (Proxy @"traceDirect") Lib.traceDirect | ||
|
||
traceNonConstant :: CompiledCode (BuiltinString -> BuiltinString) | ||
traceNonConstant = plc (Proxy @"traceNonConstant") Lib.traceNonConstant | ||
|
||
traceComplex :: CompiledCode (Bool -> ()) | ||
traceComplex = plc (Proxy @"traceComplex") Lib.traceComplex | ||
|
||
traceRepeatedly :: CompiledCode Integer | ||
traceRepeatedly = plc (Proxy @"traceRepeatedly") Lib.traceRepeatedly | ||
|
||
traceImpure :: CompiledCode () | ||
traceImpure = plc (Proxy @"traceImpure") Lib.traceImpure |
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.
👍