Editions
Editions provide a way to evolve D by obsoleting features while maintaining compatibility with code that uses those features. Editions are a module level feature, i.e. various sections of a module cannot be set to different editions.
The edition is set either by default, by putting it in the ModuleDeclaration, or with the -edition command line switch.
Editions are meant to be backwards and forwards compatible; it makes it possible for a D module targeting one edition to import a D module targeting any other edition. A template must obey the rules of the edition targeted by the module in which it is defined, not the module in which it is instantiated. Compatibility is at the source code level; no promises of ABI compatibility are made. All code, old and new, must be compiled with the same version of the compiler. Only one version of DRuntime, which must support all existing editions, is to be provided with a compiler release.
Grammar
Edition: DecimalInteger
What can editions do?
- Deleting existing features - This would be the easiest change that could be made in an edition, since it would forbid future code from using deprecated features. Aside from maintaining the compiler for those features, there would be no impact.
- Adding new features - Editions are not necessary for adding new features that are purely additive, i.e., that do not interact with existing features. Editions may backport them to previous editions where possible.
- Changing defaults - Defaults matter because they encourage and influence behavior. Newer editions could change defaults such as @system / @safe and others.
- Changing semantics -
An edition could make it so that:
shared int i; i += 5;
would be lowered to:
shared int i; i.atomicOp!"+="(1);
Specifying the Edition
An edition level is determined by:
- an explicit 4 digit number corresponding to the year in which the desired edition was released
- if no edition is specified, and there is no ModuleDeclaration in the source code, the edition used is the Baseline Edition, which corresponds to 2023.
- if no edition is specified, and there is a ModuleDeclaration in the source code, the edition used is the year the compiler was released.