Universal Function Attribute Inference

Paul Backus snarwin at gmail.com
Thu Feb 29 23:09:56 UTC 2024


On Thursday, 29 February 2024 at 14:03:30 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> We will need to consider adding the opposite of a given 
> attribute, to maximize the possibility of inference not 
> interfering with peoples code negatively.

I agree that adding opposites for the remaining function 
attributes without them is a good idea, but it isn't strictly 
necessary. Even if you only have a single @noinfer attribute, you 
can simulate "impure" and "@gc" like this:

     @noinfer @safe nothrow @nogc
     void inferImpure() {}

     @noinfer @safe pure nothrow
     void inferGC() {}

     // Will never be pure or @nogc
     void example()
     {
         inferImpure();
         inferGC();

         // etc.
     }

The main benefit of @noinfer (compared to impure/@gc) is that it 
does not require adding a new reserved word. Since one of the 
main benefits of universal inference is that it works with 
existing code, I plan to propose it for inclusion in the base 
language edition, and that means avoiding breaking language 
changes.


More information about the dip.ideas mailing list