Rewrite rules

Erik de Castro Lopo mle+hs at mega-nerd.com
Mon Jan 16 09:09:13 UTC 2017


Joachim Breitner wrote:

> very little. The best one can do right now is to know enough about Core
> and the inliner to predict when things are going to be inlined and when
> not, what else can go wrong (wrappers maybe?), add the necessary
> controls (`NOINLINE [0]` etc.), and then hope for the best. And track
> down any instances of failed rewriting that you learn about.
> 
> You might also be able to set up your code so that it fails (at
> runtime, with error) if the desired rules did not fire. This would be
> nicer if we had https://ghc.haskell.org/trac/ghc/ticket/9180.
> 
> You can also ask for review if it is public code.

Ok, I'm heading in this direction and then I figure out that the parser
for the rewrite rules doesn't even reject obvious syntax errors.

Say I have a data types:

    data Word128 = Word128 Word64 Word64

and inspired by the `fromIntegral` rules for Word64 I write:

    {-# RULES
    "fromIntegral/Word64->Word128"  fromIntegral = \w64 -> Word128 0 w64
       #-}

all is fine and dandy. However if I introduce an obvious syntax error
like reversing the `->`:

    {-# RULES
    "fromIntegral/Word64<-Word128"  fromIntegral = \w64 -> Word128 0 w64
       #-}

I don't get any warning or anything. I've read the docs for rewrite
rules:

    https://downloads.haskell.org/~ghc/8.0.1/docs/html/users_guide/glasgow_exts.html#rewrite-rules

but they are rather sparse and again are very short on guarantees.

Have I just managed to find myself a new project?


Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the Glasgow-haskell-users mailing list