Commit eb17481
Add deriveEq for Plinth similar to deriving stock Eq (#7433)
* feat(plutus-tx): add deriveEq Template Haskell function
Extract the Eq typeclass into PlutusTx.Eq.Class and add a new
PlutusTx.Eq.TH module providing deriveEq, a TH function that generates
PlutusTx.Eq instances analogous to GHC's `deriving stock Eq`.
This enables replacing hand-written structural equality instances with
a single `deriveEq ''TypeName` call, reducing boilerplate and ensuring
consistent pattern-matching with short-circuit evaluation and INLINABLE
pragmas across the codebase.
* test(plutus-tx): add unit and golden tests for deriveEq
Add comprehensive tests covering product types, sum types, newtypes,
records, void types, phantom types, and recursive types. Golden tests
capture exact TH-generated code to detect regressions.
Fix goldenCodeGen to use `pretty @String` for proper Doc type
conversion needed by nestedGoldenVsDoc.
* refactor(plutus-tx): replace manual Eq instances with deriveEq
Replace hand-written Eq instances for Rational and These with
deriveEq calls. The generated instances are structurally identical
to the manual ones.
* refactor(plutus-ledger-api): replace manual Eq instances with deriveEq
Replace hand-written PlutusTx.Eq instances across all V1, V2, and V3
modules (both Original and Data representations) with deriveEq calls.
MintValue retains its manual instance because its equality semantics
differ from structural equality (it normalizes zero-quantity entries).
* test: add golden tests for deriveEq generated code
Add golden TH tests capturing the exact generated Eq instances for
every type where manual instances were replaced with deriveEq. This
covers 42 types in plutus-ledger-api (V1/V2/V3, Original and Data
variants) and 2 types in plutus-tx (Rational, These).
These tests will detect any unintended changes to the generated
equality code.
* test: regenerate golden files affected by deriveEq
Variable naming in deriveEq-generated code differs from manual
instances, causing golden file updates in plutus-benchmark and
plutus-tx-plugin test suites.
* docs: add changelog entries for deriveEq feature
Add entries to plutus-tx and plutus-ledger-api changelogs documenting
the new deriveEq function and the migration from manual Eq instances.
* test: update AST size golden for Rational.compare after deriveEq changes
* test: make deriveEq golden tests deterministic for asData types
Strip TH-generated unique name suffixes (7+ digits) from golden test
output for Data-variant types (V*D.*), which use TH.newName via asData
and produce non-deterministic constructor names across compilations.
* test: regenerate golden files for cardano-constitution and plutus-benchmark
* fix: disable plutus-ledger-api-test on Windows (needs diff)
The golden tests added by deriveEq require the 'diff' binary which is
not available in the Windows (mingW64) cross-compilation environment.
* refactor: replace TH.pprint with custom width-aware pretty-printer
Replace formatTHOutput + TH.pprint with a new PlutusTx.Test.THPretty
module that uses prettyprinter's Wadler/Lindig algorithm with 100-column
page width. This produces much more readable golden test output -- lines
that previously stretched 200+ chars now wrap intelligently.
* style: remove commented-out deriveEq calls for AssocMap types
Replace commented-out deriveEq code with plain comments explaining
why PlutusTx.Eq instances are absent, addressing review feedback.
* style: add Haddock markers to MintValue Eq instance comments
---------
Co-authored-by: Yuriy Lazaryev <yuriy.lazaryev@iohk.io>1 parent a6201d1 commit eb17481
File tree
146 files changed
+6812
-7727
lines changed- cardano-constitution/test/Cardano/Constitution/Validator
- Data/GoldenTests
- GoldenTests
- plutus-benchmark
- cardano-loans/test/9.6
- coop/test/9.6
- linear-vesting/test/9.6
- marlowe/test
- nofib/test/9.6
- script-contexts/test
- V2/9.6
- V3/Data/9.6
- plutus-ledger-api
- changelog.d
- src/PlutusLedgerApi
- V1
- Data
- V2
- Data
- V3
- Data
- test
- Spec/Eq
- Golden
- plutus-tx-plugin/test
- AstSize/Golden/Rational/Ord
- IsData
- 9.12
- 9.6
- plutus-tx
- changelog.d
- src/PlutusTx
- Eq
- testlib/PlutusTx/Test
- test
- Enum/Golden
- 9.12
- 9.6
- Eq
- Golden
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
146 files changed
+6812
-7727
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 18 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
| 250 | + | |
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
| 254 | + | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | | - | |
| 259 | + | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
266 | 266 | | |
267 | | - | |
| 267 | + | |
268 | 268 | | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
| 269 | + | |
274 | 270 | | |
275 | 271 | | |
276 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
280 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
281 | 284 | | |
282 | 285 | | |
283 | 286 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 823 additions & 827 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 18 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | | - | |
| 259 | + | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
266 | 266 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
| 267 | + | |
272 | 268 | | |
273 | 269 | | |
274 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
275 | 276 | | |
276 | 277 | | |
277 | 278 | | |
278 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
279 | 282 | | |
280 | 283 | | |
281 | 284 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
0 commit comments