Change Log: 2.104.0
Download D 2.104.0
released Jun 01, 2023
Compiler changes
- Better error message when attribute inference fails down the call stack
- Using ; as an empty statement has been turned into an error
- Using in parameters with non extern(D)/extern(C++) functions is deprecated
- in ref on parameters has been deprecated in favor of -preview=in
- Throwing qualified objects is now deprecated
- User Defined Attributes now parse Template Arguments
Library changes
Tools changes
Dub changes
List of all bug fixes and enhancements in D 2.104.0.
Compiler changes
- Better error message when attribute inference fails down the call stack
When a function fails to infer a function attribute, all callers of that function also fail to infer the attribute. The resulting error message only points to the top most function with the explicit attribute:
void main() @nogc { fun(); } auto fun() { funImpl(); } auto funImpl() { int[] a = [1, 2, 3]; }
app.d(4): Error: @nogc function D main cannot call non-@nogc function app.fun
This doesn't tell the underlying reason why fun wasn't inferred @nogc, and led to use of workarounds to get better information. The new error message will point to the function which failed to infer the attribute:
app.d(4): Error: @nogc function D main cannot call non-@nogc function app.fun app.d(7): which calls app.funImpl app.d(14): which wasn't inferred @nogc because of: app.d(14): array literal in @nogc function app.funImpl may cause a GC allocation
Note: this was already implemented for @safe since 2.101, but it has now been extended to @nogc, nothrow, and pure.
- Using ; as an empty statement has been turned into an error
This has been deprecated since 2.075.0 because it's error prone:
void main() { foreach (i; 0 .. 8); { // Because of the accidental semicolon above, // this block statement is executed once. // It's not the loop body } }
It will now result in an error.
app.d(3): Error: use { } for an empty statement, not ;
- Using in parameters with non extern(D)/extern(C++) functions is deprecated
In preparation for enabling -preview=in by default, using in parameters on function that have neither D nor C++ linkage is deprecated. Users can replace instances of in with either const or scope const. Refer to v2.101.0 changelog's for a full rationale.
- in ref on parameters has been deprecated in favor of -preview=in
Using in ref (or ref in) on function parameters will now yield a deprecation. Users are encouraged to remove the ref and compile with -preview=in, which will infer whether the parameter should be passed by reference or value. Users wanting a specific ABI are encouraged to use scope const ref instead. Note that this also applies to auto ref in, which is equivalent to in with -preview=in, but the latter doesn't require the function to be templated.
- Throwing qualified objects is now deprecated
Previously, an immutable, const, inout or shared exception could be thrown and then caught in an unqualified catch (Exception e) clause. That breaks type safety. Throwing a qualified object is now deprecated. This helps to prevent possible mutation of an immutable object in a catch clause.
The runtime also modifies a thrown object (e.g. to contain a stack trace) which can violate const or immutable objects. Throwing qualified objects has been deprecated for this reason also.
- User Defined Attributes now parse Template Arguments
It was already allowed to put types in UDAs, but the parser would reject basic types written directly, requiring the use of an alias.
alias Tint = int; @Tint void f();
Also, simple literals that can appear in template instantiations without brackets (example: foo!"arg") require parentheses when used as an attribute:
@("my test") unittest { }
Now, arguments that can appear after a template instantiation foo! can also appear after an @ attribute.
@int void f(); @"my test" unittest { }
Library changes
- Better static assert messages for std.algorithm.comparison.clamp
Until now, clamp used a template constraint to check if the passed types could be used. If they were not, it was very tedious to figure out why.
As the template constraint is not used for overload resolution the constrains are moved into static asserts with expressive error messages.
- std.typecons.Rebindable now supports all types
Rebindable can now be used to store and rebind values of any type, including immutable struct values.
To ensure const safety is preserved, the stored values cannot be accessed by reference.
The implementation used for all previously supported types (classes, interfaces and arrays) is unchanged.
Tools changes
- rdmd supports -shared
rdmd now understands DMD's -shared switch, and sets the default output file name appropriately (.dll, .so, or .dylib depending on the platform), in the same way as -lib.
Dub changes
- Add new properties 'cSourcePaths' and 'cImportPaths' to SDL/JSON
cSourcePaths passes the C source files in all specified directories to the compiler. All C sources found in the given directories for 'cImportPaths' are passed to the D compiler. This ensures backward compatible behaviour for projects that stored C sources aside of D source file, while porting them to D.
The second keyword 'cImportPaths' will add additional search paths for C headers. These directories are passed to the D compilers as addition include paths. The feature might need additional tweaking, because the include paths are currently joint with the D import paths. This might change in future to support independant search paths for C to be passed to the D compilers.
- The way packages are stored internally has changed
Previous versions of dub stored packages in the following format: $CACHE_PATH/$PACKAGE_NAME-$PACKAGE_VERSION/$PACKAGE_NAME/ Starting from this version, the format will be: $CACHE_PATH/$PACKAGE_NAME/$PACKAGE_VERSION/$PACKAGE_NAME.
Introducing a new level will help users quickly list what packages they actually have installed, and reduce visibility of packages that might update frequently. It will render various commands (e.g. du) more useful, pave the way for a package GC function, and make manual browsing easier.
More importantly, it will allow future version of dub to infer the version from the path to the package, removing the need to read (or edit) the recipe file on every dub invocation.
List of all bug fixes and enhancements in D 2.104.0:
DMD Compiler regression fixes
- Bugzilla 23764: Message printed twice: Usage of in on parameter
- Bugzilla 23832: dmd regression 2.103.0 silent error cannot call decode at runtime
- Bugzilla 23874: -profile=gc segfaults / ICE regression
- Bugzilla 23882: ICE (segfault) on nasty alias this code
- Bugzilla 23905: Initialization of SumType with opaque enum causes ICE
- Bugzilla 23913: __traits(getMember) fails for some C symbols
DMD Compiler bug fixes
- Bugzilla 12118: Modify immutable data using throw
- Bugzilla 18493: [betterC] Can't use aggregated type with postblit
- Bugzilla 19454: Name collisions with unnamed function parameters
- Bugzilla 19706: Attribute inference in struct fails
- Bugzilla 20737: TLS variables unusable with -betterC for Windows MSVC targets
- Bugzilla 21667: scope parameter causes 'no size because of forward references'
- Bugzilla 22760: Segmentation fault in CppMangleVisitor.template_arg
- Bugzilla 22785: joiner does not support range over immutable
- Bugzilla 22960: importC: K&R-style functions assume variadic calling convention
- Bugzilla 23014: importC: static thread-locals do not work
- Bugzilla 23055: importC: using compound-literal array as pointer in CTFE gives 'dereference of invalid pointer'
- Bugzilla 23402: importc function definitions from includes can cause D name conflicts
- Bugzilla 23427: ImportC: some bitfield combinations lead to wrong size struct
- Bugzilla 23509: ImportC: need statement expressions extension for GLibC's assert()
- Bugzilla 23691: compilable/test22294.i:16:1: control Z interpreted as end of file
- Bugzilla 23715: ImportC: No rejection of _Thread_local variables declared at function scope without 'static' as per C11 6.2.4-5
- Bugzilla 23727: ImportC support imaginary real numbers
- Bugzilla 23784: ImportC: __ptr32, __ptr64
- Bugzilla 23787: ImportC: __unaligned
- Bugzilla 23789: ImportC: __declspec(align(n))
- Bugzilla 23795: Cannot cast _Complex!double to _Complex!float
- Bugzilla 23801: ImportC: enumeration constant does not fit in an int
- Bugzilla 23802: ImportC: __volatile__ is yet another alias for volatile
- Bugzilla 23808: #include
is not working with importc - Bugzilla 23822: Deprecated struct alias ignored completely
- Bugzilla 23826: Deprecated type member passed to template doesn't warn
- Bugzilla 23836: Two errors printed for typeof(super) in non-static member context
- Bugzilla 23837: importc fails to link on windows x86 but successes on x64
- Bugzilla 23838: DMD lexer / parser examples might not compile
- Bugzilla 23861: Compiler segmentation fault with ref and alias this
- Bugzilla 23863: typeof rejects AliasSeq!() as argument
- Bugzilla 23866: ImportC: Multiple __declspecs rejected
- Bugzilla 23867: ImportC: undefined identifier __builtin_isnan
- Bugzilla 23869: ImportC: undefined identifier isfinite
- Bugzilla 23873: [ICE] segfault on imported static if ; else auto x
- Bugzilla 23885: [CI] C++ interop tests with g++ fail
DMD Compiler enhancements
- Bugzilla 13577: More informative error message for refused immutable foreach loop
- Bugzilla 17374: Improve inferred attribute error message
- Bugzilla 20268: anonymous function parameter mismatch errors don't include parameters
- Bugzilla 22559: ImportC: support gnu case ranges
- Bugzilla 23401: ImportC: add -cpp=filename switch to select C preprocessor
- Bugzilla 23862: with statement should accept an expression with enum type
Phobos bug fixes
- Bugzilla 19642: std.range.slide!(No.withPartial) on lengthless forward range: get empty when expecting one window
- Bugzilla 22147: DList can't accept a struct with postblit disabled
- Bugzilla 22786: maxElement et al does not support range over immutable
- Bugzilla 23834: std.file : File links to c functions are invalid and need updating
- Bugzilla 23846: std.math can't compile under macos rosetta
Phobos enhancements
- Bugzilla 6106: Keep track of changes during replace function
- Bugzilla 14478: isInputRange should allow ranges of non-copyable elements
- Bugzilla 23769: Lambda isn't a unary predicate for lambda that doesn't compile
Druntime bug fixes
- Bugzilla 14891: profilegc_setlogfilename w/o null-terminated string might fail during fopen
- Bugzilla 23949: core.stdc.assert_ for FreeBSD and DragonFlyBSD is incorrect
Druntime enhancements
- Bugzilla 11989: Phase out TickDuration
dlang.org bug fixes
- Bugzilla 14932: The language specification does not define what the shared attribute does
- Bugzilla 23698: ImportC: __stdcall is not documented as supported MSVC/DMC extensions
- Bugzilla 23699: ImportC: Unclear documentation that struct/union/enum introduce implicit typedefs
- Bugzilla 23872: Wrong example in Interfacing to C: Calling printf section
Contributors to this release (38)
A huge thanks goes to all the awesome people who made this release possible.
- Adam D. Ruppe
- Andrew Lalis
- Ate Eskola
- Atila Neves
- Caleb Xu
- Christian Koestlin
- Denis Feklushkin
- Dennis
- Dennis Korpel
- Dmytro Katyukha
- drpriver
- Ernesto Castellotti
- Grim Maple
- Hiroki Noda
- Iain Buclaw
- jamesragray
- Jan Jurzitza
- Jeremy
- Jordi Sayol
- Lance Bachmeier
- Lucian Danescu
- lucica28
- Marcelo Silva Nascimento Mancini
- Mathias Lang
- Mathis Beer
- Max Haughton
- Mike Parker
- Nick Treleaven
- Per Nordlöw
- Petar Kirov
- Rainer Schuetze
- Razvan Nitu
- Robert burner Schadek
- Steven Schveighoffer
- Temtaime
- Teodor Dutu
- Vladimir Panteleev
- Walter Bright