PSA for D project maintainers

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Thu Oct 9 04:43:22 PDT 2014


Please test your work with (at least) a few different D compiler 
versions.

There have been some recent changes that cause somewhat trivial 
incompatibilities between compiler versions, which can be almost 
entirely avoided with some care.


A few simple simple considerations to help your code be more 
robust against recent compiler changes:

@nogc as a postfix doesn't compile in earlier compilers.

redundant attributes (e.g. a member `const void foo() const`) 
don't compile now

C-style array declaration (e.g. `int a[3]`) no longer compile

builtin type constructors (e.g. `float(4)`) are a recent addition 
and will fail on earlier compilers.*

imports have been tightened up. There were cases where missing 
imports were mistakenly OK, these are now compile-time errors.

builtin sort and reverse for arrays are now warnings. When build 
systems use warnings-as-errors by default, this is a breaking 
change.

and more I can't remember right now


I'm not asking for people to butcher their code for 
compatibility, it's perfectly fine to require a recent compiler 
if necessary. Incompatibility with un-released dmd versions is 
obviously OK. I'm asking that the simple low hanging fruit be 
cleared up, to improve the ecosystem.
It's embarrassing to send someone someone some D code to compile 
and use, only to find that due to various different dependencies 
with various tiny problems, there isn't a single released 
compiler that can compile the whole project.

P.S. remember to make a patch release for changes, so your dub 
users will get the benefit.



* I use the results of this mixin exclusively in my code, e.g. 
`float_(4)` instead of `float(4)`. Eventually I will drop it and 
change everything to use the builtin syntax, but not until e.g. 
the ubuntu ppa has a compiler that supports the new syntax

private alias BuiltinTypes = TypeTuple!(bool, byte, ubyte, short, 
ushort, int, uint,
         long, ulong, float, double, real, char, wchar, dchar);

static if(__traits(compiles, mixin(`double(3)`)))
{
     private string builtinConstructCompat()
     {
         string s;
         foreach(T; BuiltinTypes)
         {
             s ~= "alias " ~ T.stringof ~ "_ = " ~ T.stringof ~ 
";\n";
         }
         return s;
     }
}
else
{
     pragma(msg, "no uniform construction for builtin types");
     private string builtinConstructCompat()
     {
         string s;
         foreach(T; BuiltinTypes)
         {
             s ~= "auto " ~ T.stringof ~ "_(Q)(Q v) { return 
v.to!" ~ T.stringof ~ "; }\n";
         }
         return s;
     }
}
mixin(builtinConstructCompat());


More information about the Digitalmars-d mailing list