-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Make #[system_param(ignore)] and #[world_query(ignore)] unnecessary
#8030
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
alice-i-cecile
merged 42 commits into
bevyengine:main
from
joseph-gio:system-param-phantom-data
Mar 30, 2023
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
c766e7c
impl `SystemParam` for `PhantomData`
joseph-gio 8994d13
ensure state types don't collide for `SystemParam`
joseph-gio 92d7921
add a dedicated method for generating identifiers with no collision
joseph-gio 1c6d01f
add a comment describing the collision algorithm
joseph-gio a25fb60
use explicit lifetimes in the `SystemParam` derive
joseph-gio 65f332e
remove `#system_param(ignore)`
joseph-gio 43507a6
clean up state struct lifetimes
joseph-gio 6df2d0a
Merge remote-tracking branch 'upstream/main' into system-param-phanto…
joseph-gio 4e5797c
remove unused attributes
joseph-gio 6eac07a
use a descriptive name for a macro variable
joseph-gio 653fc46
implement `WorldQuery` for `PhantomData`
joseph-gio e18e7af
add a compile test
joseph-gio 715f8ec
remove `#[world_query(ignore)]`
joseph-gio f60909b
make `world_query(ignore)` an error
joseph-gio 4ee9978
add comments to `IS_DENSE` and `IS_ARCHETYPAL`
joseph-gio 3a55ca1
update a comment
joseph-gio c4005ac
disallow `#[system_param]` attributes
joseph-gio 136033c
Merge remote-tracking branch 'upstream/main' into system-param-phanto…
joseph-gio eaddf9a
remove an unused const
joseph-gio b2f4309
undo an overlapping change
joseph-gio 0ab464c
add an example demonstrating `PhantomData` queries
joseph-gio 978437a
import worldquery
joseph-gio 08d6b60
remove collision code
joseph-gio 244a589
remove needless whitespace
joseph-gio 6f5d446
Merge remote-tracking branch 'upstream/main' into system-param-phanto…
joseph-gio 3f0bd19
remove an unused import
joseph-gio 47040f2
Merge remote-tracking branch 'upstream/main' into system-param-phanto…
joseph-gio 988ec67
fix formatting for a `let ... else` block
joseph-gio 986f10c
Merge remote-tracking branch 'upstream/main' into system-param-phanto…
joseph-gio aebb03d
Merge remote-tracking branch 'upstream/main' into system-param-phanto…
joseph-gio 589361e
remove a space
joseph-gio 5dfc332
use non-conflicting lifetime names
joseph-gio 93624c3
add a test case for invariant lifetimes
joseph-gio eb3e17d
re-add `#[system_param(ignore)]`
joseph-gio f3572b1
re-add `#[world_query(ignore)]`
joseph-gio bcfee71
restore some docs
joseph-gio 10edef0
cargo fmt
joseph-gio f8469c5
re-order an example
joseph-gio 2579709
allow unlimited ignored fields
joseph-gio 6a3cfce
reduce churn
joseph-gio 8ff0178
Update crates/bevy_ecs/macros/src/lib.rs
joseph-gio 464e095
deduplicate regression tests
joseph-gio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ use bevy_utils::{all_tuples, synccell::SyncCell}; | |
| use std::{ | ||
| borrow::Cow, | ||
| fmt::Debug, | ||
| marker::PhantomData, | ||
| ops::{Deref, DerefMut}, | ||
| }; | ||
|
|
||
|
|
@@ -65,6 +66,11 @@ use std::{ | |
| /// # bevy_ecs::system::assert_is_system(my_system::<()>); | ||
| /// ``` | ||
| /// | ||
| /// ## `PhantomData` | ||
| /// | ||
| /// [`PhantomData`] is a special type of `SystemParam` that does nothing. | ||
| /// This is useful for constraining generic types or lifetimes. | ||
| /// | ||
| /// # Generic `SystemParam`s | ||
| /// | ||
| /// When using the derive macro, you may see an error in the form of: | ||
|
|
@@ -1465,7 +1471,6 @@ pub mod lifetimeless { | |
| /// #[derive(SystemParam)] | ||
| /// struct GenericParam<'w, 's, T: SystemParam> { | ||
| /// field: T, | ||
| /// #[system_param(ignore)] | ||
| /// // Use the lifetimes in this type, or they will be unbound. | ||
| /// phantom: core::marker::PhantomData<&'w &'s ()> | ||
| /// } | ||
|
|
@@ -1531,6 +1536,26 @@ unsafe impl<P: SystemParam + 'static> SystemParam for StaticSystemParam<'_, '_, | |
| } | ||
| } | ||
|
|
||
| // SAFETY: No world access. | ||
| unsafe impl<T: ?Sized> SystemParam for PhantomData<T> { | ||
| type State = (); | ||
| type Item<'world, 'state> = Self; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is better than just returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also necessary, since |
||
|
|
||
| fn init_state(_world: &mut World, _system_meta: &mut SystemMeta) -> Self::State {} | ||
|
|
||
| unsafe fn get_param<'world, 'state>( | ||
| _state: &'state mut Self::State, | ||
| _system_meta: &SystemMeta, | ||
| _world: &'world World, | ||
| _change_tick: Tick, | ||
| ) -> Self::Item<'world, 'state> { | ||
| PhantomData | ||
| } | ||
| } | ||
|
|
||
| // SAFETY: No world access. | ||
| unsafe impl<T: ?Sized> ReadOnlySystemParam for PhantomData<T> {} | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
@@ -1605,6 +1630,7 @@ mod tests { | |
| _foo: Res<'w, T>, | ||
| #[system_param(ignore)] | ||
| marker: PhantomData<&'w Marker>, | ||
| marker2: PhantomData<&'w Marker>, | ||
| } | ||
|
|
||
| // Compile tests for https://github.com/bevyengine/bevy/pull/6957. | ||
|
|
@@ -1642,4 +1668,10 @@ mod tests { | |
|
|
||
| #[derive(Resource)] | ||
| pub struct FetchState; | ||
|
|
||
| // Regression test for https://github.com/bevyengine/bevy/issues/8192. | ||
| #[derive(SystemParam)] | ||
| pub struct InvariantParam<'w, 's> { | ||
| _set: ParamSet<'w, 's, (Query<'w, 's, ()>,)>, | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.