Generic Reflection is Missing Information
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.15.0
## What you did
I'm working on converting the reflected types in bevy into a statically typed schema (specifically Cap'n Proto, but the problem is not specific to that format). The format allows using generics, and I want to map this 1-to-1 onto bevy's use of generics.
## What went wrong
The generic information does not contain information about which fields in the type are actually using that generic type. For example, there's this type:
```rs
pub struct ChunkedUnevenCore {
pub times: Vec,
pub values: Vec,
}
```
in `bevy_math::curve::cores`.
The type information for this type is:
```rs
StructInfo {
ty: bevy_math::curve::cores::ChunkedUnevenCore,
generics: Generics(
[
Type(
TypeParamInfo {
name: "T",
ty: f32,
default: None,
},
),
],
),
fields: [
NamedField {
name: "times",
type_info: 0x00005f40ff681290,
ty: alloc::vec::Vec,
custom_attributes: {},
},
NamedField {
name: "values",
type_info: 0x00005f40ff681290,
ty: alloc::vec::Vec,
custom_attributes: {},
},
],
field_names: [
"times",
"values",
],
field_indices: {
"values": 1,
"times": 0,
},
custom_attributes: {},
}
```
So, I know that there's a generic `T` that is an `f32` in this case, and I know that there's two `Vec` fields, but I don't know which one is generic (if any) and which one isn't (if any).
Also, just detecting that there's the type from the generic `T` hidden inside a generic parameter of a field is already pretty complicated (I'm using the syn crate for that, basically recreating part of the reflection parsing).
## Suggestions
The type information for fields should contain both pieces of information, the concrete type based on the generic replacement and the generic type itself.
## Additional information
I already discussed this in the chat on the bevy Discord, but I figured it should actually be a ticket.
Contributor guide
Research direction
Start with Bevy's reflection metadata for StructInfo, Generics, and NamedField, using bevy_math::curve::cores::ChunkedUnevenCore as the concrete example. Trace how generic replacements and field types are recorded, then define the metadata needed to distinguish generic usage inside nested field types. Done means reflected fields expose both their concrete type and the corresponding generic information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools, game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100