February 08, 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!
February 09, 2019
On Friday, 8 February 2019 at 23:58:49 UTC, H. S. Teoh wrote:
> Yep, the moral of the story is, if codegen quality is important to you, use ldc (and presumably gdc too) rather than dmd.

That's definitely true, but that leaves the question whether lowering rvalue references to lambdas is acceptable. There's the 'dmd for fast builds, gdc/ldc for fast code' motto, but if your debug builds of your game make it run at 15 fps it becomes unusable. I don't want the gap between dmd and compilers with modern back-ends to widen.

February 08, 2019
On Sat, Feb 09, 2019 at 12:04:20AM +0000, Dennis via Digitalmars-d-announce wrote:
> On Friday, 8 February 2019 at 23:58:49 UTC, H. S. Teoh wrote:
> > Yep, the moral of the story is, if codegen quality is important to you, use ldc (and presumably gdc too) rather than dmd.
> 
> That's definitely true, but that leaves the question whether lowering rvalue references to lambdas is acceptable. There's the 'dmd for fast builds, gdc/ldc for fast code' motto, but if your debug builds of your game make it run at 15 fps it becomes unusable. I don't want the gap between dmd and compilers with modern back-ends to widen.

TBH, I've been finding that ldc compilation times aren't all that bad compared to dmd.  It's definitely slightly slower, but it's not anywhere near the gap between, say, dmd and g++.

Recently I've been quite tempted to replace dmd with ldc as my main D compiler, esp. now that ldc releases are essentially on par with dmd releases in terms of release schedule of a particular language version. The slowdown in compilation times isn't enough to offset the benefits, as long as you're not compiling with, say, -O3 which *would* make the ldc optimizer run slower (but with the huge benefit of significantly better codegen -- I've seen performance improvements of up to ~200% with ldc -O3 vs. dmd -O -inline).

And template-heavy code is slow across all D compilers anyway, so the relatively small compilation time difference between dmd and ldc doesn't really matter that much anymore once you have a sufficiently large codebase with heavy template use.


T

-- 
What doesn't kill me makes me stranger.
February 09, 2019
On Saturday, 9 February 2019 at 00:04:20 UTC, Dennis wrote:
> On Friday, 8 February 2019 at 23:58:49 UTC, H. S. Teoh wrote:
>> Yep, the moral of the story is, if codegen quality is important to you, use ldc (and presumably gdc too) rather than dmd.
>
> That's definitely true, but that leaves the question whether lowering rvalue references to lambdas is acceptable. There's the 'dmd for fast builds, gdc/ldc for fast code' motto, but if your debug builds of your game make it run at 15 fps it becomes unusable. I don't want the gap between dmd and compilers with modern back-ends to widen.

Since the user doesn't explicitly place the lambda in their code, wouldn't it be justifiable for the compiler to take it back out again at a later step in compilation, even in debug mode?
February 08, 2019
On Sat, Feb 09, 2019 at 01:08:55AM +0000, bitwise via Digitalmars-d-announce wrote:
> On Saturday, 9 February 2019 at 00:04:20 UTC, Dennis wrote:
> > On Friday, 8 February 2019 at 23:58:49 UTC, H. S. Teoh wrote:
> > > Yep, the moral of the story is, if codegen quality is important to you, use ldc (and presumably gdc too) rather than dmd.
> > 
> > That's definitely true, but that leaves the question whether lowering rvalue references to lambdas is acceptable. There's the 'dmd for fast builds, gdc/ldc for fast code' motto, but if your debug builds of your game make it run at 15 fps it becomes unusable. I don't want the gap between dmd and compilers with modern back-ends to widen.
> 
> Since the user doesn't explicitly place the lambda in their code, wouldn't it be justifiable for the compiler to take it back out again at a later step in compilation, even in debug mode?

Using lowering to lambdas as a way of defining semantics is not the same thing as actually using lambdas to implement a feature in the compiler!

While it can be convenient to do the latter as a first stab, I'd expect that the optimizer could make use of special knowledge available in the compiler to implement this more efficiently. Since the compiler will always use a fixed pattern for the lowering, the backend could detect this pattern and optimize accordingly.  Or the compiler implementation could lower it directly to something more efficient in the first place.


T

-- 
If you look at a thing nine hundred and ninety-nine times, you are perfectly safe; if you look at it the thousandth time, you are in frightful danger of seeing it for the first time. -- G. K. Chesterton
February 10, 2019
On Saturday, 9 February 2019 at 01:31:05 UTC, H. S. Teoh wrote:
>
> Using lowering to lambdas as a way of defining semantics is not the same thing as actually using lambdas to implement a feature in the compiler!
>
> While it can be convenient to do the latter as a first stab, I'd expect that the optimizer could make use of special knowledge available in the compiler to implement this more efficiently. Since the compiler will always use a fixed pattern for the lowering, the backend could detect this pattern and optimize accordingly.  Or the compiler implementation could lower it directly to something more efficient in the first place.
>
>
> T

The lambda even correctly handles "@disable this(this);", I like it!

struct One { @disable this(this); }
void fun(ref One one) { }

One gun() { return One.init; }

void main()
{
  One one; one.fun();
  (One __temp0){ return fun( __temp0 ); }(gun()); // OK
}

5 6 7 8 9 10 11 12 13 14 15
Next ›   Last »