Skip to content

Conversation

SeungheonOh
Copy link
Collaborator

Implements

case (con Data (Constr n [x, y, z])) 
  <branch_0 :: Data -> Data -> Data -> r>
  <branch_1 :: Data -> r>
  <branch_2 :: r>

where each branches get each elements of the "field" part of Data.Constr as arguments. This allows deconstruction of Data.Constr value in single CEK step.

Copy link
Contributor

github-actions bot commented Sep 6, 2025

Execution Budget Golden Diff

ad408e9 (master) vs 190c255

output

plutus-benchmark/coop/test/9.6/authMpBurning.eval.golden

Metric Old New Δ%
CPU 160_613_384 78_597_023 -51.06%
Memory 799_466 464_146 -41.94%
Term Size 1_473 951 -35.44%
Flat Size 5_393 4_946 -8.29%

plutus-benchmark/coop/test/9.6/authMpMinting.eval.golden

Metric Old New Δ%
CPU 369_713_157 198_392_236 -46.34%
Memory 1_849_456 1_148_576 -37.90%
Term Size 1_473 951 -35.44%
Flat Size 6_790 6_343 -6.58%

plutus-benchmark/coop/test/9.6/certMpBurning.eval.golden

Metric Old New Δ%
CPU 1_842_342_144 1_726_944_433 -6.26%
Memory 10_767_218 10_326_806 -4.09%
Term Size 3_160 2_604 -17.59%
Flat Size 8_041 7_566 -5.91%

plutus-benchmark/coop/test/9.6/certMpMinting.eval.golden

Metric Old New Δ%
CPU 400_086_379 242_634_088 -39.35%
Memory 2_025_456 1_422_048 -29.79%
Term Size 3_160 2_604 -17.59%
Flat Size 8_564 8_089 -5.55%

plutus-benchmark/coop/test/9.6/fsMpBurning.eval.golden

Metric Old New Δ%
CPU 221_694_924 152_437_298 -31.24%
Memory 1_160_575 899_055 -22.53%
Term Size 3_571 2_947 -17.47%
Flat Size 7_405 6_875 -7.16%

plutus-benchmark/coop/test/9.6/fsMpMinting.eval.golden

Metric Old New Δ%
CPU 568_150_641 422_773_415 -25.59%
Memory 3_047_567 2_495_655 -18.11%
Term Size 3_571 2_947 -17.47%
Flat Size 9_223 8_693 -5.75%

plutus-benchmark/coop/test/9.6/mustBurnOwnSingleton.eval.golden

Metric Old New Δ%
CPU 114_113_035 63_288_463 -44.54%
Memory 579_805 372_773 -35.71%
Term Size 1_274 759 -40.42%
Flat Size 3_833 3_392 -11.51%

plutus-benchmark/linear-vesting/test/9.6/main.eval.golden

Metric Old New Δ%
CPU 30_837_131 26_581_286 -13.80%
Memory 131_619 114_219 -13.22%
Term Size 2_421 2_253 -6.94%
Flat Size 2_860 2_727 -4.65%

plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext1-20.eval.golden

Metric Old New Δ%
CPU 111_474_671 51_290_715 -53.99%
Memory 550_394 293_134 -46.74%
Term Size 956 470 -50.84%
Flat Size 1_465 1_045 -28.67%

plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext1-4.eval.golden

Metric Old New Δ%
CPU 32_459_423 15_328_731 -52.78%
Memory 156_122 88_430 -43.36%
Term Size 956 470 -50.84%
Flat Size 1_079 659 -38.92%

plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext2-20.eval.golden

Metric Old New Δ%
CPU 104_194_248 44_010_292 -57.76%
Memory 518_652 261_392 -49.60%
Term Size 899 413 -54.06%
Flat Size 1_390 970 -30.22%

plutus-benchmark/script-contexts/test/V1/9.6/checkScriptContext2-4.eval.golden

Metric Old New Δ%
CPU 30_382_328 13_251_636 -56.38%
Memory 146_812 79_120 -46.11%
Term Size 899 413 -54.06%
Flat Size 1_004 584 -41.83%

plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext1-20.eval.golden

