Steven Schveighoffer wrote:
On Thu, 17 Mar 2011 13:30:21 -0400, Simen kjaeraas <simen.kja...@gmail.com> wrote:

On Thu, 17 Mar 2011 18:17:08 +0100, Steven Schveighoffer <schvei...@yahoo.com> wrote:

On Thu, 17 Mar 2011 12:09:50 -0400, bearophile <bearophileh...@lycos.com> wrote:

Steven Schveighoffer:

The only problem I see with it is the inline-killing.

Please don't ignore the purity-killing :-)

I think this is not as much an easy fix. By changing one line in enforce, every instance becomes inlinable. By making enforce also pure, it doesn't automatically make all users of enforce pure.

I thought that lazy enforce cannot be pure, but I realize now that it can, as long as the delegate is pure. However, I think the compiler won't cooperate with that.

Not currently, at least. This made me wonder. A delegate created inside a
pure function would have to be pure while in the scope of that function,
right? Seems to me that should be possible to implement.

As long as the delegate does not access shared/global data, it should be able to be pure. Even delegates which modify TLS data should be able to be pure (weak-pure, but still pure).

This should be easy to enforce when the delegate is created automatically from an expression using a lazy call. However, we need some implicit casting rules for pure delegates into non-pure ones.

-Steve

Fortunately, we don't. Delegates created via lazy are not the same as external delegates; they're an even simpler case of delegate literals. This means that at the moment that a lazy function is called, all of the code of the delegate is available. Furthermore, the caller function must access every expression inside the lazy delegate; if the caller is marked as pure, every expression inside the lazy delegate must also be pure.

So the existing checks work just fine.
Patch in bug 5750.

Reply via email to