Runtime reflection idea

Rainer Schuetze r.sagitario at gmx.de
Sun Jun 2 06:28:20 PDT 2013



On 02.06.2013 11:33, Benjamin Thaut wrote:
> I think this is a very good idea. The only question is how complete this
> RTTI should be. This again highly depends on what it will be used for.
> For some users it might be ok to do a full RTTI, which will increase the
> executable size significantly. Other users might prefer a minimal RTTI
> or even no RTTI at all depending on the use case.
>
> The RTInfo template is very usefull for many different tasks, the
> question is if we shouldn't make the concept more generic so that you
> can have multiple templates which behave like the RTInfo template. I'm
> currently also using it for RTTI info see:
> http://3d.benjamin-thaut.de/?p=25
>

As a number of use cases show up for the RTInfo template (the precise GC 
also uses it), I think a simple approach for not stepping on each other 
toes would be to declare a struct type RTInfoData, and add each 
implementation as a member to this struct (not checked whether this 
actually compiles):

struct RTInfoData
{
	immutable(RuntimeReflection)* rr;
	immutable(thMemberInfo)* th;
	immutable(PreciseGCData)* gc;
}

template RTInfo(T)
{
     immutable(RTInfoData) data = RTInfoData(genRuntimeReflection!T,
                                             genMemberInfo!T,
                                             genGCData!T);
     enum RTInfo = &data;
}

and TypeInfo.rtInfo() would then return a pointer to RTInfoData instead 
of void*. This doesn't make it modifiable from outside object.di, but I 
have no idea how that could be possible to begin with (without 
recompiling the runtime library).

Unfortunately the compiler sometimes doesn't force the generation of 
RTInfo, but sets the m_rtInfo to 0 or 1 depending on whether the Type 
contains pointers or not. I always wanted to figure out why that happens...


More information about the Digitalmars-d mailing list