Refactor the Binary serialisation interface
The goal is simplifiy adding deduplication tables to `ModIface` interface serialisation. We identify two main points of interest that make this difficult: 1. UserData hardcodes what `Binary` instances can have deduplication tables. Moreover, it heavily uses partial functions. 2. GHC.Iface.Binary hardcodes the deduplication tables for 'Name' and 'FastString', making it difficult to add more deduplication. Instead of having a single `UserData` record with fields for all the types that can have deduplication tables, we allow to provide custom serialisers for any `Typeable`. These are wrapped in existentials and stored in a `Map` indexed by their respective `TypeRep`. The `Binary` instance of the type to deduplicate still needs to explicitly look up the decoder via `findUserDataReader` and `findUserDataWriter`, which is no worse than the status-quo. `Map` was chosen as microbenchmarks indicate it is the fastest for a small number of keys (< 10). To generalise the deduplication table serialisation mechanism, we introduce the types `ReaderTable` and `WriterTable` which provide a simple interface that is sufficient to implement a general purpose deduplication mechanism for `writeBinIface` and `readBinIface`. This allows us to provide a list of deduplication tables for serialisation that can be extended more easily, for example for `IfaceTyCon`, see the issue ghc/ghc#24540 for more motivation. In addition to this refactoring, we split `UserData` into `ReaderUserData` and `WriterUserData`, to avoid partial functions and reduce overall memory usage, as we need fewer mutable variables. Bump haddock submodule to accomodate for `UserData` split. ------------------------- Metric Increase: MultiLayerModulesTH_Make MultiLayerModulesRecomp T21839c -------------------------
Showing
- compiler/GHC/Iface/Binary.hs 266 additions, 62 deletionscompiler/GHC/Iface/Binary.hs
- compiler/GHC/Iface/Ext/Binary.hs 10 additions, 8 deletionscompiler/GHC/Iface/Ext/Binary.hs
- compiler/GHC/Iface/Recomp/Binary.hs 1 addition, 1 deletioncompiler/GHC/Iface/Recomp/Binary.hs
- compiler/GHC/Iface/Syntax.hs 4 additions, 3 deletionscompiler/GHC/Iface/Syntax.hs
- compiler/GHC/Iface/Type.hs 6 additions, 6 deletionscompiler/GHC/Iface/Type.hs
- compiler/GHC/StgToJS/Object.hs 8 additions, 7 deletionscompiler/GHC/StgToJS/Object.hs
- compiler/GHC/Types/Basic.hs 1 addition, 1 deletioncompiler/GHC/Types/Basic.hs
- compiler/GHC/Types/FieldLabel.hs 1 addition, 3 deletionscompiler/GHC/Types/FieldLabel.hs
- compiler/GHC/Types/Name.hs 4 additions, 4 deletionscompiler/GHC/Types/Name.hs
- compiler/GHC/Utils/Binary.hs 275 additions, 96 deletionscompiler/GHC/Utils/Binary.hs
- utils/haddock 1 addition, 1 deletionutils/haddock
Loading
Please register or sign in to comment