Skip to content

Refactor the Binary serialisation interface

Hannes Siebenhandl requested to merge wip/fendor/ghc-iface-refact into master

Refactor the Binary serialisation interface

The end goal is to dynamically add deduplication tables for 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 providing 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).

In addition to this refactoring, we split UserData into ReaderUserData and WriterUserData, to avoid partial functions.

Bump haddock submodule to accommodate for UserData split.

Split BinHandle into ReadBinHandle and WriteBinHandle

A BinHandle contains too much information for reading data. For example, it needs to keep a FastMutInt and a IORef BinData, when the non-mutable variants would suffice.

Additionally, this change has the benefit that anyone can immediately tell whether the BinHandle is used for reading or writing.

Bump haddock submodule for BinHandle split.

This PR refactors the codebase to prepare !12371 (closed) and #24615 (closed)

Edited by Hannes Siebenhandl

Merge request reports