Personal tools

GHC/Using rules

From HaskellWiki

< GHC(Difference between revisions)
Jump to: navigation, search
 
(add note about -ddump-simpl-iterations)
Line 11: Line 11:
 
* Remember to use the flag <tt>-fglasgow-exts</tt> and the optimisation flag <tt>-O</tt>
 
* Remember to use the flag <tt>-fglasgow-exts</tt> and the optimisation flag <tt>-O</tt>
 
* Use the flag <tt>-ddump-simpl-stats</tt> to see how many rules actually fired.
 
* Use the flag <tt>-ddump-simpl-stats</tt> to see how many rules actually fired.
  +
* For even more detail use <tt>-ddump-simpl-stats -ddump-simpl-iterations</tt> to see the core code at each iteration of the simplifer. Note that this produces '''lots''' of output so you'll want to direct the output to a file or pipe it to <tt>less</tt>. Looking at the output of this can help you figure out why rules are not firing when you expect them to do so.
 
* You need to be careful that your identifiers aren't inlined before your RULES have a chance to fire. To control this we add an <tt>INLINE [1]</tt> pragma to identifiers we want to match in rules, to ensure they haven't disappeared by the time the rule matching comes around.
 
* You need to be careful that your identifiers aren't inlined before your RULES have a chance to fire. To control this we add an <tt>INLINE [1]</tt> pragma to identifiers we want to match in rules, to ensure they haven't disappeared by the time the rule matching comes around.

Revision as of 11:59, 14 July 2006

1 Using Rules in GHC

GHC's rewrite rules (invoked by the RULE pragma) offer a powerful way to optimise your program. This page is place for people who use rewrite rules to collect thoughts about how to use them.

If you aren't already familiar with RULES, read this stuff first:

1.1 Advice about using rewrite rules

  • Remember to use the flag -fglasgow-exts and the optimisation flag -O
  • Use the flag -ddump-simpl-stats to see how many rules actually fired.
  • For even more detail use -ddump-simpl-stats -ddump-simpl-iterations to see the core code at each iteration of the simplifer. Note that this produces lots of output so you'll want to direct the output to a file or pipe it to less. Looking at the output of this can help you figure out why rules are not firing when you expect them to do so.
  • You need to be careful that your identifiers aren't inlined before your RULES have a chance to fire. To control this we add an INLINE [1] pragma to identifiers we want to match in rules, to ensure they haven't disappeared by the time the rule matching comes around.