Skip to content
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

reflect: treat proxy types correctly when serializing #12024

Merged
merged 4 commits into from
Feb 26, 2024

Conversation

soqb
Copy link
Contributor

@soqb soqb commented Feb 21, 2024

Objective

Solution

  • Use FromReflect to convert proxy types to concrete ones in ReflectSerialize::get_serializable.
  • Use get_represented_type_info() -> type_id() to get the correct type id to interact with the registry in bevy_reflect::serde::ser::get_serializable.

Changelog

  • Registering ReflectSerialize now imposes additional FromReflect and TypePath bounds.

Migration Guide

  • If ReflectSerialize is registered on a type, but TypePath or FromReflect implementations are omitted (perhaps by #[reflect(type_path = false) or #[reflect(from_reflect = false)]), the traits must now be implemented.

@nicopap nicopap added the A-Reflection Runtime information about types label Feb 21, 2024
@soqb soqb added the C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide label Feb 21, 2024
@rparrett
Copy link
Contributor

Not a proper review, but Is this the expected output?

// with `serialize`
"bevy_core::name::Name": "joe",

// without
"bevy_core::name::Name": (
  hash: 1651241057899607384,
  name: "joe",
),

If so, does this comment on Name need to be adjusted?

hash: u64, // Won't be serialized (see: `bevy_core::serde` module) 

Or do we need a followup issue to address hash being serialized when serialize isn't enabled?

@soqb
Copy link
Contributor Author

soqb commented Feb 22, 2024

yeah i chose not to do anything to the feature flags to make this fix as simple as possible - i don't think it's trivial (and it's probably not uncontroversial) to remove all the feature flags for serialisation throughout bevy.

crates/bevy_reflect/src/type_registry.rs Outdated Show resolved Hide resolved
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
@alice-i-cecile alice-i-cecile added this to the 0.13.1 milestone Feb 24, 2024
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 24, 2024
@alice-i-cecile
Copy link
Member

@soqb can you run cargo fmt on this for me?

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 26, 2024
Merged via the queue into bevyengine:main with commit 2b7a3b2 Feb 26, 2024
23 checks passed
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
# Objective

- Fixes bevyengine#12001.
- Note this PR doesn't change any feature flags, however flaky the issue
revealed they are.

## Solution

- Use `FromReflect` to convert proxy types to concrete ones in
`ReflectSerialize::get_serializable`.
- Use `get_represented_type_info() -> type_id()` to get the correct type
id to interact with the registry in
`bevy_reflect::serde::ser::get_serializable`.

---

## Changelog

- Registering `ReflectSerialize` now imposes additional `FromReflect`
and `TypePath` bounds.

## Migration Guide

- If `ReflectSerialize` is registered on a type, but `TypePath` or
`FromReflect` implementations are omitted (perhaps by
`#[reflect(type_path = false)` or `#[reflect(from_reflect = false)]`),
the traits must now be implemented.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
# Objective

- Fixes bevyengine#12001.
- Note this PR doesn't change any feature flags, however flaky the issue
revealed they are.

## Solution

- Use `FromReflect` to convert proxy types to concrete ones in
`ReflectSerialize::get_serializable`.
- Use `get_represented_type_info() -> type_id()` to get the correct type
id to interact with the registry in
`bevy_reflect::serde::ser::get_serializable`.

---

## Changelog

- Registering `ReflectSerialize` now imposes additional `FromReflect`
and `TypePath` bounds.

## Migration Guide

- If `ReflectSerialize` is registered on a type, but `TypePath` or
`FromReflect` implementations are omitted (perhaps by
`#[reflect(type_path = false)` or `#[reflect(from_reflect = false)]`),
the traits must now be implemented.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
mockersf pushed a commit that referenced this pull request Feb 27, 2024
# Objective

- Fixes #12001.
- Note this PR doesn't change any feature flags, however flaky the issue
revealed they are.

## Solution

- Use `FromReflect` to convert proxy types to concrete ones in
`ReflectSerialize::get_serializable`.
- Use `get_represented_type_info() -> type_id()` to get the correct type
id to interact with the registry in
`bevy_reflect::serde::ser::get_serializable`.

---

## Changelog

- Registering `ReflectSerialize` now imposes additional `FromReflect`
and `TypePath` bounds.

## Migration Guide

- If `ReflectSerialize` is registered on a type, but `TypePath` or
`FromReflect` implementations are omitted (perhaps by
`#[reflect(type_path = false)` or `#[reflect(from_reflect = false)]`),
the traits must now be implemented.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serialization of Name component may not be working correctly
5 participants