Safer casts

Dee Girl deegirl at noreply.com
Tue May 13 01:25:46 PDT 2008


Yigal Chripun Wrote:

> Dee Girl wrote:
> 
> >> I didn't know that Walter is working on making inlining delegates 
> >> possible, that this is indeed great news. :)
> > 
> > I think this is great but it is much easy said than done. Inlining an
> > indirect call means the callee must be inlined too. Or at least
> > duplicated. There is complicated analysis that shows which indirect
> > calls can be inlined that way. Not all can.
> > 
> OK. so what?
> either way, It's the compiler/linker job to make optimizations. it sure
> is more capable and has more info than I am.
> I'm not implementing the D compiler, I'm using it. my POV is that of the
> user. I believe Walter is a genius compiler writer and that if it's
> possible he'll make it happen.

But this is the interesting thing. Walter is a genius compiler writer and he made it happen already. Now. Your compiler has it already. And it has it in very elegant form. The point I tried many times to clarify is that Walter has done the great work already. But it is not in the documents. Maybe only Walter knows it now. And Andrei because he wrote std.algorithm exactly to use the feature.

> >> to answer your questions: as I understand it, a delegate is
> >> internally a struct with two pointers: a context pointer and a
> >> function pointer. the context pointer has the address of the outer
> >> function for nested functions, or the this pointer for methods. so,
> >> when passing a delegate you pass this struct. based on that, I
> >> think that the answer to your second question is that the call is
> >> indirect.
> > 
> > This answer is incorrect. The call is direct. I clarify: this is not
> > matter of optimization or tricks. It is matter of principle. It is
> > coming from the very clever way Walter instantiates templates with
> > alias arguments. He specializes the template at the call site. I wish
> > I had his idea for my project but not it is too late ^_^
> > 
> > I think this is very important feature of the D programming language.
> I'm confused by your terminology.

I am using standard terminology. But maybe my sentences are wrong.

> anyway, this is not really that
> important to me, again I trust Walter to make the compiler produce the
> best possible code.
> I meant that the sort instance calls the delegate anyway and does not
> inline it. I'm not sure what you mean in direct vs. indirect and why
> this is important. I thought that the important thing for performance
> was whether the call gets inlined or not.

It is important because of this. Direct call is trivially inlined. Indirect call is maybe 1000 times harder to inline and sometimes impossible. By direct call I mean you know the address of the function at compilation. By indirect call I mean you have a pointer with the address of the function.

> I'm saying here that both options (the template instance and the regular
>  function) do the same regarding inlining the delegate.

This sentence is incorrect. The template instance works very different from the regular function.

> >> this is true for both cases, otherwise that trick of using a
> >> sort!() instance inside a mySort function wouldn't work. all you
> >> pass to the template version is just a D symbol, in our case the 
> >> name of the delegate. in both cases you need to call that delegate.
> >> 
> > 
> > In the example I wrote it is not the name of the delegate. It is the
> > name of nested function. It is anonymous but still has internal name.
> > 
> 
> see Janice's reply. effectively this is the same thing.

They are not the same thing. I have explained in other post. Thank you, Dee Girl



More information about the Digitalmars-d mailing list