{"id":1219,"date":"2017-11-03T13:39:20","date_gmt":"2017-11-03T13:39:20","guid":{"rendered":"http:\/\/dlang.org\/blog\/?p=1219"},"modified":"2021-10-08T11:07:20","modified_gmt":"2021-10-08T11:07:20","slug":"dmd-2-077-0-released","status":"publish","type":"post","link":"https:\/\/dlang.org\/blog\/2017\/11\/03\/dmd-2-077-0-released\/","title":{"rendered":"DMD 2.077.0 Released"},"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\" \/><\/p>\n<p>The D Language Foundation is happy to announce DMD 2.077.0. This latest release of the reference compiler for the D programming language is available from the <a href=\"https:\/\/dlang.org\/download.html\">dlang.org Downloads page<\/a>. Among the usual slate of <a href=\"https:\/\/dlang.org\/changelog\/2.077.0.html\">bug and regression fixes<\/a>, this release brings a couple of particulary beneficial enhancements that will have an immediate impact on some existing projects.<\/p>\n<h3 id=\"cuttingsymbolbloat\">Cutting symbol bloat<\/h3>\n<p>Thanks to Rainer Sch\u00fctze, the compiler now produces significantly smaller mangled names in situations where they had begun to get out of control, particularly in the case of IFTI (Implicit Function Template Instantiation) where Voldemort types are involved. That may call for a bit of a detour here.<\/p>\n<h4 id=\"thetypesthatshallnotbenamed\">The types that shall not be named<\/h4>\n<p><a href=\"https:\/\/wiki.dlang.org\/Voldemort_types\">Voldemort types<\/a> are perhaps one of D\u2019s more interesting features. They look like this:<\/p>\n<pre class=\"prettyprint lang-d\">auto getHeWhoShallNotBeNamed() \r\n{\r\n    struct NoName \r\n    {\r\n        void castSpell() \r\n        {\r\n            import std.stdio : writeln;\r\n            writeln(\"Crucio!\");\r\n        }           \r\n    }\r\n    return NoName();\r\n}\r\n\r\nvoid main() \r\n{\r\n    auto voldemort = getHeWhoShallNotBeNamed();\r\n    voldemort.castSpell();\r\n}<\/pre>\n<p>Here we have an <a href=\"https:\/\/dlang.org\/spec\/function.html#auto-functions\">auto function<\/a>, a function for which the return type is inferred, returning an instance of a type declared inside the function. It\u2019s possible to access public members on the instance even though its type can never be named outside of the function where it was declared. Coupled with type inference in variable declarations, it\u2019s possible to store the returned instance and reuse it. This serves as an extra level of encapsulation where it\u2019s desired.<\/p>\n<p>In D, for any given API, as far as the world outside of a module is concerned, <em>module private<\/em> is the lowest level of encapsulation.<\/p>\n<pre class=\"prettyprint lang-d\">module foobar;\r\n\r\nprivate struct Foo\r\n{\r\n    int x;\r\n}\r\n\r\nstruct Bar \r\n{\r\n    private int y;\r\n    int z;\r\n}<\/pre>\n<p>Here, the type <code>Foo<\/code> is module private. <code>Bar<\/code> is shown here for completeness, as those new to D are often surprised to learn that private members of an aggregate type are also module private (D\u2019s equivalent of the C++ <code>friend<\/code> relationship). There is no keyword that indicates a lower level of encapsulation.<\/p>\n<p>Sometimes you just may not want <code>Foo<\/code> to be visible to the entire module. While it\u2019s true that anyone making a breaking change to Foo\u2019s interface also has access to the parts of the module that break (which is the rationale behind module-private members), there are times when you may not want the entire module to have access to <code>Foo<\/code> at all. Voldemort types fill that role of hiding details not just from the world, but from the rest of the module.<\/p>\n<h4 id=\"theevilsideofvoldemorttypes\">The evil side of Voldemort types<\/h4>\n<p>One unforeseen consequence of Voldemort types that was <a href=\"https:\/\/issues.dlang.org\/show_bug.cgi?id=15831\">first reported<\/a> in mid\u20132016 was that, when used in templated functions, they caused a serious explosion in the size of the mangled function names (in some cases up to 1 MB!), making for some massive object files. There was a good bit of forum discussion on how to trim them down, with a number of ideas tossed around. Ultimately, Rainer Sch\u00fctze took it on. His persistence has resulted in shorter mangled names all around, but the wins are particularly impressive when it comes to IFTI and Voldemort types. (Rainer is also the maintainer of <a href=\"http:\/\/rainers.github.io\/visuald\/visuald\/StartPage.html\">Visual D<\/a>, the D programming language plugin for Visual Studio)<\/p>\n<p>D\u2019s name-mangling scheme is detailed in the <a href=\"https:\/\/dlang.org\/spec\/abi.html#name_mangling\">ABI documentation<\/a>. The description of the new enhancement is in the section titled <a href=\"https:\/\/dlang.org\/spec\/abi.html#back_ref\">\u2018Back references\u2019<\/a>.<\/p>\n<h3 id=\"improvedvectorization\">Improved vectorization<\/h3>\n<p>D has long supported array operations such as element-wise addtion, multiplication, etc. For example:<\/p>\n<pre class=\"prettyprint lang-d\">int[] arr1 = [0, 1, 2];\r\nint[] arr2 = [3, 4, 5];\r\nint[3] arr3 = arr1[] + arr2[];\r\nassert(arr3 == [3, 5, 7]);<\/pre>\n<p>In some cases, such operations could be vectorized. The reason it was <em>some<\/em> cases and not <em>all<\/em> cases is because dedicated assembly routines were used to achieve the vectorization and they weren\u2019t implemented for every case.<\/p>\n<p>With 2.077.0, that\u2019s no longer true. Vectorization is now templated so that all array operations benefit. Any codebase out there using array operations that were not previously vectorized can expect a sizable performance increase for those operations thanks to the increased throughput (though whether an application benefits overall is of course context-dependent). How the benefit is received depends on the compiler being used. From the changelog:<\/p>\n<blockquote><p>For GDC\/LDC the implementation relies on auto-vectorization, for DMD the implementation performs the vectorization itself. Support for vector operations with DMD is determined statically (-mcpu=native, -mcpu=avx2) to avoid binary bloat and the small test overhead. DMD enables SSE2 for 64-bit targets by default.<\/p><\/blockquote>\n<p><em>Note that the changelog initially showed <code>-march<\/code> instead of <code>-mcpu<\/code> in the quoted lines, and the updated version had not yet been posted when this announcement was published.<\/em><\/p>\n<p>DMD\u2019s implementation is implemented in terms of <a href=\"https:\/\/dlang.org\/spec\/simd.html#core_simd\"><code>core.simd<\/code><\/a>, which is also <a href=\"https:\/\/dlang.org\/phobos\/core_simd.html\">part of DRuntime\u2019s public API<\/a>.<\/p>\n<p>The changelog also notes that there\u2019s a potential for division performed on float arrays in existing code to see a performance decrease in exchange for an increase in precision.<\/p>\n<blockquote><p>The implementation no longer weakens floating point divisions (e.g. <code>ary[] \/ scalar<\/code>) to multiplication (<code>ary[] * (1.0 \/ scalar)<\/code>) as that may reduce precision. To preserve the higher performance of float multiplication when loss of precision is acceptable, use either <code>-ffast-math<\/code> with GDC\/LDC or manually rewrite your code to multiply by (<code>1.0 \/ scalar<\/code>) for DMD.<\/p><\/blockquote>\n<h3 id=\"otherassortedtreats\">Other assorted treats<\/h3>\n<p>Just the other day, someone asked in the forums if DMD supports <a href=\"https:\/\/reproducible-builds.org\/\">reproducible builds<\/a>. As of 2.077.0, the answer is affirmative. DMD now ensures that compilation is deterministic such that given the same source code and the same compiler version, the binaries produced will be identical. If this is important to you, be sure not to use any of the non-determistic lexer tokens (<code>__DATE__<\/code>, <code>__TIME__<\/code>, and <code>__TIMESTAMP__<\/code>) in your code.<\/p>\n<p>DMD\u2019s <code>-betterC<\/code> command line option gets some more love in this release. When it&#8217;s enabled, DRuntime is not available. Library authors can now use the <a href=\"https:\/\/dlang.org\/spec\/version.html#predefined-versions\">predefined version<\/a>\u00a0<code>D_BetterC<\/code> to determine when that is the case so that, where it\u2019s feasible, they can more conveniently support applications with and without the runtime. Also, the option\u2019s behavior <a href=\"https:\/\/dlang.org\/spec\/betterc.html\">is now documented<\/a>, so it\u2019s no longer necessary to go to the forums or parse through search results to figure out what is and isn\u2019t actually supported in BetterC mode.<\/p>\n<p>The entire changelog is, as always, <a href=\"https:\/\/dlang.org\/changelog\/2.077.0.html\">available at dlang.org<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The D Language Foundation is happy to announce DMD 2.077.0. This latest release of the reference compiler for the D programming language is available from the dlang.org Downloads page. Among the usual slate of bug and regression fixes, this release brings a couple of particulary beneficial enhancements that will have an immediate impact on some existing projects.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[26,12,8,27,4],"tags":[],"_links":{"self":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/1219"}],"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=1219"}],"version-history":[{"count":11,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/1219\/revisions"}],"predecessor-version":[{"id":1370,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/posts\/1219\/revisions\/1370"}],"wp:attachment":[{"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/media?parent=1219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/categories?post=1219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dlang.org\/blog\/wp-json\/wp\/v2\/tags?post=1219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}