[Haskell-cafe] Problem finding rewrite rules

Dominik Peteler haskell at with-h.at
Fri Aug 29 22:16:12 UTC 2014


Hello Thomas,

thank you very much !
This is exactly what I was looking for.
Apparently I missed the match in MkId.hs.

Regards

Dominik



On Fri 2014-08-29 18:42, Thomas Horstmeyer wrote:
> Grepping for "Class op" brought up a candidate for the first rule:
> 
> ./compiler/basicTypes/MkId.lhs-313-
>     -- This is the built-in rule that goes
>     -- 	    op (dfT d1 d2) --->  opT d1 d2
> 
> 
> A few other greps let me think that the other rule is probably one of those
> generated by the function primOpRules in ./compiler/prelude/PrelRules.lhs
> which is called from ./compiler/basicTypes/MkId.lhs:911
> The following comment can be found in the file:
> 
> "Note [Constant folding]
> ~~~~~~~~~~~~~~~~~~~~~~~
> primOpRules generates a rewrite rule for each primop
> These rules do what is often called "constant folding"
> E.g. the rules for +# might say
>         4 +# 5 = 9
> Well, of course you'd need a lot of rules if you did it
> like that, so we use a BuiltinRule instead, so that we
> can match in any two literal values.  So the rule is really
> more like
>         (Lit x) +# (Lit y) = Lit (x+#y)
> where the (+#) on the rhs is done at compile time
> 
> That is why these rules are built in here."
> 
> 
> Hope this helps,
> Thomas
> 
> 
> Am 28.08.2014 um 22:40 schrieb Dominik Peteler:
> >Dear Cafe,
> >
> >I'm currently looking at the optimization GHC is doing and I cannot find
> >the rewrite rules it fires. When I run my test code with
> >
> >     ghc -O2 -ddump-simpl-stats -ddump-rule-firings Main.hs
> >
> >GHC shows the rules which are fired:
> >
> >     ...
> >     Rule fired: Class op +
> >     ...
> >     Rule fired: +##
> >     ...
> >
> >and so on. Nothing new, nothing special.
> >However, where do I find the definitions of these rules ?
> >I grepped[1] the GHC code base and found nothing so far. I didn't find any
> >documentation on it either.
> >
> >Can anyone point me to some place where I can find further information ?
> >
> >Thank you folks and have a nice day
> >
> >Dominik
> >
> >PS.: Since I'm working on numerical stable code with directed rounding
> >I'm only interested in these two particular rules. I suspect them to
> >break parts of my code.
> >
> >[1] http://jamie-wong.com/2013/07/12/grep-test
> >
> >
> >
> >_______________________________________________
> >Haskell-Cafe mailing list
> >Haskell-Cafe at haskell.org
> >http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140830/0d1c6e47/attachment.sig>


More information about the Haskell-Cafe mailing list