Change Log: 2.089.0
Download D 2.089.0
released Nov 02, 2019
Compiler changes
- Deprecate allowing shadowing in foreach loops
- IsExpressions now correctly match combinations of const, inout, and shared.
- extern(C) declarations in template mixins now mangle as C symbols when mixed in at global scope
- The default linker for the Digital Mars tool chain is now optlink.exe
- New -Xcc compiler flag to address issue 6952
Runtime changes
Library changes
Dub changes
List of all bug fixes and enhancements in D 2.089.0.
Compiler changes
- Deprecate allowing shadowing in foreach loops
Up until this version it was allowed to shadow a variable in a foreach loop, although it is dissallowed in a normal for loop. This patch makes the behavior of the foreach loop consistent with the for loop one. To fix any issues encountered, rename the variable inside the foreach body that shadows the one from the upper scope.
- IsExpressions now correctly match combinations of const, inout, and shared.
With Bugzilla 20138 fixed, IsExpressions now correctly match combinations of the qualifiers const, inout, and shared.
Examples that failed previously but pass now:
static assert(is(shared(const int) U == shared U) && is(U == const int)); static assert(is(shared(inout int) U == inout U) && is(U == shared int));
Note that the behavior of code like the following changes:
static if (is(T U == const U) { ...} else static if (is(T U == shared const U)) { ... }
The second case will never be reached, because the first one now matches when T is shared const. To get the old behavior, switch the order.
- extern(C) declarations in template mixins now mangle as C symbols when mixed in at global scope
This was already true for string mixins, but since template mixins introduce a new scope, symbols inside them got mangled as D symbols. However, users often use extern(C) inside a mixin template to automatically generate boilerplate code that should be accessible from C.
// library code mixin template WasmEntryPoint() { extern(C) export void _start() { // boilerplate code } } mixin template UseGpuInsteadOfIntegratedGraphics() { extern(C) export uint NvOptimusEnablement = 0x00000001; extern(C) export int AmdPowerXpressRequestHighPerformance = 1; } // application code mixin WasmEntryPoint; mixin UseGpuInsteadOfIntegratedGraphics; static assert(_start.mangleof == "_start"); static assert(NvOptimusEnablement.mangleof == "NvOptimusEnablement");
Previously, _start would be mangled like _D9onlineapp8__mixin46_startUkZv and users had to manually add pragma(mangle, "_start") or use a string mixin instead. With the new behavior this is not necessary anymore for extern(C), as well as extern(Windows) and extern(Objective-C). extern(C++) remains unchanged since it already always mangles to C++, even in nested scopes.
There is a possibility this breaks code if you mix in different extern(C) declarations with the same name in the global scope of multiple modules.
import core.stdc.stdio; mixin template GenPrintCallback(string text) { extern(C): auto textLength = text.length; auto textPointer = text.ptr; void callBackOnly() { printf("%.*s\n", textLength, textPointer); } mixin(`auto `, text, ` = &callBackOnly;`); } mixin GenPrintCallback!"foo"; // in a different module: mixin GenPrintCallback!"bar";
In this case textLength, textPointer and callBackOnly will be defined multiple times, so the linker either picks one or raises and error. The solution is to not make variables extern(C) and make C callback functions anonymous:
import core.stdc.stdio; mixin template GenPrintCallback(string text) { auto textLength = text.length; // not below an extern(C): anymore auto textPointer = text.ptr; alias FunT = extern(C) void function(); enum FunT callBackOnly = () { printf("%.*s\n", textLength, textPointer); }; mixin(`auto `, text, ` = callBackOnly;`); }
- The default linker for the Digital Mars tool chain is now optlink.exe
The default linker when building with -m32 under Windows has been changed from link.exe to optlink.exe to avoid calling the wrong linker when both the Digital Mars tool chain and the Microsoft compiler tools are found in the PATH environment variable.
- New -Xcc compiler flag to address issue 6952
On POSIX, dmd passes -L-prefixed compiler flags through the linker driver (cc by default) to the linker (e.g. ld) by prepending them with -Xlinker. Therefore, it was not possible to pass flags directly to the linker driver.
This release adds a new compiler flag, -Xcc, which specifies a flag to pass to the linker driver. This switch has already existed in the LDC compiler for several releases. Some use cases for it would be -nostartfiles, -pthread, and -static, which can now be specified as -Xcc=-nostartfiles, -Xcc=-pthread, and -Xcc=-static respectively.
Note that it was previously also possible to specify linker driver options by setting the CC environment variable, e.g. CC='cc -pthread' dmd ..., or by setting the CC variable to point to a custom linker driver wrapper script. -Xcc improves on this through composability and better opportunities for integration into build systems.
See also:
Runtime changes
- Added core.atomic.atomicFetchAdd and core.atomic.atomicFetchSub.
Added core.atomic.atomicFetchAdd and core.atomic.atomicFetchSub to the atomic suite.
- Make wstatus predicates pure and @safe
The predicates that operate on the wstatus value reported by wait(2) are now marked pure and @safe, allowing them to be used in functions with those attributes.
Library changes
- Added std.traits.Unconst
std.traits.Unconst works like std.traits.Unqual, but removes only const, inout and immutable qualifiers from a type.
Dub changes
- Improved support for LDC, incl. cross-compilation
The ldc2 driver now supports
- some more command-line options (coverage, profiling, keeping stack frame),
- separate linking,
- cross-compilation by specifying the target triple (LDC -mtriple) as --arch, e.g., --arch=x86_64-pc-windows-msvc. Check out https://wiki.dlang.org/Cross-compiling_with_LDC for how to setup LDC.
- Lint command added
Dub supports now command lint, which will execute D-Scanner on the dub package. By default dub lint will execute style check. Import paths to dependent dub packages will be passed to D-Scanner.
dub lint
- Added SemVer compatibility operator "^"
Dub now supports version specifications of the form ^x.y.z. This corresponds to a "semver compatible version", ie. any version up from x.y.z with the same major number. If the major number is 0, only the same version matches. This corresponds to the versions listed on https://semver.org/ as compatible with the public API of the version given. ^x.y is equivalent to ^x.y.0.
List of all bug fixes and enhancements in D 2.089.0:
DMD Compiler regressions
- Bugzilla 20126: codegen reloads parameter from register when iasm changed the backing memory
- Bugzilla 20212: invalid debug info with enum type in library
DMD Compiler bugs
- Bugzilla 982: Codeview: symbols of enum type are declared integer
- Bugzilla 1104: CodeView: char is marked 0x20 (T_UCHAR) instead of 0x10 (T_CHAR)
- Bugzilla 2195: Variable shadowing in foreach is not detected and reported
- Bugzilla 2450: Error using operators from named template mixin
- Bugzilla 3831: writeln of a delegate typeid
- Bugzilla 4372: type of enumerator values reduced to base type in debug info
- Bugzilla 6952: Static Linking on Linux
- Bugzilla 13582: Deprecated modules imported from other deprecated modules shouldn't be warned about
- Bugzilla 16047: Range violation in setting multi-dimensional AA entries
- Bugzilla 19965: [DIP1000] Template allows to escape internal pointer
- Bugzilla 20012: extern(C) functions inside template mixins are not mangled as C functions
- Bugzilla 20089: FPU stack not cleaned up properly
- Bugzilla 20131: Bad codegen from inline asm LOCK CMPXCHG; possible REX prefix missing
- Bugzilla 20138: is expression not evaluating correctly?
- Bugzilla 20163: Deprecated import in string mixin does not output diagnostic message
- Bugzilla 20164: Importing deprecated module at function-local scope does not output diagnostic message
- Bugzilla 20181: [nightly 2019-08-29] internal compiler error when static foreach iterating property method of struct
- Bugzilla 20244: New dmd option -preview=noXlinker does not work on Linux to build a simple D application
- Bugzilla 20267: Error: string is used as a type - and similar “smart” error messages
DMD Compiler enhancements
- Bugzilla 809: Should be possible to convert lazy argument to delegate
- Bugzilla 1547: Default parameter values should use implicit static opCall
- Bugzilla 3004: [patch] Better handling of ignored pragmas
- Bugzilla 15118: Have dmd on Win32 look for optlink.exe instead of link.exe
- Bugzilla 18272: missing changelog entry and no doc for -gf (besides cryptic emit debug info for all referenced types)
- Bugzilla 18617: need __traits(deprecated, expr) to check whether an expression would trigger deprecation
Phobos regressions
- Bugzilla 20186: File size of "Hello, world" executable increased by 185KB
- Bugzilla 20295: std.zip: zip64 with 0xff bytes in end of central dir record do not work
- Bugzilla 20328: [REG 2.089 beta] deprecation message about Nullable.get in isInputRange
Phobos bugs
- Bugzilla 15230: Inconsistent std.range.SortedRange predicate checks
- Bugzilla 17705: std.math.isFinite cannot run at compile-time
- Bugzilla 19514: gcd(BigInt(2), BigInt(1)) fails
- Bugzilla 20027: std.zip susceptible to zip malware attacks
- Bugzilla 20145: Random unittest failures inf std.datetime.stopwatch
- Bugzilla 20205: std.math: Wrong result for abs(int.min)
- Bugzilla 20218: Checked format string takes infinite time for infinite ranges
- Bugzilla 20239: chameleon zip-file should be rejected by std.zip
- Bugzilla 20240: BitArray inconsistently preserves bits past length
- Bugzilla 20241: BitArray.bitsSet ignores length
- Bugzilla 20287: std.zip: Wrong compressed data
- Bugzilla 20301: std.regex.regex doesn't accept a const/immutable array of patterns
- Bugzilla 20302: std.functional.memoize doesn't accept a functions with const/immutable parameters
Phobos enhancements
- Bugzilla 20147: Enable comparison (==, >, >=, <=, <) between std.bigint.BigInt and floating point numbers
- Bugzilla 20159: Make std.math.scalbn work in CTFE
- Bugzilla 20192: Make std.math.isSubnormal work in CTFE
- Bugzilla 20196: Make std.math.isNormal work in CTFE
- Bugzilla 20199: Make std.math.frexp work in CTFE
- Bugzilla 20200: Make std.math.isPowerOf2 work for floating point numbers in CTFE
- Bugzilla 20201: Make std.math.scalbn pure
- Bugzilla 20202: Make std.math.signbit work in CTFE
- Bugzilla 20203: Make std.math.copysign work in CTFE
- Bugzilla 20242: BitArray constructor should not modify input data
Druntime regressions
- Bugzilla 20270: [REG2.087] Deadlock in garbage collection when running processes in parallel
Druntime bugs
- Bugzilla 13821: fiber + exception + win server 2012 failures
- Bugzilla 16380: no bindings for err.h
- Bugzilla 18643: Compiling error when combining CAS and numeric literal.
- Bugzilla 19481: Aborting from local/libphobos/libdruntime/core/sync/mutex.d(95) Error: pthread_mutex_init failed.
- Bugzilla 20155: Allocating a struct with dtor on the GC heap can produce false pointers
- Bugzilla 20214: GC: realloc can result in false pointers if address doesn't change
Druntime enhancements
- Bugzilla 8831: core.atomic: add compare-and-swap function with other result type
- Bugzilla 13826: Move volatileLoad/Store to core.volatile when the volatile keyword is removed
- Bugzilla 15007: core.atomic match C++11
- Bugzilla 20105: core.atomic 'cas' function is incomplete
- Bugzilla 20106: core.atomic : atomicFence doesn't accept MemoryOrder
- Bugzilla 20107: core.atomic : Memory order is missing keys
Contributors to this release (44)
A huge thanks goes to all the awesome people who made this release possible.
- 0xEAB
- aG0aep6G
- Andrej Mitrovic
- Bastiaan Veelo
- Bernhard Seckinger
- Berni
- Cameron Ross
- Chloé
- Dan Printzell
- devel
- dkorpel
- drug007
- Eduard Staniloiu
- Ernesto Castellotti
- Feldwor
- Harry T. Vennik
- Hiroki Noda
- Iain Buclaw
- Jon Degenhardt
- Jonathan Marler
- Les De Ridder
- look-at-me
- Manu Evans
- Martin Kinkelin
- Martin Nowak
- Mathias Lang
- Mathis Beer
- Mike Franklin
- MoonlightSentinel
- Nathan Sashihara
- Nicholas Wilson
- Petar Kirov
- Rainer Schuetze
- Razvan Nitu
- Robert burner Schadek
- Robert Schadek
- Sebastian Wilzbach
- Stefanos Baziotis
- stefanos-baziotis
- Tobias Pankrath
- Tomoya Tanjo
- Viktor
- Vladimir Panteleev
- Walter Bright