Rewrite rules

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Rewrite rules

Erik de Castro Lopo-34
HI all,

I'm having an look at rewrite rules, but something bugs me a little.
How do I tell if my rewrite rules are firing or not? Even If I
introduce deliberate errors in the function name that is being
re-written I still don't get so much as a warning.

Clues?

Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Rewrite rules

Michael Snoyman
Could be I'm misunderstanding, but are you looking for -ddump-rule-firings?

On Thu, Jan 12, 2017 at 10:46 AM, Erik de Castro Lopo <[hidden email]> wrote:
HI all,

I'm having an look at rewrite rules, but something bugs me a little.
How do I tell if my rewrite rules are firing or not? Even If I
introduce deliberate errors in the function name that is being
re-written I still don't get so much as a warning.

Clues?

Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Rewrite rules

Erik de Castro Lopo-34
Michael Snoyman wrote:

> Could be I'm misunderstanding, but are you looking for -ddump-rule-firings?

Wasn't aware of that, but my question was a little more general.

If I write a library that includes rewrite rules, how can I ensure
that they fire in client code that someone else writes? What guarantees
(however loose) are there?

Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Rewrite rules

Joachim Breitner-2
Hi,

Am Freitag, den 13.01.2017, 20:27 +1100 schrieb Erik de Castro Lopo:

> Michael Snoyman wrote:
>
> > Could be I'm misunderstanding, but are you looking for -ddump-rule-
> > firings?
>
> Wasn't aware of that, but my question was a little more general.
>
> If I write a library that includes rewrite rules, how can I ensure
> that they fire in client code that someone else writes? What
> guarantees (however loose) are there?
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.

Greetings,
Joachim

--
Joachim “nomeata” Breitner
  [hidden email]https://www.joachim-breitner.de/
  XMPP: [hidden email] • OpenPGP-Key: 0xF0FBF51F
  Debian Developer: [hidden email]
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Rewrite rules

Erik de Castro Lopo-34
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/
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Rewrite rules

David Feuer
No. The part in quotes is the *name* of the rewrite rule, which is reported to the user when GHC is called with things like -ddump-rule-rewrites and is otherwise completely ignored.

On Jan 16, 2017 4:09 AM, "Erik de Castro Lopo" <[hidden email]> wrote:
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/
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users