-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
bevy_reflect: Add Type type
#14838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bevy_reflect: Add Type type
#14838
Conversation
TrialDragon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples run, and after reading the documentation and files, I think this looks good (coming from a person who hasn't really touched reflect code before).
killercup
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good refactor!
|
Merging on Monday; feel free to clean it up in the meantime :) |
|
Updated the code to use Also renamed |
843e04d to
ad513ee
Compare
Objective
Closes #7622.
I was working on adding support for reflecting generic functions and found that I wanted to use an argument's
TypeIdfor hashing and comparison, but itsTypePathfor debugging and error messaging.While I could just keep them separate, place them in a tuple or a local struct or something, I think I see an opportunity to make a dedicated type for this.
Additionally, we can use this type to clean up some duplication amongst the type info structs in a manner similar to #7622.
Solution
Added the
Typetype. This should be seen as the most basic representation of a type apart fromTypeId. It stores both theTypeIdof the type as well as itsTypePathTable.The
HashandPartialEqimplementations rely on theTypeId, while theDebugimplementation relies on theTypePath.This makes it especially useful as a key in a
HashMapsince we get the speed of theTypeIdhashing/comparisons with the readability ofTypePath.With this type, we're able to reduce the duplication across the type info structs by removing individual fields for
TypeIdandTypePathTable, replacing them with a singleTypefield. Similarly, we can remove many duplicate methods and replace it with a macro that delegates to the storedType.Caveats
It should be noted that this type is currently 3x larger than
TypeId. On my machine, it's 48 bytes compared toTypeId's 16. While this doesn't matter forTypeInfosince it would contain that data regardless, it is something to keep in mind when using elsewhere.Testing
All tests should pass as normal:
Showcase
bevy_reflectnow exports aTypestruct. This type contains both theTypeIdand theTypePathTableof the given type, allowing it to be used likeTypeIdbut have the debuggability ofTypePath.Migration Guide
Certain type info structs now only return their item types as
Typeinstead of exposing direct methods on them.The following methods have been removed:
ArrayInfo::item_type_path_tableArrayInfo::item_type_idArrayInfo::item_isListInfo::item_type_path_tableListInfo::item_type_idListInfo::item_isSetInfo::value_type_path_tableSetInfo::value_type_idSetInfo::value_isMapInfo::key_type_path_tableMapInfo::key_type_idMapInfo::key_isMapInfo::value_type_path_tableMapInfo::value_type_idMapInfo::value_isInstead, access the
Typedirectly using one of the new methods:ArrayInfo::item_tyListInfo::item_tySetInfo::value_tyMapInfo::key_tyMapInfo::value_tyFor example: