druntime icon indicating copy to clipboard operation
druntime copied to clipboard

Templated TypeInfo

Open andralex opened this issue 4 years ago • 8 comments

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.

andralex avatar Jul 28 '20 03:07 andralex

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"

dlang-bot avatar Jul 28 '20 03:07 dlang-bot

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 or RTTypeId or...?
  • The moment someone sees __typeid they'll figure a connection with typeid. With RTTypeid, they'll have to run to the manual.

andralex avatar Jul 28 '20 03:07 andralex

__typeid

__ is reserved for compiler internals like auto-generated variables. For runtime template hooks we typically use _d_.

wilzbach avatar Jul 28 '20 08:07 wilzbach

__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?

n8sh avatar Jul 28 '20 11:07 n8sh

Added statically-typed versions of all functions, so if people write typeid(T).func in generic code, an efficient version is picked up.

andralex avatar Jul 28 '20 13:07 andralex

Mind the 32bit platforms. hash_t is 32bit there.

UplinkCoder avatar Jul 28 '20 15:07 UplinkCoder

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.

andralex avatar Aug 01 '20 15:08 andralex

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

andralex avatar Aug 10 '20 01:08 andralex