3 ms·
Ah! Yes, I see now. I think that D implements closures this way? I thought you meant the closure’s conceptual stack frame. As for commonality, the most common
by steveklabnik 8y ago
Ah! Yes, I see now. I think that D implements closures this way? I thought you meant the closure’s conceptual stack frame.
As for commonality, the most common closures I see are:
* closures which have no environment
* closures that take the environment by move
* everything else
It’d be interesting to analyze crates.io and see though...and how much this would actually save you. I can't think of a time when the closure is only pointing to its parent's stack frame and you would box it. Box<Fn()> is mostly used for returning closures, and there, you'd be using a move closure to take the env by owner.
And even if you do unnecessarily box: https://play.rust-lang.org/?gist=c16ac5983579d52d4997b3f44258748b&version=stable&mode=release&edition=2015 https://play.rust-lang.org/?gist=c16ac5983579d52d4997b3f4425...
If you click "show assembly", do_closure_stuff is compiled to:
playground::do_closure_stuff:
leal 2(%rdi), %eax
retq
It gets entirely optimized away anyway.