Change Log: 2.078.0
Download D 2.078.0
released Jan 01, 2018
Compiler changes
- opDispatch resolution in with statements
- Generate header files using do instead of body as per DIP1003
- pragma(crt_constructor) and pragma(crt_destructor) were added
- Subtraction of pointers that point to different types has been deprecated.
- Variadic template arguments no longer require alias workaround
- fix Issue 16997 - Integral promotion rules not being followed for unary + - ~ operators
- Optional ModuleInfo
- Added RAII and try-finally support for -betterC mode.
- Windows: dmd can now detect Visual Studio installation paths
Runtime changes
Library changes
- mean Was Added To std.algorithm
- findSkip can now skip elements using just a predicate function
- std.array.byPair now returns a NamedTuple
- std.container.dlist supports linearRemoveElement
- std.container.slist supports linearRemoveElement
- Deprecate save for std.range.package.Transposed
- std.typecons.Ternary.opBinary supports bool bitwise operands
List of all bug fixes and enhancements in D 2.078.0.
Compiler changes
- opDispatch resolution in with statements
opDispatch resolution in with statements has been modified to bring it into compliance with the existing scope resolution rules in the language specification. See WithStatement in the language specification.
Prior to this release, the following code would not compile because the compiler would not be able to resolve the second call to f(), as Bar does not implement f() or opDispatch.
import std.stdio; struct Foo { void opDispatch(string name)() { mixin("writeln(\"Foo.opDispatch!" ~ name ~ "\");"); } } struct Bar { // `Bar` does not implement `f()` or `opDispatch` } void main() { Foo foo; Bar bar; with(foo) { f(); // prints "Foo.opDispatch!f" with(bar) { f(); // Prior to this Release: Error: undefined identifer `f` // Starting with this release: Prints "Foo.opDispatch!f". // `f`'s resolution is forwarded up the scope hierarchy. } } }
Starting with this release, the second call to f() will be forwarded up the scope hierarchy, matching the implementation of Foo.opDispatch.
- Generate header files using do instead of body as per DIP1003
Support for DIP1003 was added in release 2.075.0. Use of body in an error message and header file generation has been fixed in this release.
- pragma(crt_constructor) and pragma(crt_destructor) were added
This allows programs to run initialization code before or cleanup code after C main.
In particular those pragmas can be used in -betterC code as substitutes for shared static this() and shared static ~this().
Note: At the time of execution druntime is not initialized.
Note: The order in which constructors are executed is unspecified.
import core.stdc.stdio; pragma(crt_constructor) void init() { puts("init"); } pragma(crt_destructor) void fini() { puts("fini"); } extern(C) int main() { puts("main"); }
- Subtraction of pointers that point to different types has been deprecated.
The language specification reads: "If both operands are pointers, and the operator is -, the pointers are subtracted and the result is divided by the size of the type pointed to by the operands. It is an error if the pointers point to different types."
Prior to this release, the compiler allowed the following pointer arithmetic:
void* p1; int* p2; auto p3 = p2 - p1;
Starting with this release, the subtraction of pointers that point to different types will emit a deprecation warning. The warning will remain in place for at least a year, after which it will be changed to an error.
- Variadic template arguments no longer require alias workaround
Prior to this release, the following code would not compile.
class C(Types...) { void apply(U)(U delegate(Types[0]) f0) { } // Error: cannot deduce function from argument types } void test() { C!int c; int f(int) { return 0; } c.apply(&f); }
It could be worked around by aliasing the individual template arguments.
class C(Types...) { alias Types[0] T0; void apply(U)(U delegate(T0) f0) { } // OK }
Starting with this release, the workaround is no longer required.
- fix Issue 16997 - Integral promotion rules not being followed for unary + - ~ operators
To follow the C integral promotion rules, types are promoted to int before the unary + - or ~ operators are applied. Existing D does not do this.
This is corrected when one of the following command line switches are used:
-transition=intpromote -transition=16997
It affects operands of type byte, ubyte, short, ushort, char, and wchar. The operands are promoted to int before the operator is applied. The result type will now be int.
The values computed will be different for some values of the operands:
- All values of - and ~ applied to ubyte, ushort, char, and dchar operands will change.
- The values of -byte(-128) and -short(-32768) will change.
If one of the '-transition=' switches is not specified, a deprecation will be emitted for these operations. To fix the deprecation and work as desired with or without the '-transition=' switch:
Option 1:
Rewrite op b as op int(b) to use correct, i.e. C-like, behavior.
Option 2:
Rewrite op b as typeof(b)(op int(b)) to preserve the old behavior.
Once deprecated this will become an error, and then the C-like behavior will become the default.
- Optional ModuleInfo
ModuleInfo is not a necessary feature of D. There are use cases where the program author may choose to provide an alternate implementation of the D runtime that does not include ModuleInfo. This could be for interoperability with other software or to reduce the footprint of D programs in resource constrained platforms.
Prior to this release, the compiler would emit an error if ModuleInfo was not declared in the D runtime.
Platform support is provided by the D runtime. ModuleInfo is declared in object.d. Therefore, the compiler can see, at compile-time, whether or not the platform has provided support for ModuleInfo and generate object code accordingly.
Starting with this release, if ModuleInfo is not deсlared in the D runtime, the compiler will simply not generate ModuleInfo instances.
This should reduce friction for those wishing to incrementally port D to new platforms and use D in a more pay-as-you-go fashion.
- Added RAII and try-finally support for -betterC mode.
This also means that scope(exit) statements will also work, because they are internally lowered to try-finally statements.
This does not mean that exceptions are supported. Throwing, catching, and stack frame unwinding is not supported, as that requires support from Phobos.
It means that, for RAII, when variables go out of lexical scope their destructors get run. When try blocks from try-finally statements exit, the code in the finally block is run.
- Windows: dmd can now detect Visual Studio installation paths
dmd now determines the environment variables that are usually set if the "Command Line prompt for Visual Studio" link is used to open a console window (or vcvarsall.bat is executed). This includes Windows SDK directories and Visual C library directories. When compiling with -m64 or -m32mscoff this allows dmd to invoke the linker without having a Visual Studio version preselected by the installer.
In particular, the variables WindowsSdkDir, WindowsSdkVersion, UniversalCRTSdkDir, UCRTVersion, VSINSTALLDIR, VisualStudioVersion, VCINSTALLDIR and VCTOOLSINSTALLDIR are determined from the registry if they are not set in the environment or sc.ini.
Supported Windows SDK range from 7.0A to 10.x, supported Visual Studio Versions are VS 2008 to VS 2017. If multiple versions are installed, highest versions are preferred.
Runtime changes
- core.runtime now allows more fine-grained control over unittests.
core.runtime.extendedModuleUnitTester property allows specifying information about the tests run, and how to handle the result. See documentation for core.runtime.UnitTestResult for details.
core.runtime.moduleUnitTester (setting a unittest handler that returns bool) will continue to be supported for legacy projects.
import core.runtime; import core.stdc.stdio: printf; UnitTestResult customTester() { UnitTestResult ret; // run only the tests in my package immutable prefix = "myPackage."; foreach (m; ModuleInfo) { if (m.unitTest !is null && m.name.length >= prefix.length && m.name[0 .. prefix.length] == prefix) { ++ret.executed; // count unit tests run try { m.unitTest(); ++ret.passed; // count unit tests passed } catch(Throwable t) { auto msg = t.toString(); printf("%.*s\n", cast(uint)msg.length, msg.ptr); } } } // always summarize ret.summarize = true; // only unit testing, don't ever run main ret.runMain = false; } version(unittest) static shared this() { Runtime.extendedModuleUnitTester = &customTester; }
- The runtime learned a few new options to customize how coverage reports are created.
The format is the same as with the GC but using covopt as suffix, for example you can pass options separating them with spaces like `--DRT-covopt "merge:1 dstpath:/tmp"`.
These are the currently accepted options:
- merge
- Merge the current run with existing reports if 1, or overwrite the existing reports if 0.
- srcpath
- Set path to where source files are located.
- dstpath
- Set path to where listing files are to be written.
Library changes
- mean Was Added To std.algorithm
std.algorithm.iteration.mean accurately finds the mean (a.k.a the average) of any range of number-like elements.
import std.algorithm.iteration : mean; import std.math : approxEqual; int[] arr1 = [1, 2, 3]; real[] arr2 = [1.5, 2.5, 12.5]; assert(arr1.mean.approxEqual(2)); assert(arr2.mean.approxEqual(5.5)); // user defined number types also work import std.bigint : BigInt; auto bigint_arr = [ BigInt("1_000_000_000_000_000_000"), BigInt("2_000_000_000_000_000_000"), BigInt("3_000_000_000_000_000_000"), BigInt("6_000_000_000_000_000_000") ]; auto seed = BigInt(0); assert(bigint_arr.mean(seed) == BigInt("3_000_000_000_000_000_000"));
- findSkip can now skip elements using just a predicate function
Previously, std.algorithm.searching.findSkip could only be used to find a specific string. Now, a new overload allows elements in a range to be skipped over if the passed function returns true:
import std.ascii : isWhite; string s = " abc"; assert(findSkip!isWhite(s) == 3 && s == "abc"); assert(!findSkip!isWhite(s) && s == "abc");
- std.array.byPair now returns a NamedTuple
std.array.byPair now returns a named tuple.
import std.array : byPair; import std.typecons : Tuple; int[string] dict = ["b": 2, "c": 3]; auto pairs = dict.byPair; static assert(is(typeof(pairs.front) : Tuple!(string,int))); // access by index (existing way) assert(pairs.front[0] == "b"); assert(pairs.front[1] == 2); // access by name (enabled with this release) assert(pairs.front.key == "b"); assert(pairs.front.value == 2);
- std.container.dlist supports linearRemoveElement
linearRemoveElement removes the first occurence of an element from the dlist
import std.container : Dlist; import std.algorithm.comparison : equal; auto a = DList!int(-1, 1, 2, 1, 3, 4); a.linearRemoveElement(1); assert(equal(a[], [-1, 2, 1, 3, 4]));
- std.container.slist supports linearRemoveElement
linearRemoveElement removes the first occurence of an element from the slist
import std.container : Slist; import std.algorithm.comparison : equal; auto a = SList!int(-1, 1, 2, 1, 3, 4); a.linearRemoveElement(1); assert(equal(a[], [-1, 2, 1, 3, 4]));
- Deprecate save for std.range.package.Transposed
Transposed is incorrectly marked as a forward range. Its popFront primitive cannot be used without affecting any other copies made with save. save will be removed from Transposed in November 2018.
auto x = [[1,2,3],[4,5,6]].transposed; auto y = x.save; y.popFront; assert(x.equal([[1,4],[2,5],[3,6]])); // FAILS, x is really [[2,5],[3,6]]
For more details, please see the respective Bugzilla issue.
- std.typecons.Ternary.opBinary supports bool bitwise operands
Now std.typecons.Ternary can be used in bitwise operations with bools:
import std.typecons : Ternary; Ternary a = Ternary(true); assert(a == Ternary.yes); assert((a & false) == Ternary.no); assert((a | false) == Ternary.yes); assert((a ^ true) == Ternary.no); assert((a ^ false) == Ternary.yes);
List of all bug fixes and enhancements in D 2.078.0:
DMD Compiler regressions
- Bugzilla 17246: [REG2.053] Extra destructor call.
- Bugzilla 17371: [REG 2.074.0] di generation broken for anonymous classes
- Bugzilla 17559: [REG2.073.0] Wrong line number in stack trace
- Bugzilla 17915: [REG 2.073] core.exception.AssertError@ddmd/optimize.d(614): Assertion failure
- Bugzilla 17955: compiler segfault in DsymbolSemanticVisitor::visit(UnittestDeclaration*)
- Bugzilla 18020: [Reg 2.078] no property opCmp for anon class
- Bugzilla 18093: [Reg 2.071] MSCOFF: dmd crashes when overriding a C++ method in a mixin template
- Bugzilla 18141: [REG2.078a] dmd -v no longer prints predefs
DMD Compiler bugs
- Bugzilla 5332: Undefined reference to zero length array
- Bugzilla 6400: opDispatch with WithStatement
- Bugzilla 8262: ICE(mtype.c) alias this to alias of an expression tuple
- Bugzilla 9290: Ability to modify immutable struct members in static array assignment
- Bugzilla 10310: VRP for bitwise &|^ does not always produce the tightest bounds.
- Bugzilla 11006: Subtraction of pointers for void and non-void types compiles
- Bugzilla 12385: Enum member should not be modifiable when the member is immutable
- Bugzilla 12496: __traits(parent, x) returns incorrect type
- Bugzilla 12625: [scope] [DIP1000] implicit slicing of RValue static array should be illegal
- Bugzilla 15094: __traits(getMember) fails when the source is a struct/class field
- Bugzilla 15243: rejects-valid on variadic
- Bugzilla 15289: VRP not working as expected on division
- Bugzilla 15290: length of associative array literal with duplicate keys is wrong
- Bugzilla 16649: Header gen skips parens
- Bugzilla 16694: ICE on taking address of export function (declaration-only)
- Bugzilla 16997: Integral promotion rules not being followed for unary + - ~ expressions
- Bugzilla 17096: many traits accept an invalid parameter count without error
- Bugzilla 17167: dmd fails to write to file or create directory with more than 248 characters in the path
- Bugzilla 17382: void main(){}pragma(msg,main()); crashes DMD
- Bugzilla 17585: Wrong error message for deprecated overrides
- Bugzilla 17586: Overriding a deprecated base class function gives no warning
- Bugzilla 17842: [scope] array append allows for escaping references
- Bugzilla 17843: -betterC struct with double field generates references to TypeInfo
- Bugzilla 17853: Switch statement without braces only works with one case
- Bugzilla 17900: FreeBSD 10.3 runnable/cpp_abi_tests.d(94): Assertion failure (test suite)
- Bugzilla 17908: Can't alias an overload set with disabled function
- Bugzilla 17927: [scope] scope inout parameter value can be escaped via return
- Bugzilla 17934: [scope] scopeness entrypoint for unique/ref-counted missing
- Bugzilla 17935: [scope] auto-generated destructor not scope aware
- Bugzilla 17940: bool function parameters loaded from struct sometimes miscompiled with -O
- Bugzilla 17944: MSCOFF: debug info not compatible with LLVMs LLD
- Bugzilla 17947: C++ std::pair::swap mangled incorrectly
- Bugzilla 17976: core.exception.AssertError@ddmd/dsymbolsem.d(1624)
- Bugzilla 17997: autotester's d_do_test has strange failures with Win32
- Bugzilla 18013: DMD test suite assertion failure in test_cdvecfill.d
- Bugzilla 18014: DMD test suite fails to link on Linux distros where PIC/PIE is enforced
- Bugzilla 18045: Temporary created during comparison not destroyed
- Bugzilla 18099: betterC check throw statements error!
DMD Compiler enhancements
- Bugzilla 4946: Not good error message with wrongly positioned 'const'
- Bugzilla 17256: Inconsistent output between json and ddoc
- Bugzilla 17868: add pragma(crt_con/destructor)
- Bugzilla 17878: Add __traits(isFuture, ...)
- Bugzilla 18076: dmd -run should work with - (stdin) too
Phobos regressions
- Bugzilla 17962: dirEntries now truncates Unicode file names
- Bugzilla 17986: Erratic failure with std/experimental/allocator/common.d(445): unittest failure
- Bugzilla 18084: [REG2.072] tempCString buffer size is unittest-versioned
Phobos bugs
- Bugzilla 2447: There's no disconnectall for std.signals
- Bugzilla 6820: etc.c.curl missing const
- Bugzilla 6895: std.traits.isCovariantWith doesn't work for function, function pointer and delegate
- Bugzilla 9661: LockingTextWriter should increment file handle reference count
- Bugzilla 10395: [std.stdio] Closing a popened File with unread output throws an exception
- Bugzilla 12064: std.typecons.wrap doesn't handle NVI
- Bugzilla 14477: Nullable does not work with structs with default constructor disabled
- Bugzilla 15140: std.experimental.allocator.building_blocks.free_list.FreeList leaks memory
- Bugzilla 15637: Region allocator assert failure when expanding the last allocation
- Bugzilla 16253: BitmappedBlock allocator not working with chooseAtRuntime
- Bugzilla 16542: makeArray not usable with const initializer
- Bugzilla 16564: KRRegion.empty sometimes returns Ternary.no
- Bugzilla 17459: format("%012,3d", ...) doesn't handle field width and zero-padding correctly
- Bugzilla 17467: BitArray are broken with <<= 64
- Bugzilla 17730: [scope][dip1000] std.algorithm.move escapes scope variable in @safe code
- Bugzilla 17901: FreeBSD 10.3: AssertError@std/experimental/allocator/building_blocks/region.d(652)
- Bugzilla 17995: template NoDuplicates(TList...) bug.
- Bugzilla 18044: std.conv.to for implicitly convertible associative arrays
- Bugzilla 18047: std.format value.length modulo seperator step width leads to wrong length
- Bugzilla 18092: Can't combine take and takeExactly
- Bugzilla 18135: [REG2.078] can't join RegexMatch anymore
Phobos enhancements
- Bugzilla 1998: std.bitarray should have setAll / opSliceAssign(bool) etc
- Bugzilla 4717: std.bitmanip.BitArray changes
- Bugzilla 4763: std.stdio.File.open() : more efficient implementation
- Bugzilla 6244: Add powmod / modpow function to std.math
- Bugzilla 9362: Add a method to remove one item to std.container.SList
- Bugzilla 13532: std.regex performance (enums; regex vs ctRegex)
- Bugzilla 14034: std.algorithm.mean
- Bugzilla 16398: experimental allocators, add aligned reallocation for Posix
- Bugzilla 17742: std.range.transposed does not have opIndex
- Bugzilla 17905: byCodeUnit should allow access to underlying range
- Bugzilla 17919: std.container.Array could use pureMalloc
- Bugzilla 17952: std.range.transposed save is invalid
- Bugzilla 18021: FileLogger Member not accessible to subclasses
Druntime regressions
- Bugzilla 17914: [Reg 2.075] Fibers guard page uses a lot more memory mappings
- Bugzilla 18071: [REG2.078] byKey, byValue and byKeyValue are now a hole for unsafe code
Druntime bugs
- Bugzilla 17108: Associative array byKeyValue is unsafe
- Bugzilla 17851: htonl already defined in phobos64.lib
- Bugzilla 17956: core.memory unittest failure (possibly glibc 2.26 specific)
Druntime enhancements
- Bugzilla 17300: Enable setting code coverage options on the command line
dlang.org bugs
- Bugzilla 18033: Open in Editor button doesn't work
dlang.org enhancements
- Bugzilla 16392: drop win32.mak
- Bugzilla 17265: WithStatement: Find better Example for what "with" really does
- Bugzilla 17527: dlangspec.pdf: escape sequences table goes over the page boundaries
- Bugzilla 17529: dlangspec.pdf: grammar definitions go over the right margin
- Bugzilla 17531: dlangspec.pdf: overloading unary operators exposes LaTeX
- Bugzilla 17534: dlangspec.pdf: 25.24: getFunctionVariadicStyle's tables goes over the page margin and uses HTML
- Bugzilla 17535: dlangspec.pdf: enforce a maximal width for all code examples
- Bugzilla 17536: dlangspec.pdf: Unittests documentation uses HTML
- Bugzilla 17538: dlangspec.pdf: 33.14 Comparing D Immutable and Const with C++ Const goes over the page margin
- Bugzilla 17723: Replace Facebook on the front page with Weka.io
- Bugzilla 17925: [Contract Programming]
- Bugzilla 17993: 404 Not Found: phobos/ddmd_utf.html
- Bugzilla 18032: [Home] Print hex dump example doesn't run
- Bugzilla 18067: Benchmark example is broken on the frontpage
- Bugzilla 18081: dlangspec.pdf: don't escape dollars in code examples
- Bugzilla 18082: Ubuntu/Debian repository installation should mention dub
Tools bugs
- Bugzilla 7997: Optlink issues 'Index Range' error with static zero length array
Contributors to this release (57)
A huge thanks goes to all the awesome people who made this release possible.
- abaga129
- aG0aep6G
- aldacron
- Alexandru Caciulescu
- Alexandru Jercaianu
- Andrei Alexandrescu
- Atila Neves
- Basile Burg
- Benoit Rostykus
- Brad Roberts
- Chris Coutinho
- Dashster
- Dmitry Olshansky
- Dragos Carp
- dukc
- Eduard Staniloiu
- H. S. Teoh
- Iain Buclaw
- Ilya Yaroshenko
- Jack Stouffer
- Jean-Louis Leroy
- JinShil
- Joakim Noah
- Johan Engelen
- John Colvin
- Jon Degenhardt
- Jonathan M Davis
- Jonathan Marler
- Jordi Sayol
- Kevin De Keyser
- kinke
- Kotet
- Laeeth Isharc
- Leandro Lucarella
- Lucia Mcojocaru
- Martin Krejcirik
- Martin Nowak
- Mathias Lang
- Mathis Beer
- MetaLang
- n8sh
- Nemanja Boric
- Nick Treleaven
- Oleg Nykytenko
- Petar Kirov
- Rainer Schuetze
- Razvan Nitu
- Robert burner Schadek
- Sebastian Wilzbach
- Simen Kjærås
- skl131313
- Steven Schveighoffer
- Temtaime
- Vladimir Panteleev
- Walter Bright
- yashikno
- Yuxuan Shui