digitalmars.D.bugs - less-than-ideal codegen for Interfaces
- van eeshan (42/42) Aug 07 2004 Given this ...
- Jarrett Billingsley (6/6) Aug 09 2004 "What's with the test of 'this' against zero? I'm hoping that this is on...
- Walter (7/18) Aug 15 2004 a
- van eeshan (8/27) Aug 15 2004 only
- Walter (7/14) Aug 16 2004 That's fixed too. I sent you an email, but your reply address is invalid...
- van eeshan (4/7) Aug 16 2004 an
- Arcane Jill (5/8) Aug 16 2004 Intriguing.
- Walter (4/11) Aug 16 2004 passed
Given this ... interface I { I method(); } class A : I { I method() { return this; // ??? } } ... the compiler generates a bunch of seemingly unnecessary code to convert a 'this' into an Interface for the return value. Here's the optimized codegen output: 10: class A : I 11: { 12: I method() 00402018 enter 4,0 0040201C mov dword ptr [ebp-4],eax 13: { 14: return this; 0040201F cmp dword ptr [this],0 00402023 je _D5hello1A6methodFZC5hello1I+15h (0040202d) 00402025 mov eax,dword ptr [this] 00402028 lea eax,[eax+8] 0040202B jmp _D5hello1A6methodFZC5hello1I+17h (0040202f) 0040202D xor eax,eax 15: } 0040202F leave 00402030 ret What's with the test of 'this' against zero? I'm hoping that this is only something that fell through the cracks. I've seen the same code-pattern dozens and dozens of times with respect to Interface usage, but never for a class. It sucks ~ but then the compiler is still beta. While we're on the subject, a class implementing an Interface should probably be implicitly convertible to an Object: without going through a dynamic cast. The following code currently requires a dynamic cast: Object convert(I i) { return i; // fails. must be cast(Object) i; }
Aug 07 2004
"What's with the test of 'this' against zero? I'm hoping that this is only something that fell through the cracks" indeed.. it doesn't make much sense to see if "this" is null before calling a function on it.. especially since a member function can't be called with a null "this" in the first place, as you'd get an access violation! the cmp, je, jmp, and xor lines could all be removed and there would be no effect.
Aug 09 2004
"van eeshan" <vanee hotmail.net> wrote in message news:cf4bdn$2k3c$1 digitaldaemon.com...What's with the test of 'this' against zero? I'm hoping that this is only something that fell through the cracks. I've seen the same code-pattern dozens and dozens of times with respect to Interface usage, but never foraclass. It sucks ~ but then the compiler is still beta.That's fixed now.While we're on the subject, a class implementing an Interface should probably be implicitly convertible to an Object: without going through a dynamic cast. The following code currently requires a dynamic cast: Object convert(I i) { return i; // fails. must be cast(Object) i; }This still needs an explicit cast, because although all D interfaces are ultimately derived from Object, it is possible to have an interface passed in from some other language that is not from Object.
Aug 15 2004
"Walter" <newshound digitalmars.com> wrote in message news:cfpk7u$1qgs$1 digitaldaemon.com..."van eeshan" <vanee hotmail.net> wrote in message news:cf4bdn$2k3c$1 digitaldaemon.com...onlyWhat's with the test of 'this' against zero? I'm hoping that this isforsomething that fell through the cracks. I've seen the same code-pattern dozens and dozens of times with respect to Interface usage, but neveraThank you! May I respectfully ask about the bug named "Calling through an interface invokes the wrong method" ?class. It sucks ~ but then the compiler is still beta.That's fixed now.Good point. Glad to hear you hope other languages will adhere to the D binary spec.While we're on the subject, a class implementing an Interface should probably be implicitly convertible to an Object: without going through a dynamic cast. The following code currently requires a dynamic cast: Object convert(I i) { return i; // fails. must be cast(Object) i; }This still needs an explicit cast, because although all D interfaces are ultimately derived from Object, it is possible to have an interface passed in from some other language that is not from Object.
Aug 15 2004
"van eeshan" <vanee hotmail.net> wrote in message news:cfpktk$1qrl$1 digitaldaemon.com...Thank you! May I respectfully ask about the bug named "Calling through an interface invokes the wrong method" ?That's fixed too. I sent you an email, but your reply address is invalid.passedThis still needs an explicit cast, because although all D interfaces are ultimately derived from Object, it is possible to have an interfaceIt has a lot more to do with D's interfaces supporting the way COM works, and so can interact with COM objects. COM support is common with win32 languages.in from some other language that is not from Object.Good point. Glad to hear you hope other languages will adhere to the D binary spec.
Aug 16 2004
"Walter" <newshound digitalmars.com> wrote in message news:cfqt3v$2nem$2 digitaldaemon.com...anThank you! May I respectfully ask about the bug named "Calling throughExcellent. Much appreciated!interface invokes the wrong method" ?That's fixed too.
Aug 16 2004
In article <cfpk7u$1qgs$1 digitaldaemon.com>, Walter says...although all D interfaces are ultimately derived from Object, it is possible to have an interface passed in from some other language that is not from Object.Intriguing. Care to tell us how? Some faked-up examples in C would be neat. Jill
Aug 16 2004
"Arcane Jill" <Arcane_member pathlink.com> wrote in message news:cfq9m7$29sj$1 digitaldaemon.com...In article <cfpk7u$1qgs$1 digitaldaemon.com>, Walter says...passedalthough all D interfaces are ultimately derived from Object, it is possible to have an interfaceSure. Check out the COM examples in \dmd\src\d !in from some other language that is not from Object.Intriguing. Care to tell us how? Some faked-up examples in C would be neat.
Aug 16 2004