digitalmars.D.learn - Automatic attribute inference of functions
- Sebastian Graf (14/14) May 30 2013 Hi,
- Steven Schveighoffer (13/25) May 30 2013 It's actually 4. separate compilation model.
- Sebastian Graf (3/14) May 31 2013 Makes sense, thanks.
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
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, YAGNIIt'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
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. -SteveMakes sense, thanks.
May 31 2013