HORIZON HASKELLDocslts/ghc-10.0.x04404a62026-10-19Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 04404a6 · 2026-10-19

Moduleghc-10.0.0.20260917GHC2024

GHC.Utils.Binary

Contents
  1. For writing instances
  2. Variable length encodings
  3. Fixed length encoding
  4. Lazy Binary I/O
  5. EnumBinary
  6. User data
  7. Binary Readers & Writers
  8. Tables
  9. String table ("dictionary")
  10. Generic deduplication table
  11. Newtype wrappers
  12. Newtypes for types that have canonically more than one valid encoding
  13. FingerprintWithValue
Synopsis
newtypenewtype Bin (a :: k)
#
Instances5Bounded, Eq, Ord, Show, Binary
  • Bounded (Bin a)Defined in ghc-10.0.0.20260917 · GHC.Utils.Binary
  • Eq (Bin a)Defined in ghc-10.0.0.20260917 · GHC.Utils.Binary
  • Ord (Bin a)Defined in ghc-10.0.0.20260917 · GHC.Utils.Binary
  • Show (Bin a)Defined in ghc-10.0.0.20260917 · GHC.Utils.Binary
  • Binary (Bin a)Defined in ghc-10.0.0.20260917 · GHC.Utils.Binary
datadata RelBin (a :: k)

Like a Bin but is used to store relative offset pointers. Relative offset pointers store a relative location, but also contain an anchor that allow to obtain the absolute offset.

Constructors

Instances4Bounded, Eq, Ord, Show
  • Bounded (RelBin a)Defined in ghc-10.0.0.20260917 · GHC.Utils.Binary
  • Eq (RelBin a)Defined in ghc-10.0.0.20260917 · GHC.Utils.Binary
  • Ord (RelBin a)Defined in ghc-10.0.0.20260917 · GHC.Utils.Binary
  • Show (RelBin a)Defined in ghc-10.0.0.20260917 · GHC.Utils.Binary
classclass Binary a where

Do not rely on instance sizes for general types, we use variable length encoding for many of them.

Methods

Instances310Binary, …
datadata ReadBinHandle

A read-only handle that can be used to deserialise binary data from a buffer.

The buffer is an unboxed binary array.

datadata WriteBinHandle

A write-only handle that can be used to serialise binary data into a buffer.

The buffer is an unboxed binary array.

Copy the BinBuffer to a new BinBuffer which is exactly the right size. This performs a copy of the underlying buffer. The buffer may be truncated if the offset is not at the end of the written output.

UserData is also discarded during the copy You should just use this when translating a Put handle into a Get handle.

valueforwardPutRel :: WriteBinHandle -> (b -> IO a) -> IO b -> IO (a, b)

forwardPutRel put_A put_B outputs A after B but allows A to be read before B by using a forward reference.

This forward reference is a relative offset that allows us to skip over the result of put_A.

For writing instances

Variable length encodings

Fixed length encoding

newtypenewtype FixedLengthEncoding a

Encode the argument in its full length. This is different from many default binary instances which make no guarantee about the actual encoding and might do things using variable length encoding.

Instances7Eq, Ord, Show, Binary, …

Lazy Binary I/O

EnumBinary

User data

datadata ReaderUserData

UserData required to deserialise symbols for interface files.

See Note [Binary UserData]

datadata WriterUserData

UserData required to serialise symbols for interface files.

See Note [Binary UserData]

Binary Readers & Writers

Tables

String table ("dictionary")

Generic deduplication table

datadata GenericSymbolTable (m :: Type -> Type)

The GenericSymbolTable stores a mapping from already seen elements to an index. If an element wasn't seen before, it is added to the mapping together with a fresh index.

GenericSymbolTable is a variant of a BinSymbolTable that is polymorphic in the table implementation. As such it can be used with any container that implements the TrieMap type class.

While GenericSymbolTable is similar to the BinSymbolTable, it supports storing tree-like structures such as Type and IfaceType more efficiently.

Constructors

Newtype wrappers

Newtypes for types that have canonically more than one valid encoding

datadata FullBinData

FullBinData stores a slice to a BinArray.

It requires less memory than ReadBinHandle, and can be constructed from a ReadBinHandle via freezeBinHandle and turned back into a ReadBinHandle using thawBinHandle. Additionally, the byte array slice can be put into a WriteBinHandle without extra conversions via putFullBinData.

Constructors

Instances2Eq, Ord

FingerprintWithValue

A wrapper which allows us to store a fingerprint and optionally the value which was used to create the fingerprint.

Instances3Functor, NFData, Binary