Direct access to struct construction, copying and destruction

Benjamin Thaut code at benjamin-thaut.de
Wed Jul 11 01:21:29 PDT 2012


Am 11.07.2012 09:33, schrieb Jonathan M Davis:
> On Wednesday, July 11, 2012 09:28:15 Benjamin Thaut wrote:
>> Am 10.07.2012 07:13, schrieb Jonathan M Davis:
>>> On Tuesday, July 10, 2012 06:53:29 Benjamin Thaut wrote:
>>>> Am 10.07.2012 00:53, schrieb Jonathan M Davis:
>>>>> On Monday, July 09, 2012 22:41:57 Benjamin Thaut wrote:
>>>>>> Clear uses the TypeInfo. The proposed functions should not be library
>>>>>> functions but directly aviable from the compiler. Something like
>>>>>> __postblit and __dtor but properly implemented.
>>>>>
>>>>> Well, since all of the necessary information is in the TypeInfo, not in
>>>>> the
>>>>> type itself, I don't see how you're going to do that. As I understand
>>>>> it,
>>>>> it's not the compiler that deals with all of that. It's druntime. So,
>>>>> without a major redesign, there's no way that the compiler is going to
>>>>> generate that stuff for you. That's druntime's job.
>>>>>
>>>>> - Jonathan M Davis
>>>>
>>>> So who fills the TypeInfo objects, the runtime? I always assumed that
>>>> the compiler fills the TypeInfo and therefor has all the neccessary
>>>> information already at hand.
>>>
>>> I don't know the details, but as I understand it, all of the logic for
>>> actually copying and destroying things properly is in druntime. The
>>> compiler doesn't do any of that. That being the case, any code which
>>> wants to use a type's postblit or destructor needs to use druntime. Right
>>> now, I believe that the compiler just uses hooks into the druntime code
>>> like it does with stuff like new and AAs. So, to skip using the druntime
>>> functions to properly copy or destroy an object, the compiler would have
>>> to duplicate the logic which currently resides in druntime.
>>>
>>> - Jonathan M Davis
>>
>> Thats fine, I don't want the compiler to duplicate that logic. I just
>> want the compiler to expose all the neccessary function that are
>> provided by the compiler anyway so *I* can duplicate the logic from
>> D-Runtime *without* going over a TypeInfo Object.
>
> Then look over TypeInfo and see what it does. It may be possible to just
> duplicate what it's doing. I don't know. Certainly, TypeInfo is used by
> druntime to do the postblits and destructors, so even the compiler is using
> TypeInfo for doing that.
>
> - Jonathan M Davis
>

I already now what type info does, it does nothing.
The compiler fills in the xpostblit and xdtor fields of the 
TypeInfo_Struct with the correct function pointers to postblit or 
destruct functions. These fields always contain the correct function to 
call. But the __postblit and __dtor funtions that are directly callable 
on the struct itself, are only correct if there is a explicit destructor 
/ postblit constructor defined. So it shouldn't be much of a problem to 
also expose the __fielddtor and __fieldpostblit functions that get 
filled into the TypeInfo_Struct object anyway.

Kind Regards
Benjamin Thaut



More information about the Digitalmars-d mailing list