From c5634ea82c36b06eb26b5ad02ce56cd0bc133457 Mon Sep 17 00:00:00 2001 From: Ziyang Liu Date: Thu, 23 Nov 2023 02:30:30 -0800 Subject: [PATCH] Attempt to rewrite unnecessary constructor applications in the plugin (#5649) * Attempt to rewrite opaque constructor applications in the plugin * Update plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs Co-authored-by: Michael Peyton Jones * Update plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs Co-authored-by: Michael Peyton Jones * Rewrite all unnecessary constructor applications * cabal files --------- Co-authored-by: Michael Peyton Jones --- ...000104030002040304020400000102.eval.golden | 4 +- ...d266dd7544678743890b0e8e1add63.eval.golden | 4 +- ...050e0a0d06030f1006030701020607.eval.golden | 4 +- ...6a95115748c026f9ec129384c262c4.eval.golden | 4 +- ...03031d8de696d90ec789e70d6bc1d8.eval.golden | 4 +- ...93093efe7bc76d6322aed6ddb582ad.eval.golden | 4 +- ...c321d13fec0375606325eee9a34a6a.eval.golden | 4 +- ...11a81ca3841f47f37633e8aacbb5de.eval.golden | 4 +- ...c232125976f29b1c3e21d9f537845c.eval.golden | 4 +- ...1c878a0e0a7d6f7fe1d4a619e06112.eval.golden | 4 +- ...7539062b5728182e073e5760561a66.eval.golden | 4 +- ...109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden | 4 +- ...2c1dc6f4e7e412eeb5a3ced42fb642.eval.golden | 4 +- ...19d4342612accf40913f9ae9419fac.eval.golden | 4 +- ...b1605fe1490aa3f4f64a3fa8881b25.eval.golden | 4 +- ...fcde89510b29cccce81971e38e0835.eval.golden | 4 +- ...7e11195d161b5bb0a2b58f89b2c65a.eval.golden | 4 +- ...35aa02274161b23d57709c0f8b8de6.eval.golden | 4 +- .../test/semantics/9.2/semantics.size.golden | 2 +- ...000104030002040304020400000102.eval.golden | 4 +- ...d266dd7544678743890b0e8e1add63.eval.golden | 4 +- ...050e0a0d06030f1006030701020607.eval.golden | 4 +- ...6a95115748c026f9ec129384c262c4.eval.golden | 4 +- ...03031d8de696d90ec789e70d6bc1d8.eval.golden | 4 +- ...93093efe7bc76d6322aed6ddb582ad.eval.golden | 4 +- ...c321d13fec0375606325eee9a34a6a.eval.golden | 4 +- ...11a81ca3841f47f37633e8aacbb5de.eval.golden | 4 +- ...c232125976f29b1c3e21d9f537845c.eval.golden | 4 +- ...1c878a0e0a7d6f7fe1d4a619e06112.eval.golden | 4 +- ...7539062b5728182e073e5760561a66.eval.golden | 4 +- ...109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden | 4 +- ...2c1dc6f4e7e412eeb5a3ced42fb642.eval.golden | 4 +- ...19d4342612accf40913f9ae9419fac.eval.golden | 4 +- ...b1605fe1490aa3f4f64a3fa8881b25.eval.golden | 4 +- ...fcde89510b29cccce81971e38e0835.eval.golden | 4 +- ...7e11195d161b5bb0a2b58f89b2c65a.eval.golden | 4 +- ...35aa02274161b23d57709c0f8b8de6.eval.golden | 4 +- .../test/semantics/9.6/semantics.size.golden | 2 +- .../nofib/test/9.2/queens4-bt.pir.golden | 4 +- .../nofib/test/9.2/queens4-bt.size.golden | 2 +- .../nofib/test/9.2/queens5-fc.eval.golden | 4 +- .../nofib/test/9.2/queens5-fc.pir.golden | 4 +- .../nofib/test/9.2/queens5-fc.size.golden | 2 +- .../nofib/test/9.6/queens4-bt.pir.golden | 4 +- .../nofib/test/9.6/queens4-bt.size.golden | 2 +- .../nofib/test/9.6/queens5-fc.eval.golden | 4 +- .../nofib/test/9.6/queens5-fc.pir.golden | 4 +- .../nofib/test/9.6/queens5-fc.size.golden | 2 +- plutus-core/plutus-core.cabal | 4 +- .../20231121_151437_unsafeFixIO_opaque.md | 4 + plutus-tx-plugin/plutus-tx-plugin.cabal | 1 + .../src/PlutusTx/Compiler/Expr.hs | 99 ++++++++++++++----- .../Optimization/9.2/matchAsData.pir.golden | 57 +++++++++++ 53 files changed, 225 insertions(+), 120 deletions(-) create mode 100644 plutus-tx-plugin/changelog.d/20231121_151437_unsafeFixIO_opaque.md create mode 100644 plutus-tx-plugin/test/Optimization/9.2/matchAsData.pir.golden diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/0003040402030103010203030303000200000104030002040304020400000102.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/0003040402030103010203030303000200000104030002040304020400000102.eval.golden index 11c4a35532d..35c32bf1b7a 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/0003040402030103010203030303000200000104030002040304020400000102.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/0003040402030103010203030303000200000104030002040304020400000102.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1428979902 -| mem: 5367574}) \ No newline at end of file +({cpu: 1428703902 +| mem: 5366374}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/0543a00ba1f63076c1db6bf94c6ff13ae7d266dd7544678743890b0e8e1add63.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/0543a00ba1f63076c1db6bf94c6ff13ae7d266dd7544678743890b0e8e1add63.eval.golden index 981ef57b009..a3b05a1c81e 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/0543a00ba1f63076c1db6bf94c6ff13ae7d266dd7544678743890b0e8e1add63.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/0543a00ba1f63076c1db6bf94c6ff13ae7d266dd7544678743890b0e8e1add63.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1438491380 -| mem: 5012365}) \ No newline at end of file +({cpu: 1438353380 +| mem: 5011765}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/07070c070510030509010e050d00040907050e0a0d06030f1006030701020607.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/07070c070510030509010e050d00040907050e0a0d06030f1006030701020607.eval.golden index 0de70ad2148..a982d794cc3 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/07070c070510030509010e050d00040907050e0a0d06030f1006030701020607.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/07070c070510030509010e050d00040907050e0a0d06030f1006030701020607.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1417412598 -| mem: 5183617}) \ No newline at end of file +({cpu: 1417136598 +| mem: 5182417}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/0bcfd9487614104ec48de2ea0b2c0979866a95115748c026f9ec129384c262c4.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/0bcfd9487614104ec48de2ea0b2c0979866a95115748c026f9ec129384c262c4.eval.golden index 2c1fca2fb66..6d1c5f72210 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/0bcfd9487614104ec48de2ea0b2c0979866a95115748c026f9ec129384c262c4.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/0bcfd9487614104ec48de2ea0b2c0979866a95115748c026f9ec129384c262c4.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1544798878 -| mem: 5626951}) \ No newline at end of file +({cpu: 1544660878 +| mem: 5626351}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/0be82588e4e4bf2ef428d2f44b7687bbb703031d8de696d90ec789e70d6bc1d8.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/0be82588e4e4bf2ef428d2f44b7687bbb703031d8de696d90ec789e70d6bc1d8.eval.golden index cd7cf5e15b6..ea3f12adef3 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/0be82588e4e4bf2ef428d2f44b7687bbb703031d8de696d90ec789e70d6bc1d8.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/0be82588e4e4bf2ef428d2f44b7687bbb703031d8de696d90ec789e70d6bc1d8.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1909249237 -| mem: 6938218}) \ No newline at end of file +({cpu: 1908697237 +| mem: 6935818}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/18cefc240debc0fcab14efdd451adfd02793093efe7bc76d6322aed6ddb582ad.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/18cefc240debc0fcab14efdd451adfd02793093efe7bc76d6322aed6ddb582ad.eval.golden index 403dcdfc0c4..fc616f55b25 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/18cefc240debc0fcab14efdd451adfd02793093efe7bc76d6322aed6ddb582ad.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/18cefc240debc0fcab14efdd451adfd02793093efe7bc76d6322aed6ddb582ad.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1005387218 -| mem: 3676461}) \ No newline at end of file +({cpu: 1005249218 +| mem: 3675861}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/30aa34dfbe89e0c43f569929a96c0d2b74c321d13fec0375606325eee9a34a6a.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/30aa34dfbe89e0c43f569929a96c0d2b74c321d13fec0375606325eee9a34a6a.eval.golden index 131ce049ae9..1de5e923c76 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/30aa34dfbe89e0c43f569929a96c0d2b74c321d13fec0375606325eee9a34a6a.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/30aa34dfbe89e0c43f569929a96c0d2b74c321d13fec0375606325eee9a34a6a.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1600079695 -| mem: 5950644}) \ No newline at end of file +({cpu: 1599665695 +| mem: 5948844}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/383683bfcecdab0f4df507f59631c702bd11a81ca3841f47f37633e8aacbb5de.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/383683bfcecdab0f4df507f59631c702bd11a81ca3841f47f37633e8aacbb5de.eval.golden index 23ba031108b..ef8905e6e9b 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/383683bfcecdab0f4df507f59631c702bd11a81ca3841f47f37633e8aacbb5de.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/383683bfcecdab0f4df507f59631c702bd11a81ca3841f47f37633e8aacbb5de.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1008646729 -| mem: 3687894}) \ No newline at end of file +({cpu: 1008508729 +| mem: 3687294}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/4c3efd13b6c69112a8a888372d56c86e60c232125976f29b1c3e21d9f537845c.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/4c3efd13b6c69112a8a888372d56c86e60c232125976f29b1c3e21d9f537845c.eval.golden index f89e39b7910..6384ff21212 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/4c3efd13b6c69112a8a888372d56c86e60c232125976f29b1c3e21d9f537845c.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/4c3efd13b6c69112a8a888372d56c86e60c232125976f29b1c3e21d9f537845c.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1421735134 -| mem: 5238131}) \ No newline at end of file +({cpu: 1421597134 +| mem: 5237531}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/5d0a88250f13c49c20e146819357a808911c878a0e0a7d6f7fe1d4a619e06112.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/5d0a88250f13c49c20e146819357a808911c878a0e0a7d6f7fe1d4a619e06112.eval.golden index c8633eebcc8..496605c9ddd 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/5d0a88250f13c49c20e146819357a808911c878a0e0a7d6f7fe1d4a619e06112.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/5d0a88250f13c49c20e146819357a808911c878a0e0a7d6f7fe1d4a619e06112.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1431481884 -| mem: 5121021}) \ No newline at end of file +({cpu: 1431343884 +| mem: 5120421}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/5e274e0f593511543d41570a4b03646c1d7539062b5728182e073e5760561a66.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/5e274e0f593511543d41570a4b03646c1d7539062b5728182e073e5760561a66.eval.golden index 29661be8144..4ce7dbdb5f8 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/5e274e0f593511543d41570a4b03646c1d7539062b5728182e073e5760561a66.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/5e274e0f593511543d41570a4b03646c1d7539062b5728182e073e5760561a66.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1459372109 -| mem: 5284223}) \ No newline at end of file +({cpu: 1459234109 +| mem: 5283623}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/5e2c68ac9f62580d626636679679b97109109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/5e2c68ac9f62580d626636679679b97109109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden index 113d2ffed4d..7cbda3af8c4 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/5e2c68ac9f62580d626636679679b97109109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/5e2c68ac9f62580d626636679679b97109109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden @@ -1,2 +1,2 @@ -({cpu: 698186900 -| mem: 2541975}) \ No newline at end of file +({cpu: 698048900 +| mem: 2541375}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/5f306b4b24ff2b39dab6cdc9ac6ca9bb442c1dc6f4e7e412eeb5a3ced42fb642.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/5f306b4b24ff2b39dab6cdc9ac6ca9bb442c1dc6f4e7e412eeb5a3ced42fb642.eval.golden index 185bb2d5445..ddd8f9908a0 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/5f306b4b24ff2b39dab6cdc9ac6ca9bb442c1dc6f4e7e412eeb5a3ced42fb642.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/5f306b4b24ff2b39dab6cdc9ac6ca9bb442c1dc6f4e7e412eeb5a3ced42fb642.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1019039066 -| mem: 3760674}) \ No newline at end of file +({cpu: 1018901066 +| mem: 3760074}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/675d63836cad11b547d1b4cddd498f04c919d4342612accf40913f9ae9419fac.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/675d63836cad11b547d1b4cddd498f04c919d4342612accf40913f9ae9419fac.eval.golden index 76d6b984c1d..b42941f8452 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/675d63836cad11b547d1b4cddd498f04c919d4342612accf40913f9ae9419fac.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/675d63836cad11b547d1b4cddd498f04c919d4342612accf40913f9ae9419fac.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1439049563 -| mem: 5281393}) \ No newline at end of file +({cpu: 1438911563 +| mem: 5280793}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/9fabc4fc3440cdb776b28c9bb1dd49c9a5b1605fe1490aa3f4f64a3fa8881b25.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/9fabc4fc3440cdb776b28c9bb1dd49c9a5b1605fe1490aa3f4f64a3fa8881b25.eval.golden index 3dc2da53698..60a1617b739 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/9fabc4fc3440cdb776b28c9bb1dd49c9a5b1605fe1490aa3f4f64a3fa8881b25.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/9fabc4fc3440cdb776b28c9bb1dd49c9a5b1605fe1490aa3f4f64a3fa8881b25.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1448656659 -| mem: 5039771}) \ No newline at end of file +({cpu: 1448380659 +| mem: 5038571}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/b21a4df3b0266ad3481a26d3e3d848aad2fcde89510b29cccce81971e38e0835.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/b21a4df3b0266ad3481a26d3e3d848aad2fcde89510b29cccce81971e38e0835.eval.golden index 9d853f14ed9..2d686c32566 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/b21a4df3b0266ad3481a26d3e3d848aad2fcde89510b29cccce81971e38e0835.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/b21a4df3b0266ad3481a26d3e3d848aad2fcde89510b29cccce81971e38e0835.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1885978449 -| mem: 6837860}) \ No newline at end of file +({cpu: 1885426449 +| mem: 6835460}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/d1c03759810747b7cab38c4296593b38567e11195d161b5bb0a2b58f89b2c65a.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/d1c03759810747b7cab38c4296593b38567e11195d161b5bb0a2b58f89b2c65a.eval.golden index 89b1fad1755..a3a3b677384 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/d1c03759810747b7cab38c4296593b38567e11195d161b5bb0a2b58f89b2c65a.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/d1c03759810747b7cab38c4296593b38567e11195d161b5bb0a2b58f89b2c65a.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1423763870 -| mem: 5261307}) \ No newline at end of file +({cpu: 1423625870 +| mem: 5260707}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/ffdd68a33afd86f8844c9f5e45b2bda5b035aa02274161b23d57709c0f8b8de6.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.2/ffdd68a33afd86f8844c9f5e45b2bda5b035aa02274161b23d57709c0f8b8de6.eval.golden index 3ab0b2c8b2e..537aa2cb653 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/ffdd68a33afd86f8844c9f5e45b2bda5b035aa02274161b23d57709c0f8b8de6.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/ffdd68a33afd86f8844c9f5e45b2bda5b035aa02274161b23d57709c0f8b8de6.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1269996610 -| mem: 4667910}) \ No newline at end of file +({cpu: 1269720610 +| mem: 4666710}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.2/semantics.size.golden b/plutus-benchmark/marlowe/test/semantics/9.2/semantics.size.golden index b2395399b24..48ee3135fe7 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.2/semantics.size.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.2/semantics.size.golden @@ -1 +1 @@ -11593 \ No newline at end of file +11589 \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/0003040402030103010203030303000200000104030002040304020400000102.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/0003040402030103010203030303000200000104030002040304020400000102.eval.golden index 36898d6e834..e4d954b77e0 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/0003040402030103010203030303000200000104030002040304020400000102.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/0003040402030103010203030303000200000104030002040304020400000102.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1431072902 -| mem: 5376674}) \ No newline at end of file +({cpu: 1430796902 +| mem: 5375474}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/0543a00ba1f63076c1db6bf94c6ff13ae7d266dd7544678743890b0e8e1add63.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/0543a00ba1f63076c1db6bf94c6ff13ae7d266dd7544678743890b0e8e1add63.eval.golden index a504ff1998d..25e8d72c035 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/0543a00ba1f63076c1db6bf94c6ff13ae7d266dd7544678743890b0e8e1add63.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/0543a00ba1f63076c1db6bf94c6ff13ae7d266dd7544678743890b0e8e1add63.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1438514380 -| mem: 5012465}) \ No newline at end of file +({cpu: 1438376380 +| mem: 5011865}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/07070c070510030509010e050d00040907050e0a0d06030f1006030701020607.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/07070c070510030509010e050d00040907050e0a0d06030f1006030701020607.eval.golden index 0fb849d2909..90c92037b3c 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/07070c070510030509010e050d00040907050e0a0d06030f1006030701020607.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/07070c070510030509010e050d00040907050e0a0d06030f1006030701020607.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1420011598 -| mem: 5194917}) \ No newline at end of file +({cpu: 1419735598 +| mem: 5193717}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/0bcfd9487614104ec48de2ea0b2c0979866a95115748c026f9ec129384c262c4.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/0bcfd9487614104ec48de2ea0b2c0979866a95115748c026f9ec129384c262c4.eval.golden index 3118d72fc6f..c15e46c7529 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/0bcfd9487614104ec48de2ea0b2c0979866a95115748c026f9ec129384c262c4.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/0bcfd9487614104ec48de2ea0b2c0979866a95115748c026f9ec129384c262c4.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1547742878 -| mem: 5639751}) \ No newline at end of file +({cpu: 1547604878 +| mem: 5639151}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/0be82588e4e4bf2ef428d2f44b7687bbb703031d8de696d90ec789e70d6bc1d8.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/0be82588e4e4bf2ef428d2f44b7687bbb703031d8de696d90ec789e70d6bc1d8.eval.golden index a88bdc33431..bd9d370884c 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/0be82588e4e4bf2ef428d2f44b7687bbb703031d8de696d90ec789e70d6bc1d8.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/0be82588e4e4bf2ef428d2f44b7687bbb703031d8de696d90ec789e70d6bc1d8.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1912515237 -| mem: 6952418}) \ No newline at end of file +({cpu: 1911963237 +| mem: 6950018}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/18cefc240debc0fcab14efdd451adfd02793093efe7bc76d6322aed6ddb582ad.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/18cefc240debc0fcab14efdd451adfd02793093efe7bc76d6322aed6ddb582ad.eval.golden index 55342f3f82d..4d1167f14f8 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/18cefc240debc0fcab14efdd451adfd02793093efe7bc76d6322aed6ddb582ad.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/18cefc240debc0fcab14efdd451adfd02793093efe7bc76d6322aed6ddb582ad.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1007365218 -| mem: 3685061}) \ No newline at end of file +({cpu: 1007227218 +| mem: 3684461}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/30aa34dfbe89e0c43f569929a96c0d2b74c321d13fec0375606325eee9a34a6a.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/30aa34dfbe89e0c43f569929a96c0d2b74c321d13fec0375606325eee9a34a6a.eval.golden index 31daf8557e8..fade586da48 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/30aa34dfbe89e0c43f569929a96c0d2b74c321d13fec0375606325eee9a34a6a.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/30aa34dfbe89e0c43f569929a96c0d2b74c321d13fec0375606325eee9a34a6a.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1601482695 -| mem: 5956744}) \ No newline at end of file +({cpu: 1601068695 +| mem: 5954944}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/383683bfcecdab0f4df507f59631c702bd11a81ca3841f47f37633e8aacbb5de.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/383683bfcecdab0f4df507f59631c702bd11a81ca3841f47f37633e8aacbb5de.eval.golden index 2811f73b8b7..39457c9a0ba 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/383683bfcecdab0f4df507f59631c702bd11a81ca3841f47f37633e8aacbb5de.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/383683bfcecdab0f4df507f59631c702bd11a81ca3841f47f37633e8aacbb5de.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1008094729 -| mem: 3685494}) \ No newline at end of file +({cpu: 1007956729 +| mem: 3684894}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/4c3efd13b6c69112a8a888372d56c86e60c232125976f29b1c3e21d9f537845c.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/4c3efd13b6c69112a8a888372d56c86e60c232125976f29b1c3e21d9f537845c.eval.golden index 8e0a6ea58f3..516bcbf4471 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/4c3efd13b6c69112a8a888372d56c86e60c232125976f29b1c3e21d9f537845c.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/4c3efd13b6c69112a8a888372d56c86e60c232125976f29b1c3e21d9f537845c.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1423483134 -| mem: 5245731}) \ No newline at end of file +({cpu: 1423345134 +| mem: 5245131}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/5d0a88250f13c49c20e146819357a808911c878a0e0a7d6f7fe1d4a619e06112.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/5d0a88250f13c49c20e146819357a808911c878a0e0a7d6f7fe1d4a619e06112.eval.golden index 82fd27c75bc..686db61e871 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/5d0a88250f13c49c20e146819357a808911c878a0e0a7d6f7fe1d4a619e06112.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/5d0a88250f13c49c20e146819357a808911c878a0e0a7d6f7fe1d4a619e06112.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1431826884 -| mem: 5122521}) \ No newline at end of file +({cpu: 1431688884 +| mem: 5121921}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/5e274e0f593511543d41570a4b03646c1d7539062b5728182e073e5760561a66.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/5e274e0f593511543d41570a4b03646c1d7539062b5728182e073e5760561a66.eval.golden index d58bb1e2487..0bc5b76d6d0 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/5e274e0f593511543d41570a4b03646c1d7539062b5728182e073e5760561a66.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/5e274e0f593511543d41570a4b03646c1d7539062b5728182e073e5760561a66.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1464202109 -| mem: 5305223}) \ No newline at end of file +({cpu: 1464064109 +| mem: 5304623}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/5e2c68ac9f62580d626636679679b97109109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/5e2c68ac9f62580d626636679679b97109109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden index 2564957ca49..fdd65e60adf 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/5e2c68ac9f62580d626636679679b97109109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/5e2c68ac9f62580d626636679679b97109109df7ac1a8ce86d3e43dfb5e4f6bc.eval.golden @@ -1,2 +1,2 @@ -({cpu: 697243900 -| mem: 2537875}) \ No newline at end of file +({cpu: 697105900 +| mem: 2537275}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/5f306b4b24ff2b39dab6cdc9ac6ca9bb442c1dc6f4e7e412eeb5a3ced42fb642.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/5f306b4b24ff2b39dab6cdc9ac6ca9bb442c1dc6f4e7e412eeb5a3ced42fb642.eval.golden index 31aaae8f69f..2ca4f1eea8b 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/5f306b4b24ff2b39dab6cdc9ac6ca9bb442c1dc6f4e7e412eeb5a3ced42fb642.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/5f306b4b24ff2b39dab6cdc9ac6ca9bb442c1dc6f4e7e412eeb5a3ced42fb642.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1018165066 -| mem: 3756874}) \ No newline at end of file +({cpu: 1018027066 +| mem: 3756274}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/675d63836cad11b547d1b4cddd498f04c919d4342612accf40913f9ae9419fac.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/675d63836cad11b547d1b4cddd498f04c919d4342612accf40913f9ae9419fac.eval.golden index bb491f0172b..f8bdddde853 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/675d63836cad11b547d1b4cddd498f04c919d4342612accf40913f9ae9419fac.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/675d63836cad11b547d1b4cddd498f04c919d4342612accf40913f9ae9419fac.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1440797563 -| mem: 5288993}) \ No newline at end of file +({cpu: 1440659563 +| mem: 5288393}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/9fabc4fc3440cdb776b28c9bb1dd49c9a5b1605fe1490aa3f4f64a3fa8881b25.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/9fabc4fc3440cdb776b28c9bb1dd49c9a5b1605fe1490aa3f4f64a3fa8881b25.eval.golden index 13aa0548525..e5d080cb36d 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/9fabc4fc3440cdb776b28c9bb1dd49c9a5b1605fe1490aa3f4f64a3fa8881b25.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/9fabc4fc3440cdb776b28c9bb1dd49c9a5b1605fe1490aa3f4f64a3fa8881b25.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1448679659 -| mem: 5039871}) \ No newline at end of file +({cpu: 1448403659 +| mem: 5038671}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/b21a4df3b0266ad3481a26d3e3d848aad2fcde89510b29cccce81971e38e0835.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/b21a4df3b0266ad3481a26d3e3d848aad2fcde89510b29cccce81971e38e0835.eval.golden index 7842b4a6386..338d6b83268 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/b21a4df3b0266ad3481a26d3e3d848aad2fcde89510b29cccce81971e38e0835.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/b21a4df3b0266ad3481a26d3e3d848aad2fcde89510b29cccce81971e38e0835.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1889566449 -| mem: 6853460}) \ No newline at end of file +({cpu: 1889014449 +| mem: 6851060}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/d1c03759810747b7cab38c4296593b38567e11195d161b5bb0a2b58f89b2c65a.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/d1c03759810747b7cab38c4296593b38567e11195d161b5bb0a2b58f89b2c65a.eval.golden index a2c4a6460f3..6f7e32de79e 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/d1c03759810747b7cab38c4296593b38567e11195d161b5bb0a2b58f89b2c65a.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/d1c03759810747b7cab38c4296593b38567e11195d161b5bb0a2b58f89b2c65a.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1425511870 -| mem: 5268907}) \ No newline at end of file +({cpu: 1425373870 +| mem: 5268307}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/ffdd68a33afd86f8844c9f5e45b2bda5b035aa02274161b23d57709c0f8b8de6.eval.golden b/plutus-benchmark/marlowe/test/semantics/9.6/ffdd68a33afd86f8844c9f5e45b2bda5b035aa02274161b23d57709c0f8b8de6.eval.golden index f5d6d30936f..9fc0c4f5c97 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/ffdd68a33afd86f8844c9f5e45b2bda5b035aa02274161b23d57709c0f8b8de6.eval.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/ffdd68a33afd86f8844c9f5e45b2bda5b035aa02274161b23d57709c0f8b8de6.eval.golden @@ -1,2 +1,2 @@ -({cpu: 1272963610 -| mem: 4680810}) \ No newline at end of file +({cpu: 1272687610 +| mem: 4679610}) \ No newline at end of file diff --git a/plutus-benchmark/marlowe/test/semantics/9.6/semantics.size.golden b/plutus-benchmark/marlowe/test/semantics/9.6/semantics.size.golden index f3b30f7270f..e93082e0bd6 100644 --- a/plutus-benchmark/marlowe/test/semantics/9.6/semantics.size.golden +++ b/plutus-benchmark/marlowe/test/semantics/9.6/semantics.size.golden @@ -1 +1 @@ -11652 \ No newline at end of file +11648 \ No newline at end of file diff --git a/plutus-benchmark/nofib/test/9.2/queens4-bt.pir.golden b/plutus-benchmark/nofib/test/9.2/queens4-bt.pir.golden index 01a820050e3..c7ce5e1c0d1 100644 --- a/plutus-benchmark/nofib/test/9.2/queens4-bt.pir.golden +++ b/plutus-benchmark/nofib/test/9.2/queens4-bt.pir.golden @@ -612,9 +612,7 @@ (/\dead -> Bool_match (ds - (`Cons=` - var' - val') + ds (`Cons=` var val)) diff --git a/plutus-benchmark/nofib/test/9.2/queens4-bt.size.golden b/plutus-benchmark/nofib/test/9.2/queens4-bt.size.golden index 420a359ae0e..22f5f1cc484 100644 --- a/plutus-benchmark/nofib/test/9.2/queens4-bt.size.golden +++ b/plutus-benchmark/nofib/test/9.2/queens4-bt.size.golden @@ -1 +1 @@ -1860 \ No newline at end of file +1858 \ No newline at end of file diff --git a/plutus-benchmark/nofib/test/9.2/queens5-fc.eval.golden b/plutus-benchmark/nofib/test/9.2/queens5-fc.eval.golden index 162ca315913..ac4fce3e8c4 100644 --- a/plutus-benchmark/nofib/test/9.2/queens5-fc.eval.golden +++ b/plutus-benchmark/nofib/test/9.2/queens5-fc.eval.golden @@ -1,2 +1,2 @@ -({cpu: 282792904581 -| mem: 1078786366}) \ No newline at end of file +({cpu: 282717464581 +| mem: 1078458366}) \ No newline at end of file diff --git a/plutus-benchmark/nofib/test/9.2/queens5-fc.pir.golden b/plutus-benchmark/nofib/test/9.2/queens5-fc.pir.golden index 1b55ff44ffa..f42893cf02d 100644 --- a/plutus-benchmark/nofib/test/9.2/queens5-fc.pir.golden +++ b/plutus-benchmark/nofib/test/9.2/queens5-fc.pir.golden @@ -612,9 +612,7 @@ (/\dead -> Bool_match (ds - (`Cons=` - var' - val') + ds (`Cons=` var val)) diff --git a/plutus-benchmark/nofib/test/9.2/queens5-fc.size.golden b/plutus-benchmark/nofib/test/9.2/queens5-fc.size.golden index 420a359ae0e..22f5f1cc484 100644 --- a/plutus-benchmark/nofib/test/9.2/queens5-fc.size.golden +++ b/plutus-benchmark/nofib/test/9.2/queens5-fc.size.golden @@ -1 +1 @@ -1860 \ No newline at end of file +1858 \ No newline at end of file diff --git a/plutus-benchmark/nofib/test/9.6/queens4-bt.pir.golden b/plutus-benchmark/nofib/test/9.6/queens4-bt.pir.golden index b108e9e186c..d1a47114b3c 100644 --- a/plutus-benchmark/nofib/test/9.6/queens4-bt.pir.golden +++ b/plutus-benchmark/nofib/test/9.6/queens4-bt.pir.golden @@ -660,9 +660,7 @@ (/\dead -> Bool_match (ds - (`Cons=` - var' - val') + ds (`Cons=` var val)) diff --git a/plutus-benchmark/nofib/test/9.6/queens4-bt.size.golden b/plutus-benchmark/nofib/test/9.6/queens4-bt.size.golden index 49cf7c7c5bc..2cc1ededf6b 100644 --- a/plutus-benchmark/nofib/test/9.6/queens4-bt.size.golden +++ b/plutus-benchmark/nofib/test/9.6/queens4-bt.size.golden @@ -1 +1 @@ -1931 \ No newline at end of file +1929 \ No newline at end of file diff --git a/plutus-benchmark/nofib/test/9.6/queens5-fc.eval.golden b/plutus-benchmark/nofib/test/9.6/queens5-fc.eval.golden index 1918afc6983..27cdeccc8cb 100644 --- a/plutus-benchmark/nofib/test/9.6/queens5-fc.eval.golden +++ b/plutus-benchmark/nofib/test/9.6/queens5-fc.eval.golden @@ -1,2 +1,2 @@ -({cpu: 284790983581 -| mem: 1087473666}) \ No newline at end of file +({cpu: 284715543581 +| mem: 1087145666}) \ No newline at end of file diff --git a/plutus-benchmark/nofib/test/9.6/queens5-fc.pir.golden b/plutus-benchmark/nofib/test/9.6/queens5-fc.pir.golden index d1a0443957f..5de838d0048 100644 --- a/plutus-benchmark/nofib/test/9.6/queens5-fc.pir.golden +++ b/plutus-benchmark/nofib/test/9.6/queens5-fc.pir.golden @@ -660,9 +660,7 @@ (/\dead -> Bool_match (ds - (`Cons=` - var' - val') + ds (`Cons=` var val)) diff --git a/plutus-benchmark/nofib/test/9.6/queens5-fc.size.golden b/plutus-benchmark/nofib/test/9.6/queens5-fc.size.golden index 49cf7c7c5bc..2cc1ededf6b 100644 --- a/plutus-benchmark/nofib/test/9.6/queens5-fc.size.golden +++ b/plutus-benchmark/nofib/test/9.6/queens5-fc.size.golden @@ -1 +1 @@ -1931 \ No newline at end of file +1929 \ No newline at end of file diff --git a/plutus-core/plutus-core.cabal b/plutus-core/plutus-core.cabal index aba845eb50b..ed9dccf6963 100644 --- a/plutus-core/plutus-core.cabal +++ b/plutus-core/plutus-core.cabal @@ -744,8 +744,8 @@ library plutus-core-testlib -- This wraps up the use of the certifier library -- so we can present a consistent inteface whether we --- are building with it or not. If we aren't building --- with it, we present a conservative stub implementation +-- are building with it or not. If we aren't building +-- with it, we present a conservative stub implementation -- that just always says everything is fine. library plutus-ir-cert import: lang diff --git a/plutus-tx-plugin/changelog.d/20231121_151437_unsafeFixIO_opaque.md b/plutus-tx-plugin/changelog.d/20231121_151437_unsafeFixIO_opaque.md new file mode 100644 index 00000000000..1421c783c29 --- /dev/null +++ b/plutus-tx-plugin/changelog.d/20231121_151437_unsafeFixIO_opaque.md @@ -0,0 +1,4 @@ +### Changed + +- Updated the Plutus Tx compiler to make the "Unsupported feature: Cannot case on a value on type" + error happen less often (if not eliminating it entirely). diff --git a/plutus-tx-plugin/plutus-tx-plugin.cabal b/plutus-tx-plugin/plutus-tx-plugin.cabal index 246b2f02e51..85f392e179d 100644 --- a/plutus-tx-plugin/plutus-tx-plugin.cabal +++ b/plutus-tx-plugin/plutus-tx-plugin.cabal @@ -89,6 +89,7 @@ library , PyF >=0.11.1.0 , template-haskell , text + , uniplate if flag(use-ghc-stub) build-depends: plutus-ghc-stub diff --git a/plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs b/plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs index 67b3e089c2f..39786d3317b 100644 --- a/plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs +++ b/plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs @@ -52,6 +52,7 @@ import PlutusTx.Builtins.Class qualified as Builtins import PlutusTx.Trace import PlutusIR qualified as PIR +import PlutusIR.Analysis.Builtins import PlutusIR.Compiler.Definitions qualified as PIR import PlutusIR.Compiler.Names (safeFreshName) import PlutusIR.Core.Type (Term (..)) @@ -63,13 +64,15 @@ import PlutusCore.MkPlc qualified as PLC import PlutusCore.Pretty qualified as PP import PlutusCore.Subst qualified as PLC -import Control.Lens hiding (index, strict) +import Control.Lens hiding (index, strict, transform) import Control.Monad import Control.Monad.Reader (ask) import Data.Array qualified as Array import Data.ByteString qualified as BS +import Data.Generics.Uniplate.Data (transform, universeBi) import Data.List (elemIndex) import Data.Map qualified as Map +import Data.Maybe import Data.Set qualified as Set import Data.Text qualified as T import Data.Text.Encoding qualified as TE @@ -823,22 +826,88 @@ compileExpr e = traceCompilation 2 ("Compiling expr:" GHC.<+> GHC.ppr e) $ do body' <- compileExpr body pure $ PIR.mkLet annMayInline PIR.Rec binds body' + GHC.Case scrutinee b t alts -> + compileCase (const . GHC.isDeadOcc . GHC.occInfo . GHC.idInfo) True binfo scrutinee b t alts + + -- we can use source notes to get a better context for the inner expression + -- these are put in when you compile with -g + -- See Note [What source locations to cover] + GHC.Tick tick body | Just src <- getSourceSpan maybeModBreaks tick -> + traceCompilation 1 ("Compiling expr at:" GHC.<+> GHC.ppr src) $ do + CompileContext{ccOpts = coverageOpts} <- ask + -- See Note [Coverage annotations] + let anns = Set.toList $ activeCoverageTypes coverageOpts + compiledBody <- fmap (addSrcSpan $ src ^. srcSpanIso) <$> compileExpr body + foldM (coverageCompile body (GHC.exprType body) src) compiledBody anns + + -- ignore other annotations + GHC.Tick _ body -> compileExpr body + -- See Note [Coercions and newtypes] + GHC.Cast body _ -> compileExpr body + GHC.Type _ -> throwPlain $ UnsupportedError "Types as standalone expressions" + GHC.Coercion _ -> throwPlain $ UnsupportedError "Coercions as expressions" + +compileCase :: + (CompilingDefault uni fun m ann) => + -- | Whether the variable is dead in the expr + (GHC.Var -> GHC.CoreExpr -> Bool) -> + -- | Whether we should try to rewrite unnecessary constructor applications + Bool -> + BuiltinsInfo uni fun -> + GHC.CoreExpr -> + GHC.Var -> + GHC.Type -> + [GHC.CoreAlt] -> + m (PIRTerm uni fun) +compileCase isDead rewriteConApps binfo scrutinee binder t alts = case alts of + [GHC.Alt con bs body] -- See Note [Evaluation-only cases] - GHC.Case scrutinee b _ [GHC.Alt _ bs body] | all (GHC.isDeadOcc . GHC.occInfo . GHC.idInfo) bs -> do + | all (`isDead` body) bs -> do -- See Note [At patterns] scrutinee' <- compileExpr scrutinee - withVarScoped b $ \v -> do + withVarScoped binder $ \v -> do body' <- compileExpr body -- See Note [At patterns] let binds = [PIR.TermBind annMayInline PIR.Strict v scrutinee'] pure $ PIR.mkLet annMayInline PIR.NonRec binds body' - GHC.Case scrutinee b t alts -> do + | rewriteConApps + , GHC.DataAlt dataCon <- con -> do + -- Attempt to rewrite constructor applications, since sometimes they cannot be + -- compiled (e.g., opaque constructors). + -- For example, this rewrites + + -- ``` + -- case scrut of b {BuiltinList xs} -> ...BuiltinList @BuiltinData xs... + -- ``` + -- + -- into + -- + -- ``` + -- case scrut of b {BuiltinList xs} -> ...b... + -- ``` + -- + -- after which `xs` is hopefully dead, and we can then compile it using the + -- `all (`isDead` body) bs` branch of `compileCase`. + let f (GHC.collectArgs -> (GHC.Var (GHC.isDataConId_maybe -> Just dataCon'), args0)) + | dataCon == dataCon' + -- Discard type arguments + , let args = mapMaybe (\case GHC.Var v -> Just v; _ -> Nothing) args0 + , length bs == length args + , and (zipWith (==) bs args) = + GHC.Var binder + f other = other + -- This time we can no longer use `GHC.isDeadOcc`. Instead we check manually. + isDead' b = not . any (== b) . universeBi + -- If some binders are still alive, we have to give up (rather than trying to rewrite + -- constructor applications again, which will loop), hence `False`. + compileCase isDead' False binfo scrutinee binder t [GHC.Alt con bs (transform f body)] + _ -> do -- See Note [At patterns] scrutinee' <- compileExpr scrutinee - let scrutineeType = GHC.varType b + let scrutineeType = GHC.varType binder -- the variable for the scrutinee is bound inside the cases, but not in the scrutinee expression itself - withVarScoped b $ \v -> do + withVarScoped binder $ \v -> do (tc, argTys) <- case GHC.splitTyConApp_maybe scrutineeType of Just (tc, argTys) -> pure (tc, argTys) Nothing -> @@ -907,24 +976,6 @@ compileExpr e = traceCompilation 2 ("Compiling expr:" GHC.<+> GHC.ppr e) $ do ] pure $ PIR.mkLet annMayInline PIR.NonRec binds mainCase - -- we can use source notes to get a better context for the inner expression - -- these are put in when you compile with -g - -- See Note [What source locations to cover] - GHC.Tick tick body | Just src <- getSourceSpan maybeModBreaks tick -> - traceCompilation 1 ("Compiling expr at:" GHC.<+> GHC.ppr src) $ do - CompileContext{ccOpts = coverageOpts} <- ask - -- See Note [Coverage annotations] - let anns = Set.toList $ activeCoverageTypes coverageOpts - compiledBody <- fmap (addSrcSpan $ src ^. srcSpanIso) <$> compileExpr body - foldM (coverageCompile body (GHC.exprType body) src) compiledBody anns - - -- ignore other annotations - GHC.Tick _ body -> compileExpr body - -- See Note [Coercions and newtypes] - GHC.Cast body _ -> compileExpr body - GHC.Type _ -> throwPlain $ UnsupportedError "Types as standalone expressions" - GHC.Coercion _ -> throwPlain $ UnsupportedError "Coercions as expressions" - {- Note [What source locations to cover] We try to get as much coverage information as we can out of GHC. This means that anything we find in the GHC Core code that hints at a source location will be diff --git a/plutus-tx-plugin/test/Optimization/9.2/matchAsData.pir.golden b/plutus-tx-plugin/test/Optimization/9.2/matchAsData.pir.golden new file mode 100644 index 00000000000..6fa7df7c449 --- /dev/null +++ b/plutus-tx-plugin/test/Optimization/9.2/matchAsData.pir.golden @@ -0,0 +1,57 @@ +let + data Unit | Unit_match where + Unit : Unit + data Bool | Bool_match where + True : Bool + False : Bool + data (Tuple2 :: * -> * -> *) a b | Tuple2_match where + Tuple2 : a -> b -> Tuple2 a b +in +\(ds : (\a -> data) integer) -> + Tuple2_match + {integer} + {list data} + ((let + b = list data + in + \(tup : pair integer b) -> + Tuple2 + {integer} + {b} + (fstPair {integer} {b} tup) + (sndPair {integer} {b} tup)) + (unConstrData ds)) + {integer} + (\(ds : integer) (ds : list data) -> + ifThenElse + {all dead. integer} + (equalsInteger 0 ds) + (/\dead -> + let + !ds : integer = unIData (headList {data} (tailList {data} ds)) + in + unIData (headList {data} ds)) + (/\dead -> + Tuple2_match + {integer} + {list data} + ((let + b = list data + in + \(tup : pair integer b) -> + Tuple2 + {integer} + {b} + (fstPair {integer} {b} tup) + (sndPair {integer} {b} tup)) + (unConstrData ds)) + {integer} + (\(ds : integer) (ds : list data) -> + ifThenElse + {all dead. integer} + (equalsInteger 1 ds) + (/\dead -> 1) + (/\dead -> + Unit_match (error {Unit}) {integer} (error {integer})) + {all dead. dead})) + {all dead. dead}) \ No newline at end of file