X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fglasgow_exts.xml;h=8a213683e4edfdd881f2acdb97b9ddfbebdac50b;hb=f2dcf256399e9a2de6343c625630b51f8abf4863;hp=c1dca222a9175babae0a1125d5ac529460b1a427;hpb=aa2c486e51caa0386aaff0d1b866a60316500b41;p=ghc-hetmet.git diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index c1dca22..8a21368 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -244,7 +244,8 @@ documentation describes all the libraries that come with GHC. Enables Template Haskell (see ). Currently also implied by + linkend="template-haskell"/>). This flag must + be given explicitly; it is no longer implied by . Syntax stolen: [|, @@ -1009,8 +1010,8 @@ in a type synonym, thus: f :: Discard a f x y = (x, show y) - g :: Discard Int -> (Int,Bool) -- A rank-2 type - g f = f Int True + g :: Discard Int -> (Int,String) -- A rank-2 type + g f = f 3 True @@ -4086,9 +4087,8 @@ Tim Sheard is going to expand it.) constructions. You need to use the flag to switch these syntactic extensions on - ( is currently implied by - , but you are encouraged to - specify it explicitly). + ( is no longer implied by + ). @@ -5010,63 +5010,58 @@ key_function :: Int -> String -> (Bool, Double) If you use 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: - + phase number, thus: - You can say "inline f in Phase 2 - and all subsequent phases": - - {-# INLINE [2] f #-} - - - - + "INLINE[k] f" means: do not inline + f + until phase k, but from phase + k onwards be very keen to inline it. + - You can say "inline g in all - phases up to, but not including, Phase 3": - - {-# INLINE [~3] g #-} - - - - + "INLINE[~k] f" means: be very keen to inline + f + until phase k, but from phase + k onwards do not inline it. + - If you omit the phase indicator, you mean "inline in - all phases". - + "NOINLINE[k] f" means: do not inline + f + until phase k, but from phase + k onwards be willing to inline it (as if + there was no pragma). + + + "INLINE[~k] f" means: be willing to inline + f + until phase k, but from phase + k onwards do not inline it. + - - You can use a phase number on a NOINLINE pragma too: - - - - You can say "do not inline f - until Phase 2; in Phase 2 and subsequently behave as if - there was no pragma at all": +The same information is summarised here: - {-# NOINLINE [2] f #-} - - - + -- 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 - - You can say "do not inline g in - Phase 3 or any subsequent phase; before that, behave as if - there was no pragma": - - {-# NOINLINE [~3] g #-} + {-# INLINE f #-} -- Yes Yes + {-# NOINLINE f #-} -- No No - - - - - If you omit the phase indicator, you mean "never - inline this function". - - - - 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: + +For both INLINE and NOINLINE, the phase number says +when inlining is allowed at all. +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. + + + +The same phase-numbering control is available for RULES (). @@ -5994,6 +5989,74 @@ r) -> + +Special built-in functions +GHC has a few built-in funcions with special behaviour, +described in this section. All are exported by +GHC.Exts. + + The <literal>inline</literal> function + +The inline function is somewhat experimental. + + inline :: a -> a + +The call (inline f) arranges that f +is inlined, regardless of its size. More precisely, the call +(inline f) rewrites to the right-hand side of f's +definition. +This allows the programmer to control inlining from +a particular call site +rather than the definition site of the function +(c.f. INLINE pragmas ). + + +This inlining occurs regardless of the argument to the call +or the size of f's definition; it is unconditional. +The main caveat is that f's definition must be +visible to the compiler. That is, f must be +let-bound in the current scope. +If no inlining takes place, the inline function +expands to the identity function in Phase zero; so its use imposes +no overhead. + + If the function is defined in another +module, GHC only exposes its inlining in the interface file if the +function is sufficiently small that it might be +inlined by the automatic mechanism. There is currently no way to tell +GHC to expose arbitrarily-large functions in the interface file. (This +shortcoming is something that could be fixed, with some kind of pragma.) + + + + The <literal>inline</literal> function + +The lazy function restrains strictness analysis a little: + + lazy :: a -> a + +The call (lazy e) means the same as e, +but lazy has a magical property so far as strictness +analysis is concerned: it is lazy in its first argument, +even though its semantics is strict. After strictness analysis has run, +calls to lazy are inlined to be the identity function. + + +This behaviour is occasionally useful when controlling evaluation order. +Notably, lazy is used in the library definition of +Control.Parallel.par: + + par :: a -> b -> b + par x y = case (par# x) of { _ -> lazy y } + +If lazy were not lazy, par would +look strict in y which would defeat the whole +purpose of par. + + + + + Generic classes