Skip to content

Commit a845510

Browse files
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 a845510

File tree

24 files changed

+616
-1490
lines changed

24 files changed

+616
-1490
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Removed
2+
3+
- Generic-based `Flat` class derivation machinery (`GFlat*`, `NumConstructors`, default method implementations) and associated test/doc infrastructure.
4+
5+
### Added
6+
7+
- QuickCheck round-trip property test for PIR Flat serialization.

0 commit comments

Comments
 (0)