Add a constant folding pass to UPLC#7764
Conversation
Execution Budget Golden Diffoutputplutus-tx-plugin/test/Budget/9.6/applicative.golden.eval
plutus-tx-plugin/test/Budget/9.6/monadicDo.golden.eval
plutus-tx-plugin/test/Budget/9.6/toFromData.golden.eval
This comment will get updated when changes are made. |
5c12951 to
13e8d0b
Compare
| , PLC.Everywhere uni Eq | ||
| , MonadError (PIR.Error uni fun (Provenance ())) m | ||
| :: forall a m | ||
| . ( Lift.Lift UPLC.DefaultUni a |
There was a problem hiding this comment.
I don't see why everything in this module needs to be hardcoded to DefaultUni. If PIR constant folding doesn't require this, then neither should UPLC constant folding.
There was a problem hiding this comment.
Is Plinth ever used with anything other than DefaultUni and DefaultFun? Are there any plans to add other universes of builtins? As far as I know there aren't any, and I believe abstraction just for the sake of abstraction is a code smell.
There was a problem hiding this comment.
If we decide that only DefaultUni is needed, the right thing to do is to open a PR and remove the uni type parameter altogether. That doesn't seem like a good idea though, since other universes are being used for testing and benchmarking.
If we keep the uni parameter, then this monomorphization just makes it inconsistent with everything else.
There was a problem hiding this comment.
the right thing to do is to open a PR and remove the uni type parameter altogether.
I don't think removing it from Plinth means we need to remove it from all of the other packages at the same time. Although, I do need to double check if they're used in some other Plinth code as well.
That doesn't seem like a good idea though, since other universes are being used for testing and benchmarking.
I asked Claude where we use other universes, this is the response:
Custom Builtin Function Sets
ExtensionFun — plutus-core/examples/PlutusCore/Examples/Builtins.hs
Used as Either DefaultFun ExtensionFun in example programs and tests. Includes factorial, polymorphic identity functions, cost-tracking builtins, unsafe coercions, and semantic variant testing.
NopFun — cost-model/budgeting-bench/Benchmarks/Nops.hs
No-op builtins used exclusively for cost model calibration benchmarks — measure the raw overhead of calling a builtin function with varying argument types/counts.
Custom Builtin Function Sets ExtensionFun — plutus-core/examples/PlutusCore/Examples/Builtins.hs
Used as Either DefaultFun ExtensionFun in example programs and tests. Includes factorial, polymorphic identity functions, cost-tracking builtins, unsafe coercions, and semantic variant testing.
If Claude is correct, we're keeping the whole universe machinery just for an example and for cost model calibration. I think it would be worth looking into whether the cost model calibration can be represented in a different way. It doesn't make sense to keep all of the complicated universe abstraction around just for that. The current representation would be good if UPLC was used to target other platforms (not just Cardano), but that doesn't seem grounded in reality. Also, there might be performance benefits for the CEK machine. I think this would be worth exploring.
There was a problem hiding this comment.
Btw, I'm reverting the change to Lift here since I tend to agree this would be better done separately, but I still think we should discuss ^.
| , (\ds -> constr 1 []) ] | ||
| args) ]) ]) ] | ||
| args) ])) No newline at end of file | ||
| (program 1.1.0 (constr 1 [(constr 0 [(constr 0 [True, 1, False])])])) No newline at end of file |
There was a problem hiding this comment.
Looks like running this pass at the UPLC level as well unlocked further optimization opportunities.
c1f9b1e to
bf0fd76
Compare
Fixes https://github.com/IntersectMBO/plutus-private/issues/2172