druntime
druntime copied to clipboard
Templated TypeInfo
Starting small. This duplicates the implementation in https://github.com/dlang/druntime/blob/master/src/rt/typeinfo/ti_int.d. The idea is, of course, that the templated implementation will replace implementations for all scalar types. For testing purposes I restricted it to int.
The thing works if typeid(int)
lowers to RTTypeid!(int)
. The use of eponymous templates elegantly hides the type name.
Thanks for your pull request, @andralex!
Bugzilla references
Your PR doesn't reference any Bugzilla issue.
If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
Testing this PR locally
If you don't have a local development environment setup, you can use Digger to test this PR:
dub run digger -- build "master + druntime#3174"
I took upon painting the bikeshed by changing the name from RTTypeid
to __typeid
. Reasons:
- A value with a capitalized name breaks the convention used everywhere in druntime and phobos
- The whole thing is awkward to type - was that
RTTypeID
orRTTypeId
or...? - The moment someone sees
__typeid
they'll figure a connection withtypeid
. WithRTTypeid
, they'll have to run to the manual.
__typeid
__ is reserved for compiler internals like auto-generated variables. For runtime template hooks we typically use _d_
.
__typeid
__ is reserved for compiler internals like auto-generated variables. For runtime template hooks we typically use
_d_
.
Wouldn't this be okay for the same reason as __cmp
, __move_post_blt
, __switch_error
, etc?
Added statically-typed versions of all functions, so if people write typeid(T).func
in generic code, an efficient version is picked up.
Mind the 32bit platforms. hash_t is 32bit there.
Per discussions with @WalterBright, it turns out it's not reasonably feasible to do an incremental replacement. The plan instead is to develop __typeid
separately from the built-in typeid
, and replace uses of the latter with the former. At the very end we adjust typeid
to lower to __typeid
.
Currently no support for struct
, class
, and interface
.
Blocked by:
- https://issues.dlang.org/show_bug.cgi?id=21141
- https://issues.dlang.org/show_bug.cgi?id=21142
- https://issues.dlang.org/show_bug.cgi?id=21143
- https://issues.dlang.org/show_bug.cgi?id=21144
- https://issues.dlang.org/show_bug.cgi?id=21145
- https://issues.dlang.org/show_bug.cgi?id=21146