Automatic attribute inference of functions
Steven Schveighoffer
schveiguy at yahoo.com
Thu May 30 13:49:52 PDT 2013
On Thu, 30 May 2013 16:24:35 -0400, Sebastian Graf
<SebastianGraf at 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
More information about the Digitalmars-d-learn
mailing list