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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 14 22:52:09 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22277

--- Comment #5 from Andrei Alexandrescu <andrei at erdani.com> ---
(In reply to Max Samukha from comment #4)
> (In reply to Andrei Alexandrescu from comment #3)
> > This has been discussed a number of times in the past. One proposal was that
> > `void` pure functions must always be called - the compiler must assume since
> > they're `void` and pure (a contradiction) then they do something
> > surreptitious and must not be elided.
> 
> Could you explain why void and pure is a contradiction?

`void` implies "all of my work is done via side effects" and pure implies
"there is no side effect". In D we have the relaxation of weak purity that
makes things less clear cut. In the case of `free` in the example the parameter
is `immutable` which makes the function strongly pure; a strongly pure function
that returns `void` has no way to effect anything within the definition of the
language.

--


More information about the Digitalmars-d-bugs mailing list