Skip to content
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

Add example of PlutusTx miscompilation due to optimisation pass #6

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion plutus-tx-plugin/test/Optimization/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Test.Tasty.Extras
import PlutusCore.Test
import PlutusTx.Builtins qualified as PlutusTx
import PlutusTx.Code
import PlutusTx.Prelude qualified as P
import PlutusTx.TH (compile)
import PlutusTx.Test ()

Expand All @@ -24,7 +25,12 @@ import PlutusTx.Test ()
-- ones that run on UPLC.
tests :: TestNested
tests = testNested "Optimization" [
goldenUPlc "maybeFun" maybeFun ]
goldenUPlc "maybeFun" maybeFun
, goldenUPlc "trueOrError" trueOrError
, goldenUEval "trueOrErrorEval" [ toUPlc trueOrError ]
, goldenUPlc "trueOrErrorOpaque" trueOrErrorOpaque
, goldenUEval "trueOrErrorOpaqueEval" [ toUPlc trueOrErrorOpaque ]
]

-- The point of this test is to check that matchers get eliminated unconditionally
-- even if they're used more than once.
Expand All @@ -37,3 +43,11 @@ maybeFun = $$(compile
Nothing -> Nothing
Nothing -> Nothing
||])

trueOrError :: CompiledCode Bool
trueOrError = $$(compile [|| c True (P.error () :: Bool) ||])
where
c x _ = x

trueOrErrorOpaque :: CompiledCode Bool
trueOrErrorOpaque = $$(compile [|| P.const True (P.error () :: Bool) ||])
1 change: 1 addition & 0 deletions plutus-tx-plugin/test/Optimization/trueOrError.plc.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(program 1.0.0 (delay (lam case_True_i0 (lam case_False_i0 case_True_i2))))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(delay (lam case_True_0 (lam case_False_1 case_True_0)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(program
1.0.0
[
(lam ds_i0 (delay (lam case_True_i0 (lam case_False_i0 case_True_i2))))
(error )
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Failure