www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Effects of having multiple TypeInfo with the same type name and the

reply Ahmet Sait <nightmarex1337 hotmail.com> writes:
Hi,
I'm creating this thread to gather insight and better understand 
how could 
[mangle-prefix](https://github.com/dlang/dmd/pull/13115) changes 
would affect the language.

What are the runtime features that relly on TypeInfo? Comparing 
`typeid(a) == typeid(b)` checks if type names match, what other 
language/runtime features rely on type names?
I've been told that LDC (and GDC) is able to merge TypeInfo 
symbols correctly which means it is possible to compare 
references instead of type names in this case.

What about exceptions? How does exception mechanism interact with 
TypeInfo?

What do you think about Object.factory? It works by iterating 
TypeInfo fields from ModuleInfo and constructs the object if it 
finds one that matches the given type name. This of course breaks 
when there are more than a single type with the same name. Do you 
have a solution in mind to fix it? Also, it is possible to create 
a similar functionality to Object.factory with the existing 
meta-programming machinary so it's of questionable value. How 
would you feel if Object.factory gets deprecated?
Nov 22 2021
next sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 11/22/21 4:42 AM, Ahmet Sait wrote:

 What do you think about Object.factory? It works by iterating TypeInfo 
 fields from ModuleInfo and constructs the object if it finds one that 
 matches the given type name. This of course breaks when there are more 
 than a single type with the same name. Do you have a solution in mind to 
 fix it? Also, it is possible to create a similar functionality to 
 Object.factory with the existing meta-programming machinary so it's of 
 questionable value. How would you feel if Object.factory gets deprecated?
Object.factory should be deprecated. Anyone using it is in for trouble. It already does not work in some cases. -Steve
Nov 22 2021
prev sibling next sibling parent bauss <jj_1337 live.dk> writes:
On Monday, 22 November 2021 at 09:42:17 UTC, Ahmet Sait wrote:
 Hi,
 I'm creating this thread to gather insight and better 
 understand how could 
 [mangle-prefix](https://github.com/dlang/dmd/pull/13115) 
 changes would affect the language.

 What are the runtime features that relly on TypeInfo? Comparing 
 `typeid(a) == typeid(b)` checks if type names match, what other 
 language/runtime features rely on type names?
 I've been told that LDC (and GDC) is able to merge TypeInfo 
 symbols correctly which means it is possible to compare 
 references instead of type names in this case.

 What about exceptions? How does exception mechanism interact 
 with TypeInfo?

 What do you think about Object.factory? It works by iterating 
 TypeInfo fields from ModuleInfo and constructs the object if it 
 finds one that matches the given type name. This of course 
 breaks when there are more than a single type with the same 
 name. Do you have a solution in mind to fix it? Also, it is 
 possible to create a similar functionality to Object.factory 
 with the existing meta-programming machinary so it's of 
 questionable value. How would you feel if Object.factory gets 
 deprecated?
The solution is probably going to be core reflection as it'll let you reflect the correct type for the class you want to instantiate.
Nov 22 2021
prev sibling parent Adam D Ruppe <destructionator gmail.com> writes:
On Monday, 22 November 2021 at 09:42:17 UTC, Ahmet Sait wrote:
 What do you think about Object.factory?
Just remove it, this thing is a drain on D. If you need a runtime factory, it is trivial to register one with reflection. We should probably do a `core.factory` so these things can be centrally registered and provide the helper mixins so you can do custom ones too. Would be far more useful than Object.factory.
Nov 23 2021