On Fri, Aug 23, 2013 at 12:21 PM, Graydon Hoare <gray...@mozilla.com> wrote:

> On 13-08-23 12:16 PM, Simon Sapin wrote:
> > Le 23/08/2013 19:47, Matthieu Monrocq a écrit :
> >> The most trivial mistake is to have `+=` and `+` defined so that `a +=
> >> 5` has a different result than `a = a + 5`
> >
> > Would it work to make `a += b` always expand to `a = a + b`, and have
> > that not be overridable? Or am I missing something else?
>
> Generally these operators want to be able to implement optimized
> versions that do not produce and destroy temporaries.
>

I sympathize with this point, however I think it should be achieved in by
means of something like the GHC RULES pragma[1] where programmers are
allowed to tell the compiler about simple optimizations (rewrite rules), in
their modules. So if you're doing a math module you could detect a*b+c and
change it to a fmadd using a rule, and if there's an earlier pass that
expands a+=b to a=a+b, you could then have a rules pragma that says a=a+b
rewrites to an in-place add.

In practice, rewrite rules have been extraordinarily powerful and pretty
much essential in certain cases. E.g. efficient stream processing (stream
fusion) relies on it.

[1]
http://www.haskell.org/ghc/docs/latest/html/users_guide/rewrite-rules.html

-- 
Sebastian Sylvan
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to