Against enforce()
Steven Schveighoffer
schveiguy at yahoo.com
Thu Mar 17 10:50:48 PDT 2011
On Thu, 17 Mar 2011 13:30:21 -0400, Simen kjaeraas
<simen.kjaras at gmail.com> wrote:
> On Thu, 17 Mar 2011 18:17:08 +0100, Steven Schveighoffer
> <schveiguy at yahoo.com> wrote:
>
>> On Thu, 17 Mar 2011 12:09:50 -0400, bearophile
>> <bearophileHUGS at 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
More information about the Digitalmars-d
mailing list