Add deriveOrd for Plinth similar to deriving stock Ord#7580
Open
Add deriveOrd for Plinth similar to deriving stock Ord#7580
Conversation
Contributor
Execution Budget Golden Diffoutputplutus-benchmark/coop/test/9.6/certMpBurning.golden.eval
plutus-benchmark/coop/test/9.6/certMpMinting.golden.eval
plutus-benchmark/coop/test/9.6/fsMpBurning.golden.eval
plutus-benchmark/coop/test/9.6/fsMpMinting.golden.eval
plutus-benchmark/nofib/test/9.6/clausify-F5.golden.eval
plutus-benchmark/nofib/test/9.6/knights10-4x4.golden.eval
This comment will get updated when changes are made. |
3b9aaed to
f1817ba
Compare
Add deriveOrd tests Make deriving Ord phantom types work Fixes
Add MyNewtype, SomeLargeADT, Tree, and These golden tests to match deriveEq coverage. Add unit tests for new types including newtype, large ADT, and recursive tree comparisons.
Add Spec.Ord.Golden module with golden tests for V1.Extended and V3.ProtocolVersion types that use deriveOrd. Wire into test suite.
…ration Use wildcard patterns for cross-constructor comparisons instead of generating explicit clauses for every pair. This reduces generated clauses from O(n^2) to O(n) for types with n constructors.
Remove unused import of PlutusTx.Either from Ord.Class, prefix unused record fields with underscore in test ADT to satisfy -Werror, and disable plutus-ledger-api-test on Windows where the diff command is unavailable for golden tests.
Apply fourmolu formatting to Ord.Class module header and imports. Add HLint suppressions for deliberately inefficient max/min/compare implementations that match GHC's default definitions for consistency.
Add missing import of PlutusTx.Eq to bring Eq instances into scope, which are required as superclass constraints for deriveOrd. This fixes build failures where deriveOrd couldn't deduce Eq instances for types like [], Bool, Maybe, etc. Fixes Hydra CI build failures on both darwin and linux platforms.
99b2408 to
7397dd0
Compare
GHC 9.12 resolves TH-quoted '(<>) to GHC.Internal.Base.<> instead of GHC.Base.<>, causing golden test mismatches across GHC versions. Replace with a named thenCmp helper in PlutusTx.Ord.Class for stable output. Also replace HS.tail with HS.drop 1 in tests to fix -Wx-partial error on GHC 9.12.
The switch from (<>) to thenCmp in deriveOrd-generated code changes the compiled PIR/UPLC output for clausify and knights benchmarks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #7566
Depends on #7433
Recent Changes
Problem
Writing
PlutusTx.Ordinstances by hand is tedious and error-prone. Unlike Haskell'sderiving stock Ord, there's no automatic way to derive ordering for Plutus types.Solution
Add
PlutusTx.deriveOrd, a Template Haskell function that generatesPlutusTx.Ordinstances matching GHC's stock deriving behavior.Implementation
PlutusTx.Ord.TH: TH splice that generatescompareclauses:(<>)onOrdering(left-to-right, short-circuit)INLINEABLEpragma for on-chain optimizationderiveOrdforBool,Maybe,Either,Ordering,[], tuples up to 26-arityOrdinstances replaced forV1.ExtendedandV3.ProtocolVersionWhat's NOT replaced (custom semantics)
UpperBound/LowerBound— useinclusiveUpperBound/inclusiveLowerBoundtransformationsRational— uses cross-multiplication comparisonasDatatypes (e.g.,V1D.Extended) —deriveOrdcannot see throughBuiltinDatawrappersTests
plutus-tx):SomeVeryLargeEnum,SomeProduct,PhantomADT,MyNewtype,SomeLargeADT,Tree,Theseplutus-ledger-api):V1.Extended,V3.ProtocolVersion