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 Binary
to usePut
/Get
newtypes containingReaderT IO
, allowingencode
/decode
to 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 IO
hidden 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
, andcereal
is another option.Name
andFastString
complicate the symmetry ofencode
/decode
for lawful instances in these standard implementations, so the GHCBinary
class can remain separate while borrowing the internals of the chosen implementation.