Description
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.
The primary goal of universal inference is to solve D's "attribute soup" problem without breaking compatibility with existing code. Compatibility with existing code makes universal inference a better solution to this problem than "@safe by default," "nothrow by default," and other similar proposals.
Overridable functions (that is, non-final virtual functions) are excluded from universal inference because their bodies may be replaced at runtime.
For cases where attribute inference is not desired, an opt-out mechanism will be provided.
Currently, .di
files generated by the compiler do not include inferred function attributes. This will have to change.
Related Links
- Discussion of inference pros and cons by Andrei Alexandrescu
- Thoughts on inferred attributes by Adam Ruppe
- DIP70: @api/extern(noinfer) attribute
- Add
@default
attribute