Improve documentation of INLINE pragmas
[ghc-hetmet.git] / docs / users_guide / glasgow_exts.xml
index dd410c8..e5b7154 100644 (file)
@@ -244,7 +244,8 @@ documentation</ulink> describes all the libraries that come with GHC.
        <term><option>-fth</option></term>
        <listitem>
          <para>Enables Template Haskell (see <xref
-         linkend="template-haskell"/>).  Currently also implied by
+         linkend="template-haskell"/>).  This flag must
+         be given explicitly; it is no longer implied by
          <option>-fglasgow-exts</option>.</para>
 
          <para>Syntax stolen: <literal>[|</literal>,
@@ -3742,20 +3743,17 @@ Derived instance declarations are constructed as follows. Consider the
 declaration (after expansion of any type synonyms)
 
 <programlisting> 
-  newtype T v1...vn = T' (S t1...tk vk+1...vn) deriving (c1...cm) 
+  newtype T v1...vn = T' (t vk+1...vn) deriving (c1...cm) 
 </programlisting> 
 
 where 
  <itemizedlist>
 <listitem><para>
-  <literal>S</literal> is a type constructor, 
+  The type <literal>t</literal> is an arbitrary type
 </para></listitem>
 <listitem><para>
-  The <literal>t1...tk</literal> are types,
-</para></listitem>
-<listitem><para>
-  The <literal>vk+1...vn</literal> are type variables which do not occur in any of
-  the <literal>ti</literal>, and
+  The <literal>vk+1...vn</literal> are type variables which do not occur in 
+  <literal>t</literal>, and
 </para></listitem>
 <listitem><para>
   The <literal>ci</literal> are partial applications of
@@ -3773,7 +3771,7 @@ where
 Then, for each <literal>ci</literal>, the derived instance
 declaration is:
 <programlisting> 
-  instance ci (S t1...tk vk+1...v) => ci (T v1...vp)
+  instance ci (t vk+1...v) => ci (T v1...vp)
 </programlisting>
 where <literal>p</literal> is chosen so that <literal>T v1...vp</literal> is of the 
 right <emphasis>kind</emphasis> for the last parameter of class <literal>Ci</literal>.
@@ -4089,9 +4087,8 @@ Tim Sheard is going to expand it.)
       constructions.  You need to use the flag
       <option>-fth</option><indexterm><primary><option>-fth</option></primary>
       </indexterm>to switch these syntactic extensions on
-      (<option>-fth</option> is currently implied by
-      <option>-fglasgow-exts</option>, but you are encouraged to
-      specify it explicitly).</para>
+      (<option>-fth</option> is no longer implied by
+      <option>-fglasgow-exts</option>).</para>
 
        <itemizedlist>
              <listitem><para>
@@ -5013,63 +5010,58 @@ key_function :: Int -> String -> (Bool, Double)
         If you use <option>-dverbose-core2core</option> you'll see the
         sequence of phase numbers for successive runs of the
         simplifier.  In an INLINE pragma you can optionally specify a
-        phase number, thus:</para>
-
+        phase number, thus:
        <itemizedlist>
          <listitem>
-           <para>You can say "inline <literal>f</literal> in Phase 2
-            and all subsequent phases":
-<programlisting>
-  {-# INLINE [2] f #-}
-</programlisting>
-            </para>
-         </listitem>
-
+           <para>"<literal>INLINE[k] f</literal>" means: do not inline
+           <literal>f</literal>
+             until phase <literal>k</literal>, but from phase
+             <literal>k</literal> onwards be very keen to inline it.
+            </para></listitem>
          <listitem>
-           <para>You can say "inline <literal>g</literal> in all
-            phases up to, but not including, Phase 3":
-<programlisting>
-  {-# INLINE [~3] g #-}
-</programlisting>
-            </para>
-         </listitem>
-
+           <para>"<literal>INLINE[~k] f</literal>" means: be very keen to inline
+           <literal>f</literal>
+             until phase <literal>k</literal>, but from phase
+             <literal>k</literal> onwards do not inline it.
+            </para></listitem>
          <listitem>
-           <para>If you omit the phase indicator, you mean "inline in
-            all phases".</para>
-         </listitem>
+           <para>"<literal>NOINLINE[k] f</literal>" means: do not inline
+           <literal>f</literal>
+             until phase <literal>k</literal>, but from phase
+             <literal>k</literal> onwards be willing to inline it (as if
+             there was no pragma).
+            </para></listitem>
+           <listitem>
+           <para>"<literal>INLINE[~k] f</literal>" means: be willing to inline
+           <literal>f</literal>
+             until phase <literal>k</literal>, but from phase
+             <literal>k</literal> onwards do not inline it.
+            </para></listitem>
        </itemizedlist>
-
-       <para>You can use a phase number on a NOINLINE pragma too:</para>
-
-       <itemizedlist>
-         <listitem>
-           <para>You can say "do not inline <literal>f</literal>
-            until Phase 2; in Phase 2 and subsequently behave as if
-            there was no pragma at all":
+The same information is summarised here:
 <programlisting>
-  {-# NOINLINE [2] f #-}
-</programlisting>
-            </para>
-         </listitem>
+                           -- Before phase 2     Phase 2 and later
+  {-# INLINE   [2]  f #-}  --      No                 Yes
+  {-# INLINE   [~2] f #-}  --      Yes                No
+  {-# NOINLINE [2]  f #-}  --      No                 Maybe
+  {-# NOINLINE [~2] f #-}  --      Maybe              No
 
-         <listitem>
-           <para>You can say "do not inline <literal>g</literal> in
-            Phase 3 or any subsequent phase; before that, behave as if
-            there was no pragma":
-<programlisting>
-  {-# NOINLINE [~3] g #-}
+  {-# INLINE   f #-}       --      Yes                Yes
+  {-# NOINLINE f #-}       --      No                 No
 </programlisting>
-            </para>
-         </listitem>
-
-         <listitem>
-           <para>If you omit the phase indicator, you mean "never
-            inline this function".</para>
-         </listitem>
-       </itemizedlist>
-
-       <para>The same phase-numbering control is available for RULES
+By "Maybe" we mean that the usual heuristic inlining rules apply (if the
+function body is small, or it is applied to interesting-looking arguments etc).
+Another way to understand the semantics is this:
+<itemizedlist>
+<listitem><para>For both INLINE and NOINLINE, the phase number says
+when inlining is allowed at all.</para></listitem>
+<listitem><para>The INLINE pragma has the additional effect of making the
+function body look small, so that when inlining is allowed it is very likely to
+happen.
+</para></listitem>
+</itemizedlist>
+</para>
+<para>The same phase-numbering control is available for RULES
        (<xref linkend="rewrite-rules"/>).</para>
       </sect3>
     </sect2>