On Mon, 18 Jul 2011 16:01:08 -0400, bearophile <bearophileh...@lycos.com> wrote:

Maybe someone has already answered this question, but I don't remember it.

DMD 2.054 is able to infer if a template function is pure. Isn't it a good idea to use the same machinery to infer the unmarked functions too? A template may call a second function that's not annotated with 'pure' despite being pure. If the compiler is able to infer the purity of the second function, then both the template and the second function can be pure. This may offer optimization opportunities. Is doing this too much slow?

It might not be possible. For example, if the target function has no public implementation. This is not the case for templates -- the implementation must be available.

In theory, it's possible for the compiler to mark a function whose source is available as pure, and indeed, most could be. It would be a nice solution to the issue we have now where so much is not pure. At some point though, optional may not be what you want. In fact, you may want the compiler to complain that a function you marked as pure isn't actually pure. Relying on the compiler to determine purity has drawbacks...

-Steve

Reply via email to