Time to start compiling with -dip25
Johan Engelen
j at j.nl
Tue Jan 1 18:38:57 UTC 2019
On Saturday, 29 December 2018 at 01:08:32 UTC, Walter Bright
wrote:
> As it's going to become the default behavior. Maybe not in the
> next release, but soon.
Let me add some data points to the discussion using Weka's
complex codebase [1].
To make compilation succeed with DIP25, I had to add `return` to
a function or parameter 48 times. That's much less than I was
expecting. I didn't encounter any problems otherwise (dlang
2.083.1 frontend).
Error messages are OK for the compiler expert, but need
improvement: the error message points to the return statement
where something is "leaked", e.g.:
"mecca/lib/reflection.d(1028): Error: returning `this.a` escapes
a reference to parameter `this`, perhaps annotate with `return`"
It's not clear that `return` needs to be added as function
attribute. Also, mentioning escaping a reference to "this" is
confusing and (in some interpretations) incorrect. How about
mentioning something along the lines of "escapes a reference to
member field `this.a`". Also, a reference to DIP25 must be made,
such that people can find documentation more easily (just
addition of "(DIP25)" would already be a big improvement).
The required additions of `return` are soon up for code review. I
didn't find any bugs with it (nor was I expecting to). I want
Weka's code owners to be aware of DIP25 and verify that indeed
that's what they intended in their code (I think the returning of
slices of member arrays is least obvious to spot when data should
outlive the object).
-Johan
[1]
https://dlang.org/blog/2018/12/04/interview-liran-zvibel-of-wekaio/
Weka's codebase is interesting: 280 kloc, _many_ templates +
mixins + static ifs, separate compilation, dirty pointer tricks
in @system code but also many @safe parts.
More information about the Digitalmars-d
mailing list