Commit 6825737
committed
Remove Generic-based Flat derivation machinery (#7542)
The internal flat library contained Generic-based Flat class derivation
via GHC.Generics that had a bug: deserializing large enum types (512+
constructors) consumed infinite memory. While not a security risk (UPLC
on-chain code uses only manual Flat instances), the buggy dead code was
distracting. This commit removes the entire Generic derivation machinery.
Changes:
1. Add manual Flat instances to all types that previously relied on
Generic defaults: Maybe, Either, Complex, [], NonEmpty, tuples (2-7),
Tree, Filler, PostAligned, PreAligned, SrcSpan, SrcSpans, and all PIR
types (Recursivity, Strictness, Datatype, Binding, Program, Term).
Manual encoding is bit-identical to the Generic encoding.
2. Add missing `size` methods to partial Flat instances in
FlatInstances.hs (Name, Version, VarDecl, TyVarDecl, Program,
NamedDeBruijn) and Value.hs (K, Quantity, Value) that previously
relied on the Generic default for `size`.
3. Gut Class.hs: remove ~440 lines of GFlat*/GEncode*/GSize* classes,
NumConstructors type family, all Generic default method implementations,
and associated imports/pragmas/re-exports.
4. Remove ENUM_LARGE test infrastructure (E256/E258 types, Flat/Arbitrary
instances, ~530 lines) and delete Core.hs inspection tests.
5. Fix transitive import breakage: files that got Generic from the
PlutusCore.Flat re-export now import GHC.Generics directly.
Remove `hiding (to)` from imports that no longer re-export Generics.
6. Strip Generic-specific doctests from Tutorial.hs.
All existing tests pass (5281 across 4 suites). Manual instances produce
bit-identical encoding verified by round-trip tests and golden files.1 parent b6d66c6 commit 6825737
File tree
22 files changed
+607
-1433
lines changed- plutus-core
- flat
- src/PlutusCore/Flat
- Instances
- test
- Test
- Data2
- Data
- E
- plutus-core/src/PlutusCore
- plutus-ir
- src/PlutusIR/Core/Instance
- test/PlutusIR/Core
- untyped-plutus-core/testlib/DeBruijn
- plutus-tx/src/PlutusTx
22 files changed
+607
-1433
lines changedLarge diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
36 | 41 | | |
37 | 42 | | |
38 | 43 | | |
| |||
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
53 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
57 | 67 | | |
58 | 68 | | |
59 | 69 | | |
60 | 70 | | |
61 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
62 | 77 | | |
63 | 78 | | |
64 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | | - | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
| |||
206 | 204 | | |
207 | 205 | | |
208 | 206 | | |
209 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
210 | 215 | | |
211 | 216 | | |
212 | 217 | | |
| |||
215 | 220 | | |
216 | 221 | | |
217 | 222 | | |
218 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
219 | 231 | | |
220 | 232 | | |
221 | 233 | | |
| |||
598 | 610 | | |
599 | 611 | | |
600 | 612 | | |
601 | | - | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
602 | 617 | | |
603 | 618 | | |
604 | 619 | | |
| |||
624 | 639 | | |
625 | 640 | | |
626 | 641 | | |
627 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
628 | 650 | | |
629 | 651 | | |
630 | 652 | | |
| |||
658 | 680 | | |
659 | 681 | | |
660 | 682 | | |
661 | | - | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
662 | 687 | | |
663 | 688 | | |
664 | 689 | | |
| |||
681 | 706 | | |
682 | 707 | | |
683 | 708 | | |
684 | | - | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
685 | 713 | | |
686 | | - | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
687 | 718 | | |
688 | 719 | | |
689 | 720 | | |
690 | 721 | | |
691 | | - | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
692 | 726 | | |
693 | 727 | | |
694 | 728 | | |
695 | 729 | | |
696 | | - | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
697 | 734 | | |
698 | 735 | | |
699 | 736 | | |
700 | 737 | | |
701 | | - | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
702 | 742 | | |
703 | 743 | | |
704 | 744 | | |
| |||
710 | 750 | | |
711 | 751 | | |
712 | 752 | | |
713 | | - | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
Lines changed: 5 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
7 | | - | |
8 | 5 | | |
9 | 6 | | |
10 | 7 | | |
| |||
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
| 20 | + | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
| |||
108 | 106 | | |
109 | 107 | | |
110 | 108 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
| |||
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
19 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 10 | + | |
17 | 11 | | |
18 | 12 | | |
19 | 13 | | |
20 | 14 | | |
21 | 15 | | |
22 | 16 | | |
23 | 17 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 18 | + | |
33 | 19 | | |
34 | 20 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | 21 | | |
50 | 22 | | |
51 | 23 | | |
52 | 24 | | |
53 | 25 | | |
54 | 26 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | 27 | | |
72 | 28 | | |
73 | 29 | | |
74 | 30 | | |
75 | 31 | | |
76 | 32 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | 33 | | |
88 | 34 | | |
89 | 35 | | |
| |||
0 commit comments