www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Use template _d_newclass in TypeInfo_Class.create

reply Teodor Dutu <teodor.dutu gmail.com> writes:
Hi,

I am trying to convert `_d_newclass` to a template function.
With this, I aim to remove the old hook from 
[`rt.lifetime.d`](https://github.com/dlang/dmd/blob/b0cf6b7231124eff79ff320f45659116543e6ad2/druntime/src/rt/lifetime.d#L71-L135).
However, this function is used directly by 
[`TypeInfo_Class.create`](https://github.com/dlang/dmd/blob/b0cf6b7231124eff79ff320f45659116543e6ad2/druntime/src/object.d#L1687-L1702).
`TypeInfo_Class.create` cannot call the template hook because it 
doesn't have access to the explicit type, only to its `typeid`.

Being a public function, `TypeInfo_Class.create` can be called by 
user code and simply deleting it or changing it to a template as 
well will most likely break existing code.
For example, it will break [this 
line](https://github.com/dlang/tools/blob/204cc3620270527e186a7fcd0caac658dd5199b4/DustM
te/dustmite.d#L829) in DustMite.

I think the only thing I can do is to leave the old hook in 
`rt.lifetime.d` for now as it will only be used by 
`TypeInfo_Class.create`. Then I'll remove it in the future if 
`TypeInfo_Class.create` or `TypeInfo` itself become deprecated.

How do you say I should proceed with this? Do you see a way to 
use the template `_d_newclass` inside `TypeInfo_Class.create`?

Thanks,
Teodor
Dec 15 2022
next sibling parent Vladimir Panteleev <thecybershadow.lists gmail.com> writes:
On Thursday, 15 December 2022 at 16:34:26 UTC, Teodor Dutu wrote:
 How do you say I should proceed with this? Do you see a way to 
 use the template `_d_newclass` inside `TypeInfo_Class.create`?
I recall there was a recent-ish addition which allowed getting a type using its mangleof string. Perhaps that could be a way?
Dec 15 2022
prev sibling next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
Delete it.

We are in the process of getting rid of Object.factory which would 
utilize this.

Code like Dustmite can create a method that you override to instantiate 
a new instance. This isn't end of the world.
Dec 15 2022
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 12/15/22 11:34 AM, Teodor Dutu wrote:

 How do you say I should proceed with this? Do you see a way to use the 
 template `_d_newclass` inside `TypeInfo_Class.create`?
No, but that's just the price you pay for using `TypeInfo` to create classes. Leave the function, the major goal here is to remove the link from the compiler to the old hook. Library solutions can do whatever they want. -Steve
Dec 15 2022