# The GHC Commentary - Primitives

Most user-level Haskell types and functions provided by GHC (in particular those from the Prelude and GHC's Prelude extensions) are internally constructed from even more elementary types and functions. Most notably, GHC understands a notion of unboxed types, which are the Haskell representation of primitive bit-level integer, float, etc. types (as opposed to their boxed, heap allocated counterparts) - cf. "Unboxed Values as First Class Citizens."

#### The Ultimate Source of Primitives

The hardwired types of GHC are brought into scope by the module `PrelGHC`. This modules only exists in the form of a handwritten interface file `PrelGHC.hi-boot`, which lists the type and function names, as well as instance declarations. The actually types of these names as well as their implementation is hardwired into GHC. Note that the names in this file are z-encoded, and in particular, identifiers ending on `zh` denote user-level identifiers ending in a hash mark (`#`), which is used to flag unboxed values or functions operating on unboxed values. For example, we have `Char#`, `ord#`, and so on.

#### The New Primitive Definition Scheme

As of (about) the development version 4.11, the types and various properties of primitive operations are defined in the file `primops.txt.pp`. (Personally, I don't think that the `.txt` suffix is really appropriate, as the file is used for automatic code generation; the recent addition of `.pp` means that the file is now mangled by cpp.)

The utility `genprimopcode` generates a series of Haskell files from `primops.txt`, which encode the types and various properties of the primitive operations as compiler internal data structures. These Haskell files are not complete modules, but program fragments, which are included into compiler modules during the GHC build process. The generated include files can be found in the directory `fptools/ghc/compiler/` and carry names matching the pattern `primop-*.hs-incl`. They are generate during the execution of the `boot` target in the `fptools/ghc/` directory. This scheme significantly simplifies the maintenance of primitive operations.

As of development version 5.02, the `primops.txt` file also allows the recording of documentation about intended semantics of the primitives. This can be extracted into a latex document (or rather, into latex document fragments) via an appropriate switch to `genprimopcode`. In particular, see `primops.txt` for full details of how GHC is configured to cope with different machine word sizes.

Last modified: Mon Nov 26 18:03:16 EST 2001