You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a possible optimization for the common interface casts. But it requires a breaking of not well known small assumption.
In git-head (f78b25c9fb00bf024cd1d6e394f696bba4f2187b), issue 1747 and issue 2013 has been fixed properly. With the latest dmd:
interface IA {}
interface IB {}
interface IC : IB, IA {}
interface ID : IC {}
interface IE : IC {}
// C instance layout with -m32:
// ofs: 8 12 16 20
// IB, IA IB, IA
// IC IC
class C : ID, IE
{
}
void main()
{
C c = new C();
ID id = c; // class to base interface: static castIE ie = c; // class to base interface: static castIC ic1 = id; // intreface to 1st base interface: static castIC ic2 = ie; // class to base interface: static castassert(ic1 !is ic2);// ic1 and ic2 are not identical, but they points same vtbl.// therefore any member function call via them will work.IA ia1 = ic1; // interface to 2nd base interface: dynamic cast!IA ia2 = ic2; // interface to 2nd base interface: dynamic cast!assert(ia1 is ia2);// By the dynamic cast, two IA will be identical.// However, like to the ic case, it's inherently unnecessary.
}
If we can agree to allow to fail the last assert(ia1 is ia2), we can remove costly dynamic cast from all class/interface upcasts.
The text was updated successfully, but these errors were encountered:
Kenji Hara (@9rnsr) reported this on 2015-07-19T12:45:33Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=14809
Description
This is a possible optimization for the common interface casts. But it requires a breaking of not well known small assumption. In git-head (f78b25c9fb00bf024cd1d6e394f696bba4f2187b), issue 1747 and issue 2013 has been fixed properly. With the latest dmd: interface IA {} interface IB {} interface IC : IB, IA {} interface ID : IC {} interface IE : IC {} // C instance layout with -m32: // ofs: 8 12 16 20 // IB, IA IB, IA // IC IC class C : ID, IE { } void main() { C c = new C(); ID id = c; // class to base interface: static cast IE ie = c; // class to base interface: static cast IC ic1 = id; // intreface to 1st base interface: static cast IC ic2 = ie; // class to base interface: static cast assert(ic1 !is ic2); // ic1 and ic2 are not identical, but they points same vtbl. // therefore any member function call via them will work. IA ia1 = ic1; // interface to 2nd base interface: dynamic cast! IA ia2 = ic2; // interface to 2nd base interface: dynamic cast! assert(ia1 is ia2); // By the dynamic cast, two IA will be identical. // However, like to the ic case, it's inherently unnecessary. } If we can agree to allow to fail the last assert(ia1 is ia2), we can remove costly dynamic cast from all class/interface upcasts.The text was updated successfully, but these errors were encountered: