[Issue 4440] inlined delegates produces different asm than straight lined code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 11 11:27:59 PDT 2010


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



--- Comment #4 from Leandro Lucarella <llucax at gmail.com> 2010-07-11 11:27:57 PDT ---
(In reply to comment #2)
> Reducing the test case further:
> extern(C) int printf(const char*, ...);
> 
> bool if_delegate(int i, bool delegate(ref int) predicate)
> {
>     return predicate(i);
> }
> 
> bool if_nodelegate(int i)
> {
>     return i == 99;
> }
> 
> void main()
> {
>     foreach(i; 1 .. 100)
>         if (if_delegate(i, (ref int j) { return j == 99; }))
>             printf("i = %d\n", i);
> 
>     foreach(i; 1 .. 100)
>         if (if_nodelegate(i))
>             printf("i = %d\n", i);
> }
> 
> In the previous version of the code, the use of the for loops makes the cost of
> the functions too high for the inliner to bother inlining find_if into main. 
> Also,in the non-inlined version of the function, there's no way for it to
> inline the delegate since it's a variable, not a constant thing.
>
> This changed version reduces the problem to: will it inline the delegate?  The
> answer is still no, but allows that specific problem to be explored.
> 
> Leandro, does this stray too far away from the underlying code that led you to
> file this bug?


Yes, the loop is important, because this happens a lot with opApply(), which
almost always includes a loop, and when I use (x having an opApply() method):
foreach (a; x) {
   // some code
}
I almost always want // some code to be inlined, since it's not even a function
(from the POV of the programmer), but maybe that should be another bug report,
I really don't know.

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


More information about the Digitalmars-d-bugs mailing list