4358ac8da61d12b367eccbb649a66267056e2939
[ghc-hetmet.git] / ghc / docs / users_guide / using.sgml
1 <Chapter id="using-GHC">
2 <Title>Using GHC
3 </Title>
4
5 <Para>
6 <IndexTerm><Primary>GHC, using</Primary></IndexTerm>
7 <IndexTerm><Primary>using GHC</Primary></IndexTerm>
8 GHC is a command-line compiler: in order to compile a Haskell program,
9 GHC must be invoked on the source file(s) by typing a command to the
10 shell.  The steps involved in compiling a program can be automated
11 using the <Command>make</Command> tool (this is especially useful if the program
12 consists of multiple source files which depend on each other).  This
13 section describes how to use GHC from the command-line.
14 </Para>
15
16 <Sect1 id="command-line-structure">
17 <Title>Overall command-line structure
18 </Title>
19
20 <Para>
21 <IndexTerm><Primary>structure, command-line</Primary></IndexTerm>
22 <IndexTerm><Primary>command-line structure</Primary></IndexTerm>
23 </Para>
24
25 <Para>
26 An invocation of GHC takes the following form:
27 </Para>
28
29 <Para>
30
31 <Screen>
32 ghc [argument...]
33 </Screen>
34
35 </Para>
36
37 <Para>
38 Command-line arguments are either options or file names.
39 </Para>
40
41 <Para>
42 Command-line options begin with <Literal>-</Literal>.  They may <Emphasis>not</Emphasis> be
43 grouped: <Option>-vO</Option> is different from <Option>-v -O</Option>.  Options need not
44 precede filenames: e.g., <Command>ghc *.o -o foo</Command>.  All options are
45 processed and then applied to all files; you cannot, for example, invoke
46 <Command>ghc -c -O1 Foo.hs -O2 Bar.hs</Command> to apply different optimisation
47 levels to the files <Filename>Foo.hs</Filename> and <Filename>Bar.hs</Filename>.  For conflicting
48 options, e.g., <Option>-c -S</Option>, we reserve the right to do anything we
49 want.  (Usually, the last one applies.)
50 </Para>
51
52 </Sect1>
53
54 <Sect1 id="file-suffixes">
55 <Title>Meaningful file suffixes
56 </Title>
57
58 <Para>
59 <IndexTerm><Primary>suffixes, file</Primary></IndexTerm>
60 <IndexTerm><Primary>file suffixes for GHC</Primary></IndexTerm>
61 </Para>
62
63 <Para>
64 File names with &ldquo;meaningful&rdquo; suffixes (e.g., <Filename>.lhs</Filename> or <Filename>.o</Filename>)
65 cause the &ldquo;right thing&rdquo; to happen to those files.
66 </Para>
67
68 <Para>
69 <VariableList>
70
71 <VarListEntry>
72 <Term><Filename>.lhs</Filename>:</Term>
73 <ListItem>
74 <Para>
75 <IndexTerm><Primary>lhs suffix</Primary></IndexTerm>
76 A &ldquo;literate Haskell&rdquo; module.
77 </Para>
78 </ListItem>
79 </VarListEntry>
80 <VarListEntry>
81 <Term><Filename>.hs</Filename>:</Term>
82 <ListItem>
83 <Para>
84 A not-so-literate Haskell module.
85 </Para>
86 </ListItem>
87 </VarListEntry>
88 <VarListEntry>
89 <Term><Filename>.hi</Filename>:</Term>
90 <ListItem>
91 <Para>
92 A Haskell interface file, probably compiler-generated.
93 </Para>
94 </ListItem>
95 </VarListEntry>
96 <VarListEntry>
97 <Term><Filename>.hc</Filename>:</Term>
98 <ListItem>
99 <Para>
100 Intermediate C file produced by the Haskell compiler.
101 </Para>
102 </ListItem>
103 </VarListEntry>
104 <VarListEntry>
105 <Term><Filename>.c</Filename>:</Term>
106 <ListItem>
107 <Para>
108 A C&nbsp;file not produced by the Haskell compiler.
109 </Para>
110 </ListItem>
111 </VarListEntry>
112 <VarListEntry>
113 <Term><Filename>.s</Filename>:</Term>
114 <ListItem>
115 <Para>
116 An assembly-language source file, usually
117 produced by the compiler.
118 </Para>
119 </ListItem>
120 </VarListEntry>
121 <VarListEntry>
122 <Term><Filename>.o</Filename>:</Term>
123 <ListItem>
124 <Para>
125 An object file, produced by an assembler.
126 </Para>
127 </ListItem>
128 </VarListEntry>
129 </VariableList>
130 </Para>
131
132 <Para>
133 Files with other suffixes (or without suffixes) are passed straight
134 to the linker.
135 </Para>
136
137 </Sect1>
138
139 <Sect1 id="options-help">
140 <Title>Help and verbosity options
141 </Title>
142
143 <Para>
144 <IndexTerm><Primary>help options (GHC)</Primary></IndexTerm>
145 <IndexTerm><Primary>verbose option (GHC)</Primary></IndexTerm>
146 </Para>
147
148 <Para>
149 A good option to start with is the <Option>-help</Option> (or <Option>-?</Option>) option.
150 <IndexTerm><Primary>-help option</Primary></IndexTerm>
151 <IndexTerm><Primary>-? option</Primary></IndexTerm>
152 GHC spews a long message to standard output and then exits.
153 </Para>
154
155 <Para>
156 The <Option>-v</Option><IndexTerm><Primary>-v option</Primary></IndexTerm> option makes GHC <Emphasis>verbose</Emphasis>: it
157 reports its version number and shows (on stderr) exactly how it invokes each
158 phase of the compilation system.  Moreover, it passes
159 the <Option>-v</Option> flag to most phases; each reports
160 its version number (and possibly some other information).
161 </Para>
162
163 <Para>
164 Please, oh please, use the <Option>-v</Option> option when reporting bugs!
165 Knowing that you ran the right bits in the right order is always the
166 first thing we want to verify.
167 </Para>
168
169 <Para>
170 If you're just interested in the compiler version number, the
171 <Option>--version</Option><IndexTerm><Primary>--version option</Primary></IndexTerm> option prints out a
172 one-line string containing the requested info.
173 </Para>
174
175 </Sect1>
176
177 <Sect1 id="options-order">
178 <Title>Running the right phases in the right order
179 </Title>
180
181 <Para>
182 <IndexTerm><Primary>order of passes in GHC</Primary></IndexTerm>
183 <IndexTerm><Primary>pass ordering in GHC</Primary></IndexTerm>
184 The basic task of the <Command>ghc</Command> driver is to run each input file
185 through the right phases (compiling, linking, etc.).
186 </Para>
187
188 <Para>
189 The first phase to run is determined by the input-file suffix, and the
190 last phase is determined by a flag.  If no relevant flag is present,
191 then go all the way through linking.  This table summarises:
192 </Para>
193
194 <Para>
195 <InformalTable>
196 <TGroup Cols="4">
197 <ColSpec Align="Left">
198 <ColSpec Align="Left">
199 <ColSpec Align="Left">
200 <ColSpec Align="Left">
201 <TBody>
202
203 <Row>
204 <Entry>Phase of the compilation system</Entry>
205 <Entry>Suffix saying &ldquo;start here&rdquo;</Entry>
206 <Entry>Flag saying &ldquo;stop after&rdquo;</Entry>
207 <Entry>(suffix of) output file</Entry>
208 </Row>
209
210 <Row>
211 <Entry>
212 literate pre-processor </Entry>
213 <Entry> .lhs </Entry>
214 <Entry> - </Entry>
215 <Entry> - </Entry>
216 </Row>
217 <Row>
218 <Entry>
219 C pre-processor (opt.) </Entry>
220 <Entry> - </Entry>
221 <Entry> - </Entry>
222 <Entry> - </Entry>
223 </Row>
224 <Row>
225 <Entry>
226 Haskell compiler </Entry>
227 <Entry> .hs </Entry>
228 <Entry> -C, -S </Entry>
229 <Entry> .hc, .s </Entry>
230 </Row>
231 <Row>
232 <Entry>
233 C compiler (opt.) </Entry>
234 <Entry> .hc or .c </Entry>
235 <Entry> -S </Entry>
236 <Entry> .s </Entry>
237 </Row>
238 <Row>
239 <Entry>
240 assembler </Entry>
241 <Entry> .s </Entry>
242 <Entry> -c </Entry>
243 <Entry> .o </Entry>
244 </Row>
245 <Row>
246 <Entry>
247 linker </Entry>
248 <Entry> other </Entry>
249 <Entry> - </Entry>
250 <Entry> a.out </Entry>
251 </Row>
252 </TBody>
253 </TGroup>
254 </InformalTable>
255
256 <IndexTerm><Primary>-C option</Primary></IndexTerm>
257 <IndexTerm><Primary>-S option</Primary></IndexTerm>
258 <IndexTerm><Primary>-c option</Primary></IndexTerm>
259 </Para>
260
261 <Para>
262 Thus, a common invocation would be: <Command>ghc -c Foo.hs</Command>
263 </Para>
264
265 <Para>
266 Note: What the Haskell compiler proper produces depends on whether a
267 native-code generator is used (producing assembly language) or not
268 (producing C).
269 </Para>
270
271 <Para>
272 The option <Option>-cpp</Option><IndexTerm><Primary>-cpp option</Primary></IndexTerm> must be given for the C
273 pre-processor phase to be run, that is, the pre-processor will be run
274 over your Haskell source file before continuing.
275 </Para>
276
277 <Para>
278 The option <Option>-E</Option><IndexTerm><Primary>-E option</Primary></IndexTerm> runs just the pre-processing
279 passes of the compiler, outputting the result on stdout before
280 stopping. If used in conjunction with -cpp, the output is the
281 code blocks of the original (literal) source after having put it
282 through the grinder that is the C pre-processor. Sans <Option>-cpp</Option>, the
283 output is the de-litted version of the original source.
284 </Para>
285
286 <Para>
287 The option <Option>-optcpp-E</Option><IndexTerm><Primary>-optcpp-E option</Primary></IndexTerm> runs just the
288 pre-processing stage of the C-compiling phase, sending the result to
289 stdout.  (For debugging or obfuscation contests, usually.)
290 </Para>
291
292 </Sect1>
293
294 <Sect1 id="options-output">
295 <Title>Re-directing the compilation output(s)
296 </Title>
297
298 <Para>
299 <IndexTerm><Primary>output-directing options</Primary></IndexTerm>
300 </Para>
301
302 <Para>
303 GHC's compiled output normally goes into a <Filename>.hc</Filename>, <Filename>.o</Filename>, etc., file,
304 depending on the last-run compilation phase.  The option <Option>-o
305 foo</Option><IndexTerm><Primary>-o option</Primary></IndexTerm> re-directs the output of that last-run
306 phase to file <Filename>foo</Filename>.
307 </Para>
308
309 <Para>
310 Note: this &ldquo;feature&rdquo; can be counterintuitive:
311 <Command>ghc -C -o foo.o foo.hs</Command> will put the intermediate C code in the
312 file <Filename>foo.o</Filename>, name notwithstanding!
313 </Para>
314
315 <Para>
316 EXOTICA: But the <Option>-o</Option> option isn't of much use if you have
317 <Emphasis>several</Emphasis> input files&hellip; Non-interface output files are
318 normally put in the same directory as their corresponding input file
319 came from.  You may specify that they be put in another directory
320 using the <Option>-odir &lt;dir&gt;</Option><IndexTerm><Primary>-odir &lt;dir&gt; option</Primary></IndexTerm> (the
321 &ldquo;Oh, dear&rdquo; option).  For example:
322 </Para>
323
324 <Para>
325
326 <Screen>
327 % ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch`
328 </Screen>
329
330 </Para>
331
332 <Para>
333 The output files, <Filename>Foo.o</Filename>, <Filename>Bar.o</Filename>, and <Filename>Bumble.o</Filename> would be
334 put into a subdirectory named after the architecture of the executing
335 machine (<Filename>sun4</Filename>, <Filename>mips</Filename>, etc).  The directory must already
336 exist; it won't be created.
337 </Para>
338
339 <Para>
340 Note that the <Option>-odir</Option> option does <Emphasis>not</Emphasis> affect where the
341 interface files are put.  In the above example, they would still be
342 put in <Filename>parse/Foo.hi</Filename>, <Filename>parse/Bar.hi</Filename>, and <Filename>gurgle/Bumble.hi</Filename>.
343 </Para>
344
345 <Para>
346 MORE EXOTICA: The <Option>-osuf &lt;suffix&gt;</Option><IndexTerm><Primary>-osuf &lt;suffix&gt;
347 option</Primary></IndexTerm> will change the <Filename>.o</Filename> file suffix for object files to
348 whatever you specify.  (We use this in compiling the prelude.).
349 Similarly, the <Option>-hisuf &lt;suffix&gt;</Option><IndexTerm><Primary>-hisuf &lt;suffix&gt;
350 option</Primary></IndexTerm> will change the <Filename>.hi</Filename> file suffix for non-system
351 interface files (see <XRef LinkEnd="hi-options">).
352 </Para>
353
354 <Para>
355 The <Option>-hisuf</Option>/<Option>-osuf</Option> game is useful if you want to compile a program
356 with both GHC and HBC (say) in the same directory.  Let HBC use the
357 standard <Filename>.hi</Filename>/<Filename>.o</Filename> suffixes; add <Option>-hisuf g&lowbar;hi -osuf g&lowbar;o</Option> to your
358 <Command>make</Command> rule for GHC compiling&hellip;
359 </Para>
360
361 <Para>
362 FURTHER EXOTICA: If you are doing a normal <Filename>.hs</Filename>-to-<Filename>.o</Filename> compilation
363 but would like to hang onto the intermediate <Filename>.hc</Filename> C file, just
364 throw in a <Option>-keep-hc-file-too</Option> option<IndexTerm><Primary>-keep-hc-file-too option</Primary></IndexTerm>.
365 If you would like to look at the assembler output, toss in a
366 <Option>-keep-s-file-too</Option>,<IndexTerm><Primary>-keep-s-file-too option</Primary></IndexTerm> too.
367 </Para>
368
369 <Sect2 id="saving-ghc-stderr">
370 <Title>Saving GHC's standard error output
371 </Title>
372
373 <Para>
374 <IndexTerm><Primary>standard error, saving</Primary></IndexTerm>
375 </Para>
376
377 <Para>
378 Sometimes, you may cause GHC to be rather chatty on standard error;
379 with <Option>-v</Option>, for example.  You can instruct GHC to <Emphasis>append</Emphasis> this
380 output to a particular log file with a <Option>-odump &lt;blah&gt;</Option><IndexTerm><Primary>-odump
381 &lt;blah&gt; option</Primary></IndexTerm> option.
382 </Para>
383
384 </Sect2>
385
386 <Sect2 id="temp-files">
387 <Title>Redirecting temporary files
388 </Title>
389
390 <Para>
391 <IndexTerm><Primary>temporary files, redirecting</Primary></IndexTerm>
392 </Para>
393
394 <Para>
395 If you have trouble because of running out of space in <Filename>/tmp</Filename> (or
396 wherever your installation thinks temporary files should go), you may
397 use the <Option>-tmpdir &lt;dir&gt;</Option><IndexTerm><Primary>-tmpdir &lt;dir&gt; option</Primary></IndexTerm> option
398 to specify an alternate directory.  For example, <Option>-tmpdir .</Option> says to
399 put temporary files in the current working directory.
400 </Para>
401
402 <Para>
403 Alternatively, use your <Constant>TMPDIR</Constant> environment variable.<IndexTerm><Primary>TMPDIR
404 environment variable</Primary></IndexTerm> Set it to the name of the directory where
405 temporary files should be put.  GCC and other programs will honour the
406 <Constant>TMPDIR</Constant> variable as well.
407 </Para>
408
409 <Para>
410 Even better idea: Set the <Constant>TMPDIR</Constant> variable when building GHC, and
411 never worry about <Constant>TMPDIR</Constant> again. (see the build documentation).
412 </Para>
413
414 </Sect2>
415
416 </Sect1>
417
418 <Sect1 id="options-sanity">
419 <Title>Warnings and sanity-checking
420 </Title>
421
422 <Para>
423 <IndexTerm><Primary>sanity-checking options</Primary></IndexTerm>
424 <IndexTerm><Primary>warnings</Primary></IndexTerm>
425 GHC has a number of options that select which types of non-fatal error
426 messages, otherwise known as warnings, can be generated during
427 compilation.  By default, you get a standard set of warnings which are
428 generally likely to indicate bugs in your program.  These are:
429 <Option>-fwarn-overlpapping-patterns</Option>, <Option>-fwarn-duplicate-exports</Option>, and
430 <Option>-fwarn-missing-methods</Option>.  The following flags are simple ways to
431 select standard &ldquo;packages&rdquo; of warnings:
432 </Para>
433
434 <Para>
435 <VariableList>
436
437 <VarListEntry>
438 <Term><Option>-Wnot</Option>:</Term>
439 <ListItem>
440 <Para>
441 <IndexTerm><Primary>-Wnot option</Primary></IndexTerm>
442 Turns off all warnings, including the standard ones.
443 </Para>
444 </ListItem>
445 </VarListEntry>
446
447 <VarListEntry>
448 <Term><Option>-w</Option>:</Term>
449 <ListItem>
450 <Para>
451 <IndexTerm><Primary>-w option</Primary></IndexTerm>
452 Synonym for <Option>-Wnot</Option>.
453 </Para>
454 </ListItem>
455 </VarListEntry>
456
457 <VarListEntry>
458 <Term><Option>-W</Option>:</Term>
459 <ListItem>
460 <Para>
461 <IndexTerm><Primary>-W option</Primary></IndexTerm>
462 Provides the standard warnings plus <Option>-fwarn-incomplete-patterns</Option>,
463 <Option>-fwarn-unused-imports</Option> and <Option>-fwarn-unused-binds</Option>.
464 </Para>
465 </ListItem>
466 </VarListEntry>
467
468 <VarListEntry>
469 <Term><Option>-Wall</Option>:</Term>
470 <ListItem>
471 <Para>
472 <IndexTerm><Primary>-Wall option</Primary></IndexTerm>
473 Turns on all warning options.
474 </Para>
475 </ListItem>
476 </VarListEntry>
477
478 </VariableList>
479 </Para>
480
481 <Para>
482 The full set of warning options is described below.  To turn off any
483 warning, simply give the corresponding <Option>-fno-warn-...</Option> option on
484 the command line.
485 </Para>
486
487 <Para>
488 <VariableList>
489
490 <VarListEntry>
491 <Term><Option>-fwarn-name-shadowing</Option>:</Term>
492 <ListItem>
493 <Para>
494 <IndexTerm><Primary>-fwarn-name-shadowing option</Primary></IndexTerm>
495 <IndexTerm><Primary>shadowing, warning</Primary></IndexTerm>This option causes a warning to be emitted whenever an inner-scope
496 value has the same name as an outer-scope value, i.e. the inner value
497 shadows the outer one.  This can catch typographical errors that turn
498 into hard-to-find bugs, e.g., in the inadvertent cyclic definition
499 <Literal>let x = ... x ... in</Literal>.
500 </Para>
501
502 <Para>
503 Consequently, this option does <Emphasis>not</Emphasis> allow cyclic recursive
504 definitions.
505 </Para>
506 </ListItem>
507 </VarListEntry>
508
509 <VarListEntry>
510 <Term><Option>-fwarn-overlapping-patterns</Option>:</Term>
511 <ListItem>
512 <Para>
513 <IndexTerm><Primary>-fwarn-overlapping-patterns option</Primary></IndexTerm>
514 <IndexTerm><Primary>overlapping patterns, warning</Primary></IndexTerm>
515 <IndexTerm><Primary>patterns, overlapping</Primary></IndexTerm>
516 By default, the compiler will warn you if a set of patterns are
517 overlapping, i.e.,
518 </Para>
519
520 <Para>
521 <ProgramListing>
522 f :: String -&#62; Int
523 f []     = 0
524 f (_:xs) = 1
525 f "2"    = 2
526 </ProgramListing>
527 </Para>
528
529 <Para>
530 where the last pattern match in <Function>f</Function> won't ever be reached, as the
531 second pattern overlaps it. More often than not, redundant patterns
532 is a programmer mistake/error, so this option is enabled by default.
533 </Para>
534 </ListItem>
535 </VarListEntry>
536
537 <VarListEntry>
538 <Term><Option>-fwarn-incomplete-patterns</Option>:</Term>
539 <ListItem>
540 <Para>
541 <IndexTerm><Primary>-fwarn-incomplete-patterns option</Primary></IndexTerm>
542 <IndexTerm><Primary>incomplete patterns, warning</Primary></IndexTerm>
543 <IndexTerm><Primary>patterns, incomplete</Primary></IndexTerm>
544 Similarly for incomplete patterns, the function <Function>g</Function> below will fail
545 when applied to non-empty lists, so the compiler will emit a warning
546 about this when <Option>-fwarn-incomplete-patterns</Option> is enabled.
547 </Para>
548
549 <Para>
550 <ProgramListing>
551 g [] = 2
552 </ProgramListing>
553 </Para>
554
555 <Para>
556 This option isn't enabled be default because it can be a bit noisy,
557 and it doesn't always indicate a bug in the program.  However, it's
558 generally considered good practice to cover all the cases in your
559 functions.
560 </Para>
561 </ListItem>
562 </VarListEntry>
563
564 <VarListEntry>
565 <Term><Option>-fwarn-missing-methods</Option>:</Term>
566 <ListItem>
567 <Para>
568 <IndexTerm><Primary>-fwarn-missing-methods option</Primary></IndexTerm>
569 <IndexTerm><Primary>missing methods, warning</Primary></IndexTerm>
570 <IndexTerm><Primary>methods, missing</Primary></IndexTerm>
571 This option is on by default, and warns you whenever an instance
572 declaration is missing one or more methods, and the corresponding
573 class declaration has no default declaration for them.
574 </Para>
575 </ListItem>
576 </VarListEntry>
577
578 <VarListEntry>
579 <Term><Option>-fwarn-missing-fields</Option>:</Term>
580 <ListItem>
581 <Para>
582 <IndexTerm><Primary>-fwarn-missing-fields option</Primary></IndexTerm>
583 <IndexTerm><Primary>missing fields, warning</Primary></IndexTerm>
584 <IndexTerm><Primary>fields, missing</Primary></IndexTerm>
585 This option is on by default, and warns you whenever the construction
586 of a labelled field constructor isn't complete, missing initializers
587 for one or more fields. While not an error (the missing fields are
588 initialised with bottoms), it is often an indication of a programmer
589 error.
590 </Para>
591 </ListItem>
592 </VarListEntry>
593
594 <VarListEntry>
595 <Term><Option>-fwarn-unused-imports</Option>:</Term>
596 <ListItem>
597 <Para>
598 <IndexTerm><Primary>-fwarn-unused-imports option</Primary></IndexTerm>
599 <IndexTerm><Primary>unused imports, warning</Primary></IndexTerm>
600 <IndexTerm><Primary>imports, unused</Primary></IndexTerm>
601 Report any objects that are explicitly imported but never used.
602 </Para>
603 </ListItem>
604 </VarListEntry>
605
606 <VarListEntry>
607 <Term><Option>-fwarn-unused-binds</Option>:</Term>
608 <ListItem>
609 <Para>
610 <IndexTerm><Primary>-fwarn-unused-binds option</Primary></IndexTerm>
611 <IndexTerm><Primary>unused binds, warning</Primary></IndexTerm>
612 <IndexTerm><Primary>binds, unused</Primary></IndexTerm>
613 Report any function definitions (and local bindings) which are unused.
614 For top-level functions, the warning is only given if the binding is
615 not exported.
616 </Para>
617 </ListItem>
618 </VarListEntry>
619 <VarListEntry>
620 <Term><Option>-fwarn-unused-matches</Option>:</Term>
621 <ListItem>
622 <Para>
623 <IndexTerm><Primary>-fwarn-unused-matches option</Primary></IndexTerm>
624 <IndexTerm><Primary>unused matches, warning</Primary></IndexTerm>
625 <IndexTerm><Primary>matches, unused</Primary></IndexTerm>
626 Report all unused variables which arise from pattern matches,
627 including patterns consisting of a single variable.  For instance <Literal>f x
628 y = []</Literal> would report <VarName>x</VarName> and <VarName>y</VarName> as unused.  To eliminate the warning,
629 all unused variables can be replaced with wildcards.
630 </Para>
631 </ListItem>
632 </VarListEntry>
633
634 <VarListEntry>
635 <Term><Option>-fwarn-duplicate-exports</Option>:</Term>
636 <ListItem>
637 <Para>
638 <IndexTerm><Primary>-fwarn-duplicate-exports option</Primary></IndexTerm>
639 <IndexTerm><Primary>duplicate exports, warning</Primary></IndexTerm>
640 <IndexTerm><Primary>export lists, duplicates</Primary></IndexTerm>
641 Have the compiler warn about duplicate entries in export lists. This
642 is useful information if you maintain large export lists, and want to
643 avoid the continued export of a definition after you've deleted (one)
644 mention of it in the export list.
645 </Para>
646
647 <Para>
648 This option is on by default.
649 </Para>
650 </ListItem>
651 </VarListEntry>
652
653 <VarListEntry>
654 <Term><Option>-fwarn-type-defaults</Option>:</Term>
655 <ListItem>
656 <Para>
657 <IndexTerm><Primary>-fwarn-type-defaults option</Primary></IndexTerm>
658 <IndexTerm><Primary>defaulting mechanism, warning</Primary></IndexTerm>
659 Have the compiler warn/inform you where in your source the Haskell
660 defaulting mechanism for numeric types kicks in. This is useful
661 information when converting code from a context that assumed one
662 default into one with another, e.g., the `default default' for Haskell
663 1.4 caused the otherwise unconstrained value <Constant>1</Constant> to be given
664 the type <Literal>Int</Literal>, whereas Haskell 98 defaults it to
665 <Literal>Integer</Literal>.  This may lead to differences in performance and
666 behaviour, hence the usefulness of being non-silent about this.
667 </Para>
668
669 <Para>
670 This warning is off by default.
671 </Para>
672 </ListItem>
673 </VarListEntry>
674
675 <VarListEntry>
676 <Term><Option>-fwarn-missing-signatures</Option>:</Term>
677 <ListItem>
678 <Para>
679 <IndexTerm><Primary>-fwarn-missing-signatures option</Primary></IndexTerm>
680 <IndexTerm><Primary>type signatures, missing</Primary></IndexTerm>
681 If you would like GHC to check that every top-level function/value has
682 a type signature, use the <Option>-fwarn-missing-signatures</Option> option.  This
683 option is off by default.
684 </Para>
685 </ListItem>
686 </VarListEntry>
687 </VariableList>
688 </Para>
689
690 <Para>
691 If you're feeling really paranoid, the <Option>-dcore-lint</Option>
692 option<IndexTerm><Primary>-dcore-lint option</Primary></IndexTerm> is a good choice.  It turns on
693 heavyweight intra-pass sanity-checking within GHC.  (It checks GHC's
694 sanity, not yours.)
695 </Para>
696
697 </Sect1>
698
699 <Sect1 id="separate-compilation">
700 <Title>Separate compilation
701 </Title>
702
703 <Para>
704 <IndexTerm><Primary>separate compilation</Primary></IndexTerm>
705 <IndexTerm><Primary>recompilation checker</Primary></IndexTerm>
706 <IndexTerm><Primary>make and recompilation</Primary></IndexTerm>
707 </Para>
708
709 <Para>
710 This section describes how GHC supports separate compilation.
711 </Para>
712
713 <Sect2 id="hi-files">
714 <Title>Interface files
715 </Title>
716
717 <Para>
718 <IndexTerm><Primary>interface files</Primary></IndexTerm>
719 <IndexTerm><Primary>.hi files</Primary></IndexTerm>
720 </Para>
721
722 <Para>
723 When GHC compiles a source file <Filename>F</Filename> which contains a module <Literal>A</Literal>, say,
724 it generates an object <Filename>F.o</Filename>, <Emphasis>and</Emphasis> a companion <Emphasis>interface
725 file</Emphasis> <Filename>A.hi</Filename>.  The interface file is not intended for human
726 consumption, as you'll see if you take a look at one.  It's merely
727 there to help the compiler compile other modules in the same program.
728 </Para>
729
730 <Para>
731 NOTE: Having the name of the interface file follow the module name and
732 not the file name, means that working with tools such as <Command>make</Command>
733 become harder. <Command>make</Command> implicitly assumes that any output files
734 produced by processing a translation unit will have file names that
735 can be derived from the file name of the translation unit.  For
736 instance, pattern rules becomes unusable.  For this reason, we
737 recommend you stick to using the same file name as the module name.
738 </Para>
739
740 <Para>
741 The interface file for <Literal>A</Literal> contains information needed by the compiler
742 when it compiles any module <Literal>B</Literal> that imports <Literal>A</Literal>, whether directly or
743 indirectly.  When compiling <Literal>B</Literal>, GHC will read <Filename>A.hi</Filename> to find the
744 details that it needs to know about things defined in <Literal>A</Literal>.
745 </Para>
746
747 <Para>
748 Furthermore, when compiling module <Literal>C</Literal> which imports <Literal>B</Literal>, GHC may
749 decide that it needs to know something about <Literal>A</Literal>&mdash;for example, <Literal>B</Literal>
750 might export a function that involves a type defined in <Literal>A</Literal>.  In this
751 case, GHC will go and read <Command>A.hi</Command> even though <Literal>C</Literal> does not explicitly
752 import <Literal>A</Literal> at all.
753 </Para>
754
755 <Para>
756 The interface file may contain all sorts of things that aren't
757 explicitly exported from <Literal>A</Literal> by the programmer.  For example, even
758 though a data type is exported abstractly, <Filename>A.hi</Filename> will contain the
759 full data type definition.  For small function definitions, <Filename>A.hi</Filename>
760 will contain the complete definition of the function.  For bigger
761 functions, <Filename>A.hi</Filename> will contain strictness information about the
762 function.  And so on.  GHC puts much more information into <Filename>.hi</Filename> files
763 when optimisation is turned on with the <Option>-O</Option> flag.  Without <Option>-O</Option> it
764 puts in just the minimum; with <Option>-O</Option> it lobs in a whole pile of stuff.
765 <IndexTerm><Primary>optimsation, effect on .hi files</Primary></IndexTerm>
766 </Para>
767
768 <Para>
769 <Filename>A.hi</Filename> should really be thought of as a compiler-readable version of
770 <Filename>A.o</Filename>.  If you use a <Filename>.hi</Filename> file that wasn't generated by the same
771 compilation run that generates the <Filename>.o</Filename> file the compiler may assume
772 all sorts of incorrect things about <Literal>A</Literal>, resulting in core dumps and
773 other unpleasant happenings.
774 </Para>
775
776 </Sect2>
777
778 <Sect2 id="options-finding-imports">
779 <Title>Finding interface files
780 </Title>
781
782 <Para>
783 <IndexTerm><Primary>interface files, finding them</Primary></IndexTerm>
784 <IndexTerm><Primary>finding interface files</Primary></IndexTerm>
785 </Para>
786
787 <Para>
788 In your program, you import a module <Literal>Foo</Literal> by saying
789 <Literal>import Foo</Literal>.  GHC goes looking for an interface file, <Filename>Foo.hi</Filename>.
790 It has a builtin list of directories (notably including <Filename>.</Filename>) where
791 it looks.
792 </Para>
793
794 <Para>
795 <VariableList>
796
797 <VarListEntry>
798 <Term><Option>-i&lt;dirs&gt;</Option></Term>
799 <ListItem>
800 <Para>
801 <IndexTerm><Primary>-i&lt;dirs&gt; option</Primary></IndexTerm>This flag
802 prepends a colon-separated list of <Filename>dirs</Filename> to the &ldquo;import
803 directories&rdquo; list.
804 See also <XRef LinkEnd="recomp"> for the significance of using
805 relative and absolute pathnames in the <Option>-i</Option> list.
806 </Para>
807 </ListItem>
808 </VarListEntry>
809
810 <VarListEntry>
811 <Term><Option>-i</Option></Term>
812 <ListItem>
813 <Para>
814 resets the &ldquo;import directories&rdquo; list back to nothing.
815 </Para>
816 </ListItem>
817 </VarListEntry>
818
819 <VarListEntry>
820 <Term><Option>-fno-implicit-prelude</Option></Term>
821 <ListItem>
822 <Para>
823 <IndexTerm><Primary>-fno-implicit-prelude option</Primary></IndexTerm>
824 GHC normally imports <Filename>Prelude.hi</Filename> files for you.  If you'd rather it
825 didn't, then give it a <Option>-fno-implicit-prelude</Option> option.  You are
826 unlikely to get very far without a Prelude, but, hey, it's a free
827 country.
828 </Para>
829 </ListItem>
830 </VarListEntry>
831
832 <VarListEntry>
833 <Term><Option>-syslib &lt;lib&gt;</Option></Term>
834 <ListItem>
835 <Para>
836 <IndexTerm><Primary>-syslib &lt;lib&gt; option</Primary></IndexTerm>
837 If you are using a system-supplied non-Prelude library (e.g., the
838 POSIX library), just use a <Option>-syslib posix</Option> option (for
839 example).  The right interface files should then be available.  The
840 accompanying HsLibs document lists the libraries available by this
841 mechanism.
842 </Para>
843 </ListItem>
844 </VarListEntry>
845
846 <VarListEntry>
847 <Term><Option>-I&lt;dir&gt;</Option></Term>
848 <ListItem>
849 <Para>
850 <IndexTerm><Primary>-I&lt;dir&gt; option</Primary></IndexTerm>
851 Once a Haskell module has been compiled to C (<Filename>.hc</Filename> file), you may
852 wish to specify where GHC tells the C compiler to look for <Filename>.h</Filename> files.
853 (Or, if you are using the <Option>-cpp</Option> option<IndexTerm><Primary>-cpp option</Primary></IndexTerm>, where
854 it tells the C pre-processor to look&hellip;)  For this purpose, use a <Option>-I</Option>
855 option in the usual C-ish way.
856 </Para>
857 </ListItem>
858 </VarListEntry>
859
860 </VariableList>
861 </Para>
862
863 </Sect2>
864
865 <Sect2 id="hi-options">
866 <Title>Other options related to interface files
867 </Title>
868
869 <Para>
870 <IndexTerm><Primary>interface files, options</Primary></IndexTerm>
871 The interface output may be directed to another file
872 <Filename>bar2/Wurble.iface</Filename> with the option <Option>-ohi bar2/Wurble.iface</Option><IndexTerm><Primary>-ohi
873 &lt;file&gt; option</Primary></IndexTerm> (not recommended).
874 </Para>
875
876 <Para>
877 To avoid generating an interface file at all, use a <Option>-nohi</Option>
878 option.<IndexTerm><Primary>-nohi option</Primary></IndexTerm>
879 </Para>
880
881 <Para>
882 The compiler does not overwrite an existing <Filename>.hi</Filename> interface file if
883 the new one is byte-for-byte the same as the old one; this is friendly
884 to <Command>make</Command>.  When an interface does change, it is often enlightening to
885 be informed.  The <Option>-hi-diffs</Option><IndexTerm><Primary>-hi-diffs option</Primary></IndexTerm> option will
886 make GHC run <Command>diff</Command> on the old and new <Filename>.hi</Filename> files. You can also
887 record the difference in the interface file itself, the
888 <Option>-keep-hi-diffs</Option><IndexTerm><Primary>-keep-hi-diffs</Primary></IndexTerm> option takes care of that.
889 </Para>
890
891 <Para>
892 The <Filename>.hi</Filename> files from GHC contain &ldquo;usage&rdquo; information which changes
893 often and uninterestingly.  If you really want to see these changes
894 reported, you need to use the
895 <Option>-hi-diffs-with-usages</Option><IndexTerm><Primary>-hi-diffs-with-usages option</Primary></IndexTerm>
896 option.
897 </Para>
898
899 <Para>
900 Interface files are normally jammed full of compiler-produced
901 <Emphasis>pragmas</Emphasis>, which record arities, strictness info, etc.  If you
902 think these pragmas are messing you up (or you are doing some kind of
903 weird experiment), you can tell GHC to ignore them with the
904 <Option>-fignore-interface-pragmas</Option><IndexTerm><Primary>-fignore-interface-pragmas
905 option</Primary></IndexTerm> option.
906 </Para>
907
908 <Para>
909 When compiling without optimisations on, the compiler is extra-careful
910 about not slurping in data constructors and instance declarations that
911 it will not need. If you believe it is getting it wrong and not
912 importing stuff which you think it should, this optimisation can be
913 turned off with <Option>-fno-prune-tydecls</Option> and <Option>-fno-prune-instdecls</Option>.
914 <IndexTerm><Primary>-fno-prune-tydecls option</Primary></IndexTerm><IndexTerm><Primary>-fno-prune-instdecls
915 option</Primary></IndexTerm>
916 </Para>
917
918 <Para>
919 See also <XRef LinkEnd="options-linker">, which describes how the linker finds standard
920 Haskell libraries.
921 </Para>
922
923 </Sect2>
924
925 <Sect2 id="recomp">
926 <Title>The recompilation checker
927 </Title>
928
929 <IndexTerm><Primary>recompilation checker</Primary></IndexTerm>
930
931 <Para>
932 <variablelist>
933 <VarListEntry>
934 <Term><Option>-recomp</Option></Term>
935 <IndexTerm><Primary><option>-recomp</option> option</Primary></IndexTerm>
936 <ListItem>
937 <Para>
938 (On by default) Turn on recompilation checking.  This will stop
939 compilation early, leaving an existing <filename>.o</filename> file in
940 place, if it can be determined that the module does not need to be
941 recompiled.
942 </Para>
943 </ListItem>
944 </VarListEntry>
945 <VarListEntry>
946 <Term><Option>-no-recomp</Option></Term>
947 <IndexTerm><Primary><option>-recomp</option> option</Primary></IndexTerm>
948 <ListItem>
949 <Para>
950 Turn off recompilation checking.
951 </Para>
952 </ListItem>
953 </VarListEntry>
954 </VariableList>
955 </Para>
956
957 <Para>
958 In the olden days, GHC compared the newly-generated
959 <Filename>.hi</Filename> file with the previous version; if they were
960 identical, it left the old one alone and didn't change its
961 modification date.  In consequence, importers of a module with an
962 unchanged output <Filename>.hi</Filename> file were not recompiled.
963 </Para>
964
965 <Para>
966 This doesn't work any more.  In our earlier example, module
967 <Literal>C</Literal> does not import module <Literal>A</Literal>
968 directly, yet changes to <Filename>A.hi</Filename> should force a
969 recompilation of <Literal>C</Literal>.  And some changes to
970 <Literal>A</Literal> (changing the definition of a function that
971 appears in an inlining of a function exported by <Literal>B</Literal>,
972 say) may conceivably not change <Filename>B.hi</Filename> one jot.  So
973 now&hellip;
974 </Para>
975
976 <Para>
977 GHC keeps a version number on each interface file, and on each type
978 signature within the interface file.  It also keeps in every interface
979 file a list of the version numbers of everything it used when it last
980 compiled the file.  If the source file's modification date is earlier
981 than the <Filename>.o</Filename> file's date (i.e. the source hasn't
982 changed since the file was last compiled), and the
983 <option>-recomp</option> is given on the command line, GHC will be
984 clever.  It compares the version numbers on the things it needs this
985 time with the version numbers on the things it needed last time
986 (gleaned from the interface file of the module being compiled); if
987 they are all the same it stops compiling rather early in the process
988 saying &ldquo;Compilation IS NOT required&rdquo;.  What a beautiful
989 sight!
990 </Para>
991
992 <Para>
993 GHC <Emphasis>only</Emphasis> keeps detailed dependency information
994 for &ldquo;user&rdquo; modules, not for &ldquo;library&rdquo; modules.
995 It distinguishes the two by a hack: a module whose
996 <Filename>.hi</Filename> file has an absolute path name is considered
997 a library module, while a relative path name indicates a user module.
998 So if you have a multi-directory application, use
999 <Emphasis>relative</Emphasis> path names in your <Option>-i</Option>
1000 path, to force GHC to record detailed dependency information.  Use
1001 absolute path names only for directories containing slowly-changing
1002 library modules.
1003 </Para>
1004
1005 <Para>
1006 A path is considered &ldquo;absolute&rdquo; if it starts with
1007 &ldquo;<Filename>/</Filename>&rdquo;, or
1008 &ldquo;<Filename>A:/</Filename>&rdquo;, or
1009 &ldquo;<Filename>A:\</Filename>&rdquo; (or
1010 &ldquo;<Filename>B:/</Filename>&rdquo;,
1011 &ldquo;<Filename>B:\</Filename>&rdquo; etc).
1012 </Para>
1013
1014 <Para>
1015 Patrick Sansom had a workshop paper about how all this is done (though
1016 the details have changed quite a bit). <ULink URL="mailto:sansom@dcs.gla.ac.uk">Ask him</ULink> if you want a copy.
1017 </Para>
1018
1019 </Sect2>
1020
1021 <Sect2 id="using-make">
1022 <Title>Using <Command>make</Command>
1023 </Title>
1024
1025 <Para>
1026 <IndexTerm><Primary><literal>make</literal></Primary></IndexTerm>
1027 </Para>
1028
1029 <Para>
1030 It is reasonably straightforward to set up a <Filename>Makefile</Filename> to use with
1031 GHC, assuming you name your source files the same as your modules.
1032 Thus:
1033 </Para>
1034
1035 <Para>
1036
1037 <ProgramListing>
1038 HC      = ghc
1039 HC_OPTS = -cpp $(EXTRA_HC_OPTS)
1040
1041 SRCS = Main.lhs Foo.lhs Bar.lhs
1042 OBJS = Main.o   Foo.o   Bar.o
1043
1044 .SUFFIXES : .o .hi .lhs .hc .s
1045
1046 cool_pgm : $(OBJS)
1047         rm $@
1048         $(HC) -o $@ $(HC_OPTS) $(OBJS)
1049
1050 # Standard suffix rules
1051 .o.hi:
1052         @:
1053
1054 .lhs.o:
1055         $(HC) -c $&#60; $(HC_OPTS)
1056
1057 .hs.o:
1058         $(HC) -c $&#60; $(HC_OPTS)
1059
1060 # Inter-module dependencies
1061 Foo.o Foo.hc Foo.s    : Baz.hi          # Foo imports Baz
1062 Main.o Main.hc Main.s : Foo.hi Baz.hi   # Main imports Foo and Baz
1063 </ProgramListing>
1064
1065 </Para>
1066
1067 <Para>
1068 (Sophisticated <Command>make</Command> variants may achieve some of the above more
1069 elegantly.  Notably, <Command>gmake</Command>'s pattern rules let you write the more
1070 comprehensible:
1071 </Para>
1072
1073 <Para>
1074
1075 <ProgramListing>
1076 %.o : %.lhs
1077         $(HC) -c $&#60; $(HC_OPTS)
1078 </ProgramListing>
1079
1080 </Para>
1081
1082 <Para>
1083 What we've shown should work with any <Command>make</Command>.)
1084 </Para>
1085
1086 <Para>
1087 Note the cheesy <Literal>.o.hi</Literal> rule: It records the dependency of the
1088 interface (<Filename>.hi</Filename>) file on the source.  The rule says a <Filename>.hi</Filename> file can
1089 be made from a <Filename>.o</Filename> file by doing&hellip;nothing.  Which is true.
1090 </Para>
1091
1092 <Para>
1093 Note the inter-module dependencies at the end of the Makefile, which
1094 take the form
1095 </Para>
1096
1097 <Para>
1098
1099 <ProgramListing>
1100 Foo.o Foo.hc Foo.s    : Baz.hi          # Foo imports Baz
1101 </ProgramListing>
1102
1103 </Para>
1104
1105 <Para>
1106 They tell <Command>make</Command> that if any of <Literal>Foo.o</Literal>, <Literal>Foo.hc</Literal> or <Literal>Foo.s</Literal> have an
1107 earlier modification date than <Literal>Baz.hi</Literal>, then the out-of-date file
1108 must be brought up to date.  To bring it up to date, <Literal>make</Literal> looks for
1109 a rule to do so; one of the preceding suffix rules does the job
1110 nicely.
1111 </Para>
1112
1113 <Para>
1114 Putting inter-dependencies of the form <Literal>Foo.o : Bar.hi</Literal> into your
1115 <Filename>Makefile</Filename> by hand is rather error-prone.  Don't worry&mdash;never fear,
1116 <Command>mkdependHS</Command> is here! (and is distributed as part of GHC) Add the
1117 following to your <Filename>Makefile</Filename>:
1118 </Para>
1119
1120 <Para>
1121
1122 <ProgramListing>
1123 depend :
1124         mkdependHS -- $(HC_OPTS) -- $(SRCS)
1125 </ProgramListing>
1126
1127 </Para>
1128
1129 <Para>
1130 Now, before you start compiling, and any time you change the <Literal>imports</Literal>
1131 in your program, do <Command>make depend</Command> before you do <Command>make cool&lowbar;pgm</Command>.
1132 <Command>mkdependHS</Command> will append the needed dependencies to your <Filename>Makefile</Filename>.
1133 <Command>mkdependHS</Command> is fully described in <XRef LinkEnd="mkdependHS">.
1134 </Para>
1135
1136 <Para>
1137 A few caveats about this simple scheme:
1138 </Para>
1139
1140 <Para>
1141
1142 <ItemizedList>
1143 <ListItem>
1144
1145 <Para>
1146  You may need to compile some modules explicitly to create their
1147 interfaces in the first place (e.g., <Command>make Bar.o</Command> to create <Filename>Bar.hi</Filename>).
1148
1149 </Para>
1150 </ListItem>
1151 <ListItem>
1152
1153 <Para>
1154  You may have to type <Command>make</Command> more than once for the dependencies
1155 to have full effect.  However, a <Command>make</Command> run that does nothing
1156 <Emphasis>does</Emphasis> mean &ldquo;everything's up-to-date.&rdquo;
1157
1158 </Para>
1159 </ListItem>
1160 <ListItem>
1161
1162 <Para>
1163  This scheme will work with mutually-recursive modules but,
1164 again, it may take multiple iterations to &ldquo;settle.&rdquo;
1165
1166 </Para>
1167 </ListItem>
1168
1169 </ItemizedList>
1170
1171 </Para>
1172
1173 </Sect2>
1174
1175 <Sect2 id="mutual-recursion">
1176 <Title>How to compile mutually recursive modules
1177 </Title>
1178
1179 <Para>
1180 <IndexTerm><Primary>module system, recursion</Primary></IndexTerm>
1181 <IndexTerm><Primary>recursion, between modules</Primary></IndexTerm>
1182 </Para>
1183
1184 <Para>
1185 Currently, the compiler does not have proper support for dealing with
1186 mutually recursive modules:
1187 </Para>
1188
1189 <Para>
1190
1191 <ProgramListing>
1192 module A where
1193
1194 import B
1195
1196 newtype TA = MkTA Int
1197
1198 f :: TB -&#62; TA
1199 f (MkTB x) = MkTA x
1200 --------
1201 module B where
1202
1203 import A
1204
1205 data TB = MkTB !Int
1206
1207 g :: TA -&#62; TB
1208 g (MkTA x) = MkTB x
1209 </ProgramListing>
1210
1211 </Para>
1212
1213 <Para>
1214 When compiling either module A and B, the compiler will try (in vain)
1215 to look for the interface file of the other. So, to get mutually
1216 recursive modules off the ground, you need to hand write an interface
1217 file for A or B, so as to break the loop.  These hand-written
1218 interface files are called <Literal>hi-boot</Literal> files, and are placed in a file
1219 called <Filename>&lt;module&gt;.hi-boot</Filename>.  To import from an <Literal>hi-boot</Literal> file instead
1220 of the standard <Filename>.hi</Filename> file, use the following syntax in the importing module:
1221 <IndexTerm><Primary>hi-boot files</Primary></IndexTerm>
1222 <IndexTerm><Primary>importing, hi-boot files</Primary></IndexTerm>
1223 </Para>
1224
1225 <Para>
1226
1227 <ProgramListing>
1228 import {-# SOURCE #-} A
1229 </ProgramListing>
1230
1231 </Para>
1232
1233 <Para>
1234 The hand-written interface need only contain the bare minimum of
1235 information needed to get the bootstrapping process started.  For
1236 example, it doesn't need to contain declarations for <Emphasis>everything</Emphasis>
1237 that module <Literal>A</Literal> exports, only the things required by the module that
1238 imports <Literal>A</Literal> recursively.
1239 </Para>
1240
1241 <Para>
1242 For the example at hand, the boot interface file for A would look like
1243 the following:
1244 </Para>
1245
1246 <Para>
1247
1248 <ProgramListing>
1249 __interface A 1 404 where
1250 __export A TA{MkTA} ;
1251 1 newtype TA = MkTA PrelBase.Int ;
1252 </ProgramListing>
1253
1254 </Para>
1255
1256 <Para>
1257 The syntax is essentially the same as a normal <Filename>.hi</Filename> file
1258 (unfortunately), but you can usually tailor an existing <Filename>.hi</Filename> file to
1259 make a <Filename>.hi-boot</Filename> file.
1260 </Para>
1261
1262 <Para>
1263 Notice that we only put the declaration for the newtype <Literal>TA</Literal> in the
1264 <Literal>hi-boot</Literal> file, not the signature for <Function>f</Function>, since <Function>f</Function> isn't used by
1265 <Literal>B</Literal>.
1266 </Para>
1267
1268 <Para>
1269 The number &ldquo;1&rdquo; after &ldquo;&lowbar;&lowbar;interface A&rdquo; gives the version number of module A;
1270 it is incremented whenever anything in A's interface file changes.  The &ldquo;404&rdquo; is
1271 the version number of the interface file <Emphasis>syntax</Emphasis>; we change it when
1272 we change the syntax of interface files so that you get a better error message when
1273 you try to read an old-format file with a new-format compiler.
1274 </Para>
1275
1276 <Para>
1277 The number &ldquo;1&rdquo; at the beginning of a declaration is the <Emphasis>version
1278 number</Emphasis> of that declaration: for the purposes of <Filename>.hi-boot</Filename> files
1279 these can all be set to 1.  All names must be fully qualified with the
1280 <Emphasis>original</Emphasis> module that an object comes from: for example, the
1281 reference to <Literal>Int</Literal> in the interface for <Literal>A</Literal> comes from <Literal>PrelBase</Literal>,
1282 which is a module internal to GHC's prelude.  It's a pain, but that's
1283 the way it is.
1284 </Para>
1285
1286 <Para>
1287 If you want an hi-boot file to export a data type, but you don't want to give its constructors
1288 (because the constructors aren't used by the SOURCE-importing module), you can write simply:
1289 </Para>
1290
1291 <Para>
1292
1293 <ProgramListing>
1294 __interface A 1 404 where
1295 __export A TA;
1296 1 data TA
1297 </ProgramListing>
1298
1299 </Para>
1300
1301 <Para>
1302 (You must write all the type parameters, but leave out the '=' and everything that follows it.)
1303 </Para>
1304
1305 <Para>
1306 <Emphasis>Note:</Emphasis> This is all a temporary solution, a version of the
1307 compiler that handles mutually recursive modules properly without the manual
1308 construction of interface files, is (allegedly) in the works.
1309 </Para>
1310
1311 </Sect2>
1312
1313 </Sect1>
1314
1315 <Sect1 id="options-optimise">
1316 <Title>Optimisation (code improvement)
1317 </Title>
1318
1319 <Para>
1320 <IndexTerm><Primary>optimisation (GHC)</Primary></IndexTerm>
1321 <IndexTerm><Primary>improvement, code (GHC)</Primary></IndexTerm>
1322 </Para>
1323
1324 <Para>
1325 The <Option>-O*</Option> options specify convenient &ldquo;packages&rdquo; of optimisation
1326 flags; the <Option>-f*</Option> options described later on specify
1327 <Emphasis>individual</Emphasis> optimisations to be turned on/off; the <Option>-m*</Option>
1328 options specify <Emphasis>machine-specific</Emphasis> optimisations to be turned
1329 on/off.
1330 </Para>
1331
1332 <Sect2 id="optimise-pkgs">
1333 <Title><Option>-O*</Option>: convenient &ldquo;packages&rdquo; of optimisation flags.
1334 </Title>
1335
1336 <Para>
1337 <IndexTerm><Primary>-O options</Primary></IndexTerm>
1338 </Para>
1339
1340 <Para>
1341 There are <Emphasis>many</Emphasis> options that affect the quality of code
1342 produced by GHC.  Most people only have a general goal, something like
1343 &ldquo;Compile quickly&rdquo; or &ldquo;Make my program run like greased lightning.&rdquo;
1344 The following &ldquo;packages&rdquo; of optimisations (or lack thereof) should
1345 suffice.
1346 </Para>
1347
1348 <Para>
1349 Once you choose a <Option>-O*</Option> &ldquo;package,&rdquo; stick with it&mdash;don't chop and
1350 change.  Modules' interfaces <Emphasis>will</Emphasis> change with a shift to a new
1351 <Option>-O*</Option> option, and you may have to recompile a large chunk of all
1352 importing modules before your program can again be run
1353 safely (see <XRef LinkEnd="recomp">).
1354 </Para>
1355
1356 <Para>
1357 <VariableList>
1358
1359 <VarListEntry>
1360 <Term>No <Option>-O*</Option>-type option specified:</Term>
1361 <IndexTerm><Primary>-O* not specified</Primary></IndexTerm>
1362 <ListItem>
1363 <Para>
1364 This is taken to mean: &ldquo;Please compile quickly; I'm not over-bothered
1365 about compiled-code quality.&rdquo;  So, for example: <Command>ghc -c Foo.hs</Command>
1366 </Para>
1367 </ListItem>
1368 </VarListEntry>
1369 <VarListEntry>
1370 <Term><Option>-O</Option> or <Option>-O1</Option>:</Term>
1371 <IndexTerm><Primary>-O option</Primary></IndexTerm>
1372 <IndexTerm><Primary>-O1 option</Primary></IndexTerm>
1373 <IndexTerm><Primary>optimise</Primary><secondary>normally</secondary></IndexTerm>
1374 <ListItem>
1375 <Para>
1376 Means: &ldquo;Generate good-quality code without taking too long about
1377 it.&rdquo; Thus, for example: <Command>ghc -c -O Main.lhs</Command>
1378 </Para>
1379 </ListItem>
1380 </VarListEntry>
1381 <VarListEntry>
1382 <Term><Option>-O2</Option>:</Term>
1383 <IndexTerm><Primary>-O2 option</Primary></IndexTerm>
1384 <IndexTerm><Primary>optimise</Primary><secondary>aggressively</secondary></IndexTerm>
1385 <ListItem>
1386 <Para>
1387 Means: &ldquo;Apply every non-dangerous optimisation, even if it means
1388 significantly longer compile times.&rdquo;
1389 </Para>
1390
1391 <Para>
1392 The avoided &ldquo;dangerous&rdquo; optimisations are those that can make
1393 runtime or space <Emphasis>worse</Emphasis> if you're unlucky.  They are
1394 normally turned on or off individually.
1395 </Para>
1396
1397 <Para>
1398 At the moment, <Option>-O2</Option> is <Emphasis>unlikely</Emphasis> to produce
1399 better code than <Option>-O</Option>.
1400 </Para>
1401 </ListItem>
1402 </VarListEntry>
1403 <VarListEntry>
1404 <Term><Option>-O2-for-C</Option>:</Term>
1405 <IndexTerm><Primary>-O2-for-C option</Primary></IndexTerm>
1406 <IndexTerm><Primary>gcc, invoking with -O2</Primary></IndexTerm>
1407 <ListItem>
1408 <Para>
1409 Says to run GCC with <Option>-O2</Option>, which may be worth a few percent in
1410 execution speed.  Don't forget <Option>-fvia-C</Option>, lest you use the native-code
1411 generator and bypass GCC altogether!
1412 </Para>
1413 </ListItem>
1414 </VarListEntry>
1415 <VarListEntry>
1416 <Term><Option>-Onot</Option>:</Term>
1417 <IndexTerm><Primary>-Onot option</Primary></IndexTerm>
1418 <IndexTerm><Primary>optimising, reset</Primary></IndexTerm>
1419 <ListItem>
1420 <Para>
1421 This option will make GHC &ldquo;forget&rdquo; any
1422 <Option>-O</Option>ish options it has seen so far.  Sometimes useful;
1423 for example: <Command>make all
1424 EXTRA&lowbar;HC&lowbar;OPTS=-Onot</Command>.
1425 </Para>
1426 </ListItem>
1427 </VarListEntry>
1428 <VarListEntry>
1429 <Term><Option>-Ofile &lt;file&gt;</Option>:</Term>
1430 <IndexTerm><Primary>-Ofile &lt;file&gt; option</Primary></IndexTerm>
1431 <IndexTerm><Primary>optimising, customised</Primary></IndexTerm>
1432 <ListItem>
1433 <Para>
1434 For those who need <Emphasis>absolute</Emphasis> control over
1435 <Emphasis>exactly</Emphasis> what options are used (e.g., compiler
1436 writers, sometimes :-), a list of options can be put in a file and
1437 then slurped in with <Option>-Ofile</Option>.
1438 </Para>
1439
1440 <Para>
1441 In that file, comments are of the
1442 <Literal>&num;</Literal>-to-end-of-line variety; blank lines and most
1443 whitespace is ignored.
1444 </Para>
1445
1446 <Para>
1447 Please ask if you are baffled and would like an example of <Option>-Ofile</Option>!
1448 </Para>
1449 </ListItem>
1450 </VarListEntry>
1451 </VariableList>
1452 </Para>
1453
1454 <Para>
1455 At Glasgow, we don't use a <Option>-O*</Option> flag for day-to-day work.  We use
1456 <Option>-O</Option> to get respectable speed; e.g., when we want to measure
1457 something.  When we want to go for broke, we tend to use <Option>-O -fvia-C
1458 -O2-for-C</Option> (and we go for lots of coffee breaks).
1459 </Para>
1460
1461 <Para>
1462 The easiest way to see what <Option>-O</Option> (etc.) &ldquo;really mean&rdquo; is to run with
1463 <Option>-v</Option>, then stand back in amazement.  Alternatively, just look at the
1464 <Literal>HsC&lowbar;minus&lt;blah&gt;</Literal> lists in the GHC driver script.
1465 </Para>
1466
1467 </Sect2>
1468
1469 <Sect2>
1470 <Title><Option>-f*</Option>: platform-independent flags</Title>
1471
1472 <Para>
1473 <IndexTerm><Primary>-f* options (GHC)</Primary></IndexTerm>
1474 <IndexTerm><Primary>-fno-* options (GHC)</Primary></IndexTerm>
1475 </Para>
1476
1477 <Para>
1478 Flags can be turned <Emphasis>off</Emphasis> individually.  (NB: I hope you have a
1479 good reason for doing this&hellip;) To turn off the <Option>-ffoo</Option> flag, just use
1480 the <Option>-fno-foo</Option> flag.<IndexTerm><Primary>-fno-&lt;opt&gt; anti-option</Primary></IndexTerm> So, for
1481 example, you can say <Option>-O2 -fno-strictness</Option>, which will then drop out
1482 any running of the strictness analyser.
1483 </Para>
1484
1485 <Para>
1486 The options you are most likely to want to turn off are:
1487
1488 <ItemizedList>
1489 <ListItem>
1490
1491 <Para>
1492 <Option>-fno-strictness</Option><IndexTerm><Primary>-fno-strictness option</Primary></IndexTerm> (strictness
1493 analyser, because it is sometimes slow),
1494 </Para>
1495 </ListItem>
1496 <ListItem>
1497
1498 <Para>
1499 <Option>-fno-specialise</Option><IndexTerm><Primary>-fno-specialise option</Primary></IndexTerm> (automatic
1500 specialisation of overloaded functions, because it can make your code
1501 bigger) (US spelling also accepted), and
1502 </Para>
1503 </ListItem>
1504 <ListItem>
1505
1506 <Para>
1507 <Option>-fno-cpr-analyse</Option><IndexTerm><Primary>-fno-cpr-analyse option</Primary></IndexTerm> switches off the CPR (constructed product
1508 result) analyser.
1509 </Para>
1510 </ListItem>
1511
1512 </ItemizedList>
1513
1514 </Para>
1515
1516 <Para>
1517 Should you wish to turn individual flags <Emphasis>on</Emphasis>, you are advised
1518 to use the <Option>-Ofile</Option> option, described above.  Because the order in
1519 which optimisation passes are run is sometimes crucial, it's quite
1520 hard to do with command-line options.
1521 </Para>
1522
1523 <Para>
1524 Here are some &ldquo;dangerous&rdquo; optimisations you <Emphasis>might</Emphasis> want to try:
1525 <VariableList>
1526
1527 <VarListEntry>
1528 <Term><Option>-fvia-C</Option>:</Term>
1529 <ListItem>
1530 <Para>
1531 <IndexTerm><Primary>-fvia-C option</Primary></IndexTerm>
1532 <IndexTerm><Primary>native code generator, turning off</Primary></IndexTerm>
1533 </Para>
1534
1535 <Para>
1536 Compile via C, and don't use the native-code generator.  (There are
1537 many cases when GHC does this on its own.)  You might pick up a little
1538 bit of speed by compiling via C.  If you use <Function>&lowbar;ccall&lowbar;gc&lowbar;</Function>s or
1539 <Function>&lowbar;casm&lowbar;</Function>s, you probably <Emphasis>have</Emphasis> to use <Option>-fvia-C</Option>.
1540 </Para>
1541
1542 <Para>
1543 The lower-case incantation, <Option>-fvia-c</Option>, is synonymous.
1544 </Para>
1545
1546 <Para>
1547 Compiling via C will probably be slower (in compilation time) than
1548 using GHC's native code generator.
1549 </Para>
1550 </ListItem>
1551 </VarListEntry>
1552 <VarListEntry>
1553 <Term><Option>-funfolding-interface-threshold&lt;n&gt;</Option>:</Term>
1554 <ListItem>
1555 <Para>
1556 <IndexTerm><Primary>-funfolding-interface-threshold option</Primary></IndexTerm>
1557 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
1558 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
1559 (Default: 30) By raising or lowering this number, you can raise or
1560 lower the amount of pragmatic junk that gets spewed into interface
1561 files.  (An unfolding has a &ldquo;size&rdquo; that reflects the cost in terms
1562 of &ldquo;code bloat&rdquo; of expanding that unfolding in another module.  A
1563 bigger function would be assigned a bigger cost.)
1564 </Para>
1565 </ListItem>
1566 </VarListEntry>
1567 <VarListEntry>
1568 <Term><Option>-funfolding-creation-threshold&lt;n&gt;</Option>:</Term>
1569 <ListItem>
1570 <Para>
1571 <IndexTerm><Primary>-funfolding-creation-threshold option</Primary></IndexTerm>
1572 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
1573 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
1574 (Default: 30) This option is similar to
1575 <Option>-funfolding-interface-threshold</Option>, except that it governs unfoldings
1576 within a single module.  Increasing this figure is more likely to
1577 result in longer compile times than faster code.  The next option is
1578 more useful:
1579 </Para>
1580 </ListItem>
1581 </VarListEntry>
1582 <VarListEntry>
1583 <Term><Option>-funfolding-use-threshold&lt;n&gt;</Option>:</Term>
1584 <ListItem>
1585 <Para>
1586 <IndexTerm><Primary>-funfolding-use-threshold option</Primary></IndexTerm>
1587 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
1588 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
1589 (Default: 8) This is the magic cut-off figure for unfolding: below
1590 this size, a function definition will be unfolded at the call-site,
1591 any bigger and it won't.  The size computed for a function depends on
1592 two things: the actual size of the expression minus any discounts that
1593 apply (see <Option>-funfolding-con-discount</Option>).
1594 </Para>
1595 </ListItem>
1596 </VarListEntry>
1597 <VarListEntry>
1598 <Term><Option>-funfolding-con-discount&lt;n&gt;</Option>:</Term>
1599 <ListItem>
1600 <Para>
1601 <IndexTerm><Primary>-funfolding-con-discount option</Primary></IndexTerm>
1602 <IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
1603 <IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
1604 (Default: 2) If the compiler decides that it can eliminate some
1605 computation by performing an unfolding, then this is a discount factor
1606 that it applies to the funciton size before deciding whether to unfold
1607 it or not.
1608 </Para>
1609
1610 <Para>
1611 OK, folks, these magic numbers `30', `8', and '2' are mildly
1612 arbitrary; they are of the &ldquo;seem to be OK&rdquo; variety.  The `8' is the
1613 more critical one; it's what determines how eager GHC is about
1614 expanding unfoldings.
1615 </Para>
1616 </ListItem>
1617 </VarListEntry>
1618 <VarListEntry>
1619 <Term><Option>-funbox-strict-fields</Option>:</Term>
1620 <ListItem>
1621 <Para>
1622 <IndexTerm><Primary>-funbox-strict-fields option</Primary></IndexTerm>
1623 <IndexTerm><Primary>strict constructor fields</Primary></IndexTerm>
1624 <IndexTerm><Primary>constructor fields, strict</Primary></IndexTerm>
1625 </Para>
1626
1627 <Para>
1628 This option causes all constructor fields which are marked strict
1629 (i.e. &ldquo;!&rdquo;) to be unboxed or unpacked if possible.  For example:
1630 </Para>
1631
1632 <Para>
1633
1634 <ProgramListing>
1635 data T = T !Float !Float
1636 </ProgramListing>
1637
1638 </Para>
1639
1640 <Para>
1641 will create a constructor <Literal>T</Literal> containing two unboxed floats if the
1642 <Option>-funbox-strict-fields</Option> flag is given.  This may not always be an
1643 optimisation: if the <Function>T</Function> constructor is scrutinised and the floats
1644 passed to a non-strict function for example, they will have to be
1645 reboxed (this is done automatically by the compiler).
1646 </Para>
1647
1648 <Para>
1649 This option should only be used in conjunction with <Option>-O</Option>, in order to
1650 expose unfoldings to the compiler so the reboxing can be removed as
1651 often as possible.  For example:
1652 </Para>
1653
1654 <Para>
1655
1656 <ProgramListing>
1657 f :: T -&#62; Float
1658 f (T f1 f2) = f1 + f2
1659 </ProgramListing>
1660
1661 </Para>
1662
1663 <Para>
1664 The compiler will avoid reboxing <Function>f1</Function> and <Function>f2</Function> by inlining <Function>+</Function> on
1665 floats, but only when <Option>-O</Option> is on.
1666 </Para>
1667
1668 <Para>
1669 Any single-constructor data is eligible for unpacking; for example
1670 </Para>
1671
1672 <Para>
1673
1674 <ProgramListing>
1675 data T = T !(Int,Int)
1676 </ProgramListing>
1677
1678 </Para>
1679
1680 <Para>
1681 will store the two <Literal>Int</Literal>s directly in the <Function>T</Function> constructor, by flattening
1682 the pair.  Multi-level unpacking is also supported:
1683 </Para>
1684
1685 <Para>
1686
1687 <ProgramListing>
1688 data T = T !S
1689 data S = S !Int !Int
1690 </ProgramListing>
1691
1692 </Para>
1693
1694 <Para>
1695 will store two unboxed <Literal>Int&num;</Literal>s directly in the <Function>T</Function> constructor.
1696 </Para>
1697 </ListItem>
1698 </VarListEntry>
1699 <VarListEntry>
1700 <Term><Option>-fsemi-tagging</Option>:</Term>
1701 <ListItem>
1702 <Para>
1703 This option (which <Emphasis>does not work</Emphasis> with the native-code generator)
1704 tells the compiler to add extra code to test for already-evaluated
1705 values.  You win if you have lots of such values during a run of your
1706 program, you lose otherwise.  (And you pay in extra code space.)
1707 </Para>
1708
1709 <Para>
1710 We have not played with <Option>-fsemi-tagging</Option> enough to recommend it.
1711 (For all we know, it doesn't even work anymore&hellip; Sigh.)
1712 </Para>
1713 </ListItem>
1714 </VarListEntry>
1715 </VariableList>
1716 </Para>
1717
1718 </Sect2>
1719
1720 <Sect2>
1721 <Title><Option>-m*</Option>: platform-specific flags</Title>
1722
1723 <Para>
1724 <IndexTerm><Primary>-m* options (GHC)</Primary></IndexTerm>
1725 <IndexTerm><Primary>platform-specific options</Primary></IndexTerm>
1726 <IndexTerm><Primary>machine-specific options</Primary></IndexTerm>
1727 </Para>
1728
1729 <Para>
1730 Some flags only make sense for particular target platforms.
1731 </Para>
1732
1733 <Para>
1734 <VariableList>
1735
1736 <VarListEntry>
1737 <Term><Option>-mv8</Option>:</Term>
1738 <ListItem>
1739 <Para>
1740 (SPARC machines)<IndexTerm><Primary>-mv8 option (SPARC only)</Primary></IndexTerm>
1741 Means to pass the like-named option to GCC; it says to use the
1742 Version 8 SPARC instructions, notably integer multiply and divide.
1743 The similiar <Option>-m*</Option> GCC options for SPARC also work, actually.
1744 </Para>
1745 </ListItem>
1746 </VarListEntry>
1747 <VarListEntry>
1748 <Term><Option>-mlong-calls</Option>:</Term>
1749 <ListItem>
1750 <Para>
1751 (HPPA machines)<IndexTerm><Primary>-mlong-calls option (HPPA only)</Primary></IndexTerm>
1752 Means to pass the like-named option to GCC.  Required for Very Big
1753 modules, maybe.  (Probably means you're in trouble&hellip;)
1754 </Para>
1755 </ListItem>
1756 </VarListEntry>
1757 <VarListEntry>
1758 <Term><Option>-monly-[32]-regs</Option>:</Term>
1759 <ListItem>
1760 <Para>
1761 (iX86 machines)<IndexTerm><Primary>-monly-N-regs option (iX86 only)</Primary></IndexTerm>
1762 GHC tries to &ldquo;steal&rdquo; four registers from GCC, for performance
1763 reasons; it almost always works.  However, when GCC is compiling some
1764 modules with four stolen registers, it will crash, probably saying:
1765
1766 <Screen>
1767 Foo.hc:533: fixed or forbidden register was spilled.
1768 This may be due to a compiler bug or to impossible asm
1769 statements or clauses.
1770 </Screen>
1771
1772 Just give some registers back with <Option>-monly-N-regs</Option>.  Try `3' first,
1773 then `2'.  If `2' doesn't work, please report the bug to us.
1774 </Para>
1775 </ListItem>
1776 </VarListEntry>
1777 </VariableList>
1778 </Para>
1779
1780 </Sect2>
1781
1782 <Sect2 id="optimise-C-compiler">
1783 <Title>Code improvement by the C compiler.
1784 </Title>
1785
1786 <Para>
1787 <IndexTerm><Primary>optimisation by GCC</Primary></IndexTerm>
1788 <IndexTerm><Primary>GCC optimisation</Primary></IndexTerm>
1789 </Para>
1790
1791 <Para>
1792 The C&nbsp;compiler (GCC) is run with <Option>-O</Option> turned on.  (It has
1793 to be, actually).
1794 </Para>
1795
1796 <Para>
1797 If you want to run GCC with <Option>-O2</Option>&mdash;which may be worth a few
1798 percent in execution speed&mdash;you can give a
1799 <Option>-O2-for-C</Option><IndexTerm><Primary>-O2-for-C option</Primary></IndexTerm> option.
1800 </Para>
1801
1802 </Sect2>
1803
1804 </Sect1>
1805
1806 <Sect1 id="options-phases">
1807 <Title>Options related to a particular phase
1808 </Title>
1809
1810 <Sect2 id="c-pre-processor">
1811 <Title>The C pre-processor
1812 </Title>
1813
1814 <Para>
1815 <IndexTerm><Primary>pre-processing: cpp</Primary></IndexTerm>
1816 <IndexTerm><Primary>C pre-processor options</Primary></IndexTerm>
1817 <IndexTerm><Primary>cpp, pre-processing with</Primary></IndexTerm>
1818 </Para>
1819
1820 <Para>
1821 The C pre-processor <Command>cpp</Command> is run over your Haskell code only if the
1822 <Option>-cpp</Option> option <IndexTerm><Primary>-cpp option</Primary></IndexTerm> is given.  Unless you are
1823 building a large system with significant doses of conditional
1824 compilation, you really shouldn't need it.
1825 <VariableList>
1826
1827 <VarListEntry>
1828 <Term><Option>-D&lt;foo&gt;</Option>:</Term>
1829 <ListItem>
1830 <Para>
1831 <IndexTerm><Primary>-D&lt;name&gt; option</Primary></IndexTerm>
1832 Define macro <Constant>&lt;foo&gt;</Constant> in the usual way.  NB: does <Emphasis>not</Emphasis> affect
1833 <Option>-D</Option> macros passed to the C&nbsp;compiler when compiling via C!  For those,
1834 use the <Option>-optc-Dfoo</Option> hack&hellip; (see <XRef LinkEnd="forcing-options-through">).
1835 </Para>
1836 </ListItem>
1837 </VarListEntry>
1838 <VarListEntry>
1839 <Term><Option>-U&lt;foo&gt;</Option>:</Term>
1840 <ListItem>
1841 <Para>
1842 <IndexTerm><Primary>-U&lt;name&gt; option</Primary></IndexTerm>
1843 Undefine macro <Command>&lt;foo&gt;</Command> in the usual way.
1844 </Para>
1845 </ListItem>
1846 </VarListEntry>
1847 <VarListEntry>
1848 <Term><Option>-I&lt;dir&gt;</Option>:</Term>
1849 <ListItem>
1850 <Para>
1851 <IndexTerm><Primary>-I&lt;dir&gt; option</Primary></IndexTerm>
1852 Specify a directory in which to look for <Literal>&num;include</Literal> files, in
1853 the usual C way.
1854 </Para>
1855 </ListItem>
1856 </VarListEntry>
1857 </VariableList>
1858 </Para>
1859
1860 <Para>
1861 The GHC driver pre-defines several macros when processing Haskell
1862 source code (<Filename>.hs</Filename> or <Filename>.lhs</Filename> files):
1863 </Para>
1864
1865 <Para>
1866 <VariableList>
1867
1868 <VarListEntry>
1869 <Term><Constant>&lowbar;&lowbar;HASKELL98&lowbar;&lowbar;</Constant>:</Term>
1870 <ListItem>
1871 <Para>
1872 <IndexTerm><Primary>&lowbar;&lowbar;HASKELL98&lowbar;&lowbar;</Primary></IndexTerm>
1873 If defined, this means that GHC supports the language defined by the
1874 Haskell 98 report.
1875 </Para>
1876 </ListItem>
1877 </VarListEntry>
1878 <VarListEntry>
1879 <Term><Constant>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;=98</Constant>:</Term>
1880 <ListItem>
1881 <Para>
1882 <IndexTerm><Primary>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;</Primary></IndexTerm>
1883 In GHC 4.04 and later, the <Constant>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;</Constant> macro is defined as having
1884 the value <Constant>98</Constant>.
1885 </Para>
1886 </ListItem>
1887 </VarListEntry>
1888 <VarListEntry>
1889 <Term><Constant>&lowbar;&lowbar;HASKELL1&lowbar;&lowbar;</Constant>:</Term>
1890 <ListItem>
1891 <Para>
1892 <IndexTerm><Primary>&lowbar;&lowbar;HASKELL1&lowbar;&lowbar; macro</Primary></IndexTerm>
1893 If defined to <Emphasis>n</Emphasis>, that means GHC supports the Haskell language
1894 defined in the Haskell report version <Emphasis>1.n</Emphasis>.  Currently 5.  This
1895 macro is deprecated, and will probably disappear in future versions.
1896 </Para>
1897 </ListItem>
1898 </VarListEntry>
1899 <VarListEntry>
1900 <Term><Constant>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
1901 <ListItem>
1902 <Para>
1903 <IndexTerm><Primary>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
1904 For version <Emphasis>n</Emphasis> of the GHC system, this will be <Literal>&num;define</Literal>d to
1905 <Emphasis>100n</Emphasis>.  So, for version 4.00, it is 400.
1906 </Para>
1907
1908 <Para>
1909 With any luck, <Constant>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar;</Constant> will be undefined in all other
1910 implementations that support C-style pre-processing.
1911 </Para>
1912
1913 <Para>
1914 (For reference: the comparable symbols for other systems are:
1915 <Constant>&lowbar;&lowbar;HUGS&lowbar;&lowbar;</Constant> for Hugs and <Constant>&lowbar;&lowbar;HBC&lowbar;&lowbar;</Constant> for Chalmers.)
1916 </Para>
1917
1918 <Para>
1919 NB. This macro is set when pre-processing both Haskell source and C
1920 source, including the C source generated from a Haskell module
1921 (i.e. <Filename>.hs</Filename>, <Filename>.lhs</Filename>, <Filename>.c</Filename> and <Filename>.hc</Filename> files).
1922 </Para>
1923 </ListItem>
1924 </VarListEntry>
1925 <VarListEntry>
1926 <Term><Constant>&lowbar;&lowbar;CONCURRENT&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
1927 <ListItem>
1928 <Para>
1929 <IndexTerm><Primary>&lowbar;&lowbar;CONCURRENT&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
1930 This symbol is defined when pre-processing Haskell (input) and
1931 pre-processing C (GHC output).  Since GHC from verion 4.00 now
1932 supports concurrent haskell by default, this symbol is always defined.
1933 </Para>
1934 </ListItem>
1935 </VarListEntry>
1936 <VarListEntry>
1937 <Term><Constant>&lowbar;&lowbar;PARALLEL&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
1938 <ListItem>
1939 <Para>
1940 <IndexTerm><Primary>&lowbar;&lowbar;PARALLEL&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
1941 Only defined when <Option>-parallel</Option> is in use!  This symbol is defined when
1942 pre-processing Haskell (input) and pre-processing C (GHC output).
1943 </Para>
1944 </ListItem>
1945 </VarListEntry>
1946 </VariableList>
1947 </Para>
1948
1949 <Para>
1950 Options other than the above can be forced through to the C
1951 pre-processor with the <Option>-opt</Option> flags (see
1952 <XRef LinkEnd="forcing-options-through">).
1953 </Para>
1954
1955 <Para>
1956 A small word of warning: <Option>-cpp</Option> is not friendly to &ldquo;string
1957 gaps&rdquo;.<IndexTerm><Primary>-cpp vs string gaps</Primary></IndexTerm><IndexTerm><Primary>string gaps vs
1958 -cpp</Primary></IndexTerm>.  In other words, strings such as the following:
1959 </Para>
1960
1961 <Para>
1962
1963 <ProgramListing>
1964 strmod = "\
1965 \ p \
1966 \ "
1967 </ProgramListing>
1968
1969 </Para>
1970
1971 <Para>
1972 don't work with <Option>-cpp</Option>; <Filename>/usr/bin/cpp</Filename> elides the
1973 backslash-newline pairs.
1974 </Para>
1975
1976 <Para>
1977 However, it appears that if you add a space at the end of the line,
1978 then <Command>cpp</Command> (at least GNU <Command>cpp</Command> and possibly other <Command>cpp</Command>s)
1979 leaves the backslash-space pairs alone and the string gap works as
1980 expected.
1981 </Para>
1982
1983 </Sect2>
1984
1985 <Sect2 id="options-C-compiler">
1986 <Title>Options affecting the C compiler (if applicable)
1987 </Title>
1988
1989 <Para>
1990 <IndexTerm><Primary>include-file options</Primary></IndexTerm>
1991 <IndexTerm><Primary>C compiler options</Primary></IndexTerm>
1992 <IndexTerm><Primary>GCC options</Primary></IndexTerm>
1993 </Para>
1994
1995 <Para>
1996 At the moment, quite a few common C-compiler options are passed on
1997 quietly to the C compilation of Haskell-compiler-generated C files.
1998 THIS MAY CHANGE.  Meanwhile, options so sent are:
1999 </Para>
2000
2001 <Para>
2002
2003 <InformalTable>
2004 <TGroup Cols="2">
2005 <ColSpec Align="Left" Colsep="0">
2006 <ColSpec Align="Left" Colsep="0">
2007 <TBody>
2008 <Row>
2009 <Entry><Option>-ansi</Option> </Entry>
2010 <Entry> do ANSI C (not K&amp;R) </Entry>
2011 </Row>
2012 <Row>
2013 <Entry>
2014 <Option>-pedantic</Option> </Entry>
2015 <Entry> be so</Entry>
2016 </Row>
2017 <Row>
2018 <Entry>
2019 <Option>-dgcc-lint</Option> </Entry>
2020 <Entry> (hack) short for &ldquo;make GCC very paranoid&rdquo;</Entry>
2021 </Row>
2022
2023 </TBody>
2024
2025 </TGroup>
2026 </InformalTable>
2027
2028 <IndexTerm><Primary>-ansi option (for GCC)</Primary></IndexTerm>
2029 <IndexTerm><Primary>-pedantic option (for GCC)</Primary></IndexTerm>
2030 <IndexTerm><Primary>-dgcc-lint option (GCC paranoia)</Primary></IndexTerm>
2031 </Para>
2032
2033 <Para>
2034 If you are compiling with lots of <Literal>ccalls</Literal>, etc., you may need to
2035 tell the C&nbsp;compiler about some <Literal>&num;include</Literal> files.  There is no real
2036 pretty way to do this, but you can use this hack from the
2037 command-line:
2038 </Para>
2039
2040 <Para>
2041
2042 <Screen>
2043 % ghc -c '-#include &#60;X/Xlib.h&#62;' Xstuff.lhs
2044 </Screen>
2045
2046 </Para>
2047
2048 </Sect2>
2049
2050 <Sect2 id="options-linker">
2051 <Title>Linking and consistency-checking
2052 </Title>
2053
2054 <Para>
2055 <IndexTerm><Primary>linker options</Primary></IndexTerm>
2056 <IndexTerm><Primary>ld options</Primary></IndexTerm>
2057 </Para>
2058
2059 <Para>
2060 GHC has to link your code with various libraries, possibly including:
2061 user-supplied, GHC-supplied, and system-supplied (<Option>-lm</Option> math
2062 library, for example).
2063 </Para>
2064
2065 <Para>
2066 <VariableList>
2067
2068 <VarListEntry>
2069 <Term><Option>-l&lt;FOO&gt;</Option>:</Term>
2070 <ListItem>
2071 <Para>
2072 <IndexTerm><Primary>-l&lt;lib&gt; option</Primary></IndexTerm>
2073 Link in a library named <Filename>lib&lt;FOO&gt;.a</Filename> which resides somewhere on the
2074 library directories path.
2075 </Para>
2076
2077 <Para>
2078 Because of the sad state of most UNIX linkers, the order of such
2079 options does matter.  Thus: <Command>ghc -lbar *.o</Command> is almost certainly
2080 wrong, because it will search <Filename>libbar.a</Filename> <Emphasis>before</Emphasis> it has
2081 collected unresolved symbols from the <Filename>*.o</Filename> files.
2082 <Command>ghc *.o -lbar</Command> is probably better.
2083 </Para>
2084
2085 <Para>
2086 The linker will of course be informed about some GHC-supplied
2087 libraries automatically; these are:
2088 </Para>
2089
2090 <Para>
2091
2092 <InformalTable>
2093 <TGroup Cols="2">
2094 <ColSpec Align="Left" Colsep="0">
2095 <ColSpec Align="Left" Colsep="0">
2096 <TBody>
2097 <Row>
2098 <Entry><Emphasis>-l equivalent</Emphasis> </Entry>
2099 <Entry> <Emphasis>description</Emphasis> </Entry>
2100 </Row>
2101
2102 <Row>
2103 <Entry>
2104 <Option>-lHSrts,-lHSclib</Option> </Entry>
2105 <Entry> basic runtime libraries </Entry>
2106 </Row>
2107 <Row>
2108 <Entry>
2109 <Option>-lHS</Option> </Entry>
2110 <Entry> standard Prelude library </Entry>
2111 </Row>
2112 <Row>
2113 <Entry>
2114 <Option>-lHS&lowbar;cbits</Option> </Entry>
2115 <Entry> C support code for standard Prelude library </Entry>
2116 </Row>
2117 <Row>
2118 <Entry>
2119 <Option>-lgmp</Option> </Entry>
2120 <Entry> GNU multi-precision library (for Integers)</Entry>
2121 </Row>
2122
2123 </TBody>
2124
2125 </TGroup>
2126 </InformalTable>
2127
2128 </Para>
2129
2130 <Para>
2131 <IndexTerm><Primary>-lHS library</Primary></IndexTerm>
2132 <IndexTerm><Primary>-lHS&lowbar;cbits library</Primary></IndexTerm>
2133 <IndexTerm><Primary>-lHSrts library</Primary></IndexTerm>
2134 <IndexTerm><Primary>-lgmp library</Primary></IndexTerm>
2135 </Para>
2136 </ListItem>
2137 </VarListEntry>
2138 <VarListEntry>
2139 <Term><Option>-syslib &lt;name&gt;</Option>:</Term>
2140 <ListItem>
2141 <Para>
2142 <IndexTerm><Primary>-syslib &lt;name&gt; option</Primary></IndexTerm>
2143 </Para>
2144
2145 <Para>
2146 If you are using a Haskell &ldquo;system library&rdquo; (e.g., the POSIX
2147 library), just use the <Option>-syslib posix</Option> option, and the correct code
2148 should be linked in.
2149 </Para>
2150 </ListItem>
2151 </VarListEntry>
2152 <VarListEntry>
2153 <Term><Option>-L&lt;dir&gt;</Option>:</Term>
2154 <ListItem>
2155 <Para>
2156 <IndexTerm><Primary>-L&lt;dir&gt; option</Primary></IndexTerm>
2157 Where to find user-supplied libraries&hellip;  Prepend the directory
2158 <Filename>&lt;dir&gt;</Filename> to the library directories path.
2159 </Para>
2160 </ListItem>
2161 </VarListEntry>
2162 <VarListEntry>
2163 <Term><Option>-static</Option>:</Term>
2164 <ListItem>
2165 <Para>
2166 <IndexTerm><Primary>-static option</Primary></IndexTerm>
2167 Tell the linker to avoid shared libraries.
2168 </Para>
2169 </ListItem>
2170 </VarListEntry>
2171 <VarListEntry>
2172 <Term><Option>-no-link-chk</Option> and <Option>-link-chk</Option>:</Term>
2173 <ListItem>
2174 <Para>
2175 <IndexTerm><Primary>-no-link-chk option</Primary></IndexTerm>
2176 <IndexTerm><Primary>-link-chk option</Primary></IndexTerm>
2177 <IndexTerm><Primary>consistency checking of executables</Primary></IndexTerm>
2178 By default, immediately after linking an executable, GHC verifies that
2179 the pieces that went into it were compiled with compatible flags; a
2180 &ldquo;consistency check&rdquo;.
2181 (This is to avoid mysterious failures caused by non-meshing of
2182 incompatibly-compiled programs; e.g., if one <Filename>.o</Filename> file was compiled
2183 for a parallel machine and the others weren't.)  You may turn off this
2184 check with <Option>-no-link-chk</Option>.  You can turn it (back) on with
2185 <Option>-link-chk</Option> (the default).
2186 </Para>
2187 </ListItem>
2188 </VarListEntry>
2189 <VarListEntry>
2190 <Term><Option>-no-hs-main</Option>:</Term>
2191 <ListItem>
2192 <Para>
2193 <IndexTerm><Primary>-no-hs-main option</Primary></IndexTerm>
2194 <IndexTerm><Primary>linking Haskell libraries with foreign code</Primary></IndexTerm>
2195 </Para>
2196
2197 <Para>
2198 In the event you want to include ghc-compiled code as part of another
2199 (non-Haskell) program, the RTS will not be supplying its definition of
2200 <Function>main()</Function> at link-time, you will have to. To signal that to the
2201 driver script when linking, use <Option>-no-hs-main</Option>.
2202 </Para>
2203
2204 <Para>
2205 Notice that since the command-line passed to the linker is rather
2206 involved, you probably want to use the ghc driver script to do the
2207 final link of your `mixed-language' application. This is not a
2208 requirement though, just try linking once with <Option>-v</Option> on to see what
2209 options the driver passes through to the linker.
2210 </Para>
2211 </ListItem>
2212 </VarListEntry>
2213 </VariableList>
2214 </Para>
2215
2216 </Sect2>
2217
2218 </Sect1>
2219
2220 <Sect1>
2221 <Title>Using Concurrent Haskell</Title>
2222
2223 <Para>
2224 <IndexTerm><Primary>Concurrent Haskell&mdash;use</Primary></IndexTerm>
2225 </Para>
2226
2227 <Para>
2228 GHC (as of version 4.00) supports Concurrent Haskell by default,
2229 without requiring a special option or libraries compiled in a certain
2230 way.  To get access to the support libraries for Concurrent Haskell
2231 (i.e. <Literal>Concurrent</Literal> and friends), use the
2232 <Option>-syslib concurrent</Option> option.
2233 </Para>
2234
2235 <Para>
2236 Three RTS options are provided for modifying the behaviour of the
2237 threaded runtime system.  See the descriptions of
2238 <Option>-C[&lt;us&gt;]</Option>, <Option>-q</Option>, and
2239 <Option>-t&lt;num&gt;</Option> in <XRef LinkEnd="parallel-rts-opts">.
2240 </Para>
2241
2242 <Para>
2243 Concurrent Haskell is described in more detail in <XRef
2244 LinkEnd="sec-Concurrent">.
2245 </Para>
2246
2247 </Sect1>
2248
2249 <Sect1>
2250 <Title>Using Parallel Haskell</Title>
2251
2252 <Para>
2253 <IndexTerm><Primary>Parallel Haskell&mdash;use</Primary></IndexTerm>
2254 </Para>
2255
2256 <Para>
2257 &lsqb;You won't be able to execute parallel Haskell programs unless PVM3
2258 (Parallel Virtual Machine, version 3) is installed at your site.]
2259 </Para>
2260
2261 <Para>
2262 To compile a Haskell program for parallel execution under PVM, use the
2263 <Option>-parallel</Option> option,<IndexTerm><Primary>-parallel
2264 option</Primary></IndexTerm> both when compiling <Emphasis>and
2265 linking</Emphasis>.  You will probably want to <Literal>import
2266 Parallel</Literal> into your Haskell modules.
2267 </Para>
2268
2269 <Para>
2270 To run your parallel program, once PVM is going, just invoke it
2271 &ldquo;as normal&rdquo;.  The main extra RTS option is
2272 <Option>-N&lt;n&gt;</Option>, to say how many PVM
2273 &ldquo;processors&rdquo; your program to run on.  (For more details of
2274 all relevant RTS options, please see <XRef
2275 LinkEnd="parallel-rts-opts">.)
2276 </Para>
2277
2278 <Para>
2279 In truth, running Parallel Haskell programs and getting information
2280 out of them (e.g., parallelism profiles) is a battle with the vagaries of
2281 PVM, detailed in the following sections.
2282 </Para>
2283
2284 <Sect2>
2285 <Title>Dummy's guide to using PVM</Title>
2286
2287 <Para>
2288 <IndexTerm><Primary>PVM, how to use</Primary></IndexTerm>
2289 <IndexTerm><Primary>Parallel Haskell&mdash;PVM use</Primary></IndexTerm>
2290 Before you can run a parallel program under PVM, you must set the
2291 required environment variables (PVM's idea, not ours); something like,
2292 probably in your <Filename>.cshrc</Filename> or equivalent:
2293
2294 <ProgramListing>
2295 setenv PVM_ROOT /wherever/you/put/it
2296 setenv PVM_ARCH `$PVM_ROOT/lib/pvmgetarch`
2297 setenv PVM_DPATH $PVM_ROOT/lib/pvmd
2298 </ProgramListing>
2299
2300 </Para>
2301
2302 <Para>
2303 Creating and/or controlling your &ldquo;parallel machine&rdquo; is a purely-PVM
2304 business; nothing specific to Parallel Haskell.
2305 </Para>
2306
2307 <Para>
2308 You use the <Command>pvm</Command><IndexTerm><Primary>pvm command</Primary></IndexTerm> command to start PVM on your
2309 machine.  You can then do various things to control/monitor your
2310 &ldquo;parallel machine;&rdquo; the most useful being:
2311 </Para>
2312
2313 <Para>
2314 <InformalTable>
2315 <TGroup Cols=2>
2316 <ColSpec Align="Left">
2317 <TBody>
2318
2319 <Row>
2320 <Entry><KeyCombo><KeyCap>Control</KeyCap><KeyCap>D</KeyCap></KeyCombo></Entry>
2321 <Entry>exit <Command>pvm</Command>, leaving it running</Entry>
2322 </Row>
2323
2324 <Row>
2325 <Entry><Command>halt</Command></Entry>
2326 <Entry>kill off this &ldquo;parallel machine&rdquo; &amp; exit</Entry>
2327 </Row>
2328
2329 <Row>
2330 <Entry><Command>add &lt;host&gt;</Command></Entry>
2331 <Entry>add <Command>&lt;host&gt;</Command> as a processor</Entry>
2332 </Row>
2333
2334 <Row>
2335 <Entry><Command>delete &lt;host&gt;</Command></Entry>
2336 <Entry>delete <Command>&lt;host&gt;</Command></Entry>
2337 </Row>
2338
2339 <Row>
2340 <Entry><Command>reset</Command></Entry>
2341 <Entry>kill what's going, but leave PVM up</Entry>
2342 </Row>
2343
2344 <Row>
2345 <Entry><Command>conf</Command></Entry>
2346 <Entry>list the current configuration</Entry>
2347 </Row>
2348
2349 <Row>
2350 <Entry><Command>ps</Command></Entry>
2351 <Entry>report processes' status</Entry>
2352 </Row>
2353
2354 <Row>
2355 <Entry><Command>pstat &lt;pid&gt;</Command></Entry>
2356 <Entry>status of a particular process</Entry>
2357 </Row>
2358
2359 </TBody>
2360 </TGroup>
2361 </InformalTable>
2362 </Para>
2363
2364 <Para>
2365 The PVM documentation can tell you much, much more about <Command>pvm</Command>!
2366 </Para>
2367
2368 </Sect2>
2369
2370 <Sect2>
2371 <Title>Parallelism profiles</Title>
2372
2373 <Para>
2374 <IndexTerm><Primary>parallelism profiles</Primary></IndexTerm>
2375 <IndexTerm><Primary>profiles, parallelism</Primary></IndexTerm>
2376 <IndexTerm><Primary>visualisation tools</Primary></IndexTerm>
2377 </Para>
2378
2379 <Para>
2380 With Parallel Haskell programs, we usually don't care about the
2381 results&mdash;only with &ldquo;how parallel&rdquo; it was!  We want pretty pictures.
2382 </Para>
2383
2384 <Para>
2385 Parallelism profiles (&agrave; la <Command>hbcpp</Command>) can be generated with the
2386 <Option>-q</Option><IndexTerm><Primary>-q RTS option (concurrent, parallel)</Primary></IndexTerm> RTS option.  The
2387 per-processor profiling info is dumped into files named
2388 <Filename>&lt;full-path&gt;&lt;program&gt;.gr</Filename>.  These are then munged into a PostScript picture,
2389 which you can then display.  For example, to run your program
2390 <Filename>a.out</Filename> on 8 processors, then view the parallelism profile, do:
2391 </Para>
2392
2393 <Para>
2394
2395 <Screen>
2396 % ./a.out +RTS -N8 -q
2397 % grs2gr *.???.gr &#62; temp.gr     # combine the 8 .gr files into one
2398 % gr2ps -O temp.gr              # cvt to .ps; output in temp.ps
2399 % ghostview -seascape temp.ps   # look at it!
2400 </Screen>
2401
2402 </Para>
2403
2404 <Para>
2405 The scripts for processing the parallelism profiles are distributed
2406 in <Filename>ghc/utils/parallel/</Filename>.
2407 </Para>
2408
2409 </Sect2>
2410
2411 <Sect2>
2412 <Title>Other useful info about running parallel programs</Title>
2413
2414 <Para>
2415 The &ldquo;garbage-collection statistics&rdquo; RTS options can be useful for
2416 seeing what parallel programs are doing.  If you do either
2417 <Option>+RTS -Sstderr</Option><IndexTerm><Primary>-Sstderr RTS option</Primary></IndexTerm> or <Option>+RTS -sstderr</Option>, then
2418 you'll get mutator, garbage-collection, etc., times on standard
2419 error. The standard error of all PE's other than the `main thread'
2420 appears in <Filename>/tmp/pvml.nnn</Filename>, courtesy of PVM.
2421 </Para>
2422
2423 <Para>
2424 Whether doing <Option>+RTS -Sstderr</Option> or not, a handy way to watch
2425 what's happening overall is: <Command>tail -f /tmp/pvml.nnn</Command>.
2426 </Para>
2427
2428 </Sect2>
2429
2430 <Sect2 id="parallel-rts-opts">
2431 <Title>RTS options for Concurrent/Parallel Haskell
2432 </Title>
2433
2434 <Para>
2435 <IndexTerm><Primary>RTS options, concurrent</Primary></IndexTerm>
2436 <IndexTerm><Primary>RTS options, parallel</Primary></IndexTerm>
2437 <IndexTerm><Primary>Concurrent Haskell&mdash;RTS options</Primary></IndexTerm>
2438 <IndexTerm><Primary>Parallel Haskell&mdash;RTS options</Primary></IndexTerm>
2439 </Para>
2440
2441 <Para>
2442 Besides the usual runtime system (RTS) options
2443 (<XRef LinkEnd="runtime-control">), there are a few options particularly
2444 for concurrent/parallel execution.
2445 </Para>
2446
2447 <Para>
2448 <VariableList>
2449
2450 <VarListEntry>
2451 <Term><Option>-N&lt;N&gt;</Option>:</Term>
2452 <ListItem>
2453 <Para>
2454 <IndexTerm><Primary>-N&lt;N&gt; RTS option (parallel)</Primary></IndexTerm>
2455 (PARALLEL ONLY) Use <Literal>&lt;N&gt;</Literal> PVM processors to run this program;
2456 the default is 2.
2457 </Para>
2458 </ListItem>
2459 </VarListEntry>
2460 <VarListEntry>
2461 <Term><Option>-C[&lt;us&gt;]</Option>:</Term>
2462 <ListItem>
2463 <Para>
2464 <IndexTerm><Primary>-C&lt;us&gt; RTS option</Primary></IndexTerm>
2465 Sets the context switch interval to <Literal>&lt;us&gt;</Literal> microseconds.  A context
2466 switch will occur at the next heap allocation after the timer expires.
2467 With <Option>-C0</Option> or <Option>-C</Option>, context switches will occur as often as
2468 possible (at every heap allocation).  By default, context switches
2469 occur every 10 milliseconds.  Note that many interval timers are only
2470 capable of 10 millisecond granularity, so the default setting may be
2471 the finest granularity possible, short of a context switch at every
2472 heap allocation.
2473 </Para>
2474
2475 <Para>
2476 &lsqb;NOTE: this option currently has no effect (version 4.00).  Context
2477 switches happen when the current heap block is full, i.e. every 4k of
2478 allocation].
2479 </Para>
2480 </ListItem>
2481 </VarListEntry>
2482 <VarListEntry>
2483 <Term><Option>-q[v]</Option>:</Term>
2484 <ListItem>
2485 <Para>
2486 <IndexTerm><Primary>-q RTS option</Primary></IndexTerm>
2487 (PARALLEL ONLY) Produce a quasi-parallel profile of thread activity,
2488 in the file <FIlename>&lt;program&gt;.qp</FIlename>.  In the style of <Command>hbcpp</Command>, this profile
2489 records the movement of threads between the green (runnable) and red
2490 (blocked) queues.  If you specify the verbose suboption (<Option>-qv</Option>), the
2491 green queue is split into green (for the currently running thread
2492 only) and amber (for other runnable threads).  We do not recommend
2493 that you use the verbose suboption if you are planning to use the
2494 <Command>hbcpp</Command> profiling tools or if you are context switching at every heap
2495 check (with <Option>-C</Option>).
2496 </Para>
2497 </ListItem>
2498 </VarListEntry>
2499 <VarListEntry>
2500 <Term><Option>-t&lt;num&gt;</Option>:</Term>
2501 <ListItem>
2502 <Para>
2503 <IndexTerm><Primary>-t&lt;num&gt; RTS option</Primary></IndexTerm>
2504 (PARALLEL ONLY) Limit the number of concurrent threads per processor
2505 to <Literal>&lt;num&gt;</Literal>.  The default is 32.  Each thread requires slightly over 1K
2506 <Emphasis>words</Emphasis> in the heap for thread state and stack objects.  (For
2507 32-bit machines, this translates to 4K bytes, and for 64-bit machines,
2508 8K bytes.)
2509 </Para>
2510 </ListItem>
2511 </VarListEntry>
2512 <VarListEntry>
2513 <Term><Option>-d</Option>:</Term>
2514 <ListItem>
2515 <Para>
2516 <IndexTerm><Primary>-d RTS option (parallel)</Primary></IndexTerm>
2517 (PARALLEL ONLY) Turn on debugging.  It pops up one xterm (or GDB, or
2518 something&hellip;) per PVM processor.  We use the standard <Command>debugger</Command>
2519 script that comes with PVM3, but we sometimes meddle with the
2520 <Command>debugger2</Command> script.  We include ours in the GHC distribution,
2521 in <Filename>ghc/utils/pvm/</Filename>.
2522 </Para>
2523 </ListItem>
2524 </VarListEntry>
2525 <VarListEntry>
2526 <Term><Option>-e&lt;num&gt;</Option>:</Term>
2527 <ListItem>
2528 <Para>
2529 <IndexTerm><Primary>-e&lt;num&gt; RTS option (parallel)</Primary></IndexTerm>
2530 (PARALLEL ONLY) Limit the number of pending sparks per processor to
2531 <Literal>&lt;num&gt;</Literal>. The default is 100. A larger number may be appropriate if
2532 your program generates large amounts of parallelism initially.
2533 </Para>
2534 </ListItem>
2535 </VarListEntry>
2536 <VarListEntry>
2537 <Term><Option>-Q&lt;num&gt;</Option>:</Term>
2538 <ListItem>
2539 <Para>
2540 <IndexTerm><Primary>-Q&lt;num&gt; RTS option (parallel)</Primary></IndexTerm>
2541 (PARALLEL ONLY) Set the size of packets transmitted between processors
2542 to <Literal>&lt;num&gt;</Literal>. The default is 1024 words. A larger number may be
2543 appropriate if your machine has a high communication cost relative to
2544 computation speed.
2545 </Para>
2546 </ListItem>
2547 </VarListEntry>
2548 </VariableList>
2549 </Para>
2550
2551 </Sect2>
2552
2553 </Sect1>
2554
2555 &runtime
2556 &debug
2557
2558 </Chapter>