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

reflection: replace impl_reflect_struct with impl_reflect #11437

Merged
merged 8 commits into from
Jan 30, 2024

Conversation

soqb
Copy link
Contributor

@soqb soqb commented Jan 20, 2024

Objective

  • impl_reflect_struct doesn't cover tuple structs or enums.
  • Problem brought up on Discord.

Solution

  • Replaces impl_reflect_struct with the new impl_reflect which works for tuple structs and enums too.

Changelog

  • Internally in bevy_reflect_derive, we have a new ReflectProvenance type which is composed of ReflectTraitToImpl and ReflectSource.
  • impl_reflect_struct is gone and totally superseded by impl_reflect.

@soqb soqb changed the title reflection: reflection: replace impl_reflect_struct with impl_reflect Jan 20, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great, but this needs some tests validating that it actually works on tuple and enum types :)

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change A-Reflection Runtime information about types labels Jan 20, 2024
Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) struct ReflectProvenance {
pub source: ReflectImplSource,
pub trait_: ReflectTraitToImpl,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshed: Rather than having to add the _ suffix, maybe we could rename this to trait_target (maybe even renaming ReflectTraitToImpl to ReflectTraitTarget) or trait_to_impl or something similar.

crates/bevy_reflect/bevy_reflect_derive/src/derive_data.rs Outdated Show resolved Hide resolved
Comment on lines +309 to +312
return Err(syn::Error::new(
meta.type_path().span(),
format!("a #[{TYPE_PATH_ATTRIBUTE_NAME} = \"...\"] attribute must be specified when using {provenance}")
));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@@ -1995,6 +1995,38 @@ bevy_reflect::tests::Test {
);
}

#[test]
fn assert_impl_reflect_on_all() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add assert_impl_all! assertions for these types? Specifically to test that each receives their corresponding trait (i.e. Struct for the struct, Enum for the enum, etc.)? Maybe even to verify that they do indeed get all the other traits, like Typed and friends.

I can't imagine we'd ever break something that big haha but could be nice to have a sanity check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added assert_impl_all for Reflect, which is sensible, but I don't see how we'd miss the others without also breaking #[derive(Reflect)].

@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 Jan 29, 2024
soqb and others added 4 commits January 30, 2024 11:33
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 30, 2024
Merged via the queue into bevyengine:main with commit df761af Jan 30, 2024
22 checks passed
tjamaan pushed a commit to tjamaan/bevy that referenced this pull request Feb 6, 2024
…gine#11437)

# Objective

- `impl_reflect_struct` doesn't cover tuple structs or enums.
- Problem brought up [on
Discord](https://discord.com/channels/691052431525675048/1002362493634629796/1190623345817960463).

## Solution

- Replaces `impl_reflect_struct` with the new `impl_reflect` which works
for tuple structs and enums too.

---

## Changelog

- Internally in `bevy_reflect_derive`, we have a new `ReflectProvenance`
type which is composed of `ReflectTraitToImpl` and `ReflectSource`.
- `impl_reflect_struct` is gone and totally superseded by
`impl_reflect`.

---------

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-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change 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.

None yet

3 participants