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
}