http://d.puremagic.com/issues/show_bug.cgi?id=10509


Don <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |performance
           Severity|critical                    |enhancement


--- Comment #1 from Don <[email protected]> 2013-09-19 23:28:25 PDT ---
This is a very difficult optimization.
Consider:

void f(int i)
{
    if (i)
        del = () => i;  // (1)
    ++i;                // (2)
}

If you put i on the heap only at (1), then the compiler has trouble generating
code at (2) -- is i on the heap, or on the stack?

Another example:

    if (cond1()) 
        del = () => i;
    if (cond2()) 
        del = () => i*2;
The compiler would then have to generate code to move i onto the heap in two
places, and in the second case, it might already be on the heap.

> This hits with pain as one do not expect such behaviour

I think that is inevitable. In some simple cases, the compiler might be able to
avoid creating a closure, but it will always be rather conservative.
This isn't wrong code, it's a missed optimization opportunity.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to