Commit a845510
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- plutus-core
- changelog.d
- flat
- src/PlutusCore/Flat
- Instances
- test
- Test
- Data2
- Data
- E
- plutus-core/src/PlutusCore
- Default
- plutus-ir
- src/PlutusIR/Core/Instance
- test/PlutusIR/Core
- untyped-plutus-core/testlib/DeBruijn
- plutus-tx/src/PlutusTx
24 files changed
+616
-1490
lines changedLines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments