-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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: Split #[reflect(where)]
#11597
Merged
alice-i-cecile
merged 3 commits into
bevyengine:main
from
MrGVSV:mrgvsv/reflect/improved-where-attribute
Jan 29, 2024
Merged
bevy_reflect: Split #[reflect(where)]
#11597
alice-i-cecile
merged 3 commits into
bevyengine:main
from
MrGVSV:mrgvsv/reflect/improved-where-attribute
Jan 29, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Type parameters no longer receive reflection bounds. Fields receive those bounds now (as they did before bevyengine#9046).
MrGVSV
added
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
A-Reflection
Runtime information about types
labels
Jan 29, 2024
soqb
approved these changes
Jan 29, 2024
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.
wow! that was quick. i'm really glad with how the new WhereClauseOptions
looks.
alice-i-cecile
approved these changes
Jan 29, 2024
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
tjamaan
pushed a commit
to tjamaan/bevy
that referenced
this pull request
Feb 6, 2024
# Objective Revert the changes to type parameter bounds introduced in bevyengine#9046, improves the `#[reflect(where)]` attribute (also from bevyengine#9046), and adds the ability to opt out of field bounds. This is based on suggestions by @soqb and discussion on [Discord](https://discord.com/channels/691052431525675048/1002362493634629796/1201227833826103427). ## Solution Reverts the changes to type parameter bounds when deriving `Reflect`, introduced in bevyengine#9046. This was originally done as a means of fixing a recursion issue (bevyengine#8965). However, as @soqb pointed out, we could achieve the same result by simply making an opt-out attribute instead of messing with the type parameter bounds. This PR has four main changes: 1. Reverts the type parameter bounds from bevyengine#9046 2. Includes `TypePath` as a default bound for active fields 3. Changes `#reflect(where)]` to be strictly additive 4. Adds `#reflect(no_field_bounds)]` to opt out of field bounds Change 1 means that, like before, type parameters only receive at most the `TypePath` bound (if `#[reflect(type_path = false)]` is not present) and active fields receive the `Reflect` or `FromReflect` bound. And with Change 2, they will also receive `TypePath` (since it's indirectly required by `Typed` to construct `NamedField` and `UnnamedField` instances). Change 3 was made to make room for Change 4. By splitting out the responsibility of `#reflect(where)]`, we can use it with or without `#reflect(no_field_bounds)]` for various use cases. For example, if we hadn't done this, the following would have failed: ```rust // Since we're not using `#reflect(no_field_bounds)]`, // `T::Assoc` is automatically given the required bounds // of `FromReflect + TypePath` #[derive(Reflect)] #[reflect(where T::Assoc: OtherTrait)] struct Foo<T: MyTrait> { value: T::Assoc, } ``` This provides more flexibility to the user while still letting them add or remove most trait bounds. And to solve the original recursion issue, we can do: ```rust #[derive(Reflect)] #[reflect(no_field_bounds)] // <-- Added struct Foo { foo: Vec<Foo> } ``` #### Bounds All in all, we now have four sets of trait bounds: - `Self` gets the bounds `Any + Send + Sync` - Type parameters get the bound `TypePath`. This can be opted out of with `#[reflect(type_path = false)]` - Active fields get the bounds `TypePath` and `FromReflect`/`Reflect` bounds. This can be opted out of with `#reflect(no_field_bounds)]` - Custom bounds can be added with `#[reflect(where)]` --- ## Changelog - Revert some changes bevyengine#9046 - `#reflect(where)]` is now strictly additive - Added `#reflect(no_field_bounds)]` attribute to opt out of automatic field trait bounds when deriving `Reflect` - Made the `TypePath` requirement on fields when deriving `Reflect` more explicit ## Migration Guide > [!important] > This PR shouldn't be a breaking change relative to the current version of Bevy (v0.12). And since it removes the breaking parts of bevyengine#9046, that PR also won't need a migration guide.
TrialDragon
added a commit
to TrialDragon/bevy-website
that referenced
this pull request
Feb 18, 2024
The breaking changes were removed in a follow-up PR: bevyengine/bevy#11597 . As such these changes, and their migration guide, were old and irrelevant to the released version of 0.13.
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-Usability
A targeted quality-of-life change that makes Bevy easier to use
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
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
Revert the changes to type parameter bounds introduced in #9046, improves the
#[reflect(where)]
attribute (also from #9046), and adds the ability to opt out of field bounds.This is based on suggestions by @soqb and discussion on Discord.
Solution
Reverts the changes to type parameter bounds when deriving
Reflect
, introduced in #9046. This was originally done as a means of fixing a recursion issue (#8965). However, as @soqb pointed out, we could achieve the same result by simply making an opt-out attribute instead of messing with the type parameter bounds.This PR has four main changes:
TypePath
as a default bound for active fields#reflect(where)]
to be strictly additive#reflect(no_field_bounds)]
to opt out of field boundsChange 1 means that, like before, type parameters only receive at most the
TypePath
bound (if#[reflect(type_path = false)]
is not present) and active fields receive theReflect
orFromReflect
bound. And with Change 2, they will also receiveTypePath
(since it's indirectly required byTyped
to constructNamedField
andUnnamedField
instances).Change 3 was made to make room for Change 4. By splitting out the responsibility of
#reflect(where)]
, we can use it with or without#reflect(no_field_bounds)]
for various use cases.For example, if we hadn't done this, the following would have failed:
This provides more flexibility to the user while still letting them add or remove most trait bounds.
And to solve the original recursion issue, we can do:
Bounds
All in all, we now have four sets of trait bounds:
Self
gets the boundsAny + Send + Sync
TypePath
. This can be opted out of with#[reflect(type_path = false)]
TypePath
andFromReflect
/Reflect
bounds. This can be opted out of with#reflect(no_field_bounds)]
#[reflect(where)]
Changelog
#reflect(where)]
is now strictly additive#reflect(no_field_bounds)]
attribute to opt out of automatic field trait bounds when derivingReflect
TypePath
requirement on fields when derivingReflect
more explicitMigration Guide
Important
This PR shouldn't be a breaking change relative to the current version of Bevy (v0.12). And since it removes the breaking parts of #9046, that PR also won't need a migration guide.