[project @ 2006-01-06 11:04:07 by simonmar]
[ghc-hetmet.git] / ghc / docs / users_guide / using.xml
index ffe639c..32c194a 100644 (file)
@@ -51,35 +51,38 @@ ghc [argument...]
       <option>-fglasgow-exts</option> option.  Rather than maintaining
       the list of per-file options in a <filename>Makefile</filename>,
       it is possible to do this directly in the source file using the
-      <literal>OPTIONS</literal> pragma <indexterm><primary>OPTIONS
+      <literal>OPTIONS_GHC</literal> pragma <indexterm><primary>OPTIONS_GHC
       pragma</primary></indexterm>:</para>
 
 <programlisting>
-{-# OPTIONS -fglasgow-exts #-}
+{-# OPTIONS_GHC -fglasgow-exts #-}
 module X where
 ...
 </programlisting>
       
-      <para><literal>OPTIONS</literal> pragmas are only looked for at
+      <para><literal>OPTIONS_GHC</literal> pragmas are only looked for at
       the top of your source files, upto the first
       (non-literate,non-empty) line not containing
-      <literal>OPTIONS</literal>. Multiple <literal>OPTIONS</literal>
-      pragmas are recognised. Note that your command shell does not
+      <literal>OPTIONS_GHC</literal>. Multiple <literal>OPTIONS_GHC</literal>
+      pragmas are recognised.  Do not put comments before, or on the same line
+       as, the <literal>OPTIONS_GHC</literal> pragma.</para>
+
+      <para>Note that your command shell does not
       get to the source file options, they are just included literally
-      in the array of command-line arguments the compiler driver
+      in the array of command-line arguments the compiler
       maintains internally, so you'll be desperately disappointed if
-      you try to glob etc. inside <literal>OPTIONS</literal>.</para>
+      you try to glob etc. inside <literal>OPTIONS_GHC</literal>.</para>
 
-      <para>NOTE: the contents of OPTIONS are prepended to the
+      <para>NOTE: the contents of OPTIONS_GHC are prepended to the
       command-line options, so you <emphasis>do</emphasis> have the
-      ability to override OPTIONS settings via the command
+      ability to override OPTIONS_GHC settings via the command
       line.</para>
 
       <para>It is not recommended to move all the contents of your
       Makefiles into your source files, but in some circumstances, the
-      <literal>OPTIONS</literal> pragma is the Right Thing. (If you
+      <literal>OPTIONS_GHC</literal> pragma is the Right Thing. (If you
       use <option>-keep-hc-file-too</option> and have OPTION flags in
-      your module, the OPTIONS will get put into the generated .hc
+      your module, the OPTIONS_GHC will get put into the generated .hc
       file).</para>
     </sect2>
 
@@ -93,21 +96,47 @@ module X where
   </sect1>
     
   <sect1 id="static-dynamic-flags">
-    <title>Static vs. Dynamic options</title>
+    <title>Static, Dynamic, and Mode options</title>
     <indexterm><primary>static</primary><secondary>options</secondary>
     </indexterm>
     <indexterm><primary>dynamic</primary><secondary>options</secondary>
     </indexterm>
+    <indexterm><primary>mode</primary><secondary>options</secondary>
+    </indexterm>
 
     <para>Each of GHC's command line options is classified as either
-    <firstterm>static</firstterm> or <firstterm>dynamic</firstterm>.
-    A static flag may only be specified on the command line, whereas a
-    dynamic flag may also be given in an <literal>OPTIONS</literal>
-    pragma in a source file or set from the GHCi command-line with
-    <literal>:set</literal>.</para>
-
-    <para>As a rule of thumb, options which relate to filenames are
-    static, and the rest are dynamic. The flag reference tables (<xref
+    <firstterm>static</firstterm> or <firstterm>dynamic</firstterm> or
+      <firstterm>mode</firstterm>:</para>
+
+    <variablelist>
+      <varlistentry>
+       <term>Mode flags</term>
+       <listitem>
+         <para>For example, <option>--make</option> or <option>-E</option>.
+           There may be only a single mode flag on the command line.  The
+           available modes are listed in <xref linkend="modes"/>.</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term>Dynamic Flags</term>
+       <listitem>
+         <para>Most non-mode flags fall into this category.  A dynamic flag
+           may be used on the command line, in a
+           <literal>GHC_OPTIONS</literal> pragma in a source file, or set
+           using <literal>:set</literal> in GHCi.</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term>Static Flags</term>
+       <listitem>
+         <para>A few flags are "static", which means they can only be used on
+           the command-line, and remain in force over the entire GHC/GHCi
+           run.</para>
+       </listitem>
+      </varlistentry>
+    </variablelist>
+    
+    <para>The flag reference tables (<xref
     linkend="flag-reference"/>) lists the status of each flag.</para>
   </sect1>
 
@@ -354,7 +383,7 @@ ghc &ndash;&ndash;make Main.hs
       <option>&ndash;&ndash;make</option>, but note that any options
       you give on the command line will apply to all the source files
       compiled, so if you want any options to apply to a single source
-      file only, you'll need to use an <literal>OPTIONS</literal>
+      file only, you'll need to use an <literal>OPTIONS_GHC</literal>
       pragma (see <xref linkend="source-file-options"/>).</para>
 
       <para>If the program needs to be linked with additional objects
@@ -512,6 +541,30 @@ ghc -c Foo.hs</screen>
       of the compiler, dumping the result in a file.  Note that this
       differs from the previous behaviour of dumping the file to
       standard output.</para>
+
+      <sect3 id="overriding-suffixes">
+       <title>Overriding the default behaviour for a file</title>
+
+       <para>As described above, the way in which a file is processed by GHC
+         depends on its suffix.  This behaviour can be overriden using the
+         <option>-x</option> option:</para>
+
+       <variablelist>
+         <varlistentry>
+           <term><option>-x</option> <replaceable>suffix</replaceable>
+                     <indexterm><primary><option>-x</option></primary>
+             </indexterm></term>
+             <listitem>
+               <para>Causes all files following this option on the command
+                 line to be processed as if they had the suffix
+                 <replaceable>suffix</replaceable>.  For example, to compile a
+                 Haskell module in the file <literal>M.my-hs</literal>,
+                 use <literal>ghc -c -x hs M.my-hs</literal>.</para>
+             </listitem>
+         </varlistentry>
+       </variablelist>
+      </sect3>
+
     </sect2>
   </sect1>
 
@@ -693,6 +746,19 @@ ghc -c Foo.hs</screen>
          it).</para>
        </listitem>
       </varlistentry>
+
+      <varlistentry>
+        <term><option>-Rghc-timing</option>
+        <indexterm><primary><option>-Rghc-timing</option></primary></indexterm>
+        </term>
+        <listitem>
+          <para>Prints a one-line summary of timing statistics for the
+          GHC run.  This option is equivalent to
+          <literal>+RTS&nbsp;-tstderr</literal>, see <xref
+          linkend="rts-options-gc" />.
+          </para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </sect1>
 
@@ -835,6 +901,33 @@ g [] = 2
       </varlistentry>
 
       <varlistentry>
+       <term><option>-fwarn-incomplete-record-updates</option>:</term>
+       <listitem>
+         <indexterm><primary><option>-fwarn-incomplete-record-updates</option></primary></indexterm>
+         <indexterm><primary>incomplete record updates, warning</primary></indexterm>
+         <indexterm><primary>record updates, incomplete</primary></indexterm>
+
+         <para>The function
+          <function>f</function> below will fail when applied to
+          <literal>Bar</literal>, so the compiler will emit a warning about
+          this when <option>-fwarn-incomplete-record-updates</option> is
+          enabled.</para>
+
+<programlisting>
+data Foo = Foo { x :: Int }
+         | Bar
+
+f :: Foo -> Foo
+f foo = foo { x = 6 }
+</programlisting>
+
+         <para>This option isn't enabled be default because it can be
+          very noisy, and it often doesn't indicate a bug in the
+          program.</para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
        <term>
           <option>-fwarn-misc</option>:
           <indexterm><primary><option>-fwarn-misc</option></primary></indexterm>
@@ -923,6 +1016,27 @@ g [] = 2
       </varlistentry>
 
       <varlistentry>
+       <term><option>-fwarn-orphans</option>:</term>
+       <listitem>
+         <indexterm><primary><option>-fwarn-orphans</option></primary></indexterm>
+         <indexterm><primary>orphan instances, warning</primary></indexterm>
+         <indexterm><primary>orphan rules, warning</primary></indexterm>
+         
+         <para>This option causes a warning to be emitted whenever the 
+           module contains an "orphan" instance declaration or rewrite rule.
+           An instance declartion is an orphan if it appears in a module in
+           which neither the class nor the type being instanced are declared
+           in the same module.  A rule is an orphan if it is a rule for a
+           function declared in another module.  A module containing any
+         orphans is called an orphan module.</para>
+         <para>The trouble with orphans is that GHC must pro-actively read the interface
+           files for all orphan modules, just in case their instances or rules
+           play a role, whether or not the module's interface would otherwise 
+           be of any use.  Other things being equal, avoid orphan modules.</para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
        <term>
           <option>-fwarn-overlapping-patterns</option>:
           <indexterm><primary><option>-fwarn-overlapping-patterns</option></primary></indexterm>
@@ -1239,6 +1353,18 @@ f "2"    = 2
 
        <varlistentry>
          <term>
+            <option>-fno-cse</option>
+            <indexterm><primary><option>-fno-cse</option></primary></indexterm>
+          </term>
+         <listitem>
+           <para>Turns off the common-sub-expression elimination optimisation.
+             Can be useful if you have some <literal>unsafePerformIO</literal>
+           expressions that you don't want commoned-up.</para>
+         </listitem>
+       </varlistentry>
+
+       <varlistentry>
+         <term>
             <option>-fno-strictness</option>
             <indexterm><primary><option>-fno-strictness</option></primary></indexterm>
           </term>
@@ -1250,12 +1376,27 @@ f "2"    = 2
 
        <varlistentry>
          <term>
-            <option>-fno-cpr-analyse</option>
-            <indexterm><primary><option>-fno-cpr-analyse</option></primary></indexterm>
+            <option>-fno-full-laziness</option>
+            <indexterm><primary><option>-fno-full-laziness</option></primary></indexterm>
           </term>
          <listitem>
-           <para>Turns off the CPR (constructed product result)
-           analysis; it is somewhat experimental.</para>
+           <para>Turns off the full laziness optimisation (also known as
+             let-floating).  Full laziness increases sharing, which can lead
+             to increased memory residency.</para>
+         </listitem>
+       </varlistentry>
+
+       <varlistentry>
+         <term>
+            <option>-fno-state-hack</option>
+            <indexterm><primary><option>-fno-state-hack</option></primary></indexterm>
+          </term>
+         <listitem>
+           <para>Turn off the "state hack" whereby any lambda with a
+             <literal>State#</literal> token as argument is considered to be
+             single-entry, hence it is considered OK to inline things inside
+             it.  This can improve performance of IO and ST monad code, but it
+           runs the risk of reducing sharing.</para> 
          </listitem>
        </varlistentry>
 
@@ -1350,38 +1491,47 @@ f "2"    = 2
   &phases;  
   
   <sect1 id="sec-using-concurrent">
-<title>Using Concurrent Haskell</title>
-
-            <indexterm><primary>Concurrent Haskell&mdash;use</primary></indexterm>
+    <title>Using Concurrent Haskell</title>
+    <indexterm><primary>Concurrent Haskell</primary><secondary>using</secondary></indexterm>
 
-<para>
-GHC supports Concurrent Haskell by default, without requiring a
-special option or libraries compiled in a certain way.  To get access
-to the support libraries for Concurrent Haskell, just import
-<literal>Control.Concurrent</literal> (details are in the accompanying
-library documentation).</para>
-
-<para>
-RTS options are provided for modifying the behaviour of the threaded
-runtime system.  See <xref linkend="parallel-rts-opts"/>.
-</para>
+    <para>GHC supports Concurrent Haskell by default, without requiring a
+      special option or libraries compiled in a certain way.  To get access to
+      the support libraries for Concurrent Haskell, just import
+      <ulink
+       url="../libraries/base/Control-Concurrent.html"><literal>Control.Concurrent</literal></ulink>.  More information on Concurrent Haskell is provided in the documentation for that module.</para>
 
-<para>
-Concurrent Haskell is described in more detail in the documentation
-for the <literal>Control.Concurrent</literal> module.
-</para>
+    <para>The following RTS option(s) affect the behaviour of Concurrent
+      Haskell programs:<indexterm><primary>RTS options, concurrent</primary></indexterm></para>
 
-</sect1>
+    <variablelist>
+      <varlistentry>
+       <term><option>-C<replaceable>s</replaceable></option></term>
+       <listitem>
+         <para><indexterm><primary><option>-C<replaceable>s</replaceable></option></primary><secondary>RTS option</secondary></indexterm>
+           Sets the context switch interval to <replaceable>s</replaceable>
+           seconds.  A context switch will occur at the next heap block
+           allocation after the timer expires (a heap block allocation occurs
+           every 4k of allocation).  With <option>-C0</option> or
+           <option>-C</option>, context switches will occur as often as
+           possible (at every heap block allocation).  By default, context
+           switches occur every 20ms.  Note that GHC's internal timer ticks
+           every 20ms, and the context switch timer is always a multiple of
+           this timer, so 20ms is the maximum granularity available for timed
+           context switches.</para>
+       </listitem>
+      </varlistentry>
+    </variablelist>
+  </sect1>
 
 <sect1 id="sec-using-parallel">
 <title>Using parallel Haskell</title>
 
 <para>
-<indexterm><primary>parallel Haskell&mdash;use</primary></indexterm>
-</para>
-
-<para>
-&lsqb;You won't be able to execute parallel Haskell programs unless PVM3
+<indexterm><primary>Parallel Haskell</primary><secondary>using</secondary></indexterm>
+&lsqb;NOTE: GHC does not support Parallel Haskell by default, you need to
+      obtain a special version of GHC from the <ulink
+       url="http://www.cee.hw.ac.uk/~dsg/gph/">GPH</ulink> site.  Also,
+you won't be able to execute parallel Haskell programs unless PVM3
 (parallel Virtual Machine, version 3) is installed at your site.&rsqb;
 </para>
 
@@ -1390,7 +1540,7 @@ To compile a Haskell program for parallel execution under PVM, use the
 <option>-parallel</option> option,<indexterm><primary>-parallel
 option</primary></indexterm> both when compiling <emphasis>and
 linking</emphasis>.  You will probably want to <literal>import
-parallel</literal> into your Haskell modules.
+Control.Parallel</literal> into your Haskell modules.
 </para>
 
 <para>
@@ -1522,7 +1672,7 @@ results&mdash;only with &ldquo;how parallel&rdquo; it was!  We want pretty pictu
 
 <para>
 parallelism profiles (&agrave; la <command>hbcpp</command>) can be generated with the
-<option>-qP</option><indexterm><primary>-qP RTS option (concurrent, parallel)</primary></indexterm> RTS option.  The
+<option>-qP</option><indexterm><primary>-qP RTS option</primary></indexterm> RTS option.  The
 per-processor profiling info is dumped into files named
 <filename>&lt;full-path&gt;&lt;program&gt;.gr</filename>.  These are then munged into a PostScript picture,
 which you can then display.  For example, to run your program
@@ -1567,20 +1717,18 @@ what's happening overall is: <command>tail -f /tmp/pvml.nnn</command>.
 </sect2>
 
 <sect2 id="parallel-rts-opts">
-<title>RTS options for Concurrent/parallel Haskell
+<title>RTS options for Parallel Haskell
 </title>
 
 <para>
-<indexterm><primary>RTS options, concurrent</primary></indexterm>
 <indexterm><primary>RTS options, parallel</primary></indexterm>
-<indexterm><primary>Concurrent Haskell&mdash;RTS options</primary></indexterm>
 <indexterm><primary>parallel Haskell&mdash;RTS options</primary></indexterm>
 </para>
 
 <para>
 Besides the usual runtime system (RTS) options
 (<xref linkend="runtime-control"/>), there are a few options particularly
-for concurrent/parallel execution.
+for parallel execution.
 </para>
 
 <para>
@@ -1597,17 +1745,16 @@ the default is 2.
 </listitem>
 </varlistentry>
 <varlistentry>
-<term><option>-C[&lt;us&gt;]</option>:</term>
+<term><option>-C[&lt;s&gt;]</option>:</term>
 <listitem>
 <para>
-<indexterm><primary>-C&lt;us&gt; RTS option</primary></indexterm> Sets
+<indexterm><primary>-C&lt;s&gt; RTS option</primary></indexterm> Sets
 the context switch interval to <literal>&lt;s&gt;</literal> seconds.
 A context switch will occur at the next heap block allocation after
 the timer expires (a heap block allocation occurs every 4k of
 allocation).  With <option>-C0</option> or <option>-C</option>,
 context switches will occur as often as possible (at every heap block
-allocation).  By default, context switches occur every 20ms
-milliseconds.  Note that GHC's internal timer ticks every 20ms, and
+allocation).  By default, context switches occur every 20ms.  Note that GHC's internal timer ticks every 20ms, and
 the context switch timer is always a multiple of this timer, so 20ms
 is the maximum granularity available for timed context switches.
 </para>
@@ -1636,7 +1783,7 @@ check (with <option>-C</option>).
 <listitem>
 <para>
 <indexterm><primary>-qt&lt;num&gt; RTS option</primary></indexterm>
-(paraLLEL ONLY) Limit the thread pool size, i.e. the number of concurrent
+(paraLLEL ONLY) Limit the thread pool size, i.e. the number of 
 threads per processor to <literal>&lt;num&gt;</literal>.  The default is
 32.  Each thread requires slightly over 1K <emphasis>words</emphasis> in
 the heap for thread state and stack objects.  (For 32-bit machines, this
@@ -1823,7 +1970,7 @@ ordinary Haskell 98, when translated to External Core, uses things like rank-2 t
 
 <!-- Emacs stuff:
      ;;; Local Variables: ***
-     ;;; mode: sgml ***
+     ;;; mode: xml ***
      ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter") ***
      ;;; End: ***
  -->