Metric Old New Δ%
CPU 124_328_253 53_466_651 -57.00%
Memory 606_806 306_498 -49.49%
Term Size 1_013 498 -50.84%
Flat Size 1_575 1_134 -28.00%

plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext1-4.eval.golden

Metric Old New Δ%
CPU 36_906_589 16_480_667 -55.34%
Memory 177_398 95_394 -46.23%
Term Size 1_013 498 -50.84%
Flat Size 1_141 700 -38.65%

plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext2-20.eval.golden

Metric Old New Δ%
CPU 117_015_830 46_154_228 -60.56%
Memory 574_864 274_556 -52.24%
Term Size 954 439 -53.98%
Flat Size 1_499 1_058 -29.42%

plutus-benchmark/script-contexts/test/V2/9.6/checkScriptContext2-4.eval.golden

Metric Old New Δ%
CPU 34_797_494 14_371_572 -58.70%
Memory 167_888 85_884 -48.84%
Term Size 954 439 -53.98%
Flat Size 1_065 624 -41.41%

plutus-benchmark/script-contexts/test/V2/9.6/sopFwdStakeTrick.eval.golden

Metric Old New Δ%
CPU 145_894_198 62_548_124 -57.13%
Memory 724_058 372_534 -48.55%
Term Size 1_149 634 -44.82%
Flat Size 2_145 1_704 -20.56%

plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext1-20.eval.golden

Metric Old New Δ%
CPU 126_102_096 55_129_328 -56.28%
Memory 612_722 316_662 -48.32%
Term Size 1_827 991 -45.76%
Flat Size 2_365 1_670 -29.39%

plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext1-4.eval.golden

Metric Old New Δ%
CPU 39_448_432 18_143_344 -54.01%
Memory 188_114 105_558 -43.89%
Term Size 1_827 991 -45.76%
Flat Size 1_931 1_236 -35.99%

plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext2-20.eval.golden

Metric Old New Δ%
CPU 118_709_673 47_736_905 -59.79%
Memory 580_280 284_220 -51.02%
Term Size 1_763 927 -47.42%
Flat Size 2_287 1_592 -30.39%

plutus-benchmark/script-contexts/test/V3/9.6/checkScriptContext2-4.eval.golden

Metric Old New Δ%
CPU 37_259_337 15_954_249 -57.18%
Memory 178_104 95_548 -46.35%
Term Size 1_763 927 -47.42%
Flat Size 1_853 1_158 -37.51%

plutus-benchmark/script-contexts/test/V3/Data/9.6/purposeIsWellFormed-4.eval.golden

Metric Old New Δ%
Term Size 1_773 1_756 -0.96%
Flat Size 1_844 1_833 -0.60%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq1.eval.golden

Metric Old New Δ%
CPU 339_163_895 328_592_875 -3.12%
Memory 998_845 964_285 -3.46%
Term Size 659 637 -3.34%
Flat Size 939 920 -2.02%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq2.eval.golden

Metric Old New Δ%
CPU 356_777_594 345_639_098 -3.12%
Memory 1_065_515 1_028_627 -3.46%
Term Size 659 637 -3.34%
Flat Size 990 971 -1.92%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq3.eval.golden

Metric Old New Δ%
CPU 370_496_887 357_939_701 -3.39%
Memory 1_111_429 1_068_721 -3.84%
Term Size 659 637 -3.34%
Flat Size 990 971 -1.92%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq4.eval.golden

Metric Old New Δ%
CPU 332_716_553 326_618_754 -1.83%
Memory 955_736 935_564 -2.11%
Term Size 659 637 -3.34%
Flat Size 946 927 -2.01%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/geq5.eval.golden

Metric Old New Δ%
CPU 351_276_383 340_421_625 -3.09%
Memory 1_031_900 996_176 -3.46%
Term Size 659 637 -3.34%
Flat Size 946 927 -2.01%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt1.eval.golden

Metric Old New Δ%
CPU 390_276_300 379_705_280 -2.71%
Memory 1_179_960 1_145_400 -2.93%
Term Size 1_052 1_030 -2.09%
Flat Size 1_306 1_287 -1.45%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt2.eval.golden

