DMD 0.161 release

xs0 xs0 at xs0.com
Wed Jun 21 16:12:50 PDT 2006


Walter Bright wrote:
> xs0 wrote:
>> Walter Bright wrote:
>>
>>> 85: It can't be made to work, because an interface handle is 
>>> different from a class handle. It doesn't work in C++, either, for 
>>> the same reasons.
>>
>> But it can be made to work, because an interface handle could be the 
>> same as a class handle. It works that way in Java, and is _far_ more 
>> useful, even if performance of method calls is reduced slightly.
>>
>> But we talked about that already, and I don't suppose you'll change 
>> your mind this time..
> 
> Java makes it "work" by doing runtime manipulation of interface/class 
> handles whenever they are used.

Well, I think it's quite irrelevant what Java does (and the same goes 
for C++*), the question is what is a better option, where we seem to 
disagree.

> This is too inefficient for a native 
> compiled language.

I (still) think you're over-exaggerating the efficiency issue, because 
the difference is not that large in reality. For anything but the 
simplest methods the speed penalty is practically negligible (I measured 
it), and it's not the simplest methods that most time is spent on, I'd say.

And you could use the same argument against virtual methods, but you 
still implemented them.

> Consider this:
> 
>   int can be implicitly converted to long.
>   Therefore, shouldn't int[] be usable as a long[]?
> 
> It's an exactly analogous situation.

No, it isn't. int is of a different "class" than long, while an 
interface reference and a class reference point to exactly the same object.

You also seem to miss the reduced complexity of implementation (a stated 
goal I believe). With a simple double lookup, interfaces can be handled 
in a single place, and I'd guess you could implement that very easily 
just by faking another calling convention.

On the other hand, if interface references point to a different address 
than class references, you need to store offsets somewhere, have to 
modify the address on every call, need to handle implicit conversions 
when passing function boundaries, etc. etc.


xs0

*) Note that C++ supports MI, meaning double lookup would hurt every 
method call. Otoh, in D we'd get to keep the speed of non-interface calls.



More information about the Digitalmars-d-announce mailing list