Why aren't function attributes inferred?
Sean Eskapp
eatingstaples at gmail.com
Sat Aug 20 11:16:12 PDT 2011
== Quote from Timon Gehr (timon.gehr at gmx.ch)'s article
> On 08/20/2011 06:50 PM, Sean Eskapp wrote:
> > Since the compiler can clearly tell when a function is not const, safe, pure,
> > or nothrow, why can't they just be assumed, unless proven otherwise?
> This sort of inference is already done for function/delegate literals
> and template functions.
> It is not done for other functions, because eg. their code is not
> necessarily available.
> int foo(int x) pure; // how would you infer purity here?
> Also, if normal functions would infer those attributes, they would be
> leaking implementation details all over the place. If a pure
> implementation would have to be changed to a non-pure one, all code that
> relied on the undocumented but inferred purity would break.
I understand your point about functions with no definition, but your point about
normal functions holds true anyway. If I have a pure function foo(), and a
function bar() which relies on the purity of foo(), then changing the purity of
foo() would break bar()'s internals. Either way, purity should still be inferred
at optimization time, where it could really make a difference!
More information about the Digitalmars-d-learn
mailing list