Comment #0 by lucia.mcojocaru — 2016-11-13T10:28:00Z
This involves some refactoring in object.d with the implementation of typeidImpl and the appropriate lowering of typeid.
Comment #1 by andrei — 2016-11-17T14:04:43Z
To clarify, we want to lower occurrences of typeid(Xyz), where Xyz is a type, to
.typeidImpl!(Xyz)()
Then we implement that function in object.d. For now we may leave other uses, such as typeid(5), unchanged.
The advantage of this is that we shift implementation from the compiler internals to the core runtime, which gives us more leeway. Also, the new function being a template, it's not instantiated if not used which saves on data. (Presumably the TypeInfo objects would be function-static.)
In order to get this to work, it would have to have a druntime template that generates the following info for the typeid:
{
void **vptr;
monitor_t monitor;
byte[] m_init; // static initialization data
string name; // class name
void*[] vtbl;
Interface[] interfaces;
ClassInfo base; // base class
void* destructor;
void function(Object) classInvariant; // class invariant
ClassFlags m_flags;
void* deallocator;
OffsetTypeInfo[] offTi;
void function(Object) defaultConstructor;
//const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function
immutable(void)* m_RTInfo;
//TypeInfo typeinfo;
}
which is what the compiler does in the toobj.d module in the visit(ClassDeclaration cd) function. Doing this is fairly complex, depending on how far one wishes to go with it - for example, preparing the initializer for the .vtbl field is quite daunting. Perhaps have the compiler provide that via a __traits? That would relieve some of the complexity of doing this. Or maybe have the compiler still generate this data, but only to make it accessible via __traits() and then have the druntime template cherry pick it as necessary?
Comment #4 by robert.schadek — 2024-12-07T13:37:01Z