From: simonpj Date: Wed, 19 Feb 2003 16:30:17 +0000 (+0000) Subject: [project @ 2003-02-19 16:30:17 by simonpj] X-Git-Tag: Approx_11550_changesets_converted~1140 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=ed6a7f5b5d45ac7139d2ad550914a7b2ffaee79a;p=ghc-hetmet.git [project @ 2003-02-19 16:30:17 by simonpj] Document phase control --- diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index 2d53f08..2b8dcdd 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -3519,21 +3519,13 @@ Assertion failures can be caught, see the documentation for the INLINE pragma -<indexterm><primary>INLINE pragma</primary></indexterm> +<indexterm><primary>INLINE and NOINLINE pragmas</primary></indexterm> <indexterm><primary>pragma, INLINE</primary></indexterm> GHC (with , as always) tries to inline (or “unfold”) functions/values that are “small enough,” thus avoiding the call overhead and possibly exposing other more-wonderful optimisations. - - - -You will probably see these unfoldings (in Core syntax) in your -interface files. - - - Normally, if GHC decides a function is “too expensive” to inline, it will not do so, nor will it export that unfolding for other modules to use. @@ -3550,7 +3542,6 @@ key_function :: Int -> String -> (Bool, Double) {-# INLINE key_function #-} #endif - (You don't need to do the C pre-processor carry-on unless you're going to stick the code through HBC—it doesn't like INLINE pragmas.) @@ -3562,7 +3553,7 @@ very keen to inline it. -An INLINE pragma for a function can be put anywhere its type +Syntactially, an INLINE pragma for a function can be put anywhere its type signature could be put. @@ -3580,11 +3571,8 @@ For example, in GHC's own UniqueSupply monad code, we have: - - - -NOINLINE pragma - + +The NOINLINE pragma NOINLINE pragma pragmaNOINLINE @@ -3602,9 +3590,75 @@ size. NOINLINE (NOTINLINE is specified by Haskell 98 as the standard way to disable inlining, so it should be used if you want your code to be portable). + + + + +Phase control + + Sometimes you want to control exactly when in GHC's pipeline +the INLINE pragma is switched on. Inlining happens only during runs of +the simplifier. Each run of the simplifier has a different +phase number; the phase number decreases towards zero. +If you use +you'll see the sequence of phase numbers for successive runs of the simpifier. +In an INLINE pragma you can optionally specify a phase number, thus: + + You can say "inline f in Phase 2 and all subsequent +phases": + + {-# INLINE [2] f #-} + + + + You can say "inline g in all phases up to, but +not including, Phase 3": + + {-# INLINE [~3] g #-} + + + + If you omit the phase indicator, you mean "inline in all phases". + + +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": + + {-# NOINLINE [2] f #-} + + + + 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 #-} + + + + If you omit the phase indicator, you mean "never inline this function". + + + +The same phase-numbering control is available for RULES (). + + + + + + + +RULES pragma + + +The RULES pragma lets you specify rewrite rules. It is described in +. + + SPECIALIZE pragma @@ -3727,16 +3781,6 @@ pragma. - -RULES pragma - - -The RULES pragma lets you specify rewrite rules. It is described in -. - - - - DEPRECATED pragma @@ -3810,16 +3854,34 @@ From a syntactic point of view: + There may be zero or more rules in a RULES pragma. + + + + + + Each rule has a name, enclosed in double quotes. The name itself has no significance at all. It is only used when reporting how many times the rule fired. - + - There may be zero or more rules in a RULES pragma. +A rule may optionally have a phase-control number (see ), +immediately after the name of the rule. Thus: + + {-# RULES + "map/map" [2] forall f g xs. map f (map g xs) = map (f.g) xs + #-} + +The "[2]" means that the rule is active in Phase 2 and subsequent phases. The inverse +notation "[~2]" is also accepted, meaning that the rule is active up to, but not including, +Phase 2. + + @@ -3828,6 +3890,7 @@ is set, so you must lay out your rules starting in the same column as the enclosing definitions. +