How does the compiler avoid creating a closure here?
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 2 23:05:09 PDT 2015
Consider http://dpaste.dzfl.pl/fork/ae75176d7d3f.
It's a bit roundabout but in brief it instantiates a template with a
nested function. The nested function, in turn, uses a parameter in its
environment. By the canon, that function needs to create a closure with
dynamically-allocated environment.
To my surprise, however, the generated code uses no closure (disassembly
at http://goo.gl/ti23W0) yet works correctly.
How come? Can anyone explain to me where x (used by the nested function)
is stored?
Thanks,
Andrei
P.S. I'd like to thank Iain and Vladimir for making it so easy and
pleasing to inspect and share code snippets with dpaste and asm.dlang.org.
More information about the Digitalmars-d
mailing list