On 8/2/18 3:57 PM, kinke wrote:
On Thursday, 2 August 2018 at 15:12:10 UTC, Steven Schveighoffer wrote:
On 8/2/18 11:00 AM, Kagamin wrote:
I suppose it's mostly for mutability, so if it's const, it can be
optimized based on type information only:
auto foo(in int x)
{
return { return x + 10; };
}
I'm not sure what you mean here.
I think he's saying that the check for immutability could simply consist
in checking that all captured variables (well, not too much room for a
lot of them ;)) have a const type.
OK, yes, that's what I was thinking as well. On a 64-bit system, you
could stuff 2 ints in there, which is a common theme for my code :)
It's definitely an interesting idea, and the obvious benefit over a
library solution is that you wouldn't have to think about this
optimization when writing a delegate; if the captured stuff happens to
be const and fit into a pointer, the GC won't be bothered, nice.
Yeah, a library solution is opt-in, whereas if the compiler does it as
an optimization, it's seamless (mostly invisible). And works in @nogc
when possible.
-Steve