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