reflect: TypePath part 2#8768
Merged
alice-i-cecile merged 32 commits intobevyengine:mainfrom Oct 9, 2023
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Objective
DeprecateNo longer part of this PR.TypeUuidand remove its internal references.TypePathfor the type registry, and (de)serialisation instead ofstd::any::type_name.Solution
TypeInfoand friends for dynamically querying type path. These methods supersede the oldtype_namemethods.Reflect::type_namein favor ofDynamicTypePath::type_pathandTypeInfo::type_path_table.std::any::type_namein reflection, non-debugging contexts to useTypePath.Changelog
TypePathTablefor dynamically accessing methods onTypePaththroughTypeInfoand the type registry.type_namefrom allTypeInfo-like structs.type_pathandtype_path_tablemethods to allTypeInfo-like structs.Reflect::type_namein favor ofDynamicTypePath::reflect_type_pathandTypeInfo::type_path.DynamicTypePathmethods to return strings with a static lifetime.Migration Guide
Rely on
TypePathinstead ofstd::any::type_namefor all stability guarantees and for use in all reflection contexts, this is used through with one of the following APIs:TypePath::type_pathif you have a concrete type and not a value.DynamicTypePath::reflect_type_pathif you have andyn Reflectvalue without a concrete type.TypeInfo::type_pathfor use through the registry or if you want to work with the represented type of aDynamicFoo.Remove
type_namefrom manualReflectimplementations.Use
type_pathandtype_path_tablein place oftype_nameonTypeInfo-like structs.Use
get_with_type_path(_mut)overget_with_type_name(_mut).Note to reviewers
I think if anything we were a little overzealous in merging #7184 and we should take that extra care here.
In my mind, this is the "point of no return" for
TypePathand while I think we all agree on the design, we should carefully consider if the finer details and current implementations are actually how we want them moving forward.For example this incorrect
TypePathimplementation forString(note thatStringis in the default Rust prelude) snuck in completely under the radar.