static this sucks, we should deprecate it

Don nospam at nospam.com
Tue Jun 2 23:46:01 PDT 2009


Walter Bright wrote:
> Christopher Wright wrote:
>> Eh, this would have to extend to every function, since static ctors 
>> can call functions. And these functions can be provided without 
>> implementations via a .di file. This is fail.
> 
> Such problems are called "whole program analysis", or "interprocedural 
> analysis". There are a lot of cool things you can do with that, but of 
> course they require 100% of the program text to be available to the 
> compiler.
> 
> That isn't going to happen with D (even if all the D source were 
> available, what about calling C binaries?). So we have to rely on other 
> mechanisms.

You could relax the rule: Even if modules A and B both have 'static 
this', there is no circular dependency if:
(1) throughout the whole of module A, it only uses pure functions from 
module B.
OR
(2) if the constructor of module A doesn't directly access static 
variables of module B, and EVERY function it calls is pure.

But that probably doesn't open up very many use cases.



More information about the Digitalmars-d mailing list