Change typeid
definition to be based around the canonical type hash
#4860
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
typeid
used to be a fancy index with extra metadata stored on it. Now it is direct hash of the type. This means thattypeid
is now fully deterministic.n.b. This does not mean you should pass
typeid
across DLL boundaries still, as this is most likely not work.The new definition of a
typeid
is now always 8 bytes on all platforms (rather than the previous definition of being pointer sized), and thus the size ofany
is 16 bytes with an 8 byte alignment. This does mean there is an extra 4 bytes of padding on 32-bit systems, but this is an okay cost in general for deterministictypeid
s.This is safe to do in practice since any possible collisions are checked at compile time AND the chances of having a 1% collision requires ~609K types (see the Birthday Paradox).
Therefore accessing a
^Type_Info
is now a hash table lookup with linear probing. The table is twice the size than necessary so prevent too much probing due to an overly dense hash table.As this requires a
%
operation, it might be a bit costly to gather the type info data. This could be optimized in the future by allowing that operation to be baked at compile time if possible.