Here's an article describing how to achieve the same effect in D:
Here's an article describing how to achieve the same effect in D:
Even if the lambda were to inline the call, it still would be a completely different location in the executable image.
> Even if the lambda were to inline the call, it still would be a completely different location in the executable image.
Not sure what you mean. Inlined code is not in a different location, it's right where one is executing! Also, optimizers are pretty darned good these days.
Even if they're the same code, I don't think it's that easy for linkers to merge them?
For a trampoline to have no overhead, you need the call to the trampoline to be changed to a call to the underlying function.
That's not an optimization that can easily happen due to the traditional compilation model.
Even if inlining were to happen, you end up with bloat, and few compilers are able to merge similar code like this (which can only happen at link-time, obviously, since the functions might be in different translation units). This optimization is known as ICF, and is not commonly enabled.
In practice I don't think the inliner takes ICF into consideration when deciding whether to inline anyway, so you just end up calling a function that calls another function.
You're talking about C/C++'s compilation model and ABI and there are plenty of others. ICF is a hack to deal with C++'s naive template expansion. There are lots of other languages that don't work that way at all and don't need a linker optimization like that.
All compiled languages virtually use the C model of doing things, often including its FFI.
I recommend writing some code snippets, compile them with inlining on, and looking at the resulting assembler code.