DIP 1016--ref T accepts r-values--Formal Assessment

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Feb 8 23:58:49 UTC 2019


On Fri, Feb 08, 2019 at 03:42:51PM -0800, H. S. Teoh via Digitalmars-d-announce wrote:
> On Fri, Feb 08, 2019 at 11:34:47PM +0000, Dennis via Digitalmars-d-announce wrote:
> > On Friday, 8 February 2019 at 23:02:34 UTC, Nicholas Wilson wrote:
> > > Immediately called lamdas are always inlined.
> > 
> > ```
> > extern(C) void main() {
> >     int a = (() => 1)();
> > }
> > ```
[...]
> Does LDC/GDC inline it?
> 
> I no longer trust dmd for codegen quality. :-/
[...]

Just checked: LDC does inline it.  In fact, LDC compiles the whole thing
out and just has `ret` for main(). :-D  Forcing LDC not to elide the
whole thing by inserting a writeln(a) call reveals that the lambda is
indeed inlined.

Yep, the moral of the story is, if codegen quality is important to you,
use ldc (and presumably gdc too) rather than dmd.


T

-- 
Freedom of speech: the whole world has no right *not* to hear my spouting off!


More information about the Digitalmars-d-announce mailing list