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

[Merged by Bors] - Add marker traits to distinguish base sets from regular system sets #7863

Closed
wants to merge 7 commits into from

Conversation

JoJoJet
Copy link
Member

@JoJoJet JoJoJet commented Mar 2, 2023

Objective

Base sets, added in #7466 are a special type of system set. Systems can only be added to base sets via in_base_set, while non-base sets can only be added via in_set. Unfortunately this is currently guarded by a runtime panic, which presents an unfortunate toe-stub when the wrong method is used. The delayed response between writing code and encountering the error (possibly hours) makes the distinction between base sets and other sets much more difficult to learn.

Solution

Add the marker traits BaseSystemSet and FreeSystemSet. in_base_set and in_set now respectively accept these traits, which moves the runtime panic to a compile time error.


Changelog

  • Added the marker trait BaseSystemSet, which is distinguished from a FreeSystemSet. These are both subtraits of SystemSet.

Migration Guide

None if merged with 0.10

@JoJoJet JoJoJet added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Mar 2, 2023
@alice-i-cecile alice-i-cecile added this to the 0.10 milestone Mar 2, 2023
Copy link
Contributor

@TimJentzsch TimJentzsch left a comment

Choose a reason for hiding this comment

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

IMO this is a much needed change to ease the migration from 0.9 to 0.10.

@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 Mar 2, 2023
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.

Much needed: I'm glad that we managed to get compile-time detection here and this is an elegant strategy that reduces code duplication.

FYI @cart, who tried to achieve this goal in initial implementations of base system sets.

bors r+

bors bot pushed a commit that referenced this pull request Mar 2, 2023
…7863)

# Objective

Base sets, added in #7466  are a special type of system set. Systems can only be added to base sets via `in_base_set`, while non-base sets can only be added via `in_set`. Unfortunately this is currently guarded by a runtime panic, which presents an unfortunate toe-stub when the wrong method is used. The delayed response between writing code and encountering the error (possibly hours) makes the distinction between base sets and other sets much more difficult to learn.

## Solution

Add the marker traits `BaseSystemSet` and `FreeSystemSet`. `in_base_set` and `in_set` now respectively accept these traits, which moves the runtime panic to a compile time error.

---

## Changelog

+ Added the marker trait `BaseSystemSet`, which is distinguished from a `FreeSystemSet`. These are both subtraits of `SystemSet`.

## Migration Guide

None if merged with 0.10
@bors bors bot changed the title Add marker traits to distinguish base sets from regular system sets [Merged by Bors] - Add marker traits to distinguish base sets from regular system sets Mar 2, 2023
@bors bors bot closed this Mar 2, 2023
@JoJoJet JoJoJet deleted the system-set-marker-traits branch March 2, 2023 13:46
@cart
Copy link
Member

cart commented Mar 2, 2023

This was a great idea / a good win! We might want to also remove the runtime validation as its redundant / will just take up space and compute time.

@JoJoJet
Copy link
Member Author

JoJoJet commented Mar 2, 2023

I left the runtime checks since it's possible for someone to make a custom SystemSet implementation that incorrectly implements these traits. I'm not sure what's the best way of handling a type that implements BaseSystemSet and returns is_base = false.

bors bot pushed a commit that referenced this pull request Mar 3, 2023
# Objective

#7863 introduced a potential footgun. When trying to incorrectly add a user-defined type using `in_base_set`, the compiler will suggest that the user implement `BaseSystemSet` for their type. This is a reasonable-sounding suggestion, however this is not the correct way to make a base set, and will lead to a confusing panic message when a marker trait is implemented for the wrong type.

## Solution

Rewrite the documentation for these traits, making it more clear that `BaseSystemSet` is a marker for types that are already base sets, and not a way to define a base set.
Shfty pushed a commit to shfty-rust/bevy that referenced this pull request Mar 19, 2023
…evyengine#7863)

# Objective

Base sets, added in bevyengine#7466  are a special type of system set. Systems can only be added to base sets via `in_base_set`, while non-base sets can only be added via `in_set`. Unfortunately this is currently guarded by a runtime panic, which presents an unfortunate toe-stub when the wrong method is used. The delayed response between writing code and encountering the error (possibly hours) makes the distinction between base sets and other sets much more difficult to learn.

## Solution

Add the marker traits `BaseSystemSet` and `FreeSystemSet`. `in_base_set` and `in_set` now respectively accept these traits, which moves the runtime panic to a compile time error.

---

## Changelog

+ Added the marker trait `BaseSystemSet`, which is distinguished from a `FreeSystemSet`. These are both subtraits of `SystemSet`.

## Migration Guide

None if merged with 0.10
Shfty pushed a commit to shfty-rust/bevy that referenced this pull request Mar 19, 2023
# Objective

bevyengine#7863 introduced a potential footgun. When trying to incorrectly add a user-defined type using `in_base_set`, the compiler will suggest that the user implement `BaseSystemSet` for their type. This is a reasonable-sounding suggestion, however this is not the correct way to make a base set, and will lead to a confusing panic message when a marker trait is implemented for the wrong type.

## Solution

Rewrite the documentation for these traits, making it more clear that `BaseSystemSet` is a marker for types that are already base sets, and not a way to define a base set.
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 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