Overloading Lazy Vs. Non-Lazy

Jonathan M Davis jmdavisprog at gmail.com
Thu Aug 12 13:59:19 PDT 2010


On Thursday, August 12, 2010 13:47:40 dsimcha wrote:
> Just to clarify:  enforce() calls a function called bailOut() if necessary
> that actually does the throwing.  This of course is not inlined w.r.t.
> enforce(). However, the lazy parameter also prevents inlining of enforce()
> itself and generates a ton of code at the ASM level.
> 
> Don is right, though.  In principle, when a statically known delegate D
> (lazy is just syntactic sugar for delegates) that returns a statically
> known constant is passed to a statically known function F, D can be
> inlined w.r.t. F and F can be inlined w.r.t. its caller.
> 
> The problem, though, is that F needs to be inlined first so that the
> compiler can optimize F w.r.t. the parameters passed to it from a specific
> caller.  However, F won't look worth inlining until the compiler realizes
> that it can inline D w.r.t. F.  Therefore, the compiler would need an
> inliner that uses something more sophisticated than a simple greedy
> algorithm to discover this optimization opportunity.

Well, from everything I've heard about the inliner, we're going to need a 
smarter one at some point. Whether we need one soon is another matter, but at 
some point, we really should have an inliner capable of handling these sort of 
cases. It sounds like dmd's inliner is pretty simplistic, and that's going to 
make it harder to make stuff like Phobos properly efficient.

- Jonathan M Davis


More information about the Digitalmars-d mailing list