diff --git a/plutus-tx-plugin/test/Optimization/Spec.hs b/plutus-tx-plugin/test/Optimization/Spec.hs index 2101d2a3461..6ee44d2f72e 100644 --- a/plutus-tx-plugin/test/Optimization/Spec.hs +++ b/plutus-tx-plugin/test/Optimization/Spec.hs @@ -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 () @@ -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. @@ -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) ||]) diff --git a/plutus-tx-plugin/test/Optimization/trueOrError.plc.golden b/plutus-tx-plugin/test/Optimization/trueOrError.plc.golden new file mode 100644 index 00000000000..2cd8988e372 --- /dev/null +++ b/plutus-tx-plugin/test/Optimization/trueOrError.plc.golden @@ -0,0 +1 @@ +(program 1.0.0 (delay (lam case_True_i0 (lam case_False_i0 case_True_i2)))) \ No newline at end of file diff --git a/plutus-tx-plugin/test/Optimization/trueOrErrorEval.plc.golden b/plutus-tx-plugin/test/Optimization/trueOrErrorEval.plc.golden new file mode 100644 index 00000000000..177eccb7bb0 --- /dev/null +++ b/plutus-tx-plugin/test/Optimization/trueOrErrorEval.plc.golden @@ -0,0 +1 @@ +(delay (lam case_True_0 (lam case_False_1 case_True_0))) \ No newline at end of file diff --git a/plutus-tx-plugin/test/Optimization/trueOrErrorOpaque.plc.golden b/plutus-tx-plugin/test/Optimization/trueOrErrorOpaque.plc.golden new file mode 100644 index 00000000000..058880021e8 --- /dev/null +++ b/plutus-tx-plugin/test/Optimization/trueOrErrorOpaque.plc.golden @@ -0,0 +1,7 @@ +(program + 1.0.0 + [ + (lam ds_i0 (delay (lam case_True_i0 (lam case_False_i0 case_True_i2)))) + (error ) + ] +) \ No newline at end of file diff --git a/plutus-tx-plugin/test/Optimization/trueOrErrorOpaqueEval.plc.golden b/plutus-tx-plugin/test/Optimization/trueOrErrorOpaqueEval.plc.golden new file mode 100644 index 00000000000..909c9d8ccc8 --- /dev/null +++ b/plutus-tx-plugin/test/Optimization/trueOrErrorOpaqueEval.plc.golden @@ -0,0 +1 @@ +Failure \ No newline at end of file