Why isn't purity & co. inferred for all functions?

Robert DaSilva spunit262 at yahoo.com
Fri May 11 16:03:37 PDT 2012


On Friday, 11 May 2012 at 20:29:45 UTC, Walter Bright wrote:
> On 5/11/2012 11:53 AM, Trass3r wrote:
>> It's already inferred for templated functions, so it's 
>> perfectly possible.
>> Also it should be checked anyway, so I get an error message if 
>> I marked
>> something pure or whatever while it actually isn't.
>>
>> The only functions where it can't be inferred and manual 
>> attributes are really
>> needed are function definitions (i.e. no body available).
>>
>> What speaks against it?
>
> Separate compilation.
>
> I.e. given modules A and B:
>
> A
> ===
> int foo() { return 3; }
> ===
>
> B
> ===
> import A;
>
> pure int bar() { return foo(); }
> ===
>
> and the compiler infers purity, so it compiles.
>
> Then, maintenance programmer Fred updates module A to be:
>
> A
> ===
> int x;
> int foo() { return x; }
> ===
>
> and now foo() is no longer pure. He recompiles A, links with 
> existing B.obj, and now whoops! bar() is marked as pure, but is 
> not pure.
>
> This issue does not exist for templates & literals & auto 
> funcs, because already A must be recompiled if B is modified.

I thought Purity was marked in the mangled name, so that should 
give a link error.


More information about the Digitalmars-d mailing list