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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 4 23:45:44 UTC 2021


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

--- Comment #15 from timon.gehr at gmx.ch ---
(In reply to Ate Eskola from comment #14)
> And Andrei killed that before the draft review? What was the rationale?

I was too busy to spend a lot of time on it, especially given that Andrei was
not a huge fan of the details of my idea. I think they just wanted a very
specialized solution that works for reference counting. Andrei and Razvan tried
to finish the proposal, but they completely changed it in the process:

https://github.com/RazvanN7/DIPs/blob/Mutable_Dip/DIPs/DIP1xxx-rn.md

I then requested to be removed as co-author as I did not think it was a good
approach, and they ultimately did not go ahead with that DIP.

Regarding Andrei's proposal of never eliding pure `void` functions, I think
that is a bad idea, e.g.:

auto a = [1,2,3];
writeln(a);
// a is dead now
void foo(int[] x)pure{ x[]*=2; }
foo(a); // this call can be elided, as a will never be read again

I really think the only sane way to make progress on this is to specify
precisely which rewrites are allowed for data and functions of each
qualification, giving special treatment low-level functions that implement the
high-level semantics, as in my draft. `__mutable` fields and functions solve a
lot of issues at once. (E.g., they can be used to initialize `immutable` arrays
in druntime, for sound lazy initialization of `immutable` data, or to store
metadata such as reference counts.)

Until such a solution is specced out, I think DMD should probably refrain from
optimizing on qualifiers.

--


More information about the Digitalmars-d-bugs mailing list