Metric Old New Δ%
CPU 357_145_594 346_007_098 -3.12%
Memory 1_067_815 1_030_927 -3.45%
Term Size 1_052 1_030 -2.09%
Flat Size 1_357 1_338 -1.40%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt3.eval.golden

Metric Old New Δ%
CPU 422_330_992 409_773_806 -2.97%
Memory 1_296_509 1_253_801 -3.29%
Term Size 1_052 1_030 -2.09%
Flat Size 1_357 1_338 -1.40%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt4.eval.golden

Metric Old New Δ%
CPU 333_084_553 326_986_754 -1.83%
Memory 958_036 937_864 -2.11%
Term Size 1_052 1_030 -2.09%
Flat Size 1_313 1_294 -1.45%

plutus-ledger-api/test-plugin/Spec/Data/Budget/9.6/gt5.eval.golden

Metric Old New Δ%
CPU 375_739_011 364_884_253 -2.89%
Memory 1_122_324 1_086_600 -3.18%
Term Size 1_052 1_030 -2.09%
Flat Size 1_313 1_294 -1.45%

plutus-tx-plugin/test/Budget/9.6/map3.eval.golden

Metric Old New Δ%
CPU 112_163_732 109_687_940 -2.21%
Memory 335_284 326_008 -2.77%
Term Size 671 649 -3.28%
Flat Size 697 678 -2.73%

plutus-tx-plugin/test/Budget/9.6/toFromData.eval.golden

Metric Old New Δ%
CPU 3_182_422 1_456_406 -54.24%
Memory 13_404 6_620 -50.61%
Term Size 140 70 -50.00%
Flat Size 153 94 -38.56%

This comment will get updated when changes are made.

Copy link
Contributor

github-actions bot commented Sep 6, 2025

PR Preview Action v1.6.2

🚀 View preview at
https://IntersectMBO.github.io/plutus/pr-preview/pr-7315/

Built to branch gh-pages at 2025-09-08 23:46 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link
Collaborator Author

@SeungheonOh SeungheonOh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CEK part is more or less set, but plinth part needs some rework. Feel free to just review plutus-core part only.

vArgTypes <- traverse (fmap unNormalized . normalizeTypeM) argTypes
-- made of sub-parts of a normalized type, so normalized
checkTypeM ann c (Normalized $ mkIterTyFun () vArgTypes (unNormalized vResTy))
VariableArityBranch c argType -> do
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really happy here, but don't think there's any better way to go about without bigger changes. The fact that each branch can have arbitrary number of arguments introduces this dynamic behavior. So, it is only possible to check the return type and to check if are inputs(of arbitrary number) have correct type.

Comment on lines 1075 to 1088
data CaseDataConstrBranch = forall a. CaseDataConstrBranch a

caseDataConstr :: forall r. BuiltinData -> [CaseDataConstrBranch] -> r
caseDataConstr d branches =
let
constr = unsafeDataAsConstr d
idx = PlutusTx.Builtins.Internal.fst constr
ds = PlutusTx.Builtins.Internal.snd constr
unwrap (CaseDataConstrBranch x) = unsafeCoerce x
applyToBranch :: r -> BuiltinList BuiltinData -> r
applyToBranch body =
caseList' body (\arg -> applyToBranch (unsafeCoerce body $ arg))
in applyToBranch (unwrap $ branches !! fromIntegral idx) ds
{-# OPAQUE caseDataConstr #-}
Copy link
Collaborator Author

@SeungheonOh SeungheonOh Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is horrendous; needed that existential type since number of argument each branch handler takes is arbitrary. This works, but it's impossible to make it also work for when we disable builtin-casing compilation option.

I'm going to try other ways. Namely, using \[a, b, c] -> ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some changes. It works good now without this atrocity

Memory: 574_864
Term Size: 954
Flat Size: 1_499
CPU: 46_154_228
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@SeungheonOh SeungheonOh changed the title Casing on Data.Constr [Builtin] Casing on Data.Constr Sep 6, 2025
Copy link
Contributor

@effectfully effectfully left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this design. See the "What exactly breaks if we add the unsafe constrTermFromConstrData?" section of #5777 for why.

If the team thinks this is what we should do, I won't fight it. But I believe it is not what we should do.

@SeungheonOh SeungheonOh self-assigned this Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants