0afffc5c38a9c8d210256265a70bd5feae553fb0
[ghc-hetmet.git] / ghc / docs / users_guide / how_to_run.lit
1 \section[invoking-GHC]{Invoking GHC: Command-line options}
2 \index{command-line options}
3 \index{options, GHC command-line}
4
5 Command-line arguments are either options or file names.
6
7 Command-line options begin with \tr{-}.  They may {\em not} be
8 grouped: \tr{-vO} is different from \tr{-v -O}.  Options need not
9 precede filenames: e.g., \tr{ghc *.o -o foo}.  All options are
10 processed and then applied to all files; you cannot, for example, invoke
11 \tr{ghc -c -O1 Foo.hs -O2 Bar.hs} to apply different optimisation
12 levels to the files \tr{Foo.hs} and \tr{Bar.hs}.  For conflicting
13 options, e.g., \tr{-c -S}, we reserve the right to do anything we
14 want.  (Usually, the last one applies.)
15
16 Options related to profiling, Glasgow extensions to Haskell (e.g.,
17 unboxed values), Concurrent and Parallel Haskell are described in
18 \sectionref{profiling}, \sectionref{glasgow-exts}, and
19 \sectionref{concurrent-and-parallel}, respectively.
20
21 %************************************************************************
22 %*                                                                      *
23 \subsection[file-suffixes]{Meaningful file suffixes}
24 \index{suffixes, file}
25 \index{file suffixes for GHC}
26 %*                                                                      *
27 %************************************************************************
28
29 File names with ``meaningful'' suffixes (e.g., \tr{.lhs} or \tr{.o})
30 cause the ``right thing'' to happen to those files.
31
32 \begin{description}
33 \item[\tr{.lhs}:]
34 \index{lhs suffix@.lhs suffix}
35 A ``literate Haskell'' module.
36
37 \item[\tr{.hs}:] 
38 A not-so-literate Haskell module.
39
40 \item[\tr{.hi}:]
41 A Haskell interface file, probably compiler-generated.
42
43 \item[\tr{.hc}:]
44 Intermediate C file produced by the Haskell compiler.
45
46 \item[\tr{.c}:]
47 A C~file not produced by the Haskell compiler.
48
49 % \item[\tr{.i}:]
50 % C code after it has be preprocessed by the C compiler (using the
51 % \tr{-E} flag).
52
53 \item[\tr{.s}:]
54 An assembly-language source file, usually
55 produced by the compiler.
56
57 \item[\tr{.o}:]
58 An object file, produced by an assembler.
59 \end{description}
60
61 Files with other suffixes (or without suffixes) are passed straight
62 to the linker.
63
64 %************************************************************************
65 %*                                                                      *
66 \subsection[options-help]{Help and verbosity options}
67 \index{help options (GHC)}
68 \index{verbose option (GHC)}
69 %*                                                                      *
70 %************************************************************************
71
72 A good option to start with is the \tr{-help} (or \tr{-?}) option.
73 \index{-help option}
74 \index{-? option}
75 GHC spews a long message to standard output and then exits.
76
77 The \tr{-v}\index{-v option} option makes GHC {\em verbose}: it
78 reports its version number and shows (on stderr) exactly how it invokes each 
79 phase of the compilation system.  Moreover, it passes
80 the \tr{-v} flag to most phases; each reports
81 its version number (and possibly some other information).
82
83 Please, oh please, use the \tr{-v} option when reporting bugs!
84 Knowing that you ran the right bits in the right order is always the
85 first thing we want to verify.
86
87 If you're just interested in the compiler version number, the
88 \tr{--version}\index{--version option} option prints out a
89 one-line string containing the requested info.
90
91 %************************************************************************
92 %*                                                                      *
93 \subsection[options-order]{Running the right phases in the right order}
94 \index{order of passes in GHC}
95 \index{pass ordering in GHC}
96 %*                                                                      *
97 %************************************************************************
98
99 The basic task of the \tr{ghc} driver is to run each input file
100 through the right phases (parsing, linking, etc.).
101
102 The first phase to run is determined by the input-file suffix, and the
103 last phase is determined by a flag.  If no relevant flag is present,
104 then go all the way through linking.  This table summarises:
105
106 \begin{tabular}{llll}
107 phase of the       & suffix saying & flag saying   & (suffix of) \\
108 compilation system & ``start here''& ``stop after''& output file \\ \hline
109
110 literate pre-processor & .lhs      & -      & - \\
111 C pre-processor (opt.) & -         & -      & - \\
112 Haskell compiler    & .hs    & -C, -S     & .hc, .s \\
113 C compiler (opt.)       & .hc or .c & -S            & .s  \\
114 assembler              & .s        & -c     & .o  \\
115 linker                 & other     & -      & a.out \\
116 \end{tabular}
117 \index{-C option}
118 \index{-S option}
119 \index{-c option}
120
121 Thus, a common invocation would be: \tr{ghc -c Foo.hs}
122
123 Note: What the Haskell compiler proper produces depends on whether a
124 native-code generator is used (producing assembly language) or not
125 (producing C).
126
127 %The suffix information may be overridden with a \tr{-lang <suf>}
128 %\index{-lang <suf> option} option.  This says: process all inputs
129 %files as if they had suffix \pl{<suf>}. [NOT IMPLEMENTED YET]
130
131 The option \tr{-cpp}\index{-cpp option} must be given for the C
132 pre-processor phase to be run, that is, the pre-processor will be run
133 over your Haskell source file before continuing.
134
135 The option \tr{-E}\index{-E option} runs just the pre-processing
136 passes of the compiler, outputting the result on stdout before
137 stopping. If used in conjunction with -cpp, the output is the
138 code blocks of the original (literal) source after having put it
139 through the grinder that is the C pre-processor. Sans \tr{-cpp}, the
140 output is the de-litted version of the original source.
141
142 The option \tr{-optcpp-E}\index{-optcpp-E option} runs just the
143 pre-processing stage of the C-compiling phase, sending the result to
144 stdout.  (For debugging or obfuscation contests, usually.)
145
146 %************************************************************************
147 %*                                                                      *
148 \subsection[options-optimise]{Optimisation (code improvement)}
149 \index{optimisation (GHC)}
150 \index{improvement, code (GHC)}
151 %*                                                                      *
152 %************************************************************************
153
154 The \tr{-O*} options specify convenient ``packages'' of optimisation
155 flags; the \tr{-f*} options described later on specify {\em individual}
156 optimisations to be turned on/off; the \tr{-m*} options specify {\em
157 machine-specific} optimisations to be turned on/off.
158
159 %----------------------------------------------------------------------
160 \subsubsection[optimise-pkgs]{\tr{-O*}: convenient ``packages'' of optimisation flags.}
161 \index{-O options (GHC)}
162
163 There are {\em many} options that affect the quality of code produced by
164 GHC.  Most people only have a general goal, something like ``Compile
165 quickly'' or ``Make my program run like greased lightning.''  The
166 following ``packages'' of optimisations (or lack thereof) should suffice.
167
168 Once you choose a \tr{-O*} ``package,'' stick with it---don't chop and
169 change.  Modules' interfaces {\em will} change with a shift to a new
170 \tr{-O*} option, and you may have to recompile a large chunk of all
171 importing modules before your program can again be run
172 safely\sectionref{recomp}.
173
174 \begin{description}
175 \item[No \tr{-O*}-type option specified:]
176 \index{-O* not specified}
177 This is taken to mean: ``Please compile quickly; I'm not over-bothered
178 about compiled-code quality.''  So, for example: \tr{ghc -c Foo.hs}
179
180 \item[\tr{-O} or \tr{-O1}:]
181 \index{-O option}
182 \index{-O1 option}
183 \index{optimise normally}
184 Means: ``Generate good-quality code without taking too long about it.''
185 Thus, for example: \tr{ghc -c -O Main.lhs}
186
187 \item[\tr{-O2}:]
188 \index{-O2 option}
189 \index{optimise aggressively}
190 Means: ``Apply every non-dangerous optimisation, even if it means
191 significantly longer compile times.''
192
193 The avoided ``dangerous'' optimisations are those that can make
194 runtime or space {\em worse} if you're unlucky.  They are
195 normally turned on or off individually.
196
197 At the moment, \tr{-O2} is {\em unlikely} to produce
198 better code than \tr{-O}.
199
200 % \item[\tr{-O0}:]
201 % \index{-O0 option}
202 % \index{optimise minimally}
203 % [``Oh zero''] Means: ``Turn {\em off} as many optimisations (e.g.,
204 % simplifications) as possible.''  This is the only optimisation level
205 % at which the GCC-register-trickery is turned off.  {\em You can't use
206 % it unless you have a suitably-built Prelude to match.} Intended for
207 % hard-core debugging.
208
209 \item[\tr{-fvia-C}:]
210 \index{-fvia-C option}
211 \index{-fvia-c option}
212 Compile via C, and don't use the native-code generator.
213 (There are many cases when GHC does this on its own.)  You might
214 pick up a little bit of speed by compiling via C.  If you use
215 \tr{_ccall_}s or \tr{_casm_}s, you probably {\em have to} use
216 \tr{-fvia-C}. 
217
218 The lower-case incantation, \tr{-fvia-c}, is synonymous.
219
220 \item[\tr{-O2-for-C}:]
221 \index{-O2-for-C option}
222 Says to run GCC with \tr{-O2}, which may be worth a few percent in
223 execution speed.  Don't forget \tr{-fvia-C}, lest you use the
224 native-code generator and bypass GCC altogether!
225
226 \item[\tr{-Onot}:]
227 \index{-Onot option}
228 \index{optimising, reset}
229 This option will make GHC ``forget'' any -Oish options it has seen
230 so far.  Sometimes useful; for example: \tr{make all EXTRA_HC_OPTS=-Onot}.
231
232 \item[\tr{-Ofile <file>}:]
233 \index{-Ofile <file> option}
234 \index{optimising, customised}
235 For those who need {\em absolute} control over {\em exactly} what
236 options are used (e.g., compiler writers, sometimes :-), a list of
237 options can be put in a file and then slurped in with \tr{-Ofile}.
238
239 In that file, comments are of the \tr{#}-to-end-of-line variety; blank
240 lines and most whitespace is ignored.
241
242 Please ask if you are baffled and would like an example of \tr{-Ofile}!
243 \end{description}
244
245 At Glasgow, we don't use a \tr{-O*} flag for day-to-day work.  We use
246 \tr{-O} to get respectable speed; e.g., when we want to measure
247 something.  When we want to go for broke, we tend to use
248 \tr{-O -fvia-C -O2-for-C} (and we go for lots of coffee breaks).
249
250 %Here is a table to summarise whether pragmatic interface information
251 %is used or not, whether the native-code generator is used (if
252 %available), and whether we use GCC register tricks (for speed!) on the
253 %generated C code:
254 %
255 %\begin{tabular}{lccl}
256 %\tr{-O*}    & Interface & Native code & `Registerised' C \\
257 %            & pragmas?  & (if avail.) & (if avail.) \\ \hline
258 %%
259 %\pl{<none>} & no        & yes         & yes, only if \tr{-fvia-C} \\
260 %\tr{-O,-O1} & yes       & yes         & yes, only if \tr{-fvia-C} \\
261 %\tr{-O2}    & yes       & no         & yes \\
262 %\tr{-Ofile} & yes      & yes         & yes, only if \tr{-fvia-C} \\
263 %\end{tabular}
264
265 The easiest way to see what \tr{-O} (etc) ``really mean'' is to run
266 with \tr{-v}, then stand back in amazement.
267 Alternatively, just look at the
268 \tr{@HsC_minus<blah>} lists in the \tr{ghc} driver script.
269
270 %----------------------------------------------------------------------
271 \subsubsection{\tr{-f*}: platform-independent flags}
272 \index{-f* options (GHC)}
273 \index{-fno-* options (GHC)}
274
275 Flags can be turned {\em off} individually.  (NB: I hope
276 you have a good reason for doing this....) To turn off the \tr{-ffoo}
277 flag, just use the \tr{-fno-foo} flag.\index{-fno-<opt> anti-option}
278 So, for example, you can say
279 \tr{-O2 -fno-strictness}, which will then drop out any running of the
280 strictness analyser.
281
282 The options you are most likely to want to turn off are:
283 \tr{-fno-strictness}\index{-fno-strictness option} (strictness
284 analyser [because it is sometimes slow]),
285 \tr{-fno-specialise}\index{-fno-specialise option} (automatic
286 specialisation of overloaded functions [because it makes your code
287 bigger]) [US spelling also accepted],
288 and
289 \tr{-fno-foldr-build}\index{-fno-foldr-build option}.
290
291 Should you wish to turn individual flags {\em on}, you are advised to
292 use the \tr{-Ofile} option, described above.  Because the order in
293 which optimisation passes are run is sometimes crucial, it's quite
294 hard to do with command-line options.
295
296 Here are some ``dangerous'' optimisations you {\em might} want to try:
297 \begin{description}
298 %------------------------------------------------------------------
299 \item[\tr{-funfolding-creation-threshold<n>}:]
300 (Default: 30) By raising or lowering this number, you can raise or
301 lower the amount of pragmatic junk that gets spewed into interface
302 files.  (An unfolding has a ``size'' that reflects the cost in terms
303 of ``code bloat'' of expanding that unfolding in another module.  A
304 bigger Core expression would be assigned a bigger cost.)
305
306 \item[\tr{-funfolding-use-threshold<n>}:]
307 (Default: 3) By raising or lowering this number, you can make the
308 compiler more or less keen to expand unfoldings.
309
310 OK, folks, these magic numbers `30' and `3' are mildly arbitrary; they
311 are of the ``seem to be OK'' variety.  The `3' is the more critical
312 one; it's what determines how eager GHC is about expanding unfoldings.
313
314 \item[\tr{-funfolding-override-threshold<n>}:]
315 (Default: 8) [Pretty obscure]
316 When deciding what unfoldings from a module should be made available
317 to the rest of the world (via this module's interface), the compiler
318 normally likes ``small'' expressions.
319
320 For example, if it sees \tr{foo = bar}, it will decide that the very
321 small expression \tr{bar} is a great unfolding for \tr{foo}.  But if
322 \tr{bar} turns out to be \tr{(True,False,True)}, we would probably
323 prefer {\em that} for the unfolding for \tr{foo}.
324
325 Should we ``override'' the initial small unfolding from \tr{foo=bar}
326 with the bigger-but-better one?  Yes, if the bigger one's ``size'' is
327 still under the ``override threshold.''  You can use this flag to
328 adjust this threshold (why, I'm not sure).
329
330 % \item[\tr{-fliberated-case-threshold<n>}:]
331 % (Default: 12) [Vastly obscure: NOT IMPLEMENTED YET]
332 % ``Case liberation'' lifts evaluation out of recursive functions; it
333 % does this by duplicating code.  Done without constraint, you can get
334 % serious code bloat; so we only do it if the ``size'' of the duplicated
335 % code is smaller than some ``threshold.''  This flag can fiddle that
336 % threshold.
337
338 \item[\tr{-fsemi-tagging}:]
339 This option (which {\em does not work} with the native-code generator)
340 tells the compiler to add extra code to test for already-evaluated
341 values.  You win if you have lots of such values during a run of your
342 program, you lose otherwise.  (And you pay in extra code space.)
343
344 We have not played with \tr{-fsemi-tagging} enough to recommend it.
345 (For all we know, it doesn't even work anymore...  Sigh.)
346 \end{description}
347
348 %----------------------------------------------------------------------
349 % \subsubsection[optimise-simplifier]{Controlling ``simplification'' in the Haskell compiler.}
350 %
351 %Almost everyone turns program transformation
352 % (a.k.a. ``simplification'') on/off via one of the ``packages'' above,
353 %but you can exert absolute control if you want to.  Do a \tr{ghc -v -O ...},
354 %and you'll see there are plenty of knobs to turn!
355 %
356 %The Core-to-Core and STG-to-STG passes can be run multiple times, and
357 %in varying orders (though you may live to regret it).  The on-or-off
358 %global flags, however, are simply, well, on or off.
359 %
360 %The best way to give an exact list of options is the \tr{-Ofile}
361 %option, described elsewhere.
362 %
363 % [Check out \tr{ghc/compiler/simplCore/SimplCore.lhs} and
364 %\tr{simplStg/SimplStg.lhs} if you {\em really} want to see every
365 %possible Core-to-Core and STG-to-STG pass, respectively.  The
366 %on-or-off global flags that effect what happens {\em within} one of
367 %these passes are defined by the \tr{GlobalSwitch} datatype in
368 %\tr{compiler/main/CmdLineOpts.lhs}.]
369
370 %----------------------------------------------------------------------
371 \subsubsection{\tr{-m*}: platform-specific flags}
372 \index{-m* options (GHC)}
373 \index{platform-specific options}
374 \index{machine-specific options}
375
376 Some flags only make sense for particular target platforms.
377
378 \begin{description}
379 \item[\tr{-mv8}:]
380 (SPARC machines)\index{-mv8 option (SPARC only)}
381 Means to pass the like-named option to GCC; it says to use the
382 Version 8 SPARC instructions, notably integer multiply and divide.
383 The similiar \tr{-m*} GCC options for SPARC also work, actually.
384
385 \item[\tr{-mlong-calls}:]
386 (HPPA machines)\index{-mlong-calls option (HPPA only)}
387 Means to pass the like-named option to GCC.  Required for Very Big
388 modules, maybe.  (Probably means you're in trouble...)
389
390 \item[\tr{-monly-[32]-regs}:]
391 (iX86 machines)\index{-monly-N-regs option (iX86 only)}
392 GHC tries to ``steal'' four registers from GCC, for performance
393 reasons; it almost always works.  However, when GCC is compiling some
394 modules with four stolen registers, it will crash, probably saying:
395 \begin{verbatim}
396 Foo.hc:533: fixed or forbidden register was spilled.
397 This may be due to a compiler bug or to impossible asm
398 statements or clauses.
399 \end{verbatim}
400 Just give some registers back with \tr{-monly-N-regs}.  Try `3' first,
401 then `2'.  If `2' doesn't work, please report the bug to us.
402 \end{description}
403
404 %----------------------------------------------------------------------
405 \subsubsection[optimise-C-compiler]{Code improvement by the C compiler.}
406 \index{optimisation by GCC}
407 \index{GCC optimisation}
408
409 The C~compiler (GCC) is run with \tr{-O} turned on.  (It has
410 to be, actually).
411
412 If you want to run GCC with \tr{-O2}---which may be worth a few
413 percent in execution speed---you can give a
414 \tr{-O2-for-C}\index{-O2-for-C option} option.
415
416 %If you are brave or foolish, you might want to omit some checking code
417 % (e.g., for stack-overflow checks), as sketched in
418 %\sectionref{omit-checking}.
419
420 %************************************************************************
421 %*                                                                      *
422 \subsection[options-sanity]{Warnings and sanity-checking}
423 \index{sanity-checking options}
424 \index{warnings}
425 %*                                                                      *
426 %************************************************************************
427
428 GHC has a selection of options that select which types of non-fatal
429 error messages, otherwise known as warnings, can be generated during
430 compilation.  By default, you get a standard set of warnings which are
431 generally likely to indicate bugs in your program.  These are:
432 \tr{-fwarn-overlpapping-patterns} and \tr{-fwarn-missing-methods}.
433 The following flags are simple ways to select standard ``packages'' of
434 warnings:
435
436 \begin{description}
437
438 \item[\tr{-Wnot}:]
439 \index{-Wnot option}
440
441 Turns off all warnings, including the standard ones.
442
443 \item[\tr{-w}:]
444 \index{-w option}
445
446 Synonym for \tr{-Wnot}.
447
448 \item[\tr{-W}:]
449 \index{-W option}
450
451 Provides the standard warnings plus \tr{-fwarn-incomplete-patterns}
452 and \tr{-fwarn-unused-names}.
453
454 \item[\tr{-Wall}:]
455 \index{-Wall option}
456
457 Turns on all warning options.
458
459 \end{description}
460
461 The full set of warning options is described below.  To turn off any
462 warning, simply give the corresponding \tr{-fno-warn-...} option on
463 the command line.
464
465 \begin{description}
466
467 \item[\tr{-fwarn-name-shadowing}:] 
468 \index{-fwarn-name-shadowing option}
469 \index{shadowing, warning}
470
471 This option causes a warning to be emitted whenever an inner-scope
472 value has the same name as an outer-scope value, i.e. the inner value
473 shadows the outer one.  This can catch typographical errors that turn
474 into hard-to-find bugs, e.g., in the inadvertent cyclic definition
475 \tr{let x = ... x ... in}.
476
477 Consequently, this option does {\em not} allow cyclic recursive
478 definitions.
479
480 \item[\tr{-fwarn-overlapping-patterns}:]
481 \index{-fwarn-overlapping-patterns option}
482 \index{overlapping patterns, warning}
483 \index{patterns, overlapping}
484
485 By default, the compiler will warn you if a set of patterns are either
486 incomplete (i.e., you're only matching on a subset of an algebraic
487 data type's constructors), or overlapping, i.e.,
488
489 \begin{verbatim}
490 f :: String -> Int
491 f []     = 0
492 f (_:xs) = 1
493 f "2"    = 2
494
495 g [] = 2
496 \end{verbatim}
497
498 where the last pattern match in \tr{f} won't ever be reached, as the
499 second pattern overlaps it. More often than not, redundant patterns
500 is a programmer mistake/error, so this option is enabled by default.
501
502 \item[\tr{-fwarn-incomplete-patterns}:]
503 \index{-fwarn-incomplete-patterns option}
504 \index{incomplete patterns, warning}
505 \index{patterns, incomplete}
506
507 Similarly for incomplete patterns, the function \tr{g} will fail when
508 applied to non-empty lists, so the compiler will emit a warning about
509 this when this option is enabled.
510
511 \item[\tr{-fwarn-missing-methods}:]
512 \index{-fwarn-missing-methods option}
513 \index{methods, missing}
514
515 This option is on by default, and warns you whenever an instance
516 declaration is missing one or more methods, and the corresponding
517 class declaration has no default declaration for them.
518
519 \item[\tr{-fwarn-unused-names}:]
520 \index{-fwarn-unused-names}
521 Have the renamer report which locally defined names are not
522 used/exported.  This option is not currently supported.
523
524 \item[\tr{-fwarn-duplicate-exports}:]
525 \index{-fwarn-duplicate-exports option}
526 \index{export lists, duplicates}
527
528 Have the compiler warn about duplicate entries in export lists. This
529 is useful information if you maintain large export lists, and want to
530 avoid the continued export of a definition after you've deleted (one)
531 mention of it in the export list.
532
533 This option is on by default.
534
535 \end{description}
536
537 If you would like GHC to check that every top-level value has a type
538 signature, use the \tr{-fsignatures-required}
539 option.\index{-fsignatures-required option}
540
541 If you're feeling really paranoid, the \tr{-dcore-lint}
542 option\index{-dcore-lint option} is a good choice.  It turns on
543 heavyweight intra-pass sanity-checking within GHC.  (It checks GHC's
544 sanity, not yours.)
545
546 %************************************************************************
547 %*                                                                      *
548 \subsection[options-output]{Re-directing the compilation output(s)}
549 \index{output-directing options}
550 %*                                                                      *
551 %************************************************************************
552
553 When compiling a Haskell module, GHC may produce several files of
554 output (usually two).
555
556 One file is usually an {\em interface file}.  The name of the
557 interface file follows the Haskell {\em module} name, i.e., if
558 compiling \tr{bar/Foo.hs}, and it implements \tr{module Bar ...}, the
559 interface file would normally be \tr{bar/Bar.hi}.  
560
561 The interface output may be directed to another file
562 \tr{bar2/Wurble.iface} with the option \tr{-ohi
563 bar2/Wurble.iface}\index{-ohi <file> option} (not recommended).
564
565 NOTE: Having the name of the interface file follow the module name
566 and not the file name, means that working with tools such as
567 \tr{make(1)} become harder. \tr{make} implicitly assumes that any
568 output files produced by processing a translation unit will have file
569 names that can be derived from the file name of the translation unit.
570 For instance, pattern rules becomes unusable.
571
572 To avoid generating an interface file at all, use a \tr{-nohi}
573 option.\index{-nohi option}
574
575 The compiler does not overwrite an existing \tr{.hi} interface file if
576 the new one is byte-for-byte the same as the old one; this is friendly to
577 \tr{make}.  When an interface does change, it is often enlightening to
578 be informed.  The \tr{-hi-diffs}\index{-hi-diffs option} option will
579 make \tr{ghc} run \tr{diff} on the old and new \tr{.hi} files. You can
580 also record the difference in the interface file itself, the
581 \tr{-keep-hi-diffs}\index{-keep-hi-diffs} option takes care of that.
582
583 The \tr{.hi} files from GHC 2.xx contain ``usage'' information which
584 changes often and uninterestingly.  If you really want to see these
585 changes reported, you need to use the
586 \tr{-hi-diffs-with-usages}\index{-hi-diffs-with-usages option} option.
587
588 GHC's non-interface output normally goes into a \tr{.hc}, \tr{.o},
589 etc., file, depending on the last-run compilation phase.  The option
590 \tr{-o foo}\index{-o option} re-directs the output of that last-run
591 phase to file \tr{foo}.
592
593 Note: this ``feature'' can be counterintuitive:
594 \tr{ghc -C -o foo.o foo.hs} will put the intermediate C code in the
595 file \tr{foo.o}, name notwithstanding!
596
597 EXOTICA: But the \tr{-o} option isn't of much use if you have {\em
598 several} input files... Non-interface output files are normally put
599 in the same directory as their corresponding input file came from.
600 You may specify that they be put in another directory using the
601 \tr{-odir <dir>}\index{-odir <dir> option} (the ``Oh, dear'' option).
602 For example:
603
604 \begin{verbatim}
605 % ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch`
606 \end{verbatim}
607
608 The output files, \tr{Foo.o}, \tr{Bar.o}, and \tr{Bumble.o} would be
609 put into a subdirectory named after the architecture of the executing
610 machine (\tr{sun4}, \tr{mips}, etc).  The directory must already
611 exist; it won't be created.
612
613 Note that the \tr{-odir} option does {\em not} affect where the
614 interface files are put.  In the above example, they would still be
615 put in \tr{parse/Foo.hi}, \tr{parse/Bar.hi}, and
616 \tr{gurgle/Bumble.hi}.
617
618 MORE EXOTICA: The \tr{-osuf <suffix>}\index{-osuf <suffix> option}
619 will change the \tr{.o} file suffix for object files to whatever
620 you specify.  (We use this in compiling the prelude.)
621
622 Similarly, the \tr{-hisuf <suffix>}\index{-hisuf <suffix> option} will
623 change the \tr{.hi} file suffix for non-system interface files.  This
624 can be useful when you are trying to compile a program several ways,
625 all in the same directory.  The suffix given is used for {\em all}
626 interfaces files written, {\em and} for all non-system interface files
627 that your read.
628
629 The \tr{-hisuf}/\tr{-osuf} game is useful if you want to compile a
630 program with both GHC and HBC (say) in the same directory.  Let HBC
631 use the standard \tr{.hi}/\tr{.o} suffixes; add
632 \tr{-hisuf g_hi -osuf g_o} to your \tr{make} rule for GHC compiling...
633
634 NB: {\em A change from 0.26 and before:} Before, you might have said
635 \tr{-hisuf _g.hi -osuf _g.o}; now, the \tr{.} is assumed and you
636 specify what comes {\em after} it.  (This is a more portable solution
637 for the long term.)
638
639 % THIS SHOULD HAPPEN AUTOMAGICALLY:
640 % If you want to change the suffix looked for on system-supplied
641 % interface files (notably the \tr{Prelude.hi} file), use the
642 % \tr{-hisuf-prelude <suffix>}\index{-hisuf-prelude <suffix> option}
643 % option.  (This may be useful if you've built GHC in various funny
644 % ways, and you are running tests in even more funny ways.  It happens.)
645
646 FURTHER EXOTICA: If you are doing a normal \tr{.hs}-to-\tr{.o} compilation
647 but would like to hang onto the intermediate \tr{.hc} C file, just
648 throw in a \tr{-keep-hc-file-too} option\index{-keep-hc-file-too option}.
649 If you would like to look at the assembler output, toss in a
650 \tr{-keep-s-file-too},\index{-keep-hc-file-too option} too.
651
652 SAVING GHC STDERR OUTPUT: Sometimes, you may cause GHC to be rather
653 chatty on standard error; with \tr{-fshow-import-specs}, for example.
654 You can instruct GHC to {\em append} this output to a particular log
655 file with a \tr{-odump <blah>}\index{-odump <blah> option} option.
656
657 TEMPORARY FILES: If you have trouble because of running out of space
658 in \tr{/tmp/} (or wherever your installation thinks temporary files
659 should go), you may use the \tr{-tmpdir <dir>}\index{-tmpdir <dir> option}
660 option to specify an alternate directory.  For example, \tr{-tmpdir .}
661 says to put temporary files in the current working directory.
662
663 BETTER IDEA FOR TEMPORARY FILES: Use your \tr{TMPDIR} environment
664 variable.\index{TMPDIR environment variable}  Set it to the name of
665 the directory where temporary files should be put.  GCC and other
666 programs will honour the \tr{TMPDIR} variable as well.
667
668 EVEN BETTER IDEA: Set the \tr{TMPDIR} variable when building
669 GHC, and never worry about \tr{TMPDIR} again. (see the build
670 documentation).
671
672 %************************************************************************
673 %*                                                                      *
674 \subsection[options-finding-imports-etc]{For finding interface files, etc.}
675 \index{interface files, finding them}
676 \index{finding interface files}
677 %*                                                                      *
678 %************************************************************************
679
680 In your program, you import a module \tr{Foo} by saying
681 \tr{import Foo}.  GHC goes looking for an interface file, \tr{Foo.hi}.
682 It has a builtin list of directories (notably including \tr{.}) where
683 it looks.
684
685 The \tr{-i<dirs>} option\index{-i<dirs> option} prepends a
686 colon-separated list of \tr{dirs} to the ``import directories'' list.
687
688 A plain \tr{-i} resets the ``import directories'' list back to nothing.
689
690 GHC normally imports \tr{Prelude.hi} files for you.  If you'd rather
691 it didn't, then give it a \tr{-fno-implicit-prelude}
692 option\index{-fno-implicit-prelude option}.  You are unlikely to get
693 very far without a Prelude, but, hey, it's a free country.
694
695 If you are using a system-supplied non-Prelude library (e.g., the HBC
696 library), just use a \tr{-syslib hbc}\index{-syslib <lib> option}
697 option (for example).  The right interface files should then be
698 available.
699
700 Once a Haskell module has been compiled to C (\tr{.hc} file), you may
701 wish to specify where GHC tells the C compiler to look for \tr{.h}
702 files.  (Or, if you are using the \tr{-cpp} option\index{-cpp option},
703 where it tells the C pre-processor to look...)  For this purpose, use
704 a \tr{-I<dir>}\index{-I<dir> option} in the usual C-ish way.
705
706 Pragmas: Interface files are normally jammed full of
707 compiler-produced {\em pragmas}, which record arities, strictness
708 info, etc.  If you think these pragmas are messing you up (or you are
709 doing some kind of weird experiment), you can tell GHC to ignore them
710 with the \tr{-fignore-interface-pragmas}\index{-fignore-interface-pragmas option}
711 option.
712
713 When compiling without optimisations on, the compiler is extra-careful
714 about not slurping in data constructors and instance declarations that
715 it will not need. If you believe it is getting it wrong and not
716 importing stuff which you think it should, this optimisation can be
717 turned off with \tr{-fno-prune-tydecls} and \tr{-fno-prune-instdecls}.
718 \index{-fno-prune-tydecls option}\index{-fno-prune-instdecls}
719
720 See also \sectionref{options-linker}, which describes how the linker
721 finds standard Haskell libraries.
722
723 %************************************************************************
724 %*                                                                      *
725 %\subsection[options-names]{Fiddling with namespaces}
726 %*                                                                      *
727 %************************************************************************
728
729 %-split-objs and -fglobalise-toplev-names.  You don't need them and you
730 %don't want to know; used for the prelude (ToDo).
731
732 %************************************************************************
733 %*                                                                      *
734 \subsection[options-CPP]{Related to the C pre-processor}
735 \index{C pre-processor options}
736 \index{pre-processor (cpp) options}
737 %*                                                                      *
738 %************************************************************************
739
740 The C pre-processor \tr{cpp} is run over your Haskell code only if the
741 \tr{-cpp} option \index{-cpp option} is given.  Unless you are
742 building a large system with significant doses of conditional
743 compilation, you really shouldn't need it.
744 \begin{description}
745 \item[\tr{-D<foo>}:]
746 \index{-D<name> option}
747 Define macro \tr{<foo>} in the usual way.  NB: does {\em not} affect
748 \tr{-D} macros passed to the C~compiler when compiling via C!  For
749 those, use the \tr{-optc-Dfoo} hack...
750
751 \item[\tr{-U<foo>}:]
752 \index{-U<name> option}
753 Undefine macro \tr{<foo>} in the usual way.
754
755 \item[\tr{-I<dir>}:]
756 \index{-I<dir> option}
757 Specify a directory in which to look for \tr{#include} files, in
758 the usual C way.
759 \end{description}
760
761 The \tr{ghc} driver pre-defines several macros:
762 \begin{description}
763 \item[\tr{__HASKELL1__}:]
764 \index{__HASKELL1__ macro}
765 If defined to $n$, that means GHC supports the
766 Haskell language defined in the Haskell report version $1.n$.
767 Currently 4.
768
769 NB: This macro is set both when pre-processing Haskell source and
770 when pre-processing generated C (\tr{.hc}) files.
771
772 % If you give the \tr{-fhaskell-1.3} flag\index{-fhaskell-1.3 option},
773 % then \tr{__HASKELL1__} is set to 3.  Obviously.
774
775 \item[\tr{__GLASGOW_HASKELL__}:]
776 \index{__GLASGOW_HASKELL__ macro}
777 For version $n$ of the GHC system, this will be \tr{#define}d to
778 $100 \times n$.  So, for version~2.02, it is 202.
779
780 This macro is {\em only} set when pre-processing Haskell source.
781 ({\em Not} when pre-processing generated C.)
782
783 With any luck, \tr{__GLASGOW_HASKELL__} will be undefined in all other
784 implementations that support C-style pre-processing.
785
786 (For reference: the comparable symbols for other systems are:
787 \tr{__HUGS__} for Hugs and \tr{__HBC__} for Chalmers.)
788
789 \item[\tr{__CONCURRENT_HASKELL__}:]
790 \index{__CONCURRENT_HASKELL__ macro}
791 Only defined when \tr{-concurrent} is in use!
792 This symbol is defined when pre-processing Haskell (input) and
793 pre-processing C (GHC output).
794
795 \item[\tr{__PARALLEL_HASKELL__}:]
796 \index{__PARALLEL_HASKELL__ macro}
797 Only defined when \tr{-parallel} is in use!  This symbol is defined when
798 pre-processing Haskell (input) and pre-processing C (GHC output).
799 \end{description}
800
801 Options other than the above can be forced through to the C
802 pre-processor with the \tr{-opt} flags (see
803 \sectionref{forcing-options-through}).
804
805 A small word of warning: \tr{-cpp} is not friendly to ``string
806 gaps''.\index{-cpp vs string gaps}\index{string gaps vs -cpp}.  In
807 other words, strings such as the following:
808
809 \begin{verbatim}
810         strmod = "\
811         \ p \
812         \ "
813 \end{verbatim}
814
815 don't work with \tr{-cpp}; \tr{/usr/bin/cpp} elides the
816 backslash-newline pairs.
817
818 However, it appears that if you add a space at the end of the line,
819 then \tr{cpp} (at least GNU \tr{cpp} and possibly other \tr{cpp}s)
820 leaves the backslash-space pairs alone and the string gap works as
821 expected.
822
823 %************************************************************************
824 %*                                                                      *
825 \subsection[options-C-compiler]{Options affecting the C compiler (if applicable)}
826 \index{include-file-option}
827 \index{C compiler options}
828 \index{GCC options}
829 %*                                                                      *
830 %************************************************************************
831
832 At the moment, quite a few common C-compiler options are passed on
833 quietly to the C compilation of Haskell-compiler-generated C files.
834 THIS MAY CHANGE.  Meanwhile, options so sent are:
835
836 \begin{tabular}{ll}
837 \tr{-Wall}      & get all warnings from GCC \\
838 \tr{-ansi}      & do ANSI C (not K\&R) \\
839 \tr{-pedantic}  & be so\\
840 \tr{-dgcc-lint} & (hack) short for ``make GCC very paranoid''\\
841 \end{tabular}
842 \index{-Wall option (for GCC)}
843 \index{-ansi option (for GCC)}
844 \index{-pedantic option (for GCC)}
845 \index{-dgcc-lint option (GCC paranoia)}
846
847 If you are compiling with lots of \tr{ccalls}, etc., you may need to
848 tell the C~compiler about some \tr{#include} files.  There is no real
849 pretty way to do this, but you can use this hack from the
850 command-line:
851 \begin{verbatim}
852 % ghc -c '-#include <X/Xlib.h>' Xstuff.lhs
853 \end{verbatim}
854
855
856 %************************************************************************
857 %*                                                                      *
858 %\subsection[options-native-code]{Options affecting the native-code generator(s)}
859 %*                                                                      *
860 %************************************************************************
861
862 %The only option is to select the target architecture.  Right now,
863 %you have only at most one choice: \tr{-fasm-sparc}.\index{-fasm-<target> option}
864 %
865 %EXPECT this native-code stuff to change in the future.
866
867 %************************************************************************
868 %*                                                                      *
869 \subsection[options-linker]{Linking and consistency-checking}
870 \index{linker options}
871 \index{ld options}
872 %*                                                                      *
873 %************************************************************************
874
875 GHC has to link your code with various libraries, possibly including:
876 user-supplied, GHC-supplied, and system-supplied (\tr{-lm} math
877 library, for example).
878
879 \begin{description}
880 \item[\tr{-l<FOO>}:]
881 \index{-l<lib> option}
882 Link in a library named \tr{lib<FOO>.a} which resides somewhere on the
883 library directories path.
884
885 Because of the sad state of most UNIX linkers, the order of such
886 options does matter.  Thus: \tr{ghc -lbar *.o} is almost certainly
887 wrong, because it will search \tr{libbar.a} {\em before} it has
888 collected unresolved symbols from the \tr{*.o} files.
889 \tr{ghc *.o -lbar} is probably better.
890
891 The linker will of course be informed about some GHC-supplied
892 libraries automatically; these are:
893
894 \begin{tabular}{ll}
895 -l equivalent & description \\ \hline
896
897 -lHSrts,-lHSclib & basic runtime libraries \\
898 -lHS         & standard Prelude library \\
899 -lHS\_cbits  & C support code for standard Prelude library \\
900 -lgmp        & GNU multi-precision library (for Integers)\\
901 \end{tabular}
902 \index{-lHS library}
903 \index{-lHS_cbits library}
904 \index{-lHSrts library}
905 \index{-lgmp library}
906
907 \item[\tr{-syslib <name>}:]
908 \index{-syslib <name> option}
909
910 If you are using a Haskell ``system library'' (e.g., the HBC
911 library), just use the \tr{-syslib hbc} option, and the correct code
912 should be linked in.
913
914 %Please see \sectionref{syslibs} for information about
915 %``system libraries.''
916
917 \item[\tr{-L<dir>}:]
918 \index{-L<dir> option}
919 Where to find user-supplied libraries...  Prepend the directory
920 \tr{<dir>} to the library directories path.
921
922 \item[\tr{-static}:]
923 \index{-static option}
924 Tell the linker to avoid shared libraries.
925
926 \item[\tr{-no-link-chk} and \tr{-link-chk}:]
927 \index{-no-link-chk option}
928 \index{-link-chk option}
929 \index{consistency checking of executables}
930 By default, immediately after linking an executable, GHC verifies that
931 the pieces that went into it were compiled with compatible flags; a
932 ``consistency check''.
933 (This is to avoid mysterious failures caused by non-meshing of
934 incompatibly-compiled programs; e.g., if one \tr{.o} file was compiled
935 for a parallel machine and the others weren't.)  You may turn off this
936 check with \tr{-no-link-chk}.  You can turn it (back) on with
937 \tr{-link-chk} (the default).
938 \end{description}
939
940 %************************************************************************
941 %*                                                                      *
942 \subsection[options-compiler-RTS]{For the compiler's RTS: heap, stack sizes, etc.}
943 \index{heap-size options (for GHC)}
944 \index{stack-size options (for GHC)}
945 %*                                                                      *
946 %************************************************************************
947
948 The compiler is itself a Haskell program, so it has a tweakable
949 runtime-system (RTS), just like any other Haskell program.
950
951 \begin{description}
952 \item[\tr{-H<size>} or \tr{-Rmax-heapsize <size>}:]
953 \index{-H<size> option}
954 \index{-Rmax-heapsize <size> option}
955 Don't use more than \tr{<size>} {\em bytes} for heap space.  If more
956 than one of these arguments is given, the largest will be taken.
957
958 A size of zero can be used to reset the heap size downwards.  For
959 example, to run GHC with a heap of 250KB (the default is 6MB), do
960 \tr{-H0 -H250k}.
961
962 \item[\tr{-K<size>} or \tr{-Rmax-stksize <size>}:]
963 \index{-K<size> option}
964 \index{-Rmax-stksize <size> option}
965 Set the stack space to \tr{<size>} bytes.  If you have to set it very
966 high [a megabyte or two, say], the compiler is probably looping, which
967 is a BUG (please report).
968
969 A size of zero can be used to rest the stack size downwards, as above.
970
971 \item[\tr{-Rscale-sizes<factor>}:]
972 \index{-Rscale-sizes<factor> option}
973 Multiply the given (or default) heap and stack sizes by \tr{<factor>}.
974 For example, on a DEC Alpha (a 64-bit machine), you might want to
975 double those space sizes; just use \tr{-Rscale-sizes2}.
976
977 A non-integral factor is OK, too: \tr{-Rscale-sizes1.2}.
978
979 \item[\tr{-Rghc-timing}:]
980 \index{-Rghc-timing option}
981 Reports a one-line useful collection of time- and space- statistics
982 for a module's compilation.
983
984 \item[\tr{-Rgc-stats}:]
985 \index{-Rgc-stats option}
986 Report garbage-collection statistics.  It will create a
987 \tr{<foo>.stat} file, in some obvious place (I hope).
988
989 Alternatively, if you'd rather the GC stats went straight to standard
990 error, you can ``cheat'' by using, instead: \tr{-optCrts-Sstderr}.
991 %
992 %\item[\tr{-Rhbc}:]
993 %\index{-Rhbc option}
994 %Tell the compiler it has an HBC-style RTS; i.e., it was compiled with
995 %HBC.  Not used in Real Life.
996 %
997 %\item[\tr{-Rghc}:]
998 %\index{-Rghc option}
999 %Tell the compiler it has a GHC-style RTS; i.e., it was compiled with
1000 %GHC.  Not used in Real Life.
1001 \end{description}
1002
1003 For all \tr{<size>}s: If the last character of \tr{size} is a K,
1004 multiply by 1000; if an M, by 1,000,000; if a G, by 1,000,000,000.
1005 Sizes are always in {\em bytes}, not words.  Good luck on the G's (I
1006 think the counter is still only 32-bits [WDP])!
1007
1008 %************************************************************************
1009 %*                                                                      *
1010 %\subsection[options-cross-compiling]{For cross-compiling to another architecture}
1011 %*                                                                      *
1012 %************************************************************************
1013 %
1014 % (We do this for GRIP at Glasgow; it's hacked in---not proper
1015 %cross-compiling support.  But you could do the same, if required...)
1016 %
1017 %The \tr{-target <arch>} option\index{-target <arch> option} says to
1018 %generate code for the \tr{<arch>} architecture.
1019
1020 %************************************************************************
1021 %*                                                                      *
1022 \subsection[options-parallel]{For Concurrent and Parallel Haskell}
1023 %*                                                                      *
1024 %************************************************************************
1025
1026 For the full story on using GHC for concurrent \& parallel Haskell
1027 programming, please see \Sectionref{concurrent-and-parallel}.
1028
1029 %The \tr{-fparallel} option\index{-fparallel option} tells the compiler
1030 %to generate code for parallel execution.  The \tr{-mgrip}
1031 %option\index{-mgrip option} says that the code should be explicitly
1032 %suitable for the GRIP multiprocessor (the one in our Glasgow basement).
1033
1034 %************************************************************************
1035 %*                                                                      *
1036 %\subsection[options-experimental]{For experimental purposes}
1037 %\index{experimental options}
1038 %*                                                                      *
1039 %************************************************************************
1040
1041 %From time to time, we provide GHC options for ``experimenting.''  Easy
1042 %come, easy go.  In version~0.26, the ``experimental'' options are:
1043 %\begin{description}
1044 %\item[\tr{-firrefutable-tuples} option:]
1045 %\index{-firrefutable-tuples option (experimental)}
1046 %Pretend that every tuple pattern is irrefutable; i.e., has a
1047 %``twiddle'' (\tr{~}) in front of it.
1048 %
1049 %Some parts of the GHC system {\em depend} on strictness properties which
1050 %\tr{-firrefutable-tuples} may undo, notably the low-level state-transformer
1051 %stuff, which includes I/O (!).  You're on your own...
1052 %
1053 %\item[\tr{-fall-strict} option:]
1054 %\index{-fall-strict option (experimental)}
1055 % (DOESN'T REALLY WORK, I THINK) Changes the strictness analyser so
1056 %that, when it asks the question ``Is this function argument certain to
1057 %be evaluated?'', the answer is always ``yes''.
1058 %
1059 %Compilation is changed in no other way.
1060 %\end{description}
1061
1062 % -firrefutable-everything
1063 % -fall-demanded
1064
1065 %************************************************************************
1066 %*                                                                      *
1067 \subsection[options-debugging]{For debugging the compiler}
1068 \index{debugging options (for GHC)}
1069 %*                                                                      *
1070 %************************************************************************
1071
1072 HACKER TERRITORY. HACKER TERRITORY.
1073 (You were warned.)
1074
1075 %----------------------------------------------------------------------
1076 \subsubsection[replacing-phases]{Replacing the program for one or more phases.}
1077 \index{GHC phases, changing}
1078 \index{phases, changing GHC}
1079
1080 You may specify that a different program
1081 be used for one of the phases of the compilation system, in place of
1082 whatever the driver \tr{ghc} has wired into it.  For example, you
1083 might want to try a different assembler.  The
1084 \tr{-pgm<phase-code><program-name>}\index{-pgm<phase><stuff> option} option to
1085 \tr{ghc} will cause it to use \pl{<program-name>} for phase
1086 \pl{<phase-code>}, where the codes to indicate the phases are:
1087
1088 \begin{tabular}{ll}
1089 code & phase \\ \hline
1090 L    & literate pre-processor \\
1091 P    & C pre-processor (if -cpp only) \\
1092 C    & Haskell compiler \\
1093 c    & C compiler\\
1094 a    & assembler \\
1095 l    & linker \\
1096 \end{tabular}
1097
1098 %----------------------------------------------------------------------
1099 \subsubsection[forcing-options-through]{Forcing options to a particular phase.}
1100 \index{forcing GHC-phase options}
1101
1102 The preceding sections describe driver options that are mostly
1103 applicable to one particular phase.  You may also {\em force} a
1104 specific option \tr{<option>} to be passed to a particular phase
1105 \tr{<phase-code>} by feeding the driver the option
1106 \tr{-opt<phase-code><option>}.\index{-opt<phase><stuff> option} The
1107 codes to indicate the phases are the same as in the previous section.
1108
1109 So, for example, to force an \tr{-Ewurble} option to the assembler, you
1110 would tell the driver \tr{-opta-Ewurble} (the dash before the E is
1111 required).
1112
1113 Besides getting options to the Haskell compiler with \tr{-optC<blah>},
1114 you can get options through to its runtime system with
1115 \tr{-optCrts<blah>}\index{-optCrts<blah> option}.
1116
1117 So, for example: when I want to use my normal driver but with my
1118 profiled compiler binary, I use this script:
1119 \begin{verbatim}
1120 #! /bin/sh
1121 exec /local/grasp_tmp3/simonpj/ghc-BUILDS/working-alpha/ghc/driver/ghc \
1122      -pgmC/local/grasp_tmp3/simonpj/ghc-BUILDS/working-hsc-prof/hsc \
1123      -optCrts-i0.5 \
1124      -optCrts-PT \
1125      "$@"
1126 \end{verbatim}
1127
1128 %----------------------------------------------------------------------
1129 \subsubsection[dumping-output]{Dumping out compiler intermediate structures}
1130 \index{dumping GHC intermediates}
1131 \index{intermediate passes, output}
1132
1133 \begin{description}
1134 \item[\tr{-noC}:]
1135 \index{-noC option}
1136 Don't bother generating C output {\em or} an interface file.  Usually
1137 used in conjunction with one or more of the \tr{-ddump-*} options; for
1138 example: \tr{ghc -noC -ddump-simpl Foo.hs}
1139
1140 \item[\tr{-hi}:]
1141 \index{-hi option}
1142 {\em Do} generate an interface file.  This would normally be used in
1143 conjunction with \tr{-noC}, which turns off interface generation;
1144 thus: \tr{-noC -hi}.
1145
1146 \item[\tr{-dshow-passes}:]
1147 \index{-dshow-passes option}
1148 Prints a message to stderr as each pass starts.  Gives a warm but
1149 undoubtedly misleading feeling that GHC is telling you what's
1150 happening.
1151
1152 \item[\tr{-ddump-<pass>}:]
1153 \index{-ddump-<pass> options}
1154 Make a debugging dump after pass \tr{<pass>} (may be common enough to
1155 need a short form...).  Some of the most useful ones are:
1156
1157 \begin{tabular}{ll}
1158 \tr{-ddump-rdr} & reader output (earliest stuff in the compiler) \\
1159 \tr{-ddump-rn} & renamer output \\
1160 \tr{-ddump-tc} & typechecker output \\
1161 \tr{-ddump-deriv} & derived instances \\
1162 \tr{-ddump-ds} & desugarer output \\
1163 \tr{-ddump-simpl} & simplifer output (Core-to-Core passes) \\
1164 \tr{-ddump-stranal} & strictness analyser output \\
1165 \tr{-ddump-occur-anal} & `occurrence analysis' output \\
1166 \tr{-ddump-spec} & dump specialisation info \\
1167 \tr{-ddump-stg} & output of STG-to-STG passes \\
1168 \tr{-ddump-absC} & {\em un}flattened Abstract~C \\
1169 \tr{-ddump-flatC} & {\em flattened} Abstract~C \\
1170 \tr{-ddump-realC} & same as what goes to the C compiler \\
1171 \tr{-ddump-asm} & assembly language from the native-code generator \\
1172 \end{tabular}
1173 \index{-ddump-rdr option}%
1174 \index{-ddump-rn option}%
1175 \index{-ddump-tc option}%
1176 \index{-ddump-deriv option}%
1177 \index{-ddump-ds option}%
1178 \index{-ddump-simpl option}%
1179 \index{-ddump-stranal option}%
1180 \index{-ddump-occur-anal option}%
1181 \index{-ddump-spec option}%
1182 \index{-ddump-stg option}%
1183 \index{-ddump-absC option}%
1184 \index{-ddump-flatC option}%
1185 \index{-ddump-realC option}%
1186 \index{-ddump-asm option}
1187
1188 %For any other \tr{-ddump-*} options: consult the source, notably
1189 %\tr{ghc/compiler/main/CmdLineOpts.lhs}.
1190
1191 \item[\tr{-dverbose-simpl} and \tr{-dverbose-stg}:]
1192 \index{-dverbose-simpl option}
1193 \index{-dverbose-stg option}
1194 Show the output of the intermediate Core-to-Core and STG-to-STG
1195 passes, respectively.  ({\em Lots} of output!) So: when we're 
1196 really desperate:
1197 \begin{verbatim}
1198 % ghc -noC -O -ddump-simpl -dverbose-simpl -dcore-lint Foo.hs
1199 \end{verbatim}
1200
1201 \item[\tr{-dppr-{user,debug,all}}:]
1202 \index{-dppr-user option}
1203 \index{-dppr-debug option}
1204 \index{-dppr-all option}
1205 Debugging output is in one of several ``styles.''  Take the printing
1206 of types, for example.  In the ``user'' style, the compiler's internal
1207 ideas about types are presented in Haskell source-level syntax,
1208 insofar as possible.  In the ``debug'' style (which is the default for
1209 debugging output), the types are printed in the most-often-desired
1210 form, with explicit foralls, etc.  In the ``show all'' style, very
1211 verbose information about the types (e.g., the Uniques on the
1212 individual type variables) is displayed.
1213
1214 \item[\tr{-ddump-raw-asm}:]
1215 \index{-ddump-raw-asm option}
1216 Dump out the assembly-language stuff, before the ``mangler'' gets it.
1217
1218 \item[\tr{-ddump-rn-trace}:]
1219 \index{-ddump-rn-trace}
1220 Make the renamer be *real* chatty about what it is upto.
1221
1222 \item[\tr{-dshow-rn-stats}:]
1223 \index{-dshow-rn-stats}
1224 Print out summary of what kind of information the renamer had to bring
1225 in.
1226 \item[\tr{-dshow-unused-imports}:]
1227 \index{-dshow-unused-imports}
1228 Have the renamer report what imports does not contribute.
1229
1230 %
1231 %\item[\tr{-dgc-debug}:]
1232 %\index{-dgc-debug option}
1233 %Enables some debugging code related to the garbage-collector.
1234 \end{description}
1235
1236 %ToDo: -ddump-asm-insn-counts
1237 %-ddump-asm-globals-info
1238
1239 %----------------------------------------------------------------------
1240 \subsubsection{How to read Core syntax (from some \tr{-ddump-*} flags)}
1241 \index{reading Core syntax}
1242 \index{Core syntax, how to read}
1243
1244 Let's do this by commenting an example.  It's from doing
1245 \tr{-ddump-ds} on this code:
1246 \begin{verbatim}
1247 skip2 m = m : skip2 (m+2)
1248 \end{verbatim}
1249
1250 Before we jump in, a word about names of things.  Within GHC,
1251 variables, type constructors, etc., are identified by their
1252 ``Uniques.''  These are of the form `letter' plus `number' (both
1253 loosely interpreted).  The `letter' gives some idea of where the
1254 Unique came from; e.g., \tr{_} means ``built-in type variable'';
1255 \tr{t} means ``from the typechecker''; \tr{s} means ``from the
1256 simplifier''; and so on.  The `number' is printed fairly compactly in
1257 a `base-62' format, which everyone hates except me (WDP).
1258
1259 Remember, everything has a ``Unique'' and it is usually printed out
1260 when debugging, in some form or another.  So here we go...
1261
1262 \begin{verbatim}
1263 Desugared:
1264 Main.skip2{-r1L6-} :: _forall_ a$_4 =>{{Num a$_4}} -> a$_4 -> [a$_4]
1265
1266 --# `r1L6' is the Unique for Main.skip2;
1267 --# `_4' is the Unique for the type-variable (template) `a'
1268 --# `{{Num a$_4}}' is a dictionary argument
1269
1270 _NI_
1271
1272 --# `_NI_' means "no (pragmatic) information" yet; it will later
1273 --# evolve into the GHC_PRAGMA info that goes into interface files.
1274
1275 Main.skip2{-r1L6-} =
1276     /\ _4 -> \ d.Num.t4Gt ->
1277         let {
1278           {- CoRec -}
1279           +.t4Hg :: _4 -> _4 -> _4
1280           _NI_
1281           +.t4Hg = (+{-r3JH-} _4) d.Num.t4Gt
1282
1283           fromInt.t4GS :: Int{-2i-} -> _4
1284           _NI_
1285           fromInt.t4GS = (fromInt{-r3JX-} _4) d.Num.t4Gt
1286
1287 --# The `+' class method (Unique: r3JH) selects the addition code
1288 --# from a `Num' dictionary (now an explicit lamba'd argument).
1289 --# Because Core is 2nd-order lambda-calculus, type applications
1290 --# and lambdas (/\) are explicit.  So `+' is first applied to a
1291 --# type (`_4'), then to a dictionary, yielding the actual addition
1292 --# function that we will use subsequently...
1293
1294 --# We play the exact same game with the (non-standard) class method
1295 --# `fromInt'.  Unsurprisingly, the type `Int' is wired into the
1296 --# compiler.
1297
1298           lit.t4Hb :: _4
1299           _NI_
1300           lit.t4Hb =
1301               let {
1302                 ds.d4Qz :: Int{-2i-}
1303                 _NI_
1304                 ds.d4Qz = I#! 2#
1305               } in  fromInt.t4GS ds.d4Qz
1306
1307 --# `I# 2#' is just the literal Int `2'; it reflects the fact that
1308 --# GHC defines `data Int = I# Int#', where Int# is the primitive
1309 --# unboxed type.  (see relevant info about unboxed types elsewhere...)
1310
1311 --# The `!' after `I#' indicates that this is a *saturated*
1312 --# application of the `I#' data constructor (i.e., not partially
1313 --# applied).
1314
1315           skip2.t3Ja :: _4 -> [_4]
1316           _NI_
1317           skip2.t3Ja =
1318               \ m.r1H4 ->
1319                   let { ds.d4QQ :: [_4]
1320                         _NI_
1321                         ds.d4QQ =
1322                     let {
1323                       ds.d4QY :: _4
1324                       _NI_
1325                       ds.d4QY = +.t4Hg m.r1H4 lit.t4Hb
1326                     } in  skip2.t3Ja ds.d4QY
1327                   } in
1328                   :! _4 m.r1H4 ds.d4QQ
1329
1330           {- end CoRec -}
1331         } in  skip2.t3Ja
1332 \end{verbatim}
1333
1334 (``It's just a simple functional language'' is an unregisterised
1335 trademark of Peyton Jones Enterprises, plc.)
1336
1337 %----------------------------------------------------------------------
1338 \subsubsection[source-file-options]{Command line options in source files}
1339 \index{source-file options}
1340
1341 Sometimes it is useful to make the connection between a source file
1342 and the command-line options it requires quite tight. For instance,
1343 if a (Glasgow) Haskell source file uses \tr{casm}s, the C back-end
1344 often needs to be told about which header files to include. Rather than
1345 maintaining the list of files the source depends on in a
1346 \tr{Makefile} (using the \tr{-#include} command-line option), it is
1347 possible to do this directly in the source file using the \tr{OPTIONS}
1348 pragma \index{OPTIONS pragma}: 
1349
1350 \begin{verbatim}
1351 {-# OPTIONS -#include "foo.h" #-}
1352 module X where
1353
1354 ...
1355 \end{verbatim}
1356
1357 \tr{OPTIONS} pragmas are only looked for at the top of your source
1358 files, upto the first (non-literate,non-empty) line not containing
1359 \tr{OPTIONS}. Multiple \tr{OPTIONS} pragmas are recognised. Note
1360 that your command shell does not get to the source file options, they
1361 are just included literally in the array of command-line arguments
1362 the compiler driver maintains internally, so you'll be desperately
1363 disappointed if you try to glob etc. inside \tr{OPTIONS}.
1364
1365 NOTE: the contents of OPTIONS are prepended to the command-line
1366 options, so you *do* have the ability to override OPTIONS settings
1367 via the command line.
1368
1369 It is not recommended to move all the contents of your Makefiles into
1370 your source files, but in some circumstances, the \tr{OPTIONS} pragma
1371 is the Right Thing. (If you use \tr{-keep-hc-file-too} and have OPTION
1372 flags in your module, the OPTIONS will get put into the generated .hc
1373 file).
1374
1375 %----------------------------------------------------------------------
1376 \subsubsection{How to compile mutually recursive modules}
1377 \index{module system, recursion}
1378
1379 Currently, the compiler does not have proper support for dealing with
1380 mutually recursive modules:
1381
1382 \begin{verbatim}
1383 module A where
1384
1385 import B
1386
1387 newtype A = A Int
1388
1389 f :: B -> A
1390 f (B x) = A x
1391 --------
1392 module B where
1393
1394 import A
1395
1396 data B = B !Int
1397
1398 g :: A -> B
1399 g (A x) = B x
1400 \end{verbatim}
1401
1402 When compiling either module A and B, the compiler will try (in vain)
1403 to look for the interface file of the other. So, to get mutually
1404 recursive modules off the ground, you need to hand write an interface
1405 file for A or B, so as to break the loop. For the example at hand, the
1406 boot interface file for A would like the following:
1407
1408 \begin{verbatim}
1409 _interface_ A 1
1410 _exports_
1411 A A(A) f;
1412 _declarations_
1413 1 newtype A = A PrelBase.Int ;
1414 1 f _:_ B.B -> A.A ;;
1415 \end{verbatim}
1416
1417 To make sure you get the syntax right, tailoring an existing interface
1418 file is a Good Idea.
1419
1420 {\bf Note:} This is all a temporary solution, a version of the compiler
1421 that handles mutually recursive properly without the manual
1422 construction of interface file, is in the works.
1423
1424 %----------------------------------------------------------------------
1425 %\subsubsection[arity-checking]{Options to insert arity-checking code}
1426 %\index{arity checking}
1427 %
1428 %The \tr{-darity-checks}\index{-darity-checks option} option inserts
1429 %code to check for arity violations.  Unfortunately, it's not that
1430 %simple: you have to link with a prelude that was also built with arity
1431 %checks.  If you have one, then great; otherwise...
1432 %
1433 %The \tr{-darity-checks-C-only}\index{-darity-checks-C-only option}
1434 %option inserts the self-same arity checking code into \tr{.hc} files,
1435 %but doesn't compile it into the \tr{.o} files.  We use this flag with
1436 %the \tr{-keep-hc-file-too}\index{-keep-hc-file-too option}, where we
1437 %are keeping \tr{.hc} files around for debugging purposes.
1438
1439 %----------------------------------------------------------------------
1440 %\subsubsection[omit-checking]{Options to omit checking code}
1441 %\index{omitting runtime checks}
1442 %
1443 %By default, the GHC system emits all possible not-too-expensive
1444 %runtime checking code.  If you are brave or experimenting, you might
1445 %want to turn off some of this (not recommended):
1446 %
1447 %\begin{tabular}{ll}
1448 %-dno-black-holing & won't buy you much (even if it works) \\
1449 %-dno-updates & you're crazy if you do this \\
1450 %-dno-stk-stubbing & omit stack stubbing (NOT DONE YET) \\
1451 %\end{tabular}
1452 %\index{-dno-black-holing option}%
1453 %\index{-dno-updates option}%
1454 %\index{-dno-stk-stubbing option}
1455 %
1456 %Warning: all very lightly tested, if at all...
1457
1458 %% %************************************************************************
1459 %% %*                                                                   *
1460 %% \subsection[options-GC]{Choosing a garbage collector}
1461 %% %*                                                                   *
1462 %% %************************************************************************
1463 %% 
1464 %% (Note: you need a Good Reason before launching into this territory.)
1465 %% 
1466 %% There are up to four garbage collectors to choose from (it depends how
1467 %% your local system was built); the Appel-style generational collector
1468 %% is the default.
1469 %% 
1470 %% If you choose a non-default collector, you must specify it both when
1471 %% compiling the modules and when linking them together into an
1472 %% executable.  Also, the native-code generator only works with the
1473 %% default collector (a small point to bear in mind).
1474 %% 
1475 %% \begin{description}
1476 %% \item[\tr{-gc-ap} option:]
1477 %% \index{-gc-ap option}
1478 %% Appel-like generational collector (the default).
1479 %% 
1480 %% \item[\tr{-gc-2s} option:]
1481 %% \index{-gc-2s option}
1482 %% Two-space copying collector.
1483 %% 
1484 %% \item[\tr{-gc-1s} option:]
1485 %% \index{-gc-1s option}
1486 %% One-space compacting collector.
1487 %% 
1488 %% \item[\tr{-gc-du} option:]
1489 %% \index{-gc-du option}
1490 %% Dual-mode collector (swaps between copying and compacting).
1491 %% \end{description}