1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
4 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
5 <title>The GHC Commentary - Primitives</title>
8 <body BGCOLOR="FFFFFF">
9 <h1>The GHC Commentary - Primitives</h1>
11 Most user-level Haskell types and functions provided by GHC (in
12 particular those from the Prelude and GHC's Prelude extensions) are
13 internally constructed from even more elementary types and functions.
14 Most notably, GHC understands a notion of <em>unboxed types,</em> which
15 are the Haskell representation of primitive bit-level integer, float,
16 etc. types (as opposed to their boxed, heap allocated counterparts) -
18 href="http://research.microsoft.com/Users/simonpj/Papers/unboxed-values.ps.Z">"Unboxed
19 Values as First Class Citizens."</a>
21 <h4>The Ultimate Source of Primitives</h4>
23 The hardwired types of GHC are brought into scope by the module
24 <code>PrelGHC</code>. This modules only exists in the form of a
25 handwritten interface file <a
26 href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/lib/std/PrelGHC.hi-boot"><code>PrelGHC.hi-boot</code>,</a>
27 which lists the type and function names, as well as instance
28 declarations. The actually types of these names as well as their
29 implementation is hardwired into GHC. Note that the names in this file
30 are z-encoded, and in particular, identifiers ending on <code>zh</code>
31 denote user-level identifiers ending in a hash mark (<code>#</code>),
32 which is used to flag unboxed values or functions operating on unboxed
33 values. For example, we have <code>Char#</code>, <code>ord#</code>, and
36 <h4>The New Primitive Definition Scheme</h4>
38 As of (about) the development version 4.11, the types and various
39 properties of primitive operations are defined in the file <a
40 href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/compiler/prelude/primops.txt"><code>primops.txt</code></a>
41 (Personally, I don't think that the <code>.txt</code> suffix is really
42 appropriate, as the file is used for automatic code generation).
45 href="http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/ghc/utils/genprimopcode/"><code>genprimopcode</code></a>
46 generates a series of Haskell files from <code>primops.txt</code>, which
47 encode the types and various properties of the primitive operations as
48 compiler internal data structures. These Haskell files are not complete
49 modules, but program fragments, which are included into compiler modules
50 during the GHC build process. The generated include files can be found
51 in the directory <code>fptools/ghc/compiler/</code> and carry names
52 matching the pattern <code>primop-*.hs-incl</code>. They are generate
53 during the execution of the <code>boot</code> target in the
54 <code>fptools/ghc/</code> directory. This scheme significantly
55 simplifies the maintenance of primitive operations.
57 As of development version 5.02, the <code>primops.txt</code> file also allows the
58 recording of documentation about intended semantics of the primitives. This can
59 be extracted into a latex document (or rather, into latex document fragments)
60 via an appropriate switch to <code>genprimopcode</code>. In particular, see <code>primops.txt</code>
61 for full details of how GHC is configured to cope with different machine word sizes.
64 Last modified: Wed Aug 8 19:29:12 EST 2001