Universal Function Attribute Inference

Paul Backus snarwin at gmail.com
Thu May 16 21:31:03 UTC 2024


On Thursday, 16 May 2024 at 17:25:53 UTC, Quirin Schroll wrote:
> On Wednesday, 28 February 2024 at 17:18:04 UTC, Paul Backus 
> wrote:
>> Currently, function attributes and function parameter 
>> attributes are only inferred by the D compiler for certain 
>> kinds of functions. This DIP idea proposes that such inference 
>> be extended to all non-overridable functions with bodies.
>
> Why not just provide a tool or a compiler switch that tells you 
> where something should have been annotated, but isn’t?
>
> Something like `-helpAnnotate=safe,system,nogc` and the 
> compiler will tell you which functions in your code base could 
> be `@safe` and/or `@nogc`, but aren’t annotated `@safe` and/or 
> `@nogc`, and which functions are `@system`, but lack the 
> annotation.

If programmers are required to take any kind of manual action to 
add attributes to their functions, no matter how easy or 
straightforward it is, a large portion of them simply will not do 
it. The [default effect][1] is extremely strong.

The [Github comment from Andrei][2] that I linked in the first 
post tells the same story:

> [Jonathan] Aldrich has written a number of papers about 
> augmenting Java with annotations for various properties, 
> notably ArchJava and AliasJava. He has conducted thorough 
> experiments with real developers and projects in researching 
> for this work, and has noticed (and mentioned this in his 
> papers, talks, and our group discussions) that as a rule of 
> thumb developers never go back and annotate their code with the 
> most precise signatures. [...] Although Jonathan's early work 
> focused on offering programmers the ability to add annotations, 
> before long he realized he must extend his work to do 
> annotation inference in order to make it useful.

[1]: https://en.wikipedia.org/wiki/Default_effect
[2]: https://github.com/dlang/dmd/pull/1877#issuecomment-16403663


More information about the dip.ideas mailing list