Update Binary serialization and extensible interface files
Motivation
The current Binary implementation unnecessarily exposes an exclusively IO interface, preventing a pure encode/decode. Without a pure decode, deserialization of optional fields in an extensible interface file is messy.
By hiding the data currently contained in the BinHandle type behind reader newtypes, the Binary class can present a pure interface to serialize/deserialize data, without leaking the mutable buffer.
Additionally, these readers should make it easier to generalise the inclusion of symbol tables and dictionaries that BinIface.putWithUserData and HieBin.writeHieFile use to serialize Name and FastString.
Proposal
Binary Improvements
-
Update Binaryto usePut/Getnewtypes containingReaderT IO, allowingencode/decodeto be written (!1960) -
Logic is almost entirely duplicated between ghc.BinIface.{readBinIface, writeBinIface},ghc.HieBin.{readHieFile, writeHieFile}, andhaddock.Haddock.InterfaceFile.{readInterfaceFile, writeInterfaceFile} -
With the buffer handle and IOhidden behind the readers, it will be significantly easier to switch out the implementation for one of the standard implementations. This was previously discussed in #3379 withbinary, andcerealis another option.NameandFastStringcomplicate the symmetry ofencode/decodefor lawful instances in these standard implementations, so the GHCBinaryclass can remain separate while borrowing the internals of the chosen implementation.
Edited by Simon Jakobi