Universal Function Attribute Inference

Dukc ajieskola at gmail.com
Thu Feb 29 13:46:59 UTC 2024


On Wednesday, 28 February 2024 at 17:18:04 UTC, Paul Backus wrote:
> [snip]

I do not personally care whether inference is on or off by 
default. It's easy to toggle when I want anyway. On balance maybe 
I prefer it being off by default, simply because of backwards 
compatibility.

Still, this is a worthwhile direction to pursue. I'm sometimes 
annoyed that I can't specify a return type for a function and 
still turn attribute inference on (without making it a template), 
or that I can't turn attribute inference off for templates or 
function literals. If the proposal will address those, I might 
well support it.

I feel this proposal is orthogonal to the question of attribute 
defaults per se - we will still want to debate the defaults 
regardless of inference - but it will certainly take pressure off 
from that question. Especially if this dip will include an 
ability to turn any function attribute either on, off, or to be 
inferred. In that case it'll be trivial for anyone to add their 
favorite default attributes on top of each module, and 
selectively override those as needed. Something like:

```D
module example;

@safe:
@autoinpure:
@autonothrow:
@gc:

pure int failsCompilationIfImpure(int) => // ..

@trusted int canBeUnsafeInternally(int) => // ...

@autonogc T sometimesNogcTemplate(T)(int) => // ...
```


More information about the dip.ideas mailing list