{"id":1891,"date":"2019-01-05T08:36:15","date_gmt":"2019-01-05T08:36:15","guid":{"rendered":"http:\/\/dlang.org\/blog\/?p=1891"},"modified":"2021-10-08T11:03:11","modified_gmt":"2021-10-08T11:03:11","slug":"dmd-2-084-0-has-arrived","status":"publish","type":"post","link":"https:\/\/dlang.org\/blog\/2019\/01\/05\/dmd-2-084-0-has-arrived\/","title":{"rendered":"DMD 2.084.0 Has Arrived"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"alignleft size-full wp-image-181\" src=\"http:\/\/dlang.org\/blog\/wp-content\/uploads\/2016\/08\/d6.png\" alt=\"\" width=\"200\" height=\"200\" \/>The D Language Foundation is pleased to present version 2.084.0 of DMD, the reference D compiler. It\u2019s <a href=\"https:\/\/dlang.org\/download.html\">available for download at dlang.org<\/a>, where you can also <a href=\"https:\/\/dlang.org\/changelog\/2.084.0.html\">find the full changelog<\/a>. There are a few changes and new features to be found, as usual, along with <a href=\"https:\/\/dlang.org\/changelog\/2.084.0.html#bugfix-list\">100 closed Bugzilla issues<\/a> this time around.<\/p>\n<h3 id=\"finercontroloverrun-timechecks\">Finer Control Over Run-time Checks<\/h3>\n<p><a href=\"https:\/\/dlang.org\/dmd-windows.html#switch-check\">The new compiler flag <code>-check<\/code><\/a> is a feature that <a href=\"https:\/\/github.com\/dlang\/DIPs\/blob\/master\/DIPs\/DIP1006.md\">grew out of DIP 1006<\/a> and some internal discussions around its content. The flag allows overriding the default behavior of six specific categories of run-time checks by specifically turning them <code>on<\/code> or <code>off<\/code>:<\/p>\n<ul>\n<li><code>assert<\/code> &#8211; assertion checks<\/li>\n<li><code>bounds<\/code> &#8211; bounds checks<\/li>\n<li><code>in<\/code> &#8211; <code>in<\/code> contracts<\/li>\n<li><code>invariant<\/code> &#8211; class and struct invariants<\/li>\n<li><code>out<\/code> &#8211; <code>out<\/code> contracts<\/li>\n<li><code>switch<\/code> &#8211; default switch cases<\/li>\n<\/ul>\n<p>For example, when compiling without <code>-release<\/code>, all run-time checks are enabled by default. To disable only assertion checks:<\/p>\n<pre>dmd -check=assert=off foo.d<\/pre>\n<p>This can be further refined with <a href=\"https:\/\/dlang.org\/dmd-windows.html#switch-checkaction\">the new <code>-checkaction<\/code> flag<\/a>, which determines how the program will respond when an assertion, bounds, or switch check fails. There are four options: <code>D<\/code>, <code>C<\/code>, and <code>halt<\/code>.<\/p>\n<ul>\n<li><code>D<\/code> &#8211; the default D behavior, which is to throw an <code>Error<\/code> to indicate an unrecoverable condition.<\/li>\n<li><code>C<\/code> &#8211; behave as a C program by calling the assertion failure function in the C runtime.<\/li>\n<li><code>halt<\/code> &#8211; execute a halt instruction to terminate the program.<\/li>\n<\/ul>\n<p>Listed in the language documentation is a fourth option: <code>context<\/code>. This causes failed checks to throw an <code>Error<\/code> to indicate an unrecoverable condition, and also print the error context. It isn&#8217;t present in this release, but is coming in DMD 2.085 (the online documentation is generated from <a href=\"https:\/\/github.com\/dlang\/dmd\">the DMD master branch<\/a>).<\/p>\n<h3 id=\"saveyourmixins\">Save Your Mixins<\/h3>\n<p>One of D\u2019s most popular and powerful features is <a href=\"https:\/\/dlang.org\/spec\/statement.html#mixin-statement\">the <code>mixin<\/code> statement<\/a>, commonly referred to as <em>string mixins<\/em> to avoid confusion <a href=\"https:\/\/dlang.org\/spec\/template-mixin.html\">with <em>template mixins<\/em><\/a>. Unfortunately, given that string mixins can be composed from multiple compile-time function calls, they are also notoriously painful to debug as they grow in complexity. The new <code>-mixin<\/code> compiler option aims to do away with that pain.<\/p>\n<p>Consider the following simple (contrived) example, which attempts to generate a function call with a string mixin:<\/p>\n<pre class=\"prettyprint lang-d\">import std.stdio;\r\n\r\nvoid hello() { writeln(\"Hello!\"); }\r\n\r\nvoid main() {\r\n    mixin(hello.stringof ~ \"();\");\r\n}<\/pre>\n<p>Save as <code>hello.d<\/code>, compile with <code>dmd hello<\/code>, and you\u2019ll see an error along these lines:<\/p>\n<pre><code>hello.d-mixin-6(6): Error: function expected before (), not hello() of type void<\/code><\/pre>\n<p>The error does say exactly what the problem is, but even in this simple case it may require re-reading the message a few times before working out what it\u2019s actually saying. So let\u2019s recompile with the <code>-mixin<\/code> flag. It requires a file name. I\u2019ve selected <code>mixed.txt<\/code>:<\/p>\n<pre><code>dmd -mixin=mixed.txt hello.d<\/code><\/pre>\n<p>Now we see this output:<\/p>\n<pre>mixed.txt(110): Error: function expected before (), not hello() of type void<\/pre>\n<p>See the difference? The error now refers to a line number in a file with the name we provided, rather than a line in the autogenerated <code>hello.d-mixin-6<\/code> to which we couldn\u2019t refer. Open <code>mixed.txt<\/code> and navigate to line 110 to find the generated code, along with a comment at line 109:<\/p>\n<pre>\/\/ expansion at foo.d(6)\r\nhello()();<\/pre>\n<p>And now the error is quite clear. Invoking <code>.stringof<\/code> on a function provides you with the function name including the parentheses, so there\u2019s no need to append parentheses to the result. We can now change the example so that it will compile:<\/p>\n<pre class=\"prettyprint lang-d\">void main() {\r\n    mixin(hello.stringof ~ \";\");\r\n}<\/pre>\n<p>Anyone making significant use of string mixins to generate code will undoubtedly find this feature useful. It will be particularly helpful for the maintainers of D-friendly IDEs and plugins to make the user experience more convenient.<\/p>\n<h3 id=\"newdubfeatures\">New DUB features<\/h3>\n<p>DMD 2.084.0 ships with version 1.13.0 of DUB, <a href=\"https:\/\/code.dlang.org\/\">the D build tool and package manager<\/a>. It gets some new goodies with this release.<\/p>\n<p><a href=\"https:\/\/dlang.org\/changelog\/2.084.0.html#addcommand\">The new <code>add<\/code> command<\/a> is a convenience to add dependencies to a project\u2019s package recipe. No need to worry about the syntax and whether the recipe is written using JSON or SDLang. Simply run dub with the <code>add<\/code> command, specifying one or more dub packages, and the recipe will be modified accordingly. For example, to add <a href=\"https:\/\/github.com\/BindBC\">the BindBC bindings<\/a> for the GLFW and OpenGL C libraries:<\/p>\n<pre>dub add bindbc-glfw bindbc-opengl<\/pre>\n<p>This will add the latest version of each library. This can be restricted to a specific version by appending <code>=<\/code> to the package name along with the normal <a href=\"https:\/\/github.com\/dlang\/dub\/wiki\/Version-management#basic-dependency-specification\">DUB syntax for version specifications<\/a>. This can also be used to change the version specification of an existing dependency.<\/p>\n<p>For those unfamiliar with DUB, executing <code>dub run<\/code>, or simply <code>dub<\/code>, in a directory containing a dub recipe will build a project according to the recipe and, if the project is an executable, run it once the build completes. Now, there are <a href=\"https:\/\/dlang.org\/changelog\/2.084.0.html#pre-post-run-commands\">two new recipe directives<\/a> that can be used to achieve more specialized goals. <code>preRunCommands<\/code> specifies commands to execute before the DUB target is run, and <code>postRunCommands<\/code> specifies commands to execute when the run is complete. See the DUB package recipe documentation for <a href=\"https:\/\/dub.pm\/package-format-json.html\">the JSON syntax<\/a> or <a href=\"https:\/\/dub.pm\/package-format-sdl.html\">the SDLang syntax<\/a>, under \u201cBuild Settings\u201d in each, to see what they look like.<\/p>\n<h3 id=\"thatsnotall\">That\u2019s Not All<\/h3>\n<p>Regarding the 100 closed Bugzilla issues, two points should be made.<\/p>\n<p>First is that among many of the Pull Request merges that closed those issues, you\u2019ll find Nicholas Wilson\u2019s GitHub handle. Nicholas is, of course, the community member the D Language Foundation asked to serve as PR Manager, to be paid <a href=\"https:\/\/www.flipcause.com\/secure\/cause_pdetails\/NDUwNTY=\">through a fundraising campaign<\/a>. He\u2019s been reviving old PRs and making sure new ones don\u2019t go stale. This release is evidence that the initiative is paying off. And the icing on the cake is that the D community enabled us to meet our fundraising target well before our February 14th deadline. Thanks!<\/p>\n<p>Second, a point relevant to <a href=\"https:\/\/dlang.org\/blog\/2018\/02\/03\/the-dbugfix-campaign\/\">the #dbugfix campaign<\/a>. While I was disappointed that participation in nominating Bugzilla issues on Twitter and in the Forums dwindled to near zero, the previous nominations were not forgotten. The original goal was to fix at least two nominated issues per cycle, so several nominated bugs were never selected. However, thanks to Eduard Staniloiu and Razvan Nitu, two among that group are now closed and fixed in this release:<\/p>\n<ul>\n<li>#13300 &#8211; <a href=\"https:\/\/issues.dlang.org\/show_bug.cgi?id=13300\">pure function \u2018std.array.Appender!(T[]).Appender.ensureAddable\u2019 cannot call impure function \u2018test.T.__fieldPostBlit\u2019<\/a>,<\/li>\n<li>#18572 &#8211; <a href=\"https:\/\/issues.dlang.org\/show_bug.cgi?id=18572\">AliasSeq default arguments are broken<\/a><\/li>\n<\/ul>\n<p>I\u2019m still happy to take #dbugfix nominations. If you\u2019ve got a Bugzilla issue that\u2019s bugging you, tweet a link to it with #dbugfix in the text, or start a thread in the General forum with #dbugfix in the title. I\u2019ll make a note of it and, rather than counting votes and selecting two of the top five, see if I can find someone to do something about it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The D Language Foundation is pleased to present version 2.084.0 of DMD, the reference D compiler. It\u2019s available for download at dlang.org, where you can also find the full changelog. There are a few changes and new features to be found, as usual, along with 100 closed Bugzilla issues this time around. Finer Control Over [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[35,27],"tags":[],"_links":{"self":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/1891"}],"collection":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/comments?post=1891"}],"version-history":[{"count":15,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/1891\/revisions"}],"predecessor-version":[{"id":1906,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/1891\/revisions\/1906"}],"wp:attachment":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/media?parent=1891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/categories?post=1891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/tags?post=1891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}