Thread overview | |||||
---|---|---|---|---|---|
|
May 30, 2013 Automatic attribute inference of functions | ||||
---|---|---|---|---|
| ||||
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 Re: Automatic attribute inference of functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sebastian Graf | 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 31, 2013 Re: Automatic attribute inference of functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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.
|
Copyright © 1999-2021 by the D Language Foundation