www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Automatic attribute inference of functions

reply "Sebastian Graf" <SebastianGraf t-online.de> writes:
Hi,

I wonder if there are any plans to allow automatic inference of 
function attributes. I think it's a big hassle having to pollute 
function declarations with things like  safe, nothrow, pure, etc. 
let alone rembering them all.
I know this is done for anonymous functions on a best effort 
basis, so what is holding back that feature for regular 
functions? Is it

1. Incompleteness, e.g. hard to implement correctly for all 
cases, thus we better leave it out entirely
2. The fact that every new keyword (thinking of 'public auto 
infer') bloats the language
3. In practice it isn't as annoying as I might think, YAGNI

or a mixture of all 3?
May 30 2013
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 30 May 2013 16:24:35 -0400, Sebastian Graf  
<SebastianGraf t-online.de> wrote:

 Hi,

 I wonder if there are any plans to allow automatic inference of function  
 attributes. I think it's a big hassle having to pollute function  
 declarations with things like  safe, nothrow, pure, etc. let alone  
 rembering them all.
 I know this is done for anonymous functions on a best effort basis, so  
 what is holding back that feature for regular functions? Is it

 1. Incompleteness, e.g. hard to implement correctly for all cases, thus  
 we better leave it out entirely
 2. The fact that every new keyword (thinking of 'public auto infer')  
 bloats the language
 3. In practice it isn't as annoying as I might think, YAGNI
It's actually 4. separate compilation model. If you are building a module, and it imports a d interface file which has no function body, there is no conceivable way to tell what the attributes should be. For anonymous functions, and template functions, where the entire function body MUST be present in order to use them, the compiler can and does infer attributes. We would need to change the compilation model, and potentially invent a new object file format/linker that tracks the function attributes in order to have this work. -Steve
May 30 2013
parent "Sebastian Graf" <SebastianGraf t-online.de> writes:
On Thursday, 30 May 2013 at 20:49:53 UTC, Steven Schveighoffer 
wrote:
 It's actually 4. separate compilation model.


 If you are building a module, and it imports a d interface file 
 which has no function body, there is no conceivable way to tell 
 what the attributes should be.

 For anonymous functions, and template functions, where the 
 entire function body MUST be present in order to use them, the 
 compiler can and does infer attributes.

 We would need to change the compilation model, and potentially 
 invent a new object file format/linker that tracks the function 
 attributes in order to have this work.

 -Steve
Makes sense, thanks.
May 31 2013