One step out of the TypeInfo stalemate
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Jul 25 16:34:07 UTC 2020
I think this has been attempted before. The TypeInfo* classes in
object.d are one gnarly thing after another:
https://github.com/dlang/druntime/blob/master/src/object.d
Very poor usefulness to real estate ratio, ugly and inefficient
implementation, etc. etc.
One simple step out of this would be to replace TypeInfo_Struct with a
template TypeInfo(T) if (is(T == struct)). Then expressions such as
`typeid(MyStruct)` would be lowered to
`.object.__getTypeInfo!MyStruct()`. That function uses a singleton with
lazy allocation.
That means for all structs the compiler does not need to generate
TypeInfo_Struct objects, and the implementation of the primitives is
simpler and more efficient.
We can't do exactly this for classes because typeid(obj) is dynamic, so
it requires a virtual call. But there are other ideas we can use there
as well.
More information about the Digitalmars-d
mailing list