[Issue 22277] removing strongly pure function calls is an incorrect optimization

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 22 09:41:28 UTC 2021


--- Comment #9 from Max Samukha <maxsamukha at gmail.com> ---

(In reply to João Lourenço from comment #8)
> > I am not sure this premise is true. A function returning 'void' may do no work at all or do work without observable side effects. I need to think more about this, thank you.
> If the function is strongly pure that statement is correct. To do some work,
> then it needs to be impure, or in the case of D, weakly pure. An example is
> all the pure void functions that mess around with values of `this`.

It's not correct at least in one case: when the function doesn't do work at
all. 'void foo() {}' is a strongly pure function returning the value of the
unit type. And it's not even useless - it would've found its use in generic
code if D's unit type wasn't broken in other respects.

Whether encapsulated side effects qualify to be called "work", I don't know.


More information about the Digitalmars-d-bugs mailing list