Neat 0.2.5: Refcounting for functions
The big new thing here is delegate refcounting. There's a new type, void delegate!()
, for delegates that can't be refcounted, ie. stack-scoped delegates; it cannot be copied for that reason, but it can be passed to functions and called, which is often all you need.
To create a proper delegate, use new &nestfn
. This will create a copy of the stackframe. This copy is not shared with any other new
allocated nested functions!
void delegate!()
is a bit too restrictive for lambdas: ie. you can't return it or store it in a struct, which we absolutely need for std.algorithm. So lambdas use a different strategy called "quarantining", which is a bit complicated to explain, but tl,dw: you can't return a lambda from the function it was declared in, and you can't stick a lambda anywhere where the compiler could lose track of it and so return it from the function it was declared in by accident.
super
:
class A { int i; this(this.i) { } }
class B : A { int j; this(int i, this.j) { super(i); } }
// but also, equivalently
class C : A { int j; this(super, this.j) { } }
Does exactly what you'd expect.
Changes
- Add delegate refcounting.
- void delegate!() marks a delegate as noncopyable.
- Nested functions and lambdas can be heap allocated with
new
. - lambdas are quarantine checked.
super()
calls the super constructorsuper
token in the constructor parameter list generates an implicit super call.- Change:
this
is now a reference in structs. - Quote rewrite: all of the base language should now be quotable.
- Various compilation speedups.
- Fix propagation of bottom value.
- Fix multithreading.