Major patch to add -fwarn-redundant-constraints
[ghc.git] / docs / users_guide / using.xml
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <chapter id="using-ghc">
3 <title>Using GHC</title>
4
5 <indexterm><primary>GHC, using</primary></indexterm>
6 <indexterm><primary>using GHC</primary></indexterm>
7
8 <sect1>
9 <title>Getting started: compiling programs</title>
10
11 <para>
12 In this chapter you'll find a complete reference to the GHC
13 command-line syntax, including all 400+ flags. It's a large and
14 complex system, and there are lots of details, so it can be
15 quite hard to figure out how to get started. With that in mind,
16 this introductory section provides a quick introduction to the
17 basic usage of GHC for compiling a Haskell program, before the
18 following sections dive into the full syntax.
19 </para>
20
21 <para>
22 Let's create a Hello World program, and compile and run it.
23 First, create a file <filename>hello.hs</filename> containing
24 the Haskell code:
25 </para>
26
27 <programlisting>
28 main = putStrLn "Hello, World!"
29 </programlisting>
30
31 <para>To compile the program, use GHC like this:</para>
32
33 <screen>
34 $ ghc hello.hs
35 </screen>
36
37 <para>(where <literal>$</literal> represents the prompt: don't
38 type it). GHC will compile the source
39 file <filename>hello.hs</filename>, producing
40 an <firstterm>object
41 file</firstterm> <filename>hello.o</filename> and
42 an <firstterm>interface
43 file</firstterm> <filename>hello.hi</filename>, and then it
44 will link the object file to the libraries that come with GHC
45 to produce an executable called <filename>hello</filename> on
46 Unix/Linux/Mac, or <filename>hello.exe</filename> on
47 Windows.</para>
48
49 <para>
50 By default GHC will be very quiet about what it is doing, only
51 printing error messages. If you want to see in more detail
52 what's going on behind the scenes, add <option>-v</option> to
53 the command line.
54 </para>
55
56 <para>
57 Then we can run the program like this:
58 </para>
59
60 <screen>
61 $ ./hello
62 Hello World!
63 </screen>
64
65 <para>
66 If your program contains multiple modules, then you only need to
67 tell GHC the name of the source file containing
68 the <filename>Main</filename> module, and GHC will examine
69 the <literal>import</literal> declarations to find the other
70 modules that make up the program and find their source files.
71 This means that, with the exception of
72 the <literal>Main</literal> module, every source file should be
73 named after the module name that it contains (with dots replaced
74 by directory separators). For example, the
75 module <literal>Data.Person</literal> would be in the
76 file <filename>Data/Person.hs</filename> on Unix/Linux/Mac,
77 or <filename>Data\Person.hs</filename> on Windows.
78 </para>
79 </sect1>
80
81 <sect1>
82 <title>Options overview</title>
83
84 <para>GHC's behaviour is controlled by
85 <firstterm>options</firstterm>, which for historical reasons are
86 also sometimes referred to as command-line flags or arguments.
87 Options can be specified in three ways:</para>
88
89 <sect2>
90 <title>Command-line arguments</title>
91
92 <indexterm><primary>structure, command-line</primary></indexterm>
93 <indexterm><primary>command-line</primary><secondary>arguments</secondary></indexterm>
94 <indexterm><primary>arguments</primary><secondary>command-line</secondary></indexterm>
95
96 <para>An invocation of GHC takes the following form:</para>
97
98 <screen>
99 ghc [argument...]
100 </screen>
101
102 <para>Command-line arguments are either options or file names.</para>
103
104 <para>Command-line options begin with <literal>-</literal>.
105 They may <emphasis>not</emphasis> be grouped:
106 <option>-vO</option> is different from <option>-v -O</option>.
107 Options need not precede filenames: e.g., <literal>ghc *.o -o
108 foo</literal>. All options are processed and then applied to
109 all files; you cannot, for example, invoke <literal>ghc -c -O1
110 Foo.hs -O2 Bar.hs</literal> to apply different optimisation
111 levels to the files <filename>Foo.hs</filename> and
112 <filename>Bar.hs</filename>.</para>
113 </sect2>
114
115 <sect2 id="source-file-options">
116 <title>Command line options in source files</title>
117
118 <indexterm><primary>source-file options</primary></indexterm>
119
120 <para>Sometimes it is useful to make the connection between a
121 source file and the command-line options it requires quite
122 tight. For instance, if a Haskell source file deliberately
123 uses name shadowing, it should be compiled with the
124 <option>-fno-warn-name-shadowing</option> option. Rather than maintaining
125 the list of per-file options in a <filename>Makefile</filename>,
126 it is possible to do this directly in the source file using the
127 <literal>OPTIONS_GHC</literal> pragma <indexterm><primary>OPTIONS_GHC
128 pragma</primary></indexterm>:</para>
129
130 <programlisting>
131 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
132 module X where
133 ...
134 </programlisting>
135
136 <para><literal>OPTIONS_GHC</literal> is a <emphasis>file-header pragma</emphasis>
137 (see <xref linkend="pragmas"/>).</para>
138
139 <para>Only <emphasis>dynamic</emphasis> flags can be used in an <literal>OPTIONS_GHC</literal> pragma
140 (see <xref linkend="static-dynamic-flags"/>).</para>
141
142 <para>Note that your command shell does not
143 get to the source file options, they are just included literally
144 in the array of command-line arguments the compiler
145 maintains internally, so you'll be desperately disappointed if
146 you try to glob etc. inside <literal>OPTIONS_GHC</literal>.</para>
147
148 <para>NOTE: the contents of OPTIONS_GHC are appended to the
149 command-line options, so options given in the source file
150 override those given on the command-line.</para>
151
152 <para>It is not recommended to move all the contents of your
153 Makefiles into your source files, but in some circumstances, the
154 <literal>OPTIONS_GHC</literal> pragma is the Right Thing. (If you
155 use <option>-keep-hc-file</option> and have OPTION flags in
156 your module, the OPTIONS_GHC will get put into the generated .hc
157 file).</para>
158 </sect2>
159
160 <sect2>
161 <title>Setting options in GHCi</title>
162
163 <para>Options may also be modified from within GHCi, using the
164 <literal>:set</literal> command. See <xref linkend="ghci-set"/>
165 for more details.</para>
166 </sect2>
167 </sect1>
168
169 <sect1 id="static-dynamic-flags">
170 <title>Static, Dynamic, and Mode options</title>
171 <indexterm><primary>static</primary><secondary>options</secondary>
172 </indexterm>
173 <indexterm><primary>dynamic</primary><secondary>options</secondary>
174 </indexterm>
175 <indexterm><primary>mode</primary><secondary>options</secondary>
176 </indexterm>
177
178 <para>Each of GHC's command line options is classified as
179 <firstterm>static</firstterm>, <firstterm>dynamic</firstterm> or
180 <firstterm>mode</firstterm>:</para>
181
182 <variablelist>
183 <varlistentry>
184 <term>Mode flags</term>
185 <listitem>
186 <para>For example, <option>--make</option> or <option>-E</option>.
187 There may only be a single mode flag on the command line. The
188 available modes are listed in <xref linkend="modes"/>.</para>
189 </listitem>
190 </varlistentry>
191 <varlistentry>
192 <term>Dynamic Flags</term>
193 <listitem>
194 <para>Most non-mode flags fall into this category. A dynamic flag
195 may be used on the command line, in a
196 <literal>OPTIONS_GHC</literal> pragma in a source file, or set
197 using <literal>:set</literal> in GHCi.</para>
198 </listitem>
199 </varlistentry>
200 <varlistentry>
201 <term>Static Flags</term>
202 <listitem>
203 <para>A few flags are "static", which means they can only be used on
204 the command-line, and remain in force over the entire GHC/GHCi
205 run.</para>
206 </listitem>
207 </varlistentry>
208 </variablelist>
209
210 <para>The flag reference tables (<xref
211 linkend="flag-reference"/>) lists the status of each flag.</para>
212
213 <para>There are a few flags that are static except that they can
214 also be used with GHCi's <literal>:set</literal> command; these
215 are listed as &ldquo;static/<literal>:set</literal>&rdquo; in the
216 table.</para>
217 </sect1>
218
219 <sect1 id="file-suffixes">
220 <title>Meaningful file suffixes</title>
221
222 <indexterm><primary>suffixes, file</primary></indexterm>
223 <indexterm><primary>file suffixes for GHC</primary></indexterm>
224
225 <para>File names with &ldquo;meaningful&rdquo; suffixes (e.g.,
226 <filename>.lhs</filename> or <filename>.o</filename>) cause the
227 &ldquo;right thing&rdquo; to happen to those files.</para>
228
229 <variablelist>
230
231 <varlistentry>
232 <term><filename>.hs</filename></term>
233 <listitem>
234 <para>A Haskell module.</para>
235 </listitem>
236 </varlistentry>
237
238 <varlistentry>
239 <term>
240 <filename>.lhs</filename>
241 <indexterm><primary><literal>lhs</literal> suffix</primary></indexterm>
242 </term>
243 <listitem>
244 <para>A &ldquo;literate Haskell&rdquo; module.</para>
245 </listitem>
246 </varlistentry>
247
248 <varlistentry>
249 <term><filename>.hspp</filename></term>
250 <listitem>
251 <para>A file created by the preprocessor.</para>
252 </listitem>
253 </varlistentry>
254
255 <varlistentry>
256 <term><filename>.hi</filename></term>
257 <listitem>
258 <para>A Haskell interface file, probably
259 compiler-generated.</para>
260 </listitem>
261 </varlistentry>
262
263 <varlistentry>
264 <term><filename>.hc</filename></term>
265 <listitem>
266 <para>Intermediate C file produced by the Haskell
267 compiler.</para>
268 </listitem>
269 </varlistentry>
270
271 <varlistentry>
272 <term><filename>.c</filename></term>
273 <listitem>
274 <para>A C&nbsp;file not produced by the Haskell
275 compiler.</para>
276 </listitem>
277 </varlistentry>
278
279 <varlistentry>
280 <term><filename>.ll</filename></term>
281 <listitem>
282 <para>An llvm-intermediate-language source file, usually
283 produced by the compiler.</para>
284 </listitem>
285 </varlistentry>
286
287 <varlistentry>
288 <term><filename>.bc</filename></term>
289 <listitem>
290 <para>An llvm-intermediate-language bitcode file, usually
291 produced by the compiler.</para>
292 </listitem>
293 </varlistentry>
294
295 <varlistentry>
296 <term><filename>.s</filename></term>
297 <listitem>
298 <para>An assembly-language source file, usually produced by
299 the compiler.</para>
300 </listitem>
301 </varlistentry>
302
303 <varlistentry>
304 <term><filename>.o</filename></term>
305 <listitem>
306 <para>An object file, produced by an assembler.</para>
307 </listitem>
308 </varlistentry>
309 </variablelist>
310
311 <para>Files with other suffixes (or without suffixes) are passed
312 straight to the linker.</para>
313
314 </sect1>
315
316 <sect1 id="modes">
317 <title>Modes of operation</title>
318 <indexterm><primary>help options</primary></indexterm>
319
320 <para>
321 GHC's behaviour is firstly controlled by a mode flag. Only one
322 of these flags may be given, but it does not necessarily need to
323 be the first option on the command-line.
324 </para>
325
326 <para>
327 If no mode flag is present, then GHC will enter make mode
328 (<xref linkend="make-mode" />) if there are any Haskell source
329 files given on the command line, or else it will link the
330 objects named on the command line to produce an executable.
331 </para>
332
333 <para>The available mode flags are:</para>
334
335 <variablelist>
336 <varlistentry>
337 <term>
338 <cmdsynopsis><command>ghc --interactive</command>
339 </cmdsynopsis>
340 <indexterm><primary>interactive mode</primary></indexterm>
341 <indexterm><primary>ghci</primary></indexterm>
342 </term>
343 <listitem>
344 <para>Interactive mode, which is also available as
345 <command>ghci</command>. Interactive mode is described in
346 more detail in <xref linkend="ghci"/>.</para>
347 </listitem>
348 </varlistentry>
349
350 <varlistentry>
351 <term>
352 <cmdsynopsis><command>ghc --make</command>
353 </cmdsynopsis>
354 <indexterm><primary>make mode</primary></indexterm>
355 <indexterm><primary><option>--make</option></primary></indexterm>
356 </term>
357 <listitem>
358 <para>In this mode, GHC will build a multi-module Haskell
359 program automatically, figuring out dependencies for itself.
360 If you have a straightforward Haskell program, this is
361 likely to be much easier, and faster, than using
362 <command>make</command>. Make mode is described in <xref
363 linkend="make-mode"/>.</para>
364
365 <para>
366 This mode is the default if there are any Haskell
367 source files mentioned on the command line, and in this case
368 the <option>--make</option> option can be omitted.
369 </para>
370 </listitem>
371 </varlistentry>
372
373 <varlistentry>
374 <term>
375 <cmdsynopsis><command>ghc -e</command>
376 <arg choice='plain'><replaceable>expr</replaceable></arg>
377 </cmdsynopsis>
378 <indexterm><primary>eval mode</primary></indexterm>
379 </term>
380 <listitem>
381 <para>Expression-evaluation mode. This is very similar to
382 interactive mode, except that there is a single expression
383 to evaluate (<replaceable>expr</replaceable>) which is given
384 on the command line. See <xref linkend="eval-mode"/> for
385 more details.</para>
386 </listitem>
387 </varlistentry>
388
389 <varlistentry>
390 <term>
391 <cmdsynopsis>
392 <command>ghc -E</command>
393 <command>ghc -C</command>
394 <command>ghc -S</command>
395 <command>ghc -c</command>
396 </cmdsynopsis>
397 <indexterm><primary><option>-E</option></primary></indexterm>
398 <indexterm><primary><option>-C</option></primary></indexterm>
399 <indexterm><primary><option>-S</option></primary></indexterm>
400 <indexterm><primary><option>-c</option></primary></indexterm>
401 </term>
402 <listitem>
403 <para>This is the traditional batch-compiler mode, in which
404 GHC can compile source files one at a time, or link objects
405 together into an executable. See <xref
406 linkend="options-order"/>.</para>
407 </listitem>
408 </varlistentry>
409
410 <varlistentry>
411 <term>
412 <cmdsynopsis>
413 <command>ghc -M</command>
414 </cmdsynopsis>
415 <indexterm><primary>dependency-generation mode</primary></indexterm>
416 </term>
417 <listitem>
418 <para>Dependency-generation mode. In this mode, GHC can be
419 used to generate dependency information suitable for use in
420 a <literal>Makefile</literal>. See <xref
421 linkend="makefile-dependencies"/>.</para>
422 </listitem>
423 </varlistentry>
424
425 <varlistentry>
426 <term>
427 <cmdsynopsis>
428 <command>ghc --mk-dll</command>
429 </cmdsynopsis>
430 <indexterm><primary>DLL-creation mode</primary></indexterm>
431 </term>
432 <listitem>
433 <para>DLL-creation mode (Windows only). See <xref
434 linkend="win32-dlls-create"/>.</para>
435 </listitem>
436 </varlistentry>
437
438 <varlistentry>
439 <term>
440 <cmdsynopsis>
441 <command>ghc --help</command> <command>ghc -?</command>
442 </cmdsynopsis>
443 <indexterm><primary><option>--help</option></primary></indexterm>
444 </term>
445 <listitem>
446 <para>Cause GHC to spew a long usage message to standard
447 output and then exit.</para>
448 </listitem>
449 </varlistentry>
450
451 <varlistentry>
452 <term>
453 <cmdsynopsis>
454 <command>ghc --show-iface <replaceable>file</replaceable></command>
455 </cmdsynopsis>
456 <indexterm><primary><option>--show-iface</option></primary></indexterm>
457 </term>
458 <listitem>
459 <para>Read the interface in
460 <replaceable>file</replaceable> and dump it as text to
461 <literal>stdout</literal>. For example <literal>ghc --show-iface M.hi</literal>.</para>
462 </listitem>
463 </varlistentry>
464
465 <varlistentry>
466 <term>
467 <cmdsynopsis>
468 <command>ghc --supported-extensions</command>
469 <command>ghc --supported-languages</command>
470 </cmdsynopsis>
471 <indexterm><primary><option>--supported-extensions</option></primary><primary><option>--supported-languages</option></primary></indexterm>
472 </term>
473 <listitem>
474 <para>Print the supported language extensions.</para>
475 </listitem>
476 </varlistentry>
477
478 <varlistentry>
479 <term>
480 <cmdsynopsis>
481 <command>ghc --show-options</command>
482 </cmdsynopsis>
483 <indexterm><primary><option>--show-options</option></primary></indexterm>
484 </term>
485 <listitem>
486 <para>Print the supported command line options. This flag can be used for autocompletion in a shell.</para>
487 </listitem>
488 </varlistentry>
489
490 <varlistentry>
491 <term>
492 <cmdsynopsis>
493 <command>ghc --info</command>
494 </cmdsynopsis>
495 <indexterm><primary><option>--info</option></primary></indexterm>
496 </term>
497 <listitem>
498 <para>Print information about the compiler.</para>
499 </listitem>
500 </varlistentry>
501
502 <varlistentry>
503 <term>
504 <cmdsynopsis>
505 <command>ghc --version</command>
506 <command>ghc -V</command>
507 </cmdsynopsis>
508 <indexterm><primary><option>-V</option></primary></indexterm>
509 <indexterm><primary><option>--version</option></primary></indexterm>
510 </term>
511 <listitem>
512 <para>Print a one-line string including GHC's version number.</para>
513 </listitem>
514 </varlistentry>
515
516 <varlistentry>
517 <term>
518 <cmdsynopsis>
519 <command>ghc --numeric-version</command>
520 </cmdsynopsis>
521 <indexterm><primary><option>--numeric-version</option></primary></indexterm>
522 </term>
523 <listitem>
524 <para>Print GHC's numeric version number only.</para>
525 </listitem>
526 </varlistentry>
527
528 <varlistentry>
529 <term>
530 <cmdsynopsis>
531 <command>ghc --print-libdir</command>
532 </cmdsynopsis>
533 <indexterm><primary><option>--print-libdir</option></primary></indexterm>
534 </term>
535 <listitem>
536 <para>Print the path to GHC's library directory. This is
537 the top of the directory tree containing GHC's libraries,
538 interfaces, and include files (usually something like
539 <literal>/usr/local/lib/ghc-5.04</literal> on Unix). This
540 is the value of
541 <literal>$libdir</literal><indexterm><primary><literal>libdir</literal></primary></indexterm>
542 in the package configuration file
543 (see <xref linkend="packages"/>).</para>
544 </listitem>
545 </varlistentry>
546
547 </variablelist>
548
549 <sect2 id="make-mode">
550 <title>Using <command>ghc</command> <option>--make</option></title>
551 <indexterm><primary><option>--make</option></primary></indexterm>
552 <indexterm><primary>separate compilation</primary></indexterm>
553
554 <para>In this mode, GHC will build a multi-module Haskell program by following
555 dependencies from one or more root modules (usually just
556 <literal>Main</literal>). For example, if your
557 <literal>Main</literal> module is in a file called
558 <filename>Main.hs</filename>, you could compile and link the
559 program like this:</para>
560
561 <screen>
562 ghc --make Main.hs
563 </screen>
564
565 <para>
566 In fact, GHC enters make mode automatically if there are any
567 Haskell source files on the command line and no other mode is
568 specified, so in this case we could just type
569 </para>
570
571 <screen>
572 ghc Main.hs
573 </screen>
574
575 <para>Any number of source file names or module names may be
576 specified; GHC will figure out all the modules in the program by
577 following the imports from these initial modules. It will then
578 attempt to compile each module which is out of date, and
579 finally, if there is a <literal>Main</literal> module, the
580 program will also be linked into an executable.</para>
581
582 <para>The main advantages to using <literal>ghc
583 --make</literal> over traditional
584 <literal>Makefile</literal>s are:</para>
585
586 <itemizedlist>
587 <listitem>
588 <para>GHC doesn't have to be restarted for each compilation,
589 which means it can cache information between compilations.
590 Compiling a multi-module program with <literal>ghc
591 --make</literal> can be up to twice as fast as
592 running <literal>ghc</literal> individually on each source
593 file.</para>
594 </listitem>
595 <listitem>
596 <para>You don't have to write a <literal>Makefile</literal>.</para>
597 <indexterm><primary><literal>Makefile</literal>s</primary><secondary>avoiding</secondary></indexterm>
598 </listitem>
599 <listitem>
600 <para>GHC re-calculates the dependencies each time it is
601 invoked, so the dependencies never get out of sync with the
602 source.</para>
603 </listitem>
604 <listitem>
605 <para>Using the <literal>-j</literal> flag, you can compile
606 modules in parallel. Specify <literal>-jN</literal> to
607 compile <replaceable>N</replaceable> jobs in parallel.</para>
608 </listitem>
609 </itemizedlist>
610
611 <para>Any of the command-line options described in the rest of
612 this chapter can be used with
613 <option>--make</option>, but note that any options
614 you give on the command line will apply to all the source files
615 compiled, so if you want any options to apply to a single source
616 file only, you'll need to use an <literal>OPTIONS_GHC</literal>
617 pragma (see <xref linkend="source-file-options"/>).</para>
618
619 <para>If the program needs to be linked with additional objects
620 (say, some auxiliary C code), then the object files can be
621 given on the command line and GHC will include them when linking
622 the executable.</para>
623
624 <para>For backward compatibility with existing make scripts, when
625 used in combination with <option>-c</option>, the linking phase
626 is omitted (same as <option>--make</option>
627 <option>-no-link</option>).</para>
628
629 <para>Note that GHC can only follow dependencies if it has the
630 source file available, so if your program includes a module for
631 which there is no source file, even if you have an object and an
632 interface file for the module, then GHC will complain. The
633 exception to this rule is for package modules, which may or may
634 not have source files.</para>
635
636 <para>The source files for the program don't all need to be in
637 the same directory; the <option>-i</option> option can be used
638 to add directories to the search path (see <xref
639 linkend="search-path"/>).</para>
640 </sect2>
641
642 <sect2 id="eval-mode">
643 <title>Expression evaluation mode</title>
644
645 <para>This mode is very similar to interactive mode, except that
646 there is a single expression to evaluate which is specified on
647 the command line as an argument to the <option>-e</option>
648 option:</para>
649
650 <screen>
651 ghc -e <replaceable>expr</replaceable>
652 </screen>
653
654 <para>Haskell source files may be named on the command line, and
655 they will be loaded exactly as in interactive mode. The
656 expression is evaluated in the context of the loaded
657 modules.</para>
658
659 <para>For example, to load and run a Haskell program containing
660 a module <literal>Main</literal>, we might say</para>
661
662 <screen>
663 ghc -e Main.main Main.hs
664 </screen>
665
666 <para>or we can just use this mode to evaluate expressions in
667 the context of the <literal>Prelude</literal>:</para>
668
669 <screen>
670 $ ghc -e "interact (unlines.map reverse.lines)"
671 hello
672 olleh
673 </screen>
674 </sect2>
675
676 <sect2 id="options-order">
677 <title>Batch compiler mode</title>
678
679 <para>In <emphasis>batch mode</emphasis>, GHC will compile one or more source files
680 given on the command line.</para>
681
682 <para>The first phase to run is determined by each input-file
683 suffix, and the last phase is determined by a flag. If no
684 relevant flag is present, then go all the way through to linking.
685 This table summarises:</para>
686
687 <informaltable>
688 <tgroup cols="4">
689 <colspec align="left"/>
690 <colspec align="left"/>
691 <colspec align="left"/>
692 <colspec align="left"/>
693
694 <thead>
695 <row>
696 <entry>Phase of the compilation system</entry>
697 <entry>Suffix saying &ldquo;start here&rdquo;</entry>
698 <entry>Flag saying &ldquo;stop after&rdquo;</entry>
699 <entry>(suffix of) output file</entry>
700 </row>
701 </thead>
702 <tbody>
703 <row>
704 <entry>literate pre-processor</entry>
705 <entry><literal>.lhs</literal></entry>
706 <entry>-</entry>
707 <entry><literal>.hs</literal></entry>
708 </row>
709
710 <row>
711 <entry>C pre-processor (opt.) </entry>
712 <entry><literal>.hs</literal> (with
713 <option>-cpp</option>)</entry>
714 <entry><option>-E</option></entry>
715 <entry><literal>.hspp</literal></entry>
716 </row>
717
718 <row>
719 <entry>Haskell compiler</entry>
720 <entry><literal>.hs</literal></entry>
721 <entry><option>-C</option>, <option>-S</option></entry>
722 <entry><literal>.hc</literal>, <literal>.s</literal></entry>
723 </row>
724
725 <row>
726 <entry>C compiler (opt.)</entry>
727 <entry><literal>.hc</literal> or <literal>.c</literal></entry>
728 <entry><option>-S</option></entry>
729 <entry><literal>.s</literal></entry>
730 </row>
731
732 <row>
733 <entry>assembler</entry>
734 <entry><literal>.s</literal></entry>
735 <entry><option>-c</option></entry>
736 <entry><literal>.o</literal></entry>
737 </row>
738
739 <row>
740 <entry>linker</entry>
741 <entry><replaceable>other</replaceable></entry>
742 <entry>-</entry>
743 <entry><filename>a.out</filename></entry>
744 </row>
745 </tbody>
746 </tgroup>
747 </informaltable>
748
749 <indexterm><primary><option>-C</option></primary></indexterm>
750 <indexterm><primary><option>-E</option></primary></indexterm>
751 <indexterm><primary><option>-S</option></primary></indexterm>
752 <indexterm><primary><option>-c</option></primary></indexterm>
753
754 <para>Thus, a common invocation would be: </para>
755
756 <screen>
757 ghc -c Foo.hs
758 </screen>
759
760 <para>to compile the Haskell source file
761 <filename>Foo.hs</filename> to an object file
762 <filename>Foo.o</filename>.</para>
763
764 <para>Note: What the Haskell compiler proper produces depends on what
765 backend code generator is used. See <xref linkend="code-generators"/>
766 for more details.</para>
767
768 <para>Note: C pre-processing is optional, the
769 <option>-cpp</option><indexterm><primary><option>-cpp</option></primary></indexterm>
770 flag turns it on. See <xref linkend="c-pre-processor"/> for more
771 details.</para>
772
773 <para>Note: The option <option>-E</option><indexterm><primary>-E
774 option</primary></indexterm> runs just the pre-processing passes
775 of the compiler, dumping the result in a file.</para>
776
777 <para>Note: The option <option>-C</option> is only available when
778 GHC is built in unregisterised mode. See <xref linkend="unreg"/>
779 for more details.</para>
780
781 <sect3 id="overriding-suffixes">
782 <title>Overriding the default behaviour for a file</title>
783
784 <para>As described above, the way in which a file is processed by GHC
785 depends on its suffix. This behaviour can be overridden using the
786 <option>-x</option> option:</para>
787
788 <variablelist>
789 <varlistentry>
790 <term><option>-x</option> <replaceable>suffix</replaceable>
791 <indexterm><primary><option>-x</option></primary>
792 </indexterm></term>
793 <listitem>
794 <para>Causes all files following this option on the command
795 line to be processed as if they had the suffix
796 <replaceable>suffix</replaceable>. For example, to compile a
797 Haskell module in the file <literal>M.my-hs</literal>,
798 use <literal>ghc -c -x hs M.my-hs</literal>.</para>
799 </listitem>
800 </varlistentry>
801 </variablelist>
802 </sect3>
803
804 </sect2>
805 </sect1>
806
807 <sect1 id="options-help">
808 <title>Verbosity options</title>
809
810 <indexterm><primary>verbosity options</primary></indexterm>
811
812 <para>See also the <option>--help</option>, <option>--version</option>, <option>--numeric-version</option>,
813 and <option>--print-libdir</option> modes in <xref linkend="modes"/>.</para>
814 <variablelist>
815 <varlistentry>
816 <term>
817 <option>-v</option>
818 <indexterm><primary><option>-v</option></primary></indexterm>
819 </term>
820 <listitem>
821 <para>The <option>-v</option> option makes GHC
822 <emphasis>verbose</emphasis>: it reports its version number
823 and shows (on stderr) exactly how it invokes each phase of
824 the compilation system. Moreover, it passes the
825 <option>-v</option> flag to most phases; each reports its
826 version number (and possibly some other information).</para>
827
828 <para>Please, oh please, use the <option>-v</option> option
829 when reporting bugs! Knowing that you ran the right bits in
830 the right order is always the first thing we want to
831 verify.</para>
832 </listitem>
833 </varlistentry>
834
835 <varlistentry>
836 <term>
837 <option>-v</option><replaceable>n</replaceable>
838 <indexterm><primary><option>-v</option></primary></indexterm>
839 </term>
840 <listitem>
841 <para>To provide more control over the compiler's verbosity,
842 the <option>-v</option> flag takes an optional numeric
843 argument. Specifying <option>-v</option> on its own is
844 equivalent to <option>-v3</option>, and the other levels
845 have the following meanings:</para>
846
847 <variablelist>
848 <varlistentry>
849 <term><option>-v0</option></term>
850 <listitem>
851 <para>Disable all non-essential messages (this is the
852 default).</para>
853 </listitem>
854 </varlistentry>
855
856 <varlistentry>
857 <term><option>-v1</option></term>
858 <listitem>
859 <para>Minimal verbosity: print one line per
860 compilation (this is the default when
861 <option>--make</option> or
862 <option>--interactive</option> is on).</para>
863 </listitem>
864 </varlistentry>
865
866 <varlistentry>
867 <term><option>-v2</option></term>
868 <listitem>
869 <para>Print the name of each compilation phase as it
870 is executed. (equivalent to
871 <option>-dshow-passes</option>).</para>
872 </listitem>
873 </varlistentry>
874
875 <varlistentry>
876 <term><option>-v3</option></term>
877 <listitem>
878 <para>The same as <option>-v2</option>, except that in
879 addition the full command line (if appropriate) for
880 each compilation phase is also printed.</para>
881 </listitem>
882 </varlistentry>
883
884 <varlistentry>
885 <term><option>-v4</option></term>
886 <listitem>
887 <para>The same as <option>-v3</option> except that the
888 intermediate program representation after each
889 compilation phase is also printed (excluding
890 preprocessed and C/assembly files).</para>
891 </listitem>
892 </varlistentry>
893 </variablelist>
894 </listitem>
895 </varlistentry>
896
897
898 <varlistentry>
899 <term><option>--fprint-explicit-foralls, -fprint-explicit-kinds</option>
900 <indexterm><primary><option>-fprint-explicit-foralls</option></primary></indexterm>
901 <indexterm><primary><option>-fprint-explicit-kinds</option></primary></indexterm>
902 </term>
903 <listitem>
904 <para>These two flags control the way in which GHC displays types, in error messages and in GHCi.
905 Using <option>-fprint-explicit-foralls</option> makes GHC print explicit <literal>forall</literal>
906 quantification at the top level of a type; normally this is suppressed. For example, in GHCi:
907 <screen>
908 ghci> let f x = x
909 ghci> :t f
910 f :: a -> a
911 ghci> :set -fprint-explicit-foralls
912 ghci> :t f
913 f :: forall a. a -> a
914 </screen>
915 However, regardless of the flag setting, the quantifiers are printed under these circumstances:
916 <itemizedlist>
917 <listitem><para>For nested <literal>foralls</literal>, e.g.
918 <screen>
919 ghci> :t GHC.ST.runST
920 GHC.ST.runST :: (forall s. GHC.ST.ST s a) -> a
921 </screen>
922 </para></listitem>
923 <listitem><para>If any of the quantified type variables has a kind
924 that mentions a kind variable, e.g.
925 <screen>
926 ghci> :i Data.Type.Equality.sym
927 Data.Type.Equality.sym ::
928 forall (k :: BOX) (a :: k) (b :: k).
929 (a Data.Type.Equality.:~: b) -> b Data.Type.Equality.:~: a
930 -- Defined in Data.Type.Equality
931 </screen>
932 </para></listitem>
933 </itemizedlist>
934 </para>
935 <para>
936 Using <option>-fprint-explicit-kinds</option> makes GHC print kind arguments
937 in types, which are normally suppressed. This can be important when you are using kind polymorphism.
938 For example:
939 <screen>
940 ghci> :set -XPolyKinds
941 ghci> data T a = MkT
942 ghci> :t MkT
943 MkT :: forall (k :: BOX) (a :: k). T a
944 ghci> :set -fprint-explicit-foralls
945 ghci> :t MkT
946 MkT :: forall (k :: BOX) (a :: k). T k a
947 </screen>
948 </para>
949 </listitem>
950 </varlistentry>
951
952 <varlistentry>
953 <term><option>-ferror-spans</option>
954 <indexterm><primary><option>-ferror-spans</option></primary>
955 </indexterm>
956 </term>
957 <listitem>
958 <para>Causes GHC to emit the full source span of the
959 syntactic entity relating to an error message. Normally, GHC
960 emits the source location of the start of the syntactic
961 entity only.</para>
962
963 <para>For example:</para>
964
965 <screen>
966 test.hs:3:6: parse error on input `where'
967 </screen>
968
969 <para>becomes:</para>
970
971 <screen>
972 test296.hs:3:6-10: parse error on input `where'
973 </screen>
974
975 <para>And multi-line spans are possible too:</para>
976
977 <screen>
978 test.hs:(5,4)-(6,7):
979 Conflicting definitions for `a'
980 Bound at: test.hs:5:4
981 test.hs:6:7
982 In the binding group for: a, b, a
983 </screen>
984
985 <para>Note that line numbers start counting at one, but
986 column numbers start at zero. This choice was made to
987 follow existing convention (i.e. this is how Emacs does
988 it).</para>
989 </listitem>
990 </varlistentry>
991
992 <varlistentry>
993 <term><option>-H</option><replaceable>size</replaceable>
994 <indexterm><primary><option>-H</option></primary></indexterm>
995 </term>
996 <listitem>
997 <para>Set the minimum size of the heap to
998 <replaceable>size</replaceable>.
999 This option is equivalent to
1000 <literal>+RTS&nbsp;-H<replaceable>size</replaceable></literal>,
1001 see <xref linkend="rts-options-gc" />.
1002 </para>
1003 </listitem>
1004 </varlistentry>
1005
1006 <varlistentry>
1007 <term><option>-Rghc-timing</option>
1008 <indexterm><primary><option>-Rghc-timing</option></primary></indexterm>
1009 </term>
1010 <listitem>
1011 <para>Prints a one-line summary of timing statistics for the
1012 GHC run. This option is equivalent to
1013 <literal>+RTS&nbsp;-tstderr</literal>, see <xref
1014 linkend="rts-options-gc" />.
1015 </para>
1016 </listitem>
1017 </varlistentry>
1018 </variablelist>
1019 </sect1>
1020
1021 &separate;
1022
1023 <sect1 id="options-sanity">
1024 <title>Warnings and sanity-checking</title>
1025
1026 <indexterm><primary>sanity-checking options</primary></indexterm>
1027 <indexterm><primary>warnings</primary></indexterm>
1028
1029
1030 <para>GHC has a number of options that select which types of
1031 non-fatal error messages, otherwise known as warnings, can be
1032 generated during compilation. By default, you get a standard set
1033 of warnings which are generally likely to indicate bugs in your
1034 program. These are:
1035 <option>-fwarn-overlapping-patterns</option>,
1036 <option>-fwarn-warnings-deprecations</option>,
1037 <option>-fwarn-deprecated-flags</option>,
1038 <option>-fwarn-unrecognised-pragmas</option>,
1039 <option>-fwarn-pointless-pragmas</option>,
1040 <option>-fwarn-duplicate-constraints</option>,
1041 <option>-fwarn-duplicate-exports</option>,
1042 <option>-fwarn-overflowed-literals</option>,
1043 <option>-fwarn-empty-enumerations</option>,
1044 <option>-fwarn-missing-fields</option>,
1045 <option>-fwarn-missing-methods</option>,
1046 <option>-fwarn-wrong-do-bind</option>,
1047 <option>-fwarn-unsupported-calling-conventions</option>,
1048 <option>-fwarn-dodgy-foreign-imports</option>,
1049 <option>-fwarn-inline-rule-shadowing</option>,
1050 <option>-fwarn-unsupported-llvm-version</option>,
1051 <option>-fwarn-context-quantification</option>, and
1052 <option>-fwarn-tabs</option>.
1053 The following flags are simple ways to select standard
1054 &ldquo;packages&rdquo; of warnings:
1055 </para>
1056
1057 <variablelist>
1058
1059 <varlistentry>
1060 <term><option>-W</option>:</term>
1061 <listitem>
1062 <indexterm><primary>-W option</primary></indexterm>
1063 <para>Provides the standard warnings plus
1064 <option>-fwarn-unused-binds</option>,
1065 <option>-fwarn-unused-matches</option>,
1066 <option>-fwarn-unused-imports</option>,
1067 <option>-fwarn-incomplete-patterns</option>,
1068 <option>-fwarn-dodgy-exports</option>, and
1069 <option>-fwarn-dodgy-imports</option>.</para>
1070 </listitem>
1071 </varlistentry>
1072
1073 <varlistentry>
1074 <term><option>-Wall</option>:</term>
1075 <listitem>
1076 <indexterm><primary><option>-Wall</option></primary></indexterm>
1077 <para>Turns on all warning options that indicate potentially
1078 suspicious code. The warnings that are
1079 <emphasis>not</emphasis> enabled by <option>-Wall</option>
1080 are
1081 <option>-fwarn-type-defaults</option>,
1082 <option>-fwarn-name-shadowing</option>,
1083 <option>-fwarn-missing-signatures</option>,
1084 <option>-fwarn-warn-hi-shadowing</option>,
1085 <option>-fwarn-orphans</option>,
1086 <option>-fwarn-unused-do-bind</option>, and
1087 <option>-fwarn-trustworthy-safe</option>,
1088 <option>-fwarn-unticked-promoted-constructors</option>.</para>
1089 </listitem>
1090 </varlistentry>
1091
1092 <varlistentry>
1093 <term><option>-w</option>:</term>
1094 <listitem>
1095 <indexterm><primary><option>-w</option></primary></indexterm>
1096 <para>Turns off all warnings, including the standard ones and
1097 those that <literal>-Wall</literal> doesn't enable.</para>
1098 </listitem>
1099 </varlistentry>
1100
1101 <varlistentry>
1102 <term><option>-Werror</option>:</term>
1103 <listitem>
1104 <indexterm><primary><option>-Werror</option></primary></indexterm>
1105 <para>Makes any warning into a fatal error. Useful so that you don't
1106 miss warnings when doing batch compilation. </para>
1107 </listitem>
1108 </varlistentry>
1109
1110 <varlistentry>
1111 <term><option>-Wwarn</option>:</term>
1112 <listitem>
1113 <indexterm><primary><option>-Wwarn</option></primary></indexterm>
1114 <para>Warnings are treated only as warnings, not as errors. This is
1115 the default, but can be useful to negate a
1116 <option>-Werror</option> flag.</para>
1117 </listitem>
1118 </varlistentry>
1119
1120 </variablelist>
1121
1122 <para>The full set of warning options is described below. To turn
1123 off any warning, simply give the corresponding
1124 <option>-fno-warn-...</option> option on the command line.</para>
1125
1126 <variablelist>
1127
1128 <varlistentry>
1129 <term><option>-fwarn-typed-holes</option>:</term>
1130 <listitem>
1131 <indexterm><primary><option>-fwarn-typed-holes</option></primary>
1132 </indexterm>
1133 <indexterm><primary>warnings</primary></indexterm>
1134 <para>
1135 Determines whether the compiler reports typed holes warnings. Has
1136 no effect unless typed holes errors are deferred until runtime.
1137 See <xref linkend="typed-holes"/> and <xref linkend="defer-type-errors"/>
1138 </para>
1139
1140 <para>This warning is on by default.</para>
1141 </listitem>
1142 </varlistentry>
1143
1144
1145 <varlistentry>
1146 <term><option>-fdefer-type-errors</option>:</term>
1147 <listitem>
1148 <indexterm><primary><option>-fdefer-type-errors</option></primary>
1149 </indexterm>
1150 <indexterm><primary>warnings</primary></indexterm>
1151 <para>Defer as many type errors as possible until runtime.
1152 At compile time you get a warning (instead of an error). At
1153 runtime, if you use a value that depends on a type error, you
1154 get a runtime error; but you can run any type-correct parts of your code
1155 just fine. See <xref linkend="defer-type-errors"/></para>
1156 </listitem>
1157 </varlistentry>
1158
1159 <varlistentry>
1160 <term><option>-fdefer-typed-holes</option>:</term>
1161 <listitem>
1162 <indexterm><primary><option>-fdefer-typed-holes</option></primary>
1163 </indexterm>
1164 <indexterm><primary>warnings</primary></indexterm>
1165 <para>
1166 Defer typed holes errors until runtime. This will turn the errors
1167 produced by <link linked="typed-holes">typed holes</link> into
1168 warnings. Using a value that depends on a typed hole produces a
1169 runtime error, the same as <option>-fdefer-type-errors</option>
1170 (which implies this option). See <xref linkend="typed-holes"/>
1171 and <xref linkend="defer-type-errors"/>.
1172 </para>
1173 <para>
1174 Implied by <option>-fdefer-type-errors</option>. See also
1175 <option>-fwarn-typed-holes</option>.
1176 </para>
1177 </listitem>
1178 </varlistentry>
1179
1180 <varlistentry>
1181 <term><option>-fwarn-partial-type-signatures</option>:</term>
1182 <listitem>
1183 <indexterm><primary><option>-fwarn-partial-type-signatures</option></primary>
1184 </indexterm>
1185 <indexterm><primary>warnings</primary></indexterm>
1186 <para>
1187 Determines whether the compiler reports holes in partial type
1188 signatures as warnings. Has no effect unless
1189 <option>-XPartialTypeSignatures</option> is enabled, which
1190 controls whether errors should be generated for holes in types
1191 or not. See <xref linkend="partial-type-signatures"/>.
1192 </para>
1193
1194 <para>This warning is on by default.</para>
1195 </listitem>
1196 </varlistentry>
1197
1198 <varlistentry>
1199 <term><option>-fhelpful-errors</option>:</term>
1200 <listitem>
1201 <indexterm><primary><option>-fhelpful-errors</option></primary>
1202 </indexterm>
1203 <indexterm><primary>warnings</primary></indexterm>
1204 <para>When a name or package is not found in scope, make
1205 suggestions for the name or package you might have meant instead.</para>
1206 <para>This option is on by default.</para>
1207 </listitem>
1208 </varlistentry>
1209
1210 <varlistentry>
1211 <term><option>-fwarn-unrecognised-pragmas</option>:</term>
1212 <listitem>
1213 <indexterm><primary><option>-fwarn-unrecognised-pragmas</option></primary>
1214 </indexterm>
1215 <indexterm><primary>warnings</primary></indexterm>
1216 <indexterm><primary>pragmas</primary></indexterm>
1217 <para>Causes a warning to be emitted when a
1218 pragma that GHC doesn't recognise is used. As well as pragmas
1219 that GHC itself uses, GHC also recognises pragmas known to be used
1220 by other tools, e.g. <literal>OPTIONS_HUGS</literal> and
1221 <literal>DERIVE</literal>.</para>
1222
1223 <para>This option is on by default.</para>
1224 </listitem>
1225 </varlistentry>
1226
1227 <varlistentry>
1228 <term><option>-fwarn-pointless-pragmas</option>:</term>
1229 <listitem>
1230 <indexterm><primary><option>-fwarn-pointless-pragmas</option></primary>
1231 </indexterm>
1232 <indexterm><primary>warnings</primary></indexterm>
1233 <indexterm><primary>pragmas</primary></indexterm>
1234 <para>Causes a warning to be emitted when GHC detects that a
1235 module contains a pragma that has no effect.</para>
1236
1237 <para>This option is on by default.</para>
1238 </listitem>
1239 </varlistentry>
1240
1241 <varlistentry>
1242 <term><option>-fwarn-warnings-deprecations</option>:</term>
1243 <listitem>
1244 <indexterm><primary><option>-fwarn-warnings-deprecations</option></primary>
1245 </indexterm>
1246 <indexterm><primary>warnings</primary></indexterm>
1247 <indexterm><primary>deprecations</primary></indexterm>
1248 <para>Causes a warning to be emitted when a
1249 module, function or type with a WARNING or DEPRECATED pragma
1250 is used. See <xref linkend="warning-deprecated-pragma"/> for more
1251 details on the pragmas.</para>
1252
1253 <para>This option is on by default.</para>
1254 </listitem>
1255 </varlistentry>
1256
1257 <varlistentry>
1258 <term><option>-fwarn-amp</option>:</term>
1259 <listitem>
1260 <indexterm><primary><option>-fwarn-amp</option></primary>
1261 </indexterm>
1262 <indexterm><primary>amp</primary></indexterm>
1263 <indexterm><primary>applicative-monad proposal</primary></indexterm>
1264 <para>Causes a warning to be emitted when a definition
1265 is in conflict with the AMP (Applicative-Monad proosal),
1266 namely:
1267 1. Instance of Monad without Applicative;
1268 2. Instance of MonadPlus without Alternative;
1269 3. Custom definitions of join/pure/&lt;*&gt;</para>
1270
1271 <para>This option is on by default.</para>
1272 </listitem>
1273 </varlistentry>
1274
1275 <varlistentry>
1276 <term><option>-fwarn-deprecated-flags</option>:</term>
1277 <listitem>
1278 <indexterm><primary><option>-fwarn-deprecated-flags</option></primary>
1279 </indexterm>
1280 <indexterm><primary>deprecated-flags</primary></indexterm>
1281 <para>Causes a warning to be emitted when a deprecated
1282 commandline flag is used.</para>
1283
1284 <para>This option is on by default.</para>
1285 </listitem>
1286 </varlistentry>
1287
1288 <varlistentry>
1289 <term><option>-fwarn-unsupported-calling-conventions</option>:</term>
1290 <listitem>
1291 <indexterm><primary><option>-fwarn-unsupported-calling-conventions</option></primary>
1292 </indexterm>
1293 <para>Causes a warning to be emitted for foreign declarations
1294 that use unsupported calling conventions. In particular,
1295 if the <literal>stdcall</literal> calling convention is used
1296 on an architecture other than i386 then it will be treated
1297 as <literal>ccall</literal>.</para>
1298 </listitem>
1299 </varlistentry>
1300
1301 <varlistentry>
1302 <term><option>-fwarn-dodgy-foreign-imports</option>:</term>
1303 <listitem>
1304 <indexterm><primary><option>-fwarn-dodgy-foreign-imports</option></primary>
1305 </indexterm>
1306 <para>Causes a warning to be emitted for foreign imports of
1307 the following form:</para>
1308
1309 <programlisting>
1310 foreign import "f" f :: FunPtr t
1311 </programlisting>
1312
1313 <para>on the grounds that it probably should be</para>
1314
1315 <programlisting>
1316 foreign import "&amp;f" f :: FunPtr t
1317 </programlisting>
1318
1319 <para>The first form declares that `f` is a (pure) C
1320 function that takes no arguments and returns a pointer to a
1321 C function with type `t`, whereas the second form declares
1322 that `f` itself is a C function with type `t`. The first
1323 declaration is usually a mistake, and one that is hard to
1324 debug because it results in a crash, hence this
1325 warning.</para>
1326 </listitem>
1327 </varlistentry>
1328
1329 <varlistentry>
1330 <term><option>-fwarn-dodgy-exports</option>:</term>
1331 <listitem>
1332 <indexterm><primary><option>-fwarn-dodgy-exports</option></primary>
1333 </indexterm>
1334 <para>Causes a warning to be emitted when a datatype
1335 <literal>T</literal> is exported
1336 with all constructors, i.e. <literal>T(..)</literal>, but is it
1337 just a type synonym.</para>
1338 <para>Also causes a warning to be emitted when a module is
1339 re-exported, but that module exports nothing.</para>
1340 </listitem>
1341 </varlistentry>
1342
1343 <varlistentry>
1344 <term><option>-fwarn-dodgy-imports</option>:</term>
1345 <listitem>
1346 <indexterm><primary><option>-fwarn-dodgy-imports</option></primary>
1347 </indexterm>
1348 <para>Causes a warning to be emitted in the following cases:</para>
1349 <itemizedlist>
1350 <listitem>
1351 <para>When a datatype <literal>T</literal> is imported with all
1352 constructors, i.e. <literal>T(..)</literal>, but has been
1353 exported abstractly, i.e. <literal>T</literal>.
1354 </para>
1355 </listitem>
1356 <listitem>
1357 <para>When an <literal>import</literal> statement hides an
1358 entity that is not exported.</para>
1359 </listitem>
1360 </itemizedlist>
1361 </listitem>
1362 </varlistentry>
1363
1364 <varlistentry>
1365 <term><option>-fwarn-overflowed-literals</option>:</term>
1366 <listitem>
1367 <indexterm><primary><option>-fwarn-overflowed-literals</option></primary>
1368 </indexterm>
1369 <para>
1370 Causes a warning to be emitted if a literal will overflow,
1371 e.g. <literal>300 :: Word8</literal>.
1372 </para>
1373 </listitem>
1374 </varlistentry>
1375
1376 <varlistentry>
1377 <term><option>-fwarn-empty-enumerations</option>:</term>
1378 <listitem>
1379 <indexterm><primary><option>-fwarn-empty-enumerations</option></primary>
1380 </indexterm>
1381 <para>
1382 Causes a warning to be emitted if an enumeration is
1383 empty, e.g. <literal>[5 .. 3]</literal>.
1384 </para>
1385 </listitem>
1386 </varlistentry>
1387
1388 <varlistentry>
1389 <term><option>-fwarn-lazy-unlifted-bindings</option>:</term>
1390 <listitem>
1391 <indexterm><primary><option>-fwarn-lazy-unlifted-bindings</option></primary>
1392 </indexterm>
1393 <para>This flag is a no-op, and will be removed in GHC 7.10.</para>
1394 </listitem>
1395 </varlistentry>
1396
1397 <varlistentry>
1398 <term><option>-fwarn-duplicate-constraints</option>:</term>
1399 <listitem>
1400 <indexterm><primary><option>-fwarn-duplicate-constraints</option></primary></indexterm>
1401 <indexterm><primary>duplicate constraints, warning</primary></indexterm>
1402
1403 <para>Have the compiler warn about duplicate constraints in a type signature. For
1404 example
1405 <programlisting>
1406 f :: (Eq a, Show a, Eq a) => a -> a
1407 </programlisting>
1408 The warning will indicate the duplicated <literal>Eq a</literal> constraint.
1409 </para>
1410
1411 <para>This option is now deprecated in favour of <option>-fwarn-redundant-constraints</option>.</para>
1412 </listitem>
1413 </varlistentry>
1414
1415 <varlistentry>
1416 <term><option>-fwarn-redundant-constraints</option>:</term>
1417 <listitem>
1418 <indexterm><primary><option>-fwarn-redundant-constraints</option></primary></indexterm>
1419 <indexterm><primary>redundant constraints, warning</primary></indexterm>
1420
1421 <para>Have the compiler warn about redundant constraints in a type signature. For
1422 example
1423 <itemizedlist>
1424 <listitem><para>
1425 <programlisting>
1426 f :: (Eq a, Ord a) => a -> a
1427 </programlisting>
1428 The warning will indicate the redundant <literal>Eq a</literal> constraint:
1429 it is subsumed by the <literal>Ord a</literal> constraint.
1430 </para></listitem>
1431 <listitem><para>
1432 <programlisting>
1433 f :: Eq a => a -> a -> Bool
1434 f x y = True
1435 </programlisting>
1436 The warning will indicate the redundant <literal>Eq a</literal> constraint:
1437 : it is not used by the definition of <literal>f</literal>.)
1438 </para></listitem>
1439 </itemizedlist>
1440 Similar warnings are given for a redundant constraint in an instance declaration.
1441 </para>
1442
1443 <para>This option is on by default.</para>
1444 </listitem>
1445 </varlistentry>
1446
1447 <varlistentry>
1448 <term><option>-fwarn-duplicate-exports</option>:</term>
1449 <listitem>
1450 <indexterm><primary><option>-fwarn-duplicate-exports</option></primary></indexterm>
1451 <indexterm><primary>duplicate exports, warning</primary></indexterm>
1452 <indexterm><primary>export lists, duplicates</primary></indexterm>
1453
1454 <para>Have the compiler warn about duplicate entries in
1455 export lists. This is useful information if you maintain
1456 large export lists, and want to avoid the continued export
1457 of a definition after you've deleted (one) mention of it in
1458 the export list.</para>
1459
1460 <para>This option is on by default.</para>
1461 </listitem>
1462 </varlistentry>
1463
1464 <varlistentry>
1465 <term><option>-fwarn-hi-shadowing</option>:</term>
1466 <listitem>
1467 <indexterm><primary><option>-fwarn-hi-shadowing</option></primary></indexterm>
1468 <indexterm><primary>shadowing</primary>
1469 <secondary>interface files</secondary></indexterm>
1470
1471 <para>Causes the compiler to emit a warning when a module or
1472 interface file in the current directory is shadowing one
1473 with the same module name in a library or other
1474 directory.</para>
1475 </listitem>
1476 </varlistentry>
1477
1478 <varlistentry>
1479 <term><option>-fwarn-identities</option>:</term>
1480 <listitem>
1481 <indexterm><primary><option>-fwarn-identities</option></primary></indexterm>
1482 <para>Causes the compiler to emit a warning when a Prelude numeric
1483 conversion converts a type T to the same type T; such calls
1484 are probably no-ops and can be omitted. The functions checked for
1485 are: <literal>toInteger</literal>,
1486 <literal>toRational</literal>,
1487 <literal>fromIntegral</literal>,
1488 and <literal>realToFrac</literal>.
1489 </para>
1490 </listitem>
1491 </varlistentry>
1492
1493 <varlistentry>
1494 <term><option>-fwarn-implicit-prelude</option>:</term>
1495 <listitem>
1496 <indexterm><primary><option>-fwarn-implicit-prelude</option></primary></indexterm>
1497 <indexterm><primary>implicit prelude, warning</primary></indexterm>
1498 <para>Have the compiler warn if the Prelude is implicitly
1499 imported. This happens unless either the Prelude module is
1500 explicitly imported with an <literal>import ... Prelude ...</literal>
1501 line, or this implicit import is disabled (either by
1502 <option>-XNoImplicitPrelude</option> or a
1503 <literal>LANGUAGE NoImplicitPrelude</literal> pragma).</para>
1504
1505 <para>Note that no warning is given for syntax that implicitly
1506 refers to the Prelude, even if <option>-XNoImplicitPrelude</option>
1507 would change whether it refers to the Prelude.
1508 For example, no warning is given when
1509 <literal>368</literal> means
1510 <literal>Prelude.fromInteger (368::Prelude.Integer)</literal>
1511 (where <literal>Prelude</literal> refers to the actual Prelude module,
1512 regardless of the imports of the module being compiled).</para>
1513
1514 <para>This warning is off by default.</para>
1515 </listitem>
1516 </varlistentry>
1517
1518 <varlistentry>
1519 <term><option>-fwarn-incomplete-patterns</option>,
1520 <option>-fwarn-incomplete-uni-patterns</option>:
1521 </term>
1522 <listitem>
1523 <indexterm><primary><option>-fwarn-incomplete-patterns</option></primary></indexterm>
1524 <indexterm><primary><option>-fwarn-incomplete-uni-patterns</option></primary></indexterm>
1525 <indexterm><primary>incomplete patterns, warning</primary></indexterm>
1526 <indexterm><primary>patterns, incomplete</primary></indexterm>
1527
1528 <para>The option <option>-fwarn-incomplete-patterns</option> warns
1529 about places where
1530 a pattern-match might fail at runtime.
1531 The function
1532 <function>g</function> below will fail when applied to
1533 non-empty lists, so the compiler will emit a warning about
1534 this when <option>-fwarn-incomplete-patterns</option> is
1535 enabled.
1536
1537 <programlisting>
1538 g [] = 2
1539 </programlisting>
1540
1541 This option isn't enabled by default because it can be
1542 a bit noisy, and it doesn't always indicate a bug in the
1543 program. However, it's generally considered good practice
1544 to cover all the cases in your functions, and it is switched
1545 on by <option>-W</option>.</para>
1546
1547 <para>The flag <option>-fwarn-incomplete-uni-patterns</option> is
1548 similar, except that it
1549 applies only to lambda-expressions and pattern bindings, constructs
1550 that only allow a single pattern:
1551
1552 <programlisting>
1553 h = \[] -> 2
1554 Just k = f y
1555 </programlisting>
1556
1557 </para>
1558 </listitem>
1559 </varlistentry>
1560
1561 <varlistentry>
1562 <term><option>-fwarn-incomplete-record-updates</option>:</term>
1563 <listitem>
1564 <indexterm><primary><option>-fwarn-incomplete-record-updates</option></primary></indexterm>
1565 <indexterm><primary>incomplete record updates, warning</primary></indexterm>
1566 <indexterm><primary>record updates, incomplete</primary></indexterm>
1567
1568 <para>The function
1569 <function>f</function> below will fail when applied to
1570 <literal>Bar</literal>, so the compiler will emit a warning about
1571 this when <option>-fwarn-incomplete-record-updates</option> is
1572 enabled.</para>
1573
1574 <programlisting>
1575 data Foo = Foo { x :: Int }
1576 | Bar
1577
1578 f :: Foo -> Foo
1579 f foo = foo { x = 6 }
1580 </programlisting>
1581
1582 <para>This option isn't enabled by default because it can be
1583 very noisy, and it often doesn't indicate a bug in the
1584 program.</para>
1585 </listitem>
1586 </varlistentry>
1587
1588 <varlistentry>
1589 <term>
1590 <option>-fwarn-missing-fields</option>:
1591 <indexterm><primary><option>-fwarn-missing-fields</option></primary></indexterm>
1592 <indexterm><primary>missing fields, warning</primary></indexterm>
1593 <indexterm><primary>fields, missing</primary></indexterm>
1594 </term>
1595 <listitem>
1596
1597 <para>This option is on by default, and warns you whenever
1598 the construction of a labelled field constructor isn't
1599 complete, missing initializers for one or more fields. While
1600 not an error (the missing fields are initialised with
1601 bottoms), it is often an indication of a programmer error.</para>
1602 </listitem>
1603 </varlistentry>
1604
1605 <varlistentry>
1606 <term>
1607 <option>-fwarn-missing-import-lists</option>:
1608 <indexterm><primary><option>-fwarn-import-lists</option></primary></indexterm>
1609 <indexterm><primary>missing import lists, warning</primary></indexterm>
1610 <indexterm><primary>import lists, missing</primary></indexterm>
1611 </term>
1612 <listitem>
1613
1614 <para>This flag warns if you use an unqualified
1615 <literal>import</literal> declaration
1616 that does not explicitly list the entities brought into scope. For
1617 example
1618 </para>
1619
1620 <programlisting>
1621 module M where
1622 import X( f )
1623 import Y
1624 import qualified Z
1625 p x = f x x
1626 </programlisting>
1627
1628 <para>
1629 The <option>-fwarn-import-lists</option> flag will warn about the import
1630 of <literal>Y</literal> but not <literal>X</literal>
1631 If module <literal>Y</literal> is later changed to export (say) <literal>f</literal>,
1632 then the reference to <literal>f</literal> in <literal>M</literal> will become
1633 ambiguous. No warning is produced for the import of <literal>Z</literal>
1634 because extending <literal>Z</literal>'s exports would be unlikely to produce
1635 ambiguity in <literal>M</literal>.
1636 </para>
1637 </listitem>
1638 </varlistentry>
1639
1640 <varlistentry>
1641 <term><option>-fwarn-missing-methods</option>:</term>
1642 <listitem>
1643 <indexterm><primary><option>-fwarn-missing-methods</option></primary></indexterm>
1644 <indexterm><primary>missing methods, warning</primary></indexterm>
1645 <indexterm><primary>methods, missing</primary></indexterm>
1646
1647 <para>This option is on by default, and warns you whenever
1648 an instance declaration is missing one or more methods, and
1649 the corresponding class declaration has no default
1650 declaration for them.</para>
1651 <para>The warning is suppressed if the method name
1652 begins with an underscore. Here's an example where this is useful:
1653 <programlisting>
1654 class C a where
1655 _simpleFn :: a -> String
1656 complexFn :: a -> a -> String
1657 complexFn x y = ... _simpleFn ...
1658 </programlisting>
1659 The idea is that: (a) users of the class will only call <literal>complexFn</literal>;
1660 never <literal>_simpleFn</literal>; and (b)
1661 instance declarations can define either <literal>complexFn</literal> or <literal>_simpleFn</literal>.
1662 </para>
1663 <para>The MINIMAL pragma can be used to change which combination of methods will be required for instances of a particular class. See <xref linkend="minimal-pragma"/>.</para>
1664 </listitem>
1665 </varlistentry>
1666
1667 <varlistentry>
1668 <term><option>-fwarn-missing-signatures</option>:</term>
1669 <listitem>
1670 <indexterm><primary><option>-fwarn-missing-signatures</option></primary></indexterm>
1671 <indexterm><primary>type signatures, missing</primary></indexterm>
1672
1673 <para>If you would like GHC to check that every top-level
1674 function/value has a type signature, use the
1675 <option>-fwarn-missing-signatures</option> option. As part of
1676 the warning GHC also reports the inferred type. The
1677 option is off by default.</para>
1678 </listitem>
1679 </varlistentry>
1680
1681 <varlistentry>
1682 <term><option>-fwarn-missing-exported-sigs</option>:</term>
1683 <listitem>
1684 <indexterm><primary><option>-fwarn-missing-exported-sigs</option></primary></indexterm>
1685 <indexterm><primary>type signatures, missing</primary></indexterm>
1686
1687 <para>If you would like GHC to check that every exported top-level
1688 function/value has a type signature, but not check unexported values, use the
1689 <option>-fwarn-missing-exported-sigs</option> option. This option
1690 takes precedence over <option>-fwarn-missing-signatures</option>.
1691 As part of the warning GHC also reports the inferred type. The
1692 option is off by default.</para>
1693 </listitem>
1694 </varlistentry>
1695
1696 <varlistentry>
1697 <term><option>-fwarn-missing-local-sigs</option>:</term>
1698 <listitem>
1699 <indexterm><primary><option>-fwarn-missing-local-sigs</option></primary></indexterm>
1700 <indexterm><primary>type signatures, missing</primary></indexterm>
1701
1702 <para>If you use the
1703 <option>-fwarn-missing-local-sigs</option> flag GHC will warn
1704 you about any polymorphic local bindings. As part of
1705 the warning GHC also reports the inferred type. The
1706 option is off by default.</para>
1707 </listitem>
1708 </varlistentry>
1709
1710 <varlistentry>
1711 <term><option>-fwarn-name-shadowing</option>:</term>
1712 <listitem>
1713 <indexterm><primary><option>-fwarn-name-shadowing</option></primary></indexterm>
1714 <indexterm><primary>shadowing, warning</primary></indexterm>
1715
1716 <para>This option causes a warning to be emitted whenever an
1717 inner-scope value has the same name as an outer-scope value,
1718 i.e. the inner value shadows the outer one. This can catch
1719 typographical errors that turn into hard-to-find bugs, e.g.,
1720 in the inadvertent capture of what would be a recursive call in
1721 <literal>f = ... let f = id in ... f ...</literal>.</para>
1722 <para>The warning is suppressed for names beginning with an underscore. For example
1723 <programlisting>
1724 f x = do { _ignore &lt;- this; _ignore &lt;- that; return (the other) }
1725 </programlisting>
1726 </para>
1727 </listitem>
1728 </varlistentry>
1729
1730 <varlistentry>
1731 <term><option>-fwarn-orphans, -fwarn-auto-orphans</option>:</term>
1732 <listitem>
1733 <indexterm><primary><option>-fwarn-orphans</option></primary></indexterm>
1734 <indexterm><primary><option>-fwarn-auto-orphans</option></primary></indexterm>
1735 <indexterm><primary>orphan instances, warning</primary></indexterm>
1736 <indexterm><primary>orphan rules, warning</primary></indexterm>
1737
1738 <para>These flags cause a warning to be emitted whenever the
1739 module contains an "orphan" instance declaration or rewrite rule.
1740 An instance declaration is an orphan if it appears in a module in
1741 which neither the class nor the type being instanced are declared
1742 in the same module. A rule is an orphan if it is a rule for a
1743 function declared in another module. A module containing any
1744 orphans is called an orphan module.</para>
1745 <para>The trouble with orphans is that GHC must pro-actively read the interface
1746 files for all orphan modules, just in case their instances or rules
1747 play a role, whether or not the module's interface would otherwise
1748 be of any use. See <xref linkend="orphan-modules"/> for details.
1749 </para>
1750 <para>The flag <option>-fwarn-orphans</option> warns about user-written
1751 orphan rules or instances. The flag <option>-fwarn-auto-orphans</option>
1752 warns about automatically-generated orphan rules, notably as a result of
1753 specialising functions, for type classes (<literal>Specialise</literal>)
1754 or argument values (<literal>-fspec-constr</literal>).</para>
1755 </listitem>
1756 </varlistentry>
1757
1758 <varlistentry>
1759 <term>
1760 <option>-fwarn-overlapping-patterns</option>:
1761 <indexterm><primary><option>-fwarn-overlapping-patterns</option></primary></indexterm>
1762 <indexterm><primary>overlapping patterns, warning</primary></indexterm>
1763 <indexterm><primary>patterns, overlapping</primary></indexterm>
1764 </term>
1765 <listitem>
1766 <para>By default, the compiler will warn you if a set of
1767 patterns are overlapping, e.g.,</para>
1768
1769 <programlisting>
1770 f :: String -&#62; Int
1771 f [] = 0
1772 f (_:xs) = 1
1773 f "2" = 2
1774 </programlisting>
1775
1776 <para>where the last pattern match in <function>f</function>
1777 won't ever be reached, as the second pattern overlaps
1778 it. More often than not, redundant patterns is a programmer
1779 mistake/error, so this option is enabled by default.</para>
1780 </listitem>
1781 </varlistentry>
1782
1783 <varlistentry>
1784 <term><option>-fwarn-tabs</option>:</term>
1785 <listitem>
1786 <indexterm><primary><option>-fwarn-tabs</option></primary></indexterm>
1787 <indexterm><primary>tabs, warning</primary></indexterm>
1788 <para>Have the compiler warn if there are tabs in your source
1789 file.</para>
1790
1791 <para>This warning is off by default.</para>
1792 </listitem>
1793 </varlistentry>
1794
1795 <varlistentry>
1796 <term><option>-fwarn-type-defaults</option>:</term>
1797 <listitem>
1798 <indexterm><primary><option>-fwarn-type-defaults</option></primary></indexterm>
1799 <indexterm><primary>defaulting mechanism, warning</primary></indexterm>
1800 <para>Have the compiler warn/inform you where in your source
1801 the Haskell defaulting mechanism for numeric types kicks
1802 in. This is useful information when converting code from a
1803 context that assumed one default into one with another,
1804 e.g., the &lsquo;default default&rsquo; for Haskell 1.4 caused the
1805 otherwise unconstrained value <constant>1</constant> to be
1806 given the type <literal>Int</literal>, whereas Haskell 98
1807 and later
1808 defaults it to <literal>Integer</literal>. This may lead to
1809 differences in performance and behaviour, hence the
1810 usefulness of being non-silent about this.</para>
1811
1812 <para>This warning is off by default.</para>
1813 </listitem>
1814 </varlistentry>
1815
1816 <varlistentry>
1817 <term><option>-fwarn-monomorphism-restriction</option>:</term>
1818 <listitem>
1819 <indexterm><primary><option>-fwarn-monomorphism-restriction</option></primary></indexterm>
1820 <indexterm><primary>monomorphism restriction, warning</primary></indexterm>
1821 <para>Have the compiler warn/inform you where in your source
1822 the Haskell Monomorphism Restriction is applied. If applied silently
1823 the MR can give rise to unexpected behaviour, so it can be helpful
1824 to have an explicit warning that it is being applied.</para>
1825
1826 <para>This warning is off by default.</para>
1827 </listitem>
1828 </varlistentry>
1829
1830 <varlistentry>
1831 <term><option>-fwarn-unticked-promoted-constructors</option>:</term>
1832 <listitem>
1833 <indexterm><primary><option>-fwarn-unticked-promoted-constructors</option></primary></indexterm>
1834 <indexterm><primary>promoted constructor, warning</primary></indexterm>
1835 <para>Warn if a promoted data constructor is used without a tick preceding it's name.
1836 </para>
1837 <para>For example:
1838 </para>
1839 <programlisting>
1840 data Nat = Succ Nat | Zero
1841
1842 data Vec n s where
1843 Nil :: Vec Zero a
1844 Cons :: a -> Vec n a -> Vec (Succ n) a
1845 </programlisting>
1846 <para> Will raise two warnings because <function>Zero</function>
1847 and <function>Succ</function> are not written as <function>'Zero</function> and
1848 <function>'Succ</function>.
1849 </para>
1850 <para>This warning is off by default.</para>
1851 </listitem>
1852 </varlistentry>
1853
1854 <varlistentry>
1855 <term><option>-fwarn-unused-binds</option>:</term>
1856 <listitem>
1857 <indexterm><primary><option>-fwarn-unused-binds</option></primary></indexterm>
1858 <indexterm><primary>unused binds, warning</primary></indexterm>
1859 <indexterm><primary>binds, unused</primary></indexterm>
1860 <para>Report any function definitions (and local bindings)
1861 which are unused. More precisely:
1862
1863 <itemizedlist>
1864 <listitem><para>Warn if a binding brings into scope a variable that is not used,
1865 except if the variable's name starts with an underscore. The "starts-with-underscore"
1866 condition provides a way to selectively disable the warning.
1867 </para>
1868 <para>
1869 A variable is regarded as "used" if
1870 <itemizedlist>
1871 <listitem><para>It is exported, or</para></listitem>
1872 <listitem><para>It appears in the right hand side of a binding that binds at
1873 least one used variable that is used</para></listitem>
1874 </itemizedlist>
1875 For example
1876 <programlisting>
1877 module A (f) where
1878 f = let (p,q) = rhs1 in t p -- Warning about unused q
1879 t = rhs3 -- No warning: f is used, and hence so is t
1880 g = h x -- Warning: g unused
1881 h = rhs2 -- Warning: h is only used in the right-hand side of another unused binding
1882 _w = True -- No warning: _w starts with an underscore
1883 </programlisting>
1884 </para></listitem>
1885
1886 <listitem><para>
1887 Warn if a pattern binding binds no variables at all, unless it is a lone, possibly-banged, wild-card pattern.
1888 For example:
1889 <programlisting>
1890 Just _ = rhs3 -- Warning: unused pattern binding
1891 (_, _) = rhs4 -- Warning: unused pattern binding
1892 _ = rhs3 -- No warning: lone wild-card pattern
1893 !_ = rhs4 -- No warning: banged wild-card pattern; behaves like seq
1894 </programlisting>
1895 The motivation for allowing lone wild-card patterns is they
1896 are not very different from <literal>_v = rhs3</literal>,
1897 which elicits no warning; and they can be useful to add a type
1898 constraint, e.g. <literal>_ = x::Int</literal>. A lone
1899 banged wild-card pattern is is useful as an alternative
1900 (to <literal>seq</literal>) way to force evaluation.
1901 </para>
1902 </listitem>
1903 </itemizedlist>
1904 </para>
1905 </listitem>
1906 </varlistentry>
1907
1908 <varlistentry>
1909 <term><option>-fwarn-unused-imports</option>:</term>
1910 <listitem>
1911 <indexterm><primary><option>-fwarn-unused-imports</option></primary></indexterm>
1912 <indexterm><primary>unused imports, warning</primary></indexterm>
1913 <indexterm><primary>imports, unused</primary></indexterm>
1914
1915 <para>Report any modules that are explicitly imported but
1916 never used. However, the form <literal>import M()</literal> is
1917 never reported as an unused import, because it is a useful idiom
1918 for importing instance declarations, which are anonymous in Haskell.</para>
1919 </listitem>
1920 </varlistentry>
1921
1922 <varlistentry>
1923 <term><option>-fwarn-unused-matches</option>:</term>
1924 <listitem>
1925 <indexterm><primary><option>-fwarn-unused-matches</option></primary></indexterm>
1926 <indexterm><primary>unused matches, warning</primary></indexterm>
1927 <indexterm><primary>matches, unused</primary></indexterm>
1928
1929 <para>Report all unused variables which arise from pattern
1930 matches, including patterns consisting of a single variable.
1931 For instance <literal>f x y = []</literal> would report
1932 <varname>x</varname> and <varname>y</varname> as unused. The
1933 warning is suppressed if the variable name begins with an underscore, thus:
1934 <programlisting>
1935 f _x = True
1936 </programlisting>
1937 </para>
1938 </listitem>
1939 </varlistentry>
1940
1941 <varlistentry>
1942 <term><option>-fwarn-unused-do-bind</option>:</term>
1943 <listitem>
1944 <indexterm><primary><option>-fwarn-unused-do-bind</option></primary></indexterm>
1945 <indexterm><primary>unused do binding, warning</primary></indexterm>
1946 <indexterm><primary>do binding, unused</primary></indexterm>
1947
1948 <para>Report expressions occurring in <literal>do</literal> and <literal>mdo</literal> blocks
1949 that appear to silently throw information away.
1950 For instance <literal>do { mapM popInt xs ; return 10 }</literal> would report
1951 the first statement in the <literal>do</literal> block as suspicious,
1952 as it has the type <literal>StackM [Int]</literal> and not <literal>StackM ()</literal>, but that
1953 <literal>[Int]</literal> value is not bound to anything. The warning is suppressed by
1954 explicitly mentioning in the source code that your program is throwing something away:
1955 <programlisting>
1956 do { _ &lt;- mapM popInt xs ; return 10 }
1957 </programlisting>
1958 Of course, in this particular situation you can do even better:
1959 <programlisting>
1960 do { mapM_ popInt xs ; return 10 }
1961 </programlisting>
1962 </para>
1963 </listitem>
1964 </varlistentry>
1965
1966 <varlistentry>
1967 <term><option>-fwarn-context-quantification</option>:</term>
1968 <listitem>
1969 <indexterm><primary><option>-fwarn-context-quantification</option></primary></indexterm>
1970 <indexterm><primary>implicit context quantification, warning</primary></indexterm>
1971 <indexterm><primary>context, implicit quantification</primary></indexterm>
1972
1973 <para>Report if a variable is quantified only due to its presence
1974 in a context (see <xref linkend="universal-quantification"/>). For example,
1975 <programlisting>
1976 type T a = Monad m => a -> f a
1977 </programlisting>
1978 It is recommended to write this polymorphic type as
1979 <programlisting>
1980 type T a = forall m. Monad m => a -> f a
1981 </programlisting>
1982 instead.
1983 </para>
1984 </listitem>
1985 </varlistentry>
1986
1987 <varlistentry>
1988 <term><option>-fwarn-wrong-do-bind</option>:</term>
1989 <listitem>
1990 <indexterm><primary><option>-fwarn-wrong-do-bind</option></primary></indexterm>
1991 <indexterm><primary>apparently erroneous do binding, warning</primary></indexterm>
1992 <indexterm><primary>do binding, apparently erroneous</primary></indexterm>
1993
1994 <para>Report expressions occurring in <literal>do</literal> and <literal>mdo</literal> blocks
1995 that appear to lack a binding.
1996 For instance <literal>do { return (popInt 10) ; return 10 }</literal> would report
1997 the first statement in the <literal>do</literal> block as suspicious,
1998 as it has the type <literal>StackM (StackM Int)</literal> (which consists of two nested applications
1999 of the same monad constructor), but which is not then &quot;unpacked&quot; by binding the result.
2000 The warning is suppressed by explicitly mentioning in the source code that your program is throwing something away:
2001 <programlisting>
2002 do { _ &lt;- return (popInt 10) ; return 10 }
2003 </programlisting>
2004 For almost all sensible programs this will indicate a bug, and you probably intended to write:
2005 <programlisting>
2006 do { popInt 10 ; return 10 }
2007 </programlisting>
2008 </para>
2009 </listitem>
2010 </varlistentry>
2011
2012 <varlistentry>
2013 <term><option>-fwarn-inline-rule-shadowing</option>:</term>
2014 <listitem>
2015 <indexterm><primary><option>-fwarn-inline-rule-shadowing</option></primary></indexterm>
2016 <para>Warn if a rewrite RULE might fail to fire because the function might be
2017 inlined before the rule has a chance to fire. See <xref linkend="rules-inline"/>.
2018 </para>
2019 </listitem>
2020 </varlistentry>
2021
2022 </variablelist>
2023
2024 <para>If you're feeling really paranoid, the
2025 <option>-dcore-lint</option>
2026 option<indexterm><primary><option>-dcore-lint</option></primary></indexterm>
2027 is a good choice. It turns on heavyweight intra-pass
2028 sanity-checking within GHC. (It checks GHC's sanity, not
2029 yours.)</para>
2030
2031 </sect1>
2032
2033 &packages;
2034
2035 <sect1 id="options-optimise">
2036 <title>Optimisation (code improvement)</title>
2037
2038 <indexterm><primary>optimisation</primary></indexterm>
2039 <indexterm><primary>improvement, code</primary></indexterm>
2040
2041 <para>The <option>-O*</option> options specify convenient
2042 &ldquo;packages&rdquo; of optimisation flags; the
2043 <option>-f*</option> options described later on specify
2044 <emphasis>individual</emphasis> optimisations to be turned on/off;
2045 the <option>-m*</option> options specify
2046 <emphasis>machine-specific</emphasis> optimisations to be turned
2047 on/off.</para>
2048
2049 <sect2 id="optimise-pkgs">
2050 <title><option>-O*</option>: convenient &ldquo;packages&rdquo; of optimisation flags.</title>
2051
2052 <para>There are <emphasis>many</emphasis> options that affect
2053 the quality of code produced by GHC. Most people only have a
2054 general goal, something like &ldquo;Compile quickly&rdquo; or
2055 &ldquo;Make my program run like greased lightning.&rdquo; The
2056 following &ldquo;packages&rdquo; of optimisations (or lack
2057 thereof) should suffice.</para>
2058
2059 <para>Note that higher optimisation levels cause more
2060 cross-module optimisation to be performed, which can have an
2061 impact on how much of your program needs to be recompiled when
2062 you change something. This is one reason to stick to
2063 no-optimisation when developing code.</para>
2064
2065 <variablelist>
2066
2067 <varlistentry>
2068 <term>
2069 No <option>-O*</option>-type option specified:
2070 <indexterm><primary>-O* not specified</primary></indexterm>
2071 </term>
2072 <listitem>
2073 <para>This is taken to mean: &ldquo;Please compile
2074 quickly; I'm not over-bothered about compiled-code
2075 quality.&rdquo; So, for example: <command>ghc -c
2076 Foo.hs</command></para>
2077 </listitem>
2078 </varlistentry>
2079
2080 <varlistentry>
2081 <term>
2082 <option>-O0</option>:
2083 <indexterm><primary><option>-O0</option></primary></indexterm>
2084 </term>
2085 <listitem>
2086 <para>Means &ldquo;turn off all optimisation&rdquo;,
2087 reverting to the same settings as if no
2088 <option>-O</option> options had been specified. Saying
2089 <option>-O0</option> can be useful if
2090 eg. <command>make</command> has inserted a
2091 <option>-O</option> on the command line already.</para>
2092 </listitem>
2093 </varlistentry>
2094
2095 <varlistentry>
2096 <term>
2097 <option>-O</option> or <option>-O1</option>:
2098 <indexterm><primary>-O option</primary></indexterm>
2099 <indexterm><primary>-O1 option</primary></indexterm>
2100 <indexterm><primary>optimise</primary><secondary>normally</secondary></indexterm>
2101 </term>
2102 <listitem>
2103 <para>Means: &ldquo;Generate good-quality code without
2104 taking too long about it.&rdquo; Thus, for example:
2105 <command>ghc -c -O Main.lhs</command></para>
2106 </listitem>
2107 </varlistentry>
2108
2109 <varlistentry>
2110 <term>
2111 <option>-O2</option>:
2112 <indexterm><primary>-O2 option</primary></indexterm>
2113 <indexterm><primary>optimise</primary><secondary>aggressively</secondary></indexterm>
2114 </term>
2115 <listitem>
2116 <para>Means: &ldquo;Apply every non-dangerous
2117 optimisation, even if it means significantly longer
2118 compile times.&rdquo;</para>
2119
2120 <para>The avoided &ldquo;dangerous&rdquo; optimisations
2121 are those that can make runtime or space
2122 <emphasis>worse</emphasis> if you're unlucky. They are
2123 normally turned on or off individually.</para>
2124
2125 <para>At the moment, <option>-O2</option> is
2126 <emphasis>unlikely</emphasis> to produce better code than
2127 <option>-O</option>.</para>
2128 </listitem>
2129 </varlistentry>
2130
2131 <varlistentry>
2132 <term>
2133 <option>-Odph</option>:
2134 <indexterm><primary>-Odph</primary></indexterm>
2135 <indexterm><primary>optimise</primary><secondary>DPH</secondary></indexterm>
2136 </term>
2137 <listitem>
2138 <para>Enables all <option>-O2</option> optimisation, sets
2139 <option>-fmax-simplifier-iterations=20</option>
2140 and <option>-fsimplifier-phases=3</option>. Designed for use with
2141 <link linkend="dph">Data Parallel Haskell (DPH)</link>.</para>
2142 </listitem>
2143 </varlistentry>
2144
2145 </variablelist>
2146
2147 <para>We don't use a <option>-O*</option> flag for day-to-day
2148 work. We use <option>-O</option> to get respectable speed;
2149 e.g., when we want to measure something. When we want to go for
2150 broke, we tend to use <option>-O2</option> (and we go for
2151 lots of coffee breaks).</para>
2152
2153 <para>The easiest way to see what <option>-O</option> (etc.)
2154 &ldquo;really mean&rdquo; is to run with <option>-v</option>,
2155 then stand back in amazement.</para>
2156 </sect2>
2157
2158 <sect2 id="options-f">
2159 <title><option>-f*</option>: platform-independent flags</title>
2160
2161 <indexterm><primary>-f* options (GHC)</primary></indexterm>
2162 <indexterm><primary>-fno-* options (GHC)</primary></indexterm>
2163
2164 <para>These flags turn on and off individual optimisations.
2165 Flags marked as <emphasis>Enabled by default</emphasis> are
2166 enabled by <option>-O</option>, and as such you shouldn't
2167 need to set any of them explicitly. A flag <option>-fwombat</option>
2168 can be negated by saying <option>-fno-wombat</option>.
2169 See <xref linkend="options-f-compact"/> for a compact list.
2170 </para>
2171
2172 <variablelist>
2173 <varlistentry>
2174 <term>
2175 <option>-fcase-merge</option>
2176 <indexterm><primary><option></option></primary></indexterm>
2177 </term>
2178 <listitem>
2179 <para><emphasis>On by default.</emphasis>
2180 Merge immediately-nested case expressions that scrutinse the same variable. Example
2181 <programlisting>
2182 case x of
2183 Red -> e1
2184 _ -> case x of
2185 Blue -> e2
2186 Green -> e3
2187 ==>
2188 case x of
2189 Red -> e1
2190 Blue -> e2
2191 Green -> e2
2192 </programlisting>
2193 </para>
2194 </listitem>
2195 </varlistentry>
2196
2197 <varlistentry>
2198 <term>
2199 <option>-fcall-arity</option>
2200 <indexterm><primary><option>-fcall-arity</option></primary></indexterm>
2201 </term>
2202 <listitem>
2203 <para><emphasis>On by default.</emphasis>.
2204 </para>
2205 </listitem>
2206 </varlistentry>
2207
2208 <varlistentry>
2209 <term>
2210 <option>-fcmm-elim-common-blocks</option>
2211 <indexterm><primary><option>-felim-common-blocks</option></primary></indexterm>
2212 </term>
2213 <listitem>
2214 <para><emphasis>On by default.</emphasis>. Enables the common block
2215 elimination optimisation in the code generator. This optimisation
2216 attempts to find identical Cmm blocks and eliminate the duplicates.
2217 </para>
2218 </listitem>
2219 </varlistentry>
2220
2221 <varlistentry>
2222 <term>
2223 <option>-fcmm-sink</option>
2224 <indexterm><primary><option>-fcmm-sink</option></primary></indexterm>
2225 </term>
2226 <listitem>
2227 <para><emphasis>On by default.</emphasis>. Enables the sinking pass
2228 in the code generator. This optimisation
2229 attempts to find identical Cmm blocks and eliminate the duplicates
2230 attempts to move variable bindings closer to their usage sites. It
2231 also inlines simple expressions like literals or registers.
2232 </para>
2233 </listitem>
2234 </varlistentry>
2235
2236 <varlistentry>
2237 <term>
2238 <option>-fcpr-off</option>
2239 <indexterm><primary><option>-fcpr-Off</option></primary></indexterm>
2240 </term>
2241 <listitem>
2242 <para>Switch off CPR analysis in the demand analyser.
2243 </para>
2244 </listitem>
2245 </varlistentry>
2246
2247 <varlistentry>
2248 <term>
2249 <option>-fcse</option>
2250 <indexterm><primary><option>-fcse</option></primary></indexterm>
2251 </term>
2252 <listitem>
2253 <para><emphasis>On by default.</emphasis>. Enables the common-sub-expression
2254 elimination optimisation.
2255 Switching this off can be useful if you have some <literal>unsafePerformIO</literal>
2256 expressions that you don't want commoned-up.</para>
2257 </listitem>
2258 </varlistentry>
2259
2260 <varlistentry>
2261 <term>
2262 <option>-fdicts-cheap</option>
2263 <indexterm><primary><option></option></primary></indexterm>
2264 </term>
2265 <listitem>
2266 <para>A very experimental flag that makes dictionary-valued
2267 expressions seem cheap to the optimiser.
2268 </para>
2269 </listitem>
2270 </varlistentry>
2271
2272 <varlistentry>
2273 <term>
2274 <option>-fdicts-strict</option>
2275 <indexterm><primary><option></option></primary></indexterm>
2276 </term>
2277 <listitem>
2278 <para>Make dictionaries strict.
2279 </para>
2280 </listitem>
2281 </varlistentry>
2282
2283 <varlistentry>
2284 <term>
2285 <option>-fdmd-tx-dict-sel</option>
2286 <indexterm><primary><option>-fdmd-tx-dict-sel</option></primary></indexterm>
2287 </term>
2288 <listitem>
2289 <para><emphasis>On by default for <option>-O0</option>, <option>-O</option>,
2290 <option>-O2</option>.</emphasis>
2291 </para>
2292 <para>Use a special demand transformer for dictionary selectors.
2293 </para>
2294 </listitem>
2295 </varlistentry>
2296
2297 <varlistentry>
2298 <term>
2299 <option>-fdo-eta-reduction</option>
2300 <indexterm><primary><option></option></primary></indexterm>
2301 </term>
2302 <listitem>
2303 <para><emphasis>On by default.</emphasis>
2304 Eta-reduce lambda expressions, if doing so gets rid of a whole
2305 group of lambdas.
2306 </para>
2307 </listitem>
2308 </varlistentry>
2309
2310 <varlistentry>
2311 <term>
2312 <option>-fdo-lambda-eta-expansion</option>
2313 <indexterm><primary><option></option></primary></indexterm>
2314 </term>
2315 <listitem>
2316 <para><emphasis>On by default.</emphasis>
2317 Eta-expand let-bindings to increase their arity.
2318 </para>
2319 </listitem>
2320 </varlistentry>
2321
2322 <varlistentry>
2323 <term>
2324 <option>-feager-blackholing</option>
2325 <indexterm><primary><option></option></primary></indexterm>
2326 </term>
2327 <listitem>
2328 <para>Usually GHC black-holes a thunk only when it switches
2329 threads. This flag makes it do so as soon as the thunk is
2330 entered. See <ulink url="http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/">
2331 Haskell on a shared-memory multiprocessor</ulink>.
2332 </para>
2333 </listitem>
2334 </varlistentry>
2335
2336 <varlistentry>
2337 <term>
2338 <option>-fexcess-precision</option>
2339 <indexterm><primary><option>-fexcess-precision</option></primary></indexterm>
2340 </term>
2341 <listitem>
2342 <para>When this option is given, intermediate floating
2343 point values can have a <emphasis>greater</emphasis>
2344 precision/range than the final type. Generally this is a
2345 good thing, but some programs may rely on the exact
2346 precision/range of
2347 <literal>Float</literal>/<literal>Double</literal> values
2348 and should not use this option for their compilation.</para>
2349
2350 <para>
2351 Note that the 32-bit x86 native code generator only
2352 supports excess-precision mode, so neither
2353 <option>-fexcess-precision</option> nor
2354 <option>-fno-excess-precision</option> has any effect.
2355 This is a known bug, see <xref linkend="bugs-ghc" />.
2356 </para>
2357 </listitem>
2358 </varlistentry>
2359
2360 <varlistentry>
2361 <term>
2362 <option>-fexpose-all-unfoldings</option>
2363 <indexterm><primary><option></option></primary></indexterm>
2364 </term>
2365 <listitem>
2366 <para>An experimental flag to expose all unfoldings, even for very
2367 large or recursive functions. This allows for all functions to be
2368 inlined while usually GHC would avoid inlining larger functions.
2369 </para>
2370 </listitem>
2371 </varlistentry>
2372
2373 <varlistentry>
2374 <term>
2375 <option>-ffloat-in</option>
2376 <indexterm><primary><option></option></primary></indexterm>
2377 </term>
2378 <listitem>
2379 <para><emphasis>On by default.</emphasis>
2380 Float let-bindings inwards, nearer their binding site. See
2381 <ulink url="http://research.microsoft.com/en-us/um/people/simonpj/papers/float.ps.gz">
2382 Let-floating: moving bindings to give faster programs (ICFP'96)</ulink>.
2383 </para>
2384
2385 <para>This optimisation moves let bindings closer to their use
2386 site. The benefit here is that this may avoid unnecessary
2387 allocation if the branch the let is now on is never executed. It
2388 also enables other optimisation passes to work more effectively
2389 as they have more information locally.
2390 </para>
2391
2392 <para>This optimisation isn't always beneficial though (so GHC
2393 applies some heuristics to decide when to apply it). The details
2394 get complicated but a simple example is that it is often beneficial
2395 to move let bindings outwards so that multiple let bindings can be
2396 grouped into a larger single let binding, effectively batching
2397 their allocation and helping the garbage collector and allocator.
2398 </para>
2399 </listitem>
2400 </varlistentry>
2401
2402 <varlistentry>
2403 <term>
2404 <option>-ffull-laziness</option>
2405 <indexterm><primary><option>-ffull-laziness</option></primary></indexterm>
2406 </term>
2407 <listitem>
2408 <para><emphasis>On by default.</emphasis>
2409 Run the full laziness optimisation (also known as let-floating),
2410 which floats let-bindings outside enclosing lambdas, in the hope
2411 they will be thereby be computed less often. See
2412 <ulink url="http://research.microsoft.com/en-us/um/people/simonpj/papers/float.ps.gz">Let-floating:
2413 moving bindings to give faster programs (ICFP'96)</ulink>.
2414 Full laziness increases sharing, which can lead to increased memory
2415 residency.
2416 </para>
2417
2418 <para>NOTE: GHC doesn't implement complete full-laziness.
2419 When optimisation in on, and <option>-fno-full-laziness</option>
2420 is not given, some transformations that increase sharing are
2421 performed, such as extracting repeated computations from a loop.
2422 These are the same transformations that a fully lazy
2423 implementation would do, the difference is that GHC doesn't
2424 consistently apply full-laziness, so don't rely on it.
2425 </para>
2426 </listitem>
2427 </varlistentry>
2428
2429 <varlistentry>
2430 <term>
2431 <option>-ffun-to-thunk</option>
2432 <indexterm><primary><option>-ffun-to-thunk</option></primary></indexterm>
2433 </term>
2434 <listitem>
2435 <para>Worker-wrapper removes unused arguments, but usually we do
2436 not remove them all, lest it turn a function closure into a thunk,
2437 thereby perhaps creating a space leak and/or disrupting inlining.
2438 This flag allows worker/wrapper to remove <emphasis>all</emphasis>
2439 value lambdas. Off by default.
2440 </para>
2441 </listitem>
2442 </varlistentry>
2443
2444 <varlistentry>
2445 <term>
2446 <option>-fignore-asserts</option>
2447 <indexterm><primary><option>-fignore-asserts</option></primary></indexterm>
2448 </term>
2449 <listitem>
2450 <para><emphasis>On by default.</emphasis>.
2451 Causes GHC to ignore uses of the function
2452 <literal>Exception.assert</literal> in source code (in
2453 other words, rewriting <literal>Exception.assert p
2454 e</literal> to <literal>e</literal> (see <xref
2455 linkend="assertions"/>).
2456 </para>
2457 </listitem>
2458 </varlistentry>
2459
2460 <varlistentry>
2461 <term>
2462 <option>-fignore-interface-pragmas</option>
2463 <indexterm><primary><option>-fignore-interface-pragmas</option></primary></indexterm>
2464 </term>
2465 <listitem>
2466 <para>Tells GHC to ignore all inessential information when reading interface files.
2467 That is, even if <filename>M.hi</filename> contains unfolding or strictness information
2468 for a function, GHC will ignore that information.</para>
2469 </listitem>
2470 </varlistentry>
2471
2472 <varlistentry>
2473 <term>
2474 <option>-flate-dmd-anal</option>
2475 <indexterm><primary><option>-flate-dmd-anal</option></primary></indexterm>
2476 </term>
2477 <listitem>
2478 <para>Run demand analysis
2479 again, at the end of the simplification pipeline. We found some opportunities
2480 for discovering strictness that were not visible earlier; and optimisations like
2481 <literal>-fspec-constr</literal> can create functions with unused arguments which
2482 are eliminated by late demand analysis. Improvements are modest, but so is the
2483 cost. See notes on the <ulink url="http://ghc.haskell.org/trac/ghc/wiki/LateDmd">Trac wiki page</ulink>.
2484 </para>
2485 </listitem>
2486 </varlistentry>
2487
2488 <varlistentry>
2489 <term>
2490 <option>-fliberate-case</option>
2491 <indexterm><primary><option>-fliberate-case</option></primary></indexterm>
2492 </term>
2493 <listitem>
2494 <para><emphasis>Off by default, but enabled by -O2.</emphasis>
2495 Turn on the liberate-case transformation. This unrolls recursive
2496 function once in its own RHS, to avoid repeated case analysis of
2497 free variables. It's a bit like the call-pattern specialiser
2498 (<option>-fspec-constr</option>) but for free variables rather than
2499 arguments.
2500 </para>
2501 </listitem>
2502 </varlistentry>
2503
2504 <varlistentry>
2505 <term>
2506 <option>-fliberate-case-threshold=<replaceable>n</replaceable></option>
2507 <indexterm><primary><option>-fliberate-case-threshold</option></primary></indexterm>
2508 </term>
2509 <listitem>
2510 <para>Set the size threshold for the liberate-case transformation. Default: 2000
2511 </para>
2512 </listitem>
2513 </varlistentry>
2514
2515 <varlistentry>
2516 <term>
2517 <option>-floopification</option>
2518 <indexterm><primary><option>-floopification</option></primary></indexterm>
2519 </term>
2520 <listitem>
2521 <para><emphasis>On by default.</emphasis>
2522 </para>
2523 <para>When this optimisation is enabled the code generator will turn
2524 all self-recursive saturated tail calls into local jumps rather
2525 than function calls.
2526 </para>
2527 </listitem>
2528 </varlistentry>
2529
2530 <varlistentry>
2531 <term>
2532 <option>-fmax-inline-alloc-size=<replaceable>n</replaceable></option>
2533 <indexterm><primary><option>-fmax-inline-alloc-size</option></primary></indexterm>
2534 </term>
2535 <listitem>
2536 <para>Set the maximum size of inline array allocations to n bytes
2537 (default: 128). GHC will allocate non-pinned arrays of statically
2538 known size in the current nursery block if they're no bigger
2539 than n bytes, ignoring GC overheap. This value should be quite
2540 a bit smaller than the block size (typically: 4096).
2541 </para>
2542 </listitem>
2543 </varlistentry>
2544
2545 <varlistentry>
2546 <term>
2547 <option>-fmax-inline-memcpy-insn=<replaceable>n</replaceable></option>
2548 <indexterm><primary><option>-fmax-inline-memcpy-insn</option></primary></indexterm>
2549 </term>
2550 <listitem>
2551 <para>Inline memcpy calls if they would generate no more than n pseudo instructions (default: 32).
2552 </para>
2553 </listitem>
2554 </varlistentry>
2555
2556 <varlistentry>
2557 <term>
2558 <option>-fmax-inline-memset-insns=<replaceable>n</replaceable></option>
2559 <indexterm><primary><option>-fmax-inline-memset-insns</option></primary></indexterm>
2560 </term>
2561 <listitem>
2562 <para>Inline memset calls if they would generate no more than n pseudo instructions (default: 32).
2563 </para>
2564 </listitem>
2565 </varlistentry>
2566
2567 <varlistentry>
2568 <term>
2569 <option>-fmax-relevant-binds=<replaceable>n</replaceable></option>
2570 <indexterm><primary><option>-fmax-relevant-bindings</option></primary></indexterm>
2571 </term>
2572 <listitem>
2573 <para>The type checker sometimes displays a fragment of the type environment
2574 in error messages, but only up to some maximum number, set by this flag.
2575 The default is 6. Turning it off with <option>-fno-max-relevant-bindings</option>
2576 gives an unlimited number. Syntactically top-level bindings are also
2577 usually excluded (since they may be numerous), but
2578 <option>-fno-max-relevant-bindings</option> includes them too.
2579 </para>
2580 </listitem>
2581 </varlistentry>
2582
2583 <varlistentry>
2584 <term>
2585 <option>-fmax-simplifier-iterations=<replaceable>n</replaceable></option>
2586 <indexterm><primary><option>-fmax-simplifier-iterations</option></primary></indexterm>
2587 </term>
2588 <listitem>
2589 <para>Sets the maximal number of iterations for the simplifier. Defult: 4.
2590 </para>
2591 </listitem>
2592 </varlistentry>
2593
2594 <varlistentry>
2595 <term>
2596 <option>-fmax-worker-args=<replaceable>n</replaceable></option>
2597 <indexterm><primary><option>-fmax-worker-args</option></primary></indexterm>
2598 </term>
2599 <listitem>
2600 <para>If a worker has that many arguments, none will be unpacked anymore (default: 10)
2601 </para>
2602 </listitem>
2603 </varlistentry>
2604
2605 <varlistentry>
2606 <term>
2607 <option>-fno-opt-coercion</option>
2608 <indexterm><primary><option>-fno-opt-coercion</option></primary></indexterm>
2609 </term>
2610 <listitem>
2611 <para>Turn off the coercion optimiser.
2612 </para>
2613 </listitem>
2614 </varlistentry>
2615
2616 <varlistentry>
2617 <term>
2618 <option>-fno-pre-inlining</option>
2619 <indexterm><primary><option>-fno-pre-inlining</option></primary></indexterm>
2620 </term>
2621 <listitem>
2622 <para>Turn off pre-inlining.
2623 </para>
2624 </listitem>
2625 </varlistentry>
2626
2627 <varlistentry>
2628 <term>
2629 <option>-fno-state-hack</option>
2630 <indexterm><primary><option>-fno-state-hack</option></primary></indexterm>
2631 </term>
2632 <listitem>
2633 <para>Turn off the "state hack" whereby any lambda with a
2634 <literal>State#</literal> token as argument is considered to be
2635 single-entry, hence it is considered OK to inline things inside
2636 it. This can improve performance of IO and ST monad code, but it
2637 runs the risk of reducing sharing.
2638 </para>
2639 </listitem>
2640 </varlistentry>
2641
2642 <varlistentry>
2643 <term>
2644 <option>-fomit-interface-pragmas</option>
2645 <indexterm><primary><option>-fomit-interface-pragmas</option></primary></indexterm>
2646 </term>
2647 <listitem>
2648 <para>Tells GHC to omit all inessential information from the
2649 interface file generated for the module being compiled (say M).
2650 This means that a module importing M will see only the
2651 <emphasis>types</emphasis> of the functions that M exports, but
2652 not their unfoldings, strictness info, etc. Hence, for example,
2653 no function exported by M will be inlined into an importing module.
2654 The benefit is that modules that import M will need to be
2655 recompiled less often (only when M's exports change their type, not
2656 when they change their implementation).</para>
2657 </listitem>
2658 </varlistentry>
2659
2660 <varlistentry>
2661 <term>
2662 <option>-fomit-yields</option>
2663 <indexterm><primary><option>-fomit-yields</option></primary></indexterm>
2664 </term>
2665 <listitem>
2666 <para><emphasis>On by default.</emphasis> Tells GHC to omit
2667 heap checks when no allocation is being performed. While this improves
2668 binary sizes by about 5%, it also means that threads run in
2669 tight non-allocating loops will not get preempted in a timely
2670 fashion. If it is important to always be able to interrupt such
2671 threads, you should turn this optimization off. Consider also
2672 recompiling all libraries with this optimization turned off, if you
2673 need to guarantee interruptibility.
2674 </para>
2675 </listitem>
2676 </varlistentry>
2677
2678 <varlistentry>
2679 <term>
2680 <option>-fpedantic-bottoms</option>
2681 <indexterm><primary><option>-fpedantic-bottoms</option></primary></indexterm>
2682 </term>
2683 <listitem>
2684 <para>Make GHC be more precise about its treatment of bottom (but see also
2685 <option>-fno-state-hack</option>). In particular, stop GHC
2686 eta-expanding through a case expression, which is good for
2687 performance, but bad if you are using <literal>seq</literal> on
2688 partial applications.
2689 </para>
2690 </listitem>
2691 </varlistentry>
2692
2693 <varlistentry>
2694 <term>
2695 <option>-fregs-graph</option>
2696 <indexterm><primary><option>-fregs-graph</option></primary></indexterm>
2697 </term>
2698 <listitem>
2699 <para><emphasis>Off by default due to a performance regression bug.
2700 Only applies in combination with the native code generator.</emphasis>
2701 Use the graph colouring register allocator for register allocation
2702 in the native code generator. By default, GHC uses a simpler,
2703 faster linear register allocator. The downside being that the
2704 linear register allocator usually generates worse code.
2705 </para>
2706 </listitem>
2707 </varlistentry>
2708
2709 <varlistentry>
2710 <term>
2711 <option>-fregs-iterative</option>
2712 <indexterm><primary><option>-fregs-iterative</option></primary></indexterm>
2713 </term>
2714 <listitem>
2715 <para><emphasis>Off by default, only applies in combination with
2716 the native code generator.</emphasis>
2717 Use the iterative coalescing graph colouring register allocator for
2718 register allocation in the native code generator. This is the same
2719 register allocator as the <option>-fregs-graph</option> one but also
2720 enables iterative coalescing during register allocation.
2721 </para>
2722 </listitem>
2723 </varlistentry>
2724
2725 <varlistentry>
2726 <term>
2727 <option>-fsimplifier-phases=<replaceable>n</replaceable></option>
2728 <indexterm><primary><option>-fsimplifier-phases</option></primary></indexterm>
2729 </term>
2730 <listitem>
2731 <para>Set the number of phases for the simplifier (default 2). Ignored with -O0.
2732 </para>
2733 </listitem>
2734 </varlistentry>
2735
2736 <varlistentry>
2737 <term>
2738 <option>-fsimpl-tick-factor=<replaceable>n</replaceable></option>
2739 <indexterm><primary><option>-fsimpl-tick-factor</option></primary></indexterm>
2740 </term>
2741 <listitem>
2742 <para>GHC's optimiser can diverge if you write rewrite rules (
2743 <xref linkend="rewrite-rules"/>) that don't terminate, or (less
2744 satisfactorily) if you code up recursion through data types
2745 (<xref linkend="bugs-ghc"/>). To avoid making the compiler fall
2746 into an infinite loop, the optimiser carries a "tick count" and
2747 stops inlining and applying rewrite rules when this count is
2748 exceeded. The limit is set as a multiple of the program size, so
2749 bigger programs get more ticks. The
2750 <option>-fsimpl-tick-factor</option> flag lets you change the
2751 multiplier. The default is 100; numbers larger than 100 give more
2752 ticks, and numbers smaller than 100 give fewer.
2753 </para>
2754
2755 <para>If the tick-count expires, GHC summarises what simplifier
2756 steps it has done; you can use
2757 <option>-fddump-simpl-stats</option> to generate a much more
2758 detailed list. Usually that identifies the loop quite
2759 accurately, because some numbers are very large.
2760 </para>
2761 </listitem>
2762 </varlistentry>
2763
2764 <varlistentry>
2765 <term>
2766 <option>-fspec-constr</option>
2767 <indexterm><primary><option>-fspec-constr</option></primary></indexterm>
2768 </term>
2769 <listitem>
2770 <para><emphasis>Off by default, but enabled by -O2.</emphasis>
2771 Turn on call-pattern specialisation; see
2772 <ulink url="http://research.microsoft.com/en-us/um/people/simonpj/papers/spec-constr/index.htm">
2773 Call-pattern specialisation for Haskell programs</ulink>.
2774 </para>
2775
2776 <para>This optimisation specializes recursive functions according to
2777 their argument "shapes". This is best explained by example so
2778 consider:
2779 <programlisting>
2780 last :: [a] -> a
2781 last [] = error "last"
2782 last (x : []) = x
2783 last (x : xs) = last xs
2784 </programlisting>
2785 In this code, once we pass the initial check for an empty list we
2786 know that in the recursive case this pattern match is redundant. As
2787 such <option>-fspec-constr</option> will transform the above code
2788 to:
2789 <programlisting>
2790 last :: [a] -> a
2791 last [] = error "last"
2792 last (x : xs) = last' x xs
2793 where
2794 last' x [] = x
2795 last' x (y : ys) = last' y ys
2796 </programlisting>
2797 </para>
2798
2799 <para>As well avoid unnecessary pattern matching it also helps avoid
2800 unnecessary allocation. This applies when a argument is strict in
2801 the recursive call to itself but not on the initial entry. As
2802 strict recursive branch of the function is created similar to the
2803 above example.
2804 </para>
2805
2806 <para>It is also possible for library writers to instruct
2807 GHC to perform call-pattern specialisation extremely
2808 aggressively. This is necessary for some highly optimized
2809 libraries, where we may want to specialize regardless of
2810 the number of specialisations, or the size of the code. As
2811 an example, consider a simplified use-case from the
2812 <literal>vector</literal> library:</para>
2813 <programlisting>
2814 import GHC.Types (SPEC(..))
2815
2816 foldl :: (a -> b -> a) -> a -> Stream b -> a
2817 {-# INLINE foldl #-}
2818 foldl f z (Stream step s _) = foldl_loop SPEC z s
2819 where
2820 foldl_loop !sPEC z s = case step s of
2821 Yield x s' -> foldl_loop sPEC (f z x) s'
2822 Skip -> foldl_loop sPEC z s'
2823 Done -> z
2824 </programlisting>
2825
2826 <para>Here, after GHC inlines the body of
2827 <literal>foldl</literal> to a call site, it will perform
2828 call-pattern specialization very aggressively on
2829 <literal>foldl_loop</literal> due to the use of
2830 <literal>SPEC</literal> in the argument of the loop
2831 body. <literal>SPEC</literal> from
2832 <literal>GHC.Types</literal> is specifically recognized by
2833 the compiler.</para>
2834
2835 <para>(NB: it is extremely important you use
2836 <literal>seq</literal> or a bang pattern on the
2837 <literal>SPEC</literal> argument!)</para>
2838
2839 <para>In particular, after inlining this will
2840 expose <literal>f</literal> to the loop body directly,
2841 allowing heavy specialisation over the recursive
2842 cases.</para>
2843 </listitem>
2844 </varlistentry>
2845
2846 <varlistentry>
2847 <term>
2848 <option>-fspec-constr-count=<replaceable>n</replaceable></option>
2849 <indexterm><primary><option>-fspec-constr-count</option></primary></indexterm>
2850 </term>
2851 <listitem>
2852 <para>Set the maximum number of specialisations
2853 that will be created for any one function by the SpecConstr
2854 transformation (default: 3).
2855 </para>
2856 </listitem>
2857 </varlistentry>
2858
2859 <varlistentry>
2860 <term>
2861 <option>-fspec-constr-threshold=<replaceable>n</replaceable></option>
2862 <indexterm><primary><option>-fspec-constr-threshold</option></primary></indexterm>
2863 </term>
2864 <listitem>
2865 <para>Set the size threshold for the SpecConstr transformation (default: 2000).
2866 </para>
2867 </listitem>
2868 </varlistentry>
2869
2870 <varlistentry>
2871 <term>
2872 <option>-fspecialise</option>
2873 <indexterm><primary><option>-fspecialise</option></primary></indexterm>
2874 </term>
2875 <listitem>
2876 <para><emphasis>On by default.</emphasis>
2877 Specialise each type-class-overloaded function defined in this
2878 module for the types at which it is called in this module. Also
2879 specialise imported functions that have an INLINABLE pragma
2880 (<xref linkend="inlinable-pragma"/>) for the types at which they
2881 are called in this module.
2882 </para>
2883 </listitem>
2884 </varlistentry>
2885
2886 <varlistentry>
2887 <term>
2888 <option>-fstatic-argument-transformation</option>
2889 <indexterm><primary><option>-fstatic-argument-transformation</option></primary></indexterm>
2890 </term>
2891 <listitem>
2892 <para>Turn on the static argument transformation, which turns a
2893 recursive function into a non-recursive one with a local
2894 recursive loop. See Chapter 7 of
2895 <ulink url="http://research.microsoft.com/en-us/um/people/simonpj/papers/santos-thesis.ps.gz">
2896 Andre Santos's PhD thesis</ulink>
2897 </para>
2898 </listitem>
2899 </varlistentry>
2900
2901 <varlistentry>
2902 <term>
2903 <option>-fstrictness</option>
2904 <indexterm><primary><option></option></primary></indexterm>
2905 </term>
2906 <listitem>
2907 <para> <emphasis>On by default.</emphasis>.
2908 Switch on the strictness analyser. There is a very old paper about GHC's
2909 strictness analyser, <ulink url="http://research.microsoft.com/en-us/um/people/simonpj/papers/simple-strictnes-analyser.ps.gz">
2910 Measuring the effectiveness of a simple strictness analyser</ulink>,
2911 but the current one is quite a bit different.
2912 </para>
2913
2914 <para>The strictness analyser figures out when arguments and
2915 variables in a function can be treated 'strictly' (that is they
2916 are always evaluated in the function at some point). This allow
2917 GHC to apply certain optimisations such as unboxing that
2918 otherwise don't apply as they change the semantics of the program
2919 when applied to lazy arguments.
2920 </para>
2921 </listitem>
2922 </varlistentry>
2923
2924 <varlistentry>
2925 <term>
2926 <option>-fstrictness-before=<replaceable>n</replaceable></option>
2927 <indexterm><primary><option>-fstrictness-before</option></primary></indexterm>
2928 </term>
2929 <listitem>
2930 <para>Run an additional strictness analysis before simplifier phase n.
2931 </para>
2932 </listitem>
2933 </varlistentry>
2934
2935 <varlistentry>
2936 <term>
2937 <option>-funbox-small-strict-fields</option>:
2938 <indexterm><primary><option>-funbox-small-strict-fields</option></primary></indexterm>
2939 <indexterm><primary>strict constructor fields</primary></indexterm>
2940 <indexterm><primary>constructor fields, strict</primary></indexterm>
2941 </term>
2942 <listitem>
2943 <para><emphasis>On by default.</emphasis>. This option
2944 causes all constructor fields which are marked strict
2945 (i.e. &ldquo;!&rdquo;) and which representation is smaller
2946 or equal to the size of a pointer to be unpacked, if
2947 possible. It is equivalent to adding an
2948 <literal>UNPACK</literal> pragma (see <xref
2949 linkend="unpack-pragma"/>) to every strict constructor
2950 field that fulfils the size restriction.
2951 </para>
2952
2953 <para>For example, the constructor fields in the following
2954 data types
2955 <programlisting>
2956 data A = A !Int
2957 data B = B !A
2958 newtype C = C B
2959 data D = D !C
2960 </programlisting>
2961 would all be represented by a single
2962 <literal>Int#</literal> (see <xref linkend="primitives"/>)
2963 value with
2964 <option>-funbox-small-strict-fields</option> enabled.
2965 </para>
2966
2967 <para>This option is less of a sledgehammer than
2968 <option>-funbox-strict-fields</option>: it should rarely make things
2969 worse. If you use <option>-funbox-small-strict-fields</option>
2970 to turn on unboxing by default you can disable it for certain
2971 constructor fields using the <literal>NOUNPACK</literal> pragma (see
2972 <xref linkend="nounpack-pragma"/>).</para>
2973
2974 <para>
2975 Note that for consistency <literal>Double</literal>,
2976 <literal>Word64</literal>, and <literal>Int64</literal> constructor
2977 fields are unpacked on 32-bit platforms, even though they are
2978 technically larger than a pointer on those platforms.
2979 </para>
2980 </listitem>
2981 </varlistentry>
2982
2983 <varlistentry>
2984 <term>
2985 <option>-funbox-strict-fields</option>:
2986 <indexterm><primary><option>-funbox-strict-fields</option></primary></indexterm>
2987 <indexterm><primary>strict constructor fields</primary></indexterm>
2988 <indexterm><primary>constructor fields, strict</primary></indexterm>
2989 </term>
2990 <listitem>
2991 <para>This option causes all constructor fields which are marked
2992 strict (i.e. &ldquo;!&rdquo;) to be unpacked if possible. It is
2993 equivalent to adding an <literal>UNPACK</literal> pragma to every
2994 strict constructor field (see <xref linkend="unpack-pragma"/>).
2995 </para>
2996
2997 <para>This option is a bit of a sledgehammer: it might sometimes
2998 make things worse. Selectively unboxing fields by using
2999 <literal>UNPACK</literal> pragmas might be better. An alternative
3000 is to use <option>-funbox-strict-fields</option> to turn on
3001 unboxing by default but disable it for certain constructor
3002 fields using the <literal>NOUNPACK</literal> pragma (see
3003 <xref linkend="nounpack-pragma"/>).</para>
3004 </listitem>
3005 </varlistentry>
3006
3007 <varlistentry>
3008 <term>
3009 <option>-funfolding-creation-threshold=<replaceable>n</replaceable></option>:
3010 <indexterm><primary><option>-funfolding-creation-threshold</option></primary></indexterm>
3011 <indexterm><primary>inlining, controlling</primary></indexterm>
3012 <indexterm><primary>unfolding, controlling</primary></indexterm>
3013 </term>
3014 <listitem>
3015 <para>(Default: 750) Governs the maximum size that GHC will allow a
3016 function unfolding to be. (An unfolding has a &ldquo;size&rdquo;
3017 that reflects the cost in terms of &ldquo;code bloat&rdquo; of
3018 expanding (aka inlining) that unfolding at a call site. A bigger
3019 function would be assigned a bigger cost.)
3020 </para>
3021
3022 <para>Consequences: (a) nothing larger than this will be inlined
3023 (unless it has an INLINE pragma); (b) nothing larger than this
3024 will be spewed into an interface file.
3025 </para>
3026
3027 <para>Increasing this figure is more likely to result in longer
3028 compile times than faster code. The
3029 <option>-funfolding-use-threshold</option> is more useful.
3030 </para>
3031 </listitem>
3032 </varlistentry>
3033
3034 <varlistentry>
3035 <term>
3036 <option>-funfolding-dict-discount=<replaceable>n</replaceable></option>:
3037 <indexterm><primary><option>-funfolding-dict-discount</option></primary></indexterm>
3038 <indexterm><primary>inlining, controlling</primary></indexterm>
3039 <indexterm><primary>unfolding, controlling</primary></indexterm>
3040 </term>
3041 <listitem>
3042 <para>Default: 30
3043 </para>
3044 </listitem>
3045 </varlistentry>
3046
3047 <varlistentry>
3048 <term>
3049 <option>-funfolding-fun-discount=<replaceable>n</replaceable></option>:
3050 <indexterm><primary><option>-funfolding-fun-discount</option></primary></indexterm>
3051 <indexterm><primary>inlining, controlling</primary></indexterm>
3052 <indexterm><primary>unfolding, controlling</primary></indexterm>
3053 </term>
3054 <listitem>
3055 <para>Default: 60
3056 </para>
3057 </listitem>
3058 </varlistentry>
3059
3060 <varlistentry>
3061 <term>
3062 <option>-funfolding-keeness-factor=<replaceable>n</replaceable></option>:
3063 <indexterm><primary><option>-funfolding-keeness-factor</option></primary></indexterm>
3064 <indexterm><primary>inlining, controlling</primary></indexterm>
3065 <indexterm><primary>unfolding, controlling</primary></indexterm>
3066 </term>
3067 <listitem>
3068 <para>Default: 1.5
3069 </para>
3070 </listitem>
3071 </varlistentry>
3072
3073 <varlistentry>
3074 <term>
3075 <option>-funfolding-use-threshold=<replaceable>n</replaceable></option>
3076 <indexterm><primary><option>-funfolding-use-threshold</option></primary></indexterm>
3077 <indexterm><primary>inlining, controlling</primary></indexterm>
3078 <indexterm><primary>unfolding, controlling</primary></indexterm>
3079 </term>
3080 <listitem>
3081 <para>(Default: 60) This is the magic cut-off figure for unfolding
3082 (aka inlining): below this size, a function definition will be
3083 unfolded at the call-site, any bigger and it won't. The size
3084 computed for a function depends on two things: the actual size of
3085 the expression minus any discounts that apply depending on the
3086 context into which the expression is to be inlined.
3087 </para>
3088
3089 <para>The difference between this and
3090 <option>-funfolding-creation-threshold</option> is that this one
3091 determines if a function definition will be inlined <emphasis>at
3092 a call site</emphasis>. The other option determines if a
3093 function definition will be kept around at all for potential
3094 inlining.
3095 </para>
3096 </listitem>
3097 </varlistentry>
3098
3099 <varlistentry>
3100 <term>
3101 <option>-fvectorisation-avoidance</option>
3102 <indexterm><primary><option></option></primary></indexterm>
3103 </term>
3104 <listitem>
3105 <para>Part of <link linkend="dph">Data Parallel Haskell
3106 (DPH)</link>.</para>
3107
3108 <para><emphasis>On by default.</emphasis> Enable the
3109 <emphasis>vectorisation</emphasis> avoidance optimisation. This
3110 optimisation only works when used in combination with the
3111 <option>-fvectorise</option> transformation.</para>
3112
3113 <para>While vectorisation of code using DPH is often a big win, it
3114 can also produce worse results for some kinds of code. This
3115 optimisation modifies the vectorisation transformation to try to
3116 determine if a function would be better of unvectorised and if
3117 so, do just that.</para>
3118 </listitem>
3119 </varlistentry>
3120
3121 <varlistentry>
3122 <term>
3123 <option>-fvectorise</option>
3124 <indexterm><primary><option></option></primary></indexterm>
3125 </term>
3126 <listitem>
3127 <para>Part of <link linkend="dph">Data Parallel Haskell
3128 (DPH)</link>.</para>
3129
3130 <para><emphasis>Off by default.</emphasis> Enable the
3131 <emphasis>vectorisation</emphasis> optimisation transformation. This
3132 optimisation transforms the nested data parallelism code of programs
3133 using DPH into flat data parallelism. Flat data parallel programs
3134 should have better load balancing, enable SIMD parallelism and
3135 friendlier cache behaviour.</para>
3136 </listitem>
3137 </varlistentry>
3138
3139 </variablelist>
3140
3141 </sect2>
3142
3143 </sect1>
3144
3145 &code-gens;
3146
3147 &phases;
3148
3149 &shared_libs;
3150
3151 <sect1 id="using-concurrent">
3152 <title>Using Concurrent Haskell</title>
3153 <indexterm><primary>Concurrent Haskell</primary><secondary>using</secondary></indexterm>
3154
3155 <para>GHC supports Concurrent Haskell by default, without requiring a
3156 special option or libraries compiled in a certain way. To get access to
3157 the support libraries for Concurrent Haskell, just import
3158 <ulink
3159 url="&libraryBaseLocation;/Control-Concurrent.html"><literal>Control.Concurrent</literal></ulink>. More information on Concurrent Haskell is provided in the documentation for that module.</para>
3160
3161 <para>
3162 Optionally, the program may be linked with
3163 the <option>-threaded</option> option (see
3164 <xref linkend="options-linker" />. This provides two benefits:
3165
3166 <itemizedlist>
3167 <listitem>
3168 <para>It enables the <option>-N</option><indexterm><primary><option>-N<replaceable>x</replaceable></option></primary><secondary>RTS option</secondary></indexterm> RTS option to be
3169 used, which allows threads to run in
3170 parallel<indexterm><primary>parallelism</primary></indexterm>
3171 on a
3172 multiprocessor<indexterm><primary>multiprocessor</primary></indexterm><indexterm><primary>SMP</primary></indexterm>
3173 or
3174 multicore<indexterm><primary>multicore</primary></indexterm>
3175 machine. See <xref linkend="using-smp" />.</para>
3176 </listitem>
3177 <listitem>
3178 <para>If a thread makes a foreign call (and the call is
3179 not marked <literal>unsafe</literal>), then other
3180 Haskell threads in the program will continue to run
3181 while the foreign call is in progress.
3182 Additionally, <literal>foreign export</literal>ed
3183 Haskell functions may be called from multiple OS
3184 threads simultaneously. See
3185 <xref linkend="ffi-threads" />.</para>
3186 </listitem>
3187 </itemizedlist>
3188 </para>
3189
3190 <para>The following RTS option(s) affect the behaviour of Concurrent
3191 Haskell programs:<indexterm><primary>RTS options, concurrent</primary></indexterm></para>
3192
3193 <variablelist>
3194 <varlistentry>
3195 <term><option>-C<replaceable>s</replaceable></option></term>
3196 <listitem>
3197 <para><indexterm><primary><option>-C<replaceable>s</replaceable></option></primary><secondary>RTS option</secondary></indexterm>
3198 Sets the context switch interval to <replaceable>s</replaceable>
3199 seconds. A context switch will occur at the next heap block
3200 allocation after the timer expires (a heap block allocation occurs
3201 every 4k of allocation). With <option>-C0</option> or
3202 <option>-C</option>, context switches will occur as often as
3203 possible (at every heap block allocation). By default, context
3204 switches occur every 20ms.</para>
3205 </listitem>
3206 </varlistentry>
3207 </variablelist>
3208 </sect1>
3209
3210 <sect1 id="using-smp">
3211 <title>Using SMP parallelism</title>
3212 <indexterm><primary>parallelism</primary>
3213 </indexterm>
3214 <indexterm><primary>SMP</primary>
3215 </indexterm>
3216
3217 <para>GHC supports running Haskell programs in parallel on an SMP
3218 (symmetric multiprocessor).</para>
3219
3220 <para>There's a fine distinction between
3221 <emphasis>concurrency</emphasis> and <emphasis>parallelism</emphasis>:
3222 parallelism is all about making your program run
3223 <emphasis>faster</emphasis> by making use of multiple processors
3224 simultaneously. Concurrency, on the other hand, is a means of
3225 abstraction: it is a convenient way to structure a program that must
3226 respond to multiple asynchronous events.</para>
3227
3228 <para>However, the two terms are certainly related. By making use of
3229 multiple CPUs it is possible to run concurrent threads in parallel,
3230 and this is exactly what GHC's SMP parallelism support does. But it
3231 is also possible to obtain performance improvements with parallelism
3232 on programs that do not use concurrency. This section describes how to
3233 use GHC to compile and run parallel programs, in <xref
3234 linkend="lang-parallel" /> we describe the language features that affect
3235 parallelism.</para>
3236
3237 <sect2 id="parallel-compile-options">
3238 <title>Compile-time options for SMP parallelism</title>
3239
3240 <para>In order to make use of multiple CPUs, your program must be
3241 linked with the <option>-threaded</option> option (see <xref
3242 linkend="options-linker" />). Additionally, the following
3243 compiler options affect parallelism:</para>
3244
3245 <variablelist>
3246 <varlistentry>
3247 <term><option>-feager-blackholing</option></term>
3248 <indexterm><primary><option>-feager-blackholing</option></primary></indexterm>
3249 <listitem>
3250 <para>
3251 Blackholing is the act of marking a thunk (lazy
3252 computuation) as being under evaluation. It is useful for
3253 three reasons: firstly it lets us detect certain kinds of
3254 infinite loop (the <literal>NonTermination</literal>
3255 exception), secondly it avoids certain kinds of space
3256 leak, and thirdly it avoids repeating a computation in a
3257 parallel program, because we can tell when a computation
3258 is already in progress.</para>
3259
3260 <para>
3261 The option <option>-feager-blackholing</option> causes
3262 each thunk to be blackholed as soon as evaluation begins.
3263 The default is "lazy blackholing", whereby thunks are only
3264 marked as being under evaluation when a thread is paused
3265 for some reason. Lazy blackholing is typically more
3266 efficient (by 1-2&percnt; or so), because most thunks don't
3267 need to be blackholed. However, eager blackholing can
3268 avoid more repeated computation in a parallel program, and
3269 this often turns out to be important for parallelism.
3270 </para>
3271
3272 <para>
3273 We recommend compiling any code that is intended to be run
3274 in parallel with the <option>-feager-blackholing</option>
3275 flag.
3276 </para>
3277 </listitem>
3278 </varlistentry>
3279 </variablelist>
3280 </sect2>
3281
3282 <sect2 id="parallel-options">
3283 <title>RTS options for SMP parallelism</title>
3284
3285 <para>There are two ways to run a program on multiple
3286 processors:
3287 call <literal>Control.Concurrent.setNumCapabilities</literal> from your
3288 program, or use the RTS <option>-N</option> option.</para>
3289
3290 <variablelist>
3291 <varlistentry>
3292 <term><option>-N<optional><replaceable>x</replaceable></optional></option></term>
3293 <listitem>
3294 <para><indexterm><primary><option>-N<replaceable>x</replaceable></option></primary><secondary>RTS option</secondary></indexterm>
3295 Use <replaceable>x</replaceable> simultaneous threads when
3296 running the program. Normally <replaceable>x</replaceable>
3297 should be chosen to match the number of CPU cores on the
3298 machine<footnote><para>Whether hyperthreading cores should be counted or not is an
3299 open question; please feel free to experiment and let us know what
3300 results you find.</para></footnote>. For example,
3301 on a dual-core machine we would probably use
3302 <literal>+RTS -N2 -RTS</literal>.</para>
3303
3304 <para>Omitting <replaceable>x</replaceable>,
3305 i.e. <literal>+RTS -N -RTS</literal>, lets the runtime
3306 choose the value of <replaceable>x</replaceable> itself
3307 based on how many processors are in your machine.</para>
3308
3309 <para>Be careful when using all the processors in your
3310 machine: if some of your processors are in use by other
3311 programs, this can actually harm performance rather than
3312 improve it.</para>
3313
3314 <para>Setting <option>-N</option> also has the effect of
3315 enabling the parallel garbage collector (see
3316 <xref linkend="rts-options-gc" />).</para>
3317
3318 <para>The current value of the <option>-N</option> option
3319 is available to the Haskell program
3320 via <literal>Control.Concurrent.getNumCapabilities</literal>, and
3321 it may be changed while the program is running by
3322 calling <literal>Control.Concurrent.setNumCapabilities</literal>.</para>
3323 </listitem>
3324 </varlistentry>
3325 </variablelist>
3326
3327 <para>The following options affect the way the runtime schedules
3328 threads on CPUs:</para>
3329
3330 <variablelist>
3331 <varlistentry>
3332 <term><option>-qa</option></term>
3333 <indexterm><primary><option>-qa</option></primary><secondary>RTS
3334 option</secondary></indexterm>
3335 <listitem>
3336 <para>Use the OS's affinity facilities to try to pin OS
3337 threads to CPU cores. This is an experimental feature,
3338 and may or may not be useful. Please let us know
3339 whether it helps for you!</para>
3340 </listitem>
3341 </varlistentry>
3342 <varlistentry>
3343 <term><option>-qm</option></term>
3344 <indexterm><primary><option>-qm</option></primary><secondary>RTS
3345 option</secondary></indexterm>
3346 <listitem>
3347 <para>Disable automatic migration for load balancing.
3348 Normally the runtime will automatically try to schedule
3349 threads across the available CPUs to make use of idle
3350 CPUs; this option disables that behaviour. Note that
3351 migration only applies to threads; sparks created
3352 by <literal>par</literal> are load-balanced separately
3353 by work-stealing.</para>
3354
3355 <para>
3356 This option is probably only of use for concurrent
3357 programs that explicitly schedule threads onto CPUs
3358 with <literal>Control.Concurrent.forkOn</literal>.
3359 </para>
3360 </listitem>
3361 </varlistentry>
3362 </variablelist>
3363 </sect2>
3364
3365 <sect2>
3366 <title>Hints for using SMP parallelism</title>
3367
3368 <para>Add the <literal>-s</literal> RTS option when
3369 running the program to see timing stats, which will help to tell you
3370 whether your program got faster by using more CPUs or not. If the user
3371 time is greater than
3372 the elapsed time, then the program used more than one CPU. You should
3373 also run the program without <literal>-N</literal> for
3374 comparison.</para>
3375
3376 <para>The output of <literal>+RTS -s</literal> tells you how
3377 many &ldquo;sparks&rdquo; were created and executed during the
3378 run of the program (see <xref linkend="rts-options-gc" />), which
3379 will give you an idea how well your <literal>par</literal>
3380 annotations are working.</para>
3381
3382 <para>GHC's parallelism support has improved in 6.12.1 as a
3383 result of much experimentation and tuning in the runtime
3384 system. We'd still be interested to hear how well it works
3385 for you, and we're also interested in collecting parallel
3386 programs to add to our benchmarking suite.</para>
3387 </sect2>
3388 </sect1>
3389
3390 <sect1 id="options-platform">
3391 <title>Platform-specific Flags</title>
3392
3393 <indexterm><primary>-m* options</primary></indexterm>
3394 <indexterm><primary>platform-specific options</primary></indexterm>
3395 <indexterm><primary>machine-specific options</primary></indexterm>
3396
3397 <para>Some flags only make sense for particular target
3398 platforms.</para>
3399
3400 <variablelist>
3401
3402 <varlistentry>
3403 <term><option>-msse2</option>:</term>
3404 <listitem>
3405 <para>
3406 (x86 only, added in GHC 7.0.1) Use the SSE2 registers and
3407 instruction set to implement floating point operations when using
3408 the <link linkend="native-code-gen">native code generator</link>.
3409 This gives a substantial performance improvement for floating
3410 point, but the resulting compiled code
3411 will only run on processors that support SSE2 (Intel Pentium 4 and
3412 later, or AMD Athlon 64 and later). The
3413 <link linkend="llvm-code-gen">LLVM backend</link> will also use SSE2
3414 if your processor supports it but detects this automatically so no
3415 flag is required.
3416 </para>
3417 <para>
3418 SSE2 is unconditionally used on x86-64 platforms.
3419 </para>
3420 </listitem>
3421 </varlistentry>
3422
3423 <varlistentry>
3424 <term><option>-msse4.2</option>:</term>
3425 <listitem>
3426 <para>
3427 (x86 only, added in GHC 7.4.1) Use the SSE4.2 instruction set to
3428 implement some floating point and bit operations when using the
3429 <link linkend="native-code-gen">native code generator</link>. The
3430 resulting compiled code will only run on processors that
3431 support SSE4.2 (Intel Core i7 and later). The
3432 <link linkend="llvm-code-gen">LLVM backend</link> will also use
3433 SSE4.2 if your processor supports it but detects this automatically
3434 so no flag is required.
3435 </para>
3436 </listitem>
3437 </varlistentry>
3438
3439 </variablelist>
3440
3441 </sect1>
3442
3443 &runtime;
3444 &debug;
3445 &flags;
3446
3447 </chapter>
3448
3449 <!-- Emacs stuff:
3450 ;;; Local Variables: ***
3451 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter") ***
3452 ;;; End: ***
3453 -->