# Using GHC

## Options overview

GHC's behaviour is controlled by options, which for historical reasons are also sometimes referred to as command-line flags or arguments. Options can be specified in three ways:

### command-line arguments

An invocation of GHC takes the following form:

    ghc [argument...]

command-line arguments are either options or file names.

command-line options begin with `-`. They may not be grouped: `-vO` is different from `-v -O`. Options need not precede filenames: e.g., `ghc *.o -o foo`. All options are processed and then applied to all files; you cannot, for example, invoke `ghc -c -O1 Foo.hs -O2 Bar.hs` to apply different optimisation levels to the files `Foo.hs` and `Bar.hs`.

### command line options in source files

Sometimes it is useful to make the connection between a source file and the command-line options it requires quite tight. For instance, if a Haskell source file uses GHC extensions, it will always need to be compiled with the `-fglasgow-exts` option. Rather than maintaining the list of per-file options in a `Makefile`, it is possible to do this directly in the source file using the `OPTIONS_GHC` pragma
:

    {-# OPTIONS_GHC -fglasgow-exts #-}
    module X where
    ...

`OPTIONS_GHC` pragmas are only looked for at the top of your source files, upto the first (non-literate,non-empty) line not containing `OPTIONS_GHC`. Multiple `OPTIONS_GHC` pragmas are recognised. Do not put comments before, or on the same line as, the `OPTIONS_GHC` pragma.

Note that your command shell does not get to the source file options, they are just included literally in the array of command-line arguments the compiler maintains internally, so you'll be desperately disappointed if you try to glob etc. inside `OPTIONS_GHC`.

NOTE: the contents of OPTIONS_GHC are prepended to the command-line options, so you do have the ability to override OPTIONS_GHC settings via the command line.

It is not recommended to move all the contents of your Makefiles into your source files, but in some circumstances, the `OPTIONS_GHC` pragma is the Right Thing. (If you use `-keep-hc-file-too` and have OPTION flags in your module, the OPTIONS_GHC will get put into the generated .hc file).

### Setting options in GHCi

Options may also be modified from within GHCi, using the `:set` command. See for more details.

## Static, Dynamic, and Mode options

Each of GHC's command line options is classified as either static or dynamic or mode:

Mode flags

  For example, `--make` or `-E`. There may be only a single mode flag on the command line. The available modes are listed in .

Dynamic Flags

  Most non-mode flags fall into this category. A dynamic flag may be used on the command line, in a `GHC_OPTIONS` pragma in a source file, or set using `:set` in GHCi.

Static Flags

  A few flags are "static", which means they can only be used on the command-line, and remain in force over the entire GHC/GHCi run.

The flag reference tables () lists the status of each flag.

There are a few flags that are static except that they can also be used with GHCi's `:set` command; these are listed as “static/`:set`” in the table.

## Meaningful file suffixes

File names with “meaningful” suffixes (e.g., `.lhs` or `.o`) cause the “right thing” to happen to those files.

`.hs`

  A Haskell module.

`.lhs`

  A “literate Haskell” module.

`.hi`

  A Haskell interface file, probably compiler-generated.

`.hc`

  Intermediate C file produced by the Haskell compiler.

`.c`

  A C file not produced by the Haskell compiler.

`.s`

  An assembly-language source file, usually produced by the compiler.

`.o`

  An object file, produced by an assembler.

Files with other suffixes (or without suffixes) are passed straight to the linker.

## Modes of operation

GHC's behaviour is firstly controlled by a mode flag. Only one of these flags may be given, but it does not necessarily need to be the first option on the command-line. The available modes are:

    ghc
    	    ––interactive

  Interactive mode, which is also available as `ghci`. Interactive mode is described in more detail in .

    ghc
    	    ––make

  In this mode, GHC will build a multi-module Haskell program automatically, figuring out dependencies for itself. If you have a straightforward Haskell program, this is likely to be much easier, and faster, than using `make`. Make mode is described in .

    ghc
    	    –e expr

  Expression-evaluation mode. This is very similar to interactive mode, except that there is a single expression to evaluate (expr) which is given on the command line. See for more details.

    	    ghc

    	      -E
    	      -C
    	      -S
    	      -c

  This is the traditional batch-compiler mode, in which GHC can compile source files one at a time, or link objects together into an executable. This mode also applies if there is no other mode flag specified on the command line, in which case it means that the specified files should be compiled and then linked to form a program. See .

                ghc
    	    –M

  Dependency-generation mode. In this mode, GHC can be used to generate dependency information suitable for use in a `Makefile`. See .

                ghc
    	    ––mk-dll

  DLL-creation mode (Windows only). See .

### Using `ghc` `––make`

When given the `––make` option, GHC will build a multi-module Haskell program by following dependencies from a single root module (usually `Main`). For example, if your `Main` module is in a file called `Main.hs`, you could compile and link the program like this:

    ghc ––make Main.hs

The command line may contain any number of source file names or module names; GHC will figure out all the modules in the program by following the imports from these initial modules. It will then attempt to compile each module which is out of date, and finally if there is a `Main` module, the program will also be linked into an executable.

The main advantages to using `ghc ––make` over traditional `Makefile`s are:

- GHC doesn't have to be restarted for each compilation, which means it can cache information between compilations. Compiling a multi-module program with `ghc ––make` can be up to twice as fast as running `ghc` individually on each source file.

- You don't have to write a `Makefile`.

- GHC re-calculates the dependencies each time it is invoked, so the dependencies never get out of sync with the source.

Any of the command-line options described in the rest of this chapter can be used with `––make`, but note that any options you give on the command line will apply to all the source files compiled, so if you want any options to apply to a single source file only, you'll need to use an `OPTIONS_GHC` pragma (see ).

If the program needs to be linked with additional objects (say, some auxiliary C code), then the object files can be given on the command line and GHC will include them when linking the executable.

Note that GHC can only follow dependencies if it has the source file available, so if your program includes a module for which there is no source file, even if you have an object and an interface file for the module, then GHC will complain. The exception to this rule is for package modules, which may or may not have source files.

The source files for the program don't all need to be in the same directory; the `-i` option can be used to add directories to the search path (see ).

### Expression evaluation mode

This mode is very similar to interactive mode, except that there is a single expression to evaluate which is specified on the command line as an argument to the `-e` option:

    ghc -e expr

Haskell source files may be named on the command line, and they will be loaded exactly as in interactive mode. The expression is evaluated in the context of the loaded modules.

For example, to load and run a Haskell program containing a module `Main`, we might say

    ghc -e Main.main Main.hs

or we can just use this mode to evaluate expressions in the context of the `Prelude`:

    $ ghc -e "interact (unlines.map reverse.lines)"
    hello
    olleh

### Batch compiler mode

In batch mode, GHC will compile one or more source files given on the command line.

The first phase to run is determined by each input-file suffix, and the last phase is determined by a flag. If no relevant flag is present, then go all the way through linking. This table summarises:

Phase of the compilation system | Suffix saying “start here” | Flag saying “stop after” | (suffix of) output file
--- | --- | --- | ---
literate pre-processor | `.lhs` | - | `.hs`
C pre-processor (opt.) | `.hs` (with `-cpp`) | `-E` | `.hspp`
Haskell compiler | `.hs` | `-C`, `-S` | `.hc`, `.s`
C compiler (opt.) | `.hc` or `.c` | `-S` | `.s`
assembler | `.s` | `-c` | `.o`
linker | other | - | `a.out`

Thus, a common invocation would be:

    ghc -c Foo.hs

to compile the Haskell source file `Foo.hs` to an object file `Foo.o`.

Note: What the Haskell compiler proper produces depends on whether a native-code generator
is used (producing assembly language) or not (producing C). See for more details.

Note: C pre-processing is optional, the `-cpp`
flag turns it on. See for more details.

Note: The option `-E`
runs just the pre-processing passes of the compiler, dumping the result in a file. Note that this differs from the previous behaviour of dumping the file to standard output.

#### Overriding the default behaviour for a file

As described above, the way in which a file is processed by GHC depends on its suffix. This behaviour can be overriden using the `-x` option:

`-x` suffix

  Causes all files following this option on the command line to be processed as if they had the suffix suffix. For example, to compile a Haskell module in the file `M.my-hs`, use `ghc -c -x hs M.my-hs`.

## Help and verbosity options

`––help`
`-?`

  Cause GHC to spew a long usage message to standard output and then exit.

`-n`

  Does a dry-run, i.e. GHC goes through all the motions of compiling as normal, but does not actually run any external commands.

`-v`

  The `-v` option makes GHC verbose: it reports its version number and shows (on stderr) exactly how it invokes each phase of the compilation system. Moreover, it passes the `-v` flag to most phases; each reports its version number (and possibly some other information).

  Please, oh please, use the `-v` option when reporting bugs! Knowing that you ran the right bits in the right order is always the first thing we want to verify.

`-v` n

  To provide more control over the compiler's verbosity, the `-v` flag takes an optional numeric argument. Specifying `-v` on its own is equivalent to `-v3`, and the other levels have the following meanings:

  `-v0`

    Disable all non-essential messages (this is the default).

  `-v1`

    Minimal verbosity: print one line per compilation (this is the default when `––make` or `––interactive` is on).

  `-v2`

    Print the name of each compilation phase as it is executed. (equivalent to `-dshow-passes`).

  `-v3`

    The same as `-v2`, except that in addition the full command line (if appropriate) for each compilation phase is also printed.

  `-v4`

    The same as `-v3` except that the intermediate program representation after each compilation phase is also printed (excluding preprocessed and C/assembly files).

`-V`
`––version`

  Print a one-line string including GHC's version number.

`––numeric-version`

  Print GHC's numeric version number only.

`––print-libdir`

  Print the path to GHC's library directory. This is the top of the directory tree containing GHC's libraries, interfaces, and include files (usually something like `/usr/local/lib/ghc-5.04` on Unix). This is the value of `$libdir`
  in the package configuration file (see ).

`-ferror-spans`

  Causes GHC to emit the full source span of the syntactic entity relating to an error message. Normally, GHC emits the source location of the start of the syntactic entity only.

  For example:

      test.hs:3:6: parse error on input `where'

  becomes:

      test296.hs:3:6-10: parse error on input `where'

  And multi-line spans are possible too:

      test.hs:(5,4)-(6,7):
          Conflicting definitions for `a'
          Bound at: test.hs:5:4
                    test.hs:6:7
          In the binding group for: a, b, a

  Note that line numbers start counting at one, but column numbers start at zero. This choice was made to follow existing convention (i.e. this is how Emacs does it).

`-H` size

  Set the minimum size of the heap to size. This option is equivalent to `+RTS -Hsize`, see .

`-Rghc-timing`

  Prints a one-line summary of timing statistics for the GHC run. This option is equivalent to `+RTS -tstderr`, see .

&separate;

## Warnings and sanity-checking

GHC has a number of options that select which types of non-fatal error messages, otherwise known as warnings, can be generated during compilation. By default, you get a standard set of warnings which are generally likely to indicate bugs in your program. These are: `-fwarn-overlapping-patterns`, `-fwarn-deprecations`, `-fwarn-duplicate-exports`, `-fwarn-missing-fields`, and `-fwarn-missing-methods`. The following flags are simple ways to select standard “packages” of warnings:

`-W`:

  Provides the standard warnings plus `-fwarn-incomplete-patterns`, `-fwarn-unused-matches`, `-fwarn-unused-imports`, and `-fwarn-unused-binds`.

`-w`:

  Turns off all warnings, including the standard ones.

`-Wall`:

  Turns on all warning options.

`-Werror`:

  Makes any warning into a fatal error. Useful so that you don't miss warnings when doing batch compilation.

The full set of warning options is described below. To turn off any warning, simply give the corresponding `-fno-warn-...` option on the command line.

`-fwarn-deprecations`:

  Causes a warning to be emitted when a deprecated function or type is used. Entities can be marked as deprecated using a pragma, see .

`-fwarn-duplicate-exports`:

  Have the compiler warn about duplicate entries in export lists. This is useful information if you maintain large export lists, and want to avoid the continued export of a definition after you've deleted (one) mention of it in the export list.

  This option is on by default.

`-fwarn-hi-shadowing`:

  Causes the compiler to emit a warning when a module or interface file in the current directory is shadowing one with the same module name in a library or other directory.

`-fwarn-incomplete-patterns`:

  Similarly for incomplete patterns, the function `g` below will fail when applied to non-empty lists, so the compiler will emit a warning about this when `-fwarn-incomplete-patterns` is enabled.

      g [] = 2

  This option isn't enabled be default because it can be a bit noisy, and it doesn't always indicate a bug in the program. However, it's generally considered good practice to cover all the cases in your functions.

`-fwarn-incomplete-record-updates`:

  The function `f` below will fail when applied to `Bar`, so the compiler will emit a warning about this when `-fwarn-incomplete-record-updates` is enabled.

      data Foo = Foo { x :: Int }
               | Bar

      f :: Foo -> Foo
      f foo = foo { x = 6 }

  This option isn't enabled be default because it can be very noisy, and it often doesn't indicate a bug in the program.

`-fwarn-missing-fields`:

  This option is on by default, and warns you whenever the construction of a labelled field constructor isn't complete, missing initializers for one or more fields. While not an error (the missing fields are initialised with bottoms), it is often an indication of a programmer error.

`-fwarn-missing-methods`:

  This option is on by default, and warns you whenever an instance declaration is missing one or more methods, and the corresponding class declaration has no default declaration for them.

  The warning is suppressed if the method name begins with an underscore. Here's an example where this is useful:

      	      class C a where
      	        _simpleFn :: a -> String
      	        complexFn :: a -> a -> String
      	        complexFn x y = ... _simpleFn ...

  The idea is that: (a) users of the class will only call `complexFn`; never `_simpleFn`; and (b) instance declarations can define either `complexFn` or `_simpleFn`.
`-fwarn-missing-signatures`:

  If you would like GHC to check that every top-level function/value has a type signature, use the `-fwarn-missing-signatures` option. This option is off by default.

`-fwarn-name-shadowing`:

  This option causes a warning to be emitted whenever an inner-scope value has the same name as an outer-scope value, i.e. the inner value shadows the outer one. This can catch typographical errors that turn into hard-to-find bugs, e.g., in the inadvertent cyclic definition `let x = ... x ... in`.

  Consequently, this option does will complain about cyclic recursive definitions.

`-fwarn-orphans`:

  This option causes a warning to be emitted whenever the module contains an "orphan" instance declaration or rewrite rule. An instance declartion is an orphan if it appears in a module in which neither the class nor the type being instanced are declared in the same module. A rule is an orphan if it is a rule for a function declared in another module. A module containing any orphans is called an orphan module.

  The trouble with orphans is that GHC must pro-actively read the interface files for all orphan modules, just in case their instances or rules play a role, whether or not the module's interface would otherwise be of any use. Other things being equal, avoid orphan modules.

`-fwarn-overlapping-patterns`:

  By default, the compiler will warn you if a set of patterns are overlapping, i.e.,

      f :: String -> Int
      f []     = 0
      f (_:xs) = 1
      f "2"    = 2

  where the last pattern match in `f` won't ever be reached, as the second pattern overlaps it. More often than not, redundant patterns is a programmer mistake/error, so this option is enabled by default.

`-fwarn-simple-patterns`:

  Causes the compiler to warn about lambda-bound patterns that can fail, eg. `\(x:xs)->...`. Normally, these aren't treated as incomplete patterns by `-fwarn-incomplete-patterns`.

  ``Lambda-bound patterns'' includes all places where there is a single pattern, including list comprehensions and do-notation. In these cases, a pattern-match failure is quite legitimate, and triggers filtering (list comprehensions) or the monad `fail` operation (monads). For example:

      	      f :: [Maybe a] -> [a]
      	      f xs = [y | Just y <- xs]

  Switching on `-fwarn-simple-patterns` will elicit warnings about these probably-innocent cases, which is why the flag is off by default.

  The `deriving( Read )` mechanism produces monadic code with pattern matches, so you will also get misleading warnings about the compiler-generated code. (This is arguably a Bad Thing, but it's awkward to fix.)

`-fwarn-type-defaults`:

  Have the compiler warn/inform you where in your source the Haskell defaulting mechanism for numeric types kicks in. This is useful information when converting code from a context that assumed one default into one with another, e.g., the `default default' for Haskell 1.4 caused the otherwise unconstrained value `1` to be given the type `Int`, whereas Haskell 98 defaults it to `Integer`. This may lead to differences in performance and behaviour, hence the usefulness of being non-silent about this.

  This warning is off by default.

`-fwarn-unused-binds`:

  Report any function definitions (and local bindings) which are unused. For top-level functions, the warning is only given if the binding is not exported.

  A definition is regarded as "used" if (a) it is exported, or (b) it is mentioned in the right hand side of another definition that is used, or (c) the function it defines begins with an underscore. The last case provides a way to suppress unused-binding warnings selectively.

  Notice that a variable is reported as unused even if it appears in the right-hand side of another unused binding.

`-fwarn-unused-imports`:

  Report any modules that are explicitly imported but never used. However, the form `import M()` is never reported as an unused import, because it is a useful idiom for importing instance declarations, which are anonymous in Haskell.

`-fwarn-unused-matches`:

  Report all unused variables which arise from pattern matches, including patterns consisting of a single variable. For instance `f x y = []` would report `x` and `y` as unused. The warning is suppressed if the variable name begins with an underscore, thus:

      	       f _x = True

If you're feeling really paranoid, the `-dcore-lint` option
is a good choice. It turns on heavyweight intra-pass sanity-checking within GHC. (It checks GHC's sanity, not yours.)

&packages;

## Optimisation (code improvement)

The `-O*` options specify convenient “packages” of optimisation flags; the `-f*` options described later on specify individual optimisations to be turned on/off; the `-m*` options specify machine-specific optimisations to be turned on/off.

### `-O*`: convenient “packages” of optimisation flags.

There are many options that affect the quality of code produced by GHC. Most people only have a general goal, something like “Compile quickly” or “Make my program run like greased lightning.” The following “packages” of optimisations (or lack thereof) should suffice.

Note that higher optimisation levels cause more cross-module optimisation to be performed, which can have an impact on how much of your program needs to be recompiled when you change something. This is one reaosn to stick to no-optimisation when developing code.

No `-O*`-type option specified:

  This is taken to mean: “Please compile quickly; I'm not over-bothered about compiled-code quality.” So, for example: `ghc -c Foo.hs`

`-O0`:

  Means “turn off all optimisation”, reverting to the same settings as if no `-O` options had been specified. Saying `-O0` can be useful if eg. `make` has inserted a `-O` on the command line already.

`-O` or `-O1`:

  Means: “Generate good-quality code without taking too long about it.” Thus, for example: `ghc -c -O Main.lhs`

  `-O` currently also implies `-fvia-C`. This may change in the future.

`-O2`:

  Means: “Apply every non-dangerous optimisation, even if it means significantly longer compile times.”

  The avoided “dangerous” optimisations are those that can make runtime or space worse if you're unlucky. They are normally turned on or off individually.

  At the moment, `-O2` is unlikely to produce better code than `-O`.

`-Ofile <file>`:

  (NOTE: not supported since GHC 4.x. Please ask if you're interested in this.)

  For those who need absolute control over exactly what options are used (e.g., compiler writers, sometimes :-), a list of options can be put in a file and then slurped in with `-Ofile`.

  In that file, comments are of the `&num;`-to-end-of-line variety; blank lines and most whitespace is ignored.

  Please ask if you are baffled and would like an example of `-Ofile`!

We don't use a `-O*` flag for day-to-day work. We use `-O` to get respectable speed; e.g., when we want to measure something. When we want to go for broke, we tend to use `-O2 -fvia-C` (and we go for lots of coffee breaks).

The easiest way to see what `-O` (etc.) “really mean” is to run with `-v`, then stand back in amazement.

### `-f*`: platform-independent flags

These flags turn on and off individual optimisations. They are normally set via the `-O` options described above, and as such, you shouldn't need to set any of them explicitly (indeed, doing so could lead to unexpected results). However, there are one or two that may be of interest:

`-fexcess-precision`:

  When this option is given, intermediate floating point values can have a greater precision/range than the final type. Generally this is a good thing, but some programs may rely on the exact precision/range of `Float`/`Double` values and should not use this option for their compilation.

`-fignore-asserts`:

  Causes GHC to ignore uses of the function `Exception.assert` in source code (in other words, rewriting `Exception.assert p e` to `e` (see ). This flag is turned on by `-O`.

`-fno-cse`

  Turns off the common-sub-expression elimination optimisation. Can be useful if you have some `unsafePerformIO` expressions that you don't want commoned-up.

`-fno-strictness`

  Turns off the strictness analyser; sometimes it eats too many cycles.

`-fno-full-laziness`

  Turns off the full laziness optimisation (also known as let-floating). Full laziness increases sharing, which can lead to increased memory residency.

  NOTE: GHC doesn't implement complete full-laziness. When optimisation in on, and `-fno-full-laziness` is not given, some transformations that increase sharing are performed, such as extracting repeated computations from a loop. These are the same transformations that a fully lazy implementation would do, the difference is that GHC doesn't consistently apply full-laziness, so don't rely on it.

`-fno-state-hack`

  Turn off the "state hack" whereby any lambda with a `State#` token as argument is considered to be single-entry, hence it is considered OK to inline things inside it. This can improve performance of IO and ST monad code, but it runs the risk of reducing sharing.

`-funbox-strict-fields`:

  This option causes all constructor fields which are marked strict (i.e. “!”) to be unboxed or unpacked if possible. It is equivalent to adding an `UNPACK` pragma to every strict constructor field (see ).

  This option is a bit of a sledgehammer: it might sometimes make things worse. Selectively unboxing fields by using `UNPACK` pragmas might be better.

`-funfolding-update-in-place<n>`

  Switches on an experimental "optimisation". Switching it on makes the compiler a little keener to inline a function that returns a constructor, if the context is that of a thunk.

         x = plusInt a b

  If we inlined plusInt we might get an opportunity to use update-in-place for the thunk 'x'.
`-funfolding-creation-threshold<n>`:

  (Default: 45) Governs the maximum size that GHC will allow a function unfolding to be. (An unfolding has a “size” that reflects the cost in terms of “code bloat” of expanding that unfolding at at a call site. A bigger function would be assigned a bigger cost.)

  Consequences: (a) nothing larger than this will be inlined (unless it has an INLINE pragma); (b) nothing larger than this will be spewed into an interface file.

  Increasing this figure is more likely to result in longer compile times than faster code. The next option is more useful:

`-funfolding-use-threshold<n>`:

  (Default: 8) This is the magic cut-off figure for unfolding: below this size, a function definition will be unfolded at the call-site, any bigger and it won't. The size computed for a function depends on two things: the actual size of the expression minus any discounts that apply (see `-funfolding-con-discount`).

&phases;

## Using Concurrent Haskell

GHC supports Concurrent Haskell by default, without requiring a special option or libraries compiled in a certain way. To get access to the support libraries for Concurrent Haskell, just import `Control.Concurrent`. More information on Concurrent Haskell is provided in the documentation for that module.

The following RTS option(s) affect the behaviour of Concurrent Haskell programs:

`-Cs`

  Sets the context switch interval to s seconds. A context switch will occur at the next heap block allocation after the timer expires (a heap block allocation occurs every 4k of allocation). With `-C0` or `-C`, context switches will occur as often as possible (at every heap block allocation). By default, context switches occur every 20ms.

## Using SMP parallelism

GHC supports running Haskell programs in parallel on an SMP (symmetric multiprocessor).

There's a fine distinction between concurrency and parallelism: parallelism is all about making your program run faster by making use of multiple processors simultaneously. Concurrency, on the other hand, is a means of abstraction: it is a convenient way to structure a program that must respond to multiple asynchronous events.

However, the two terms are certainly related. By making use of multiple CPUs it is possible to run concurrent threads in parallel, and this is exactly what GHC's SMP parallelism support does. But it is also possible to obtain performance improvements with parallelism on programs that do not use concurrency. This section describes how to use GHC to compile and run parallel programs, in we desribe the language features that affect parallelism.

### Options to enable SMP parallelism

In order to make use of multiple CPUs, your program must be linked with the `-threaded` option (see ). Then, to run a program on multiple CPUs, use the RTS `-N` option:

`-Nx`

  Use x simultaneous threads when running the program. Normally x should be chosen to match the number of CPU cores on the machine. There is no means (currently) by which this value may vary after the program has started.

  For example, on a dual-core machine we would probably use `+RTS -N2 -RTS`.

  Whether hyperthreading cores should be counted or not is an open question; please feel free to experiment and let us know what results you find.

### Hints for using SMP parallelism

Add the `-sstderr` RTS option when running the program to see timing stats, which will help to tell you whether your program got faster by using more CPUs or not. If the user time is greater than the elapsed time, then the program used more than one CPU. You should also run the program without `-N` for comparison.

GHC's parallelism support is new and experimental. It may make your program go faster, or it might slow it down - either way, we'd be interested to hear from you.

One significant limitation with the current implementation is that the garbage collector is still single-threaded, and all execution must stop when GC takes place. This can be a significant bottleneck in a parallel program, especially if your program does a lot of GC. If this happens to you, then try reducing the cost of GC by tweaking the GC settings (): enlarging the heap or the allocation area size is a good start.

## Platform-specific Flags

Some flags only make sense for particular target platforms.

`-monly-[32]-regs`:

  (iX86 machines)
  GHC tries to “steal” four registers from GCC, for performance reasons; it almost always works. However, when GCC is compiling some modules with four stolen registers, it will crash, probably saying:

      Foo.hc:533: fixed or forbidden register was spilled.
      This may be due to a compiler bug or to impossible asm
      statements or clauses.

  Just give some registers back with `-monly-N-regs`. Try `3' first, then `2'. If `2' doesn't work, please report the bug to us.

&runtime;

## Generating and compiling External Core Files

GHC can dump its optimized intermediate code (said to be in “Core” format) to a file as a side-effect of compilation. Core files, which are given the suffix `.hcr`, can be read and processed by non-GHC back-end tools. The Core format is formally described in An External Representation for the GHC Core Language, and sample tools (in Haskell) for manipulating Core files are available in the GHC source distribution directory `/fptools/ghc/utils/ext-core`. Note that the format of `.hcr` files is different (though similar) to the Core output format generated for debugging purposes ().

The Core format natively supports notes which you can add to your source code using the `CORE` pragma (see ).

`-fext-core`

  Generate `.hcr` files.

GHC can also read in External Core files as source; just give the `.hcr` file on the command line, instead of the `.hs` or `.lhs` Haskell source. A current infelicity is that you need to give the `-fglasgow-exts` flag too, because ordinary Haskell 98, when translated to External Core, uses things like rank-2 types.

&debug; &flags;