[phobos] [D-Programming-Language/phobos] 4f28db: not really pure
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jun 28 12:39:49 PDT 2011
On 2011-06-28 08:22, Don Clugston wrote:
> On 28 June 2011 15:47, Steve Schveighoffer <schveiguy at yahoo.com> wrote:
> > By definition, a strong-pure function must have all parameters immutable
> > or implicitly convertible to immutable. This function does not pass
> > this test.
> >
> > However, the function call *could* be considered strong pure if the S
> > instance itself is immutable (at the call site). Which means S s would
> > have to be immutable, and the original assignment to &w does not
> > compile. It was you who brought up this idea in the first place, if you
> > recall :)
>
> Yes, exactly.
>
> > This means whether a function that takes const parameters is weak-pure or
> > strong-pure can depend on what values you call it with.
>
> Yes, though up to now it's only been very conservative: it is
> strong-pure only if all parameters are immutable.
>
> > But, Walter's changes to phobos seems to imply that member functions
> > cannot even be weak-pure. I don't see any reason to disallow the member
> > functions as weak-pure (and I think you are saying the same thing). If
> > this is Walter's case, I think it has no merit, but I'll reserve
> > judgment until I know that this is in fact Walter's concern.
>
> Now my guess to what's happened here is that the 'this' parameter had
> escaped checks, so functions were erroneously being marked as strongly
> pure.
> But this shouldn't prevent them from being marked as weakly pure. But
> I'm only guessing, maybe Walter has a different concern.
>
> > BTW, immutable member functions could definitely be strong-pure
> > (depending on the other parameters).
>
> They could, but such cases are exceedingly rare and not very useful. I
> don't think they matter. It's weak purity that matters for member
> functions, since it allows them to be used in pure (static) functions.
Ideally, under at least some circumstances, const member functions would be
considered strongly pure given that it's known that the object that they're
called on isn't altered within the expression. I don't know how well that that
would actually work though. Certainly, the rules on weak purity would have to
be relaxed a bit based on how the functions are called (which Steve was
talking about), so I wouldn't expect it to be happening at this point
regardless. But ideally it would.
- Jonathan M Davis
More information about the phobos
mailing list