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

Add std derives to SystemParam types #16785

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

spectria-limina
Copy link
Contributor

Objective

  • Use Clone on SystemParam, when applicable, in a generic context.

Solution

  • Add some derives

Testing

  • I ran cargo test once.
  • I didn't even look at the output.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Dec 12, 2024
@alice-i-cecile
Copy link
Member

It would be helpful to reviewers to briefly explain why Clone was needed on these types.

@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Dec 12, 2024
Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

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

I'm fine with the code changes themselves, but some justification would be appreciated! :)

@BD103 BD103 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 13, 2024
@BenjaminBrienen BenjaminBrienen added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Dec 25, 2024
@BenjaminBrienen
Copy link
Contributor

If it were just Clone, that would be easier to approve. Why Copy?

@spectria-limina
Copy link
Contributor Author

Sorry for the delay replying.

Types should eagerly implement applicable traits.

My use case was playing around with some dynamic manipulation of builders in order to inject data into a system during state initialization, and my test usage with Local required cloning the builder so that the same builder could be mapped to multiple arguments of a system.

So I think the question is better asked as: why not?

Builder types are only used in the guts of

As for Copy, I think I actually should have made more of them Copy. I don't really see any reason why these shouldn't be Copy when wrapping a Copy type. And [therefore it should] (https://doc.rust-lang.org/std/marker/trait.Copy.html#when-should-my-type-be-copy).

Note that for actual SystemParams, I think Clone or especially Copy wouldn't work because the semantics are tied to the system and it's state. But this is just the builders, and they are basically fancy named closures.

@mockersf
Copy link
Member

So I think the question is better asked as: why not?

More derives mean more build time

And [therefore it should] (https://doc.rust-lang.org/std/marker/trait.Copy.html#when-should-my-type-be-copy).

A lot of people think this advice is wrong. Deriving Copy change the usage of a type from move semantics to copy semantics, and can lead to unexpected behaviour

@alice-i-cecile
Copy link
Member

I agree with everything but Copy here, and would approve it if that's removed. The explanation about dynamic manipulation of builder types makes sense to me.

@BenjaminBrienen
Copy link
Contributor

Copy on everything doesn't work when performance is a huge concern like it is in a game engine. It does make sense if you are coming from a language like Haskell, I think.

@alice-i-cecile
Copy link
Member

Copy on everything doesn't work when performance is a huge concern like it is in a game engine. It does make sense if you are coming from a language like Haskell, I think.

There's no performance concerns here: my objections center around explicitness.

@spectria-limina
Copy link
Contributor Author

Removed Copy

@BenjaminBrienen BenjaminBrienen added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jan 13, 2025
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 13, 2025
@mockersf mockersf enabled auto-merge January 13, 2025 23:16
@mockersf mockersf added this pull request to the merge queue Jan 13, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 13, 2025
@mockersf
Copy link
Member

failure due to GitHub incident

@spectria-limina
Copy link
Contributor Author

spectria-limina commented Jan 14, 2025 via email

@mockersf mockersf added this pull request to the merge queue Jan 14, 2025
Merged via the queue into bevyengine:main with commit 4dfa877 Jan 14, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples 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.

5 participants