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] - Simplify trait hierarchy for SystemParam #6865

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
// SAFETY: All parameters are constrained to ReadOnlyState, so World is only read

unsafe impl<'w, 's, #(#param,)*> ReadOnlySystemParam for ParamSet<'w, 's, (#(#param,)*)>
where #(#param: SystemParam + ReadOnlySystemParam,)*
where #(#param: ReadOnlySystemParam,)*
{ }

// SAFETY: Relevant parameter ComponentId and ArchetypeComponentId access is applied to SystemMeta. If any ParamState conflicts
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub unsafe trait SystemParamState: Send + Sync + 'static {
///
/// # Safety
/// This must only be implemented for [`SystemParam`] impls that exclusively read the World passed in to [`SystemParamState::get_param`]
pub unsafe trait ReadOnlySystemParam {}
pub unsafe trait ReadOnlySystemParam: SystemParam {}

impl<'w, 's, Q: WorldQuery + 'static, F: ReadOnlyWorldQuery + 'static> SystemParam
for Query<'w, 's, Q, F>
Expand All @@ -136,8 +136,8 @@ impl<'w, 's, Q: WorldQuery + 'static, F: ReadOnlyWorldQuery + 'static> SystemPar
}

// SAFETY: QueryState is constrained to read-only fetches, so it only reads World.
unsafe impl<'w, 's, Q: ReadOnlyWorldQuery, F: ReadOnlyWorldQuery> ReadOnlySystemParam
for Query<'w, 's, Q, F>
unsafe impl<'w, 's, Q: ReadOnlyWorldQuery + 'static, F: ReadOnlyWorldQuery + 'static>
Copy link
Member

Choose a reason for hiding this comment

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

Was this required by the compiler? This seems incorrect to me.

Copy link
Member Author

@JoJoJet JoJoJet Dec 7, 2022

Choose a reason for hiding this comment

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

These bounds are required because ReadOnlySystemParam: SystemParam -- same reason I had to add them to StaticSystemParam before. The bounds already exist on impl SystemParam for Query<>, so nothing is lost here.

Copy link
Member

Choose a reason for hiding this comment

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

oh awesome I didn't realise we were already requiring Q: 'static and F: 'static on the SystemParam impl. We should just require trait WorldQuery: 'static then

Copy link
Member

Choose a reason for hiding this comment

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

Oh man that's nutty. Seems counterintuitive in this case, though probably for the best. LGTM then, we can address the WorldQuery: 'static thing in another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should just require trait WorldQuery: 'static then

I agree -- I just tried this though and it seems like it'll add a bunch of churn, so I'll leave it for another PR.

ReadOnlySystemParam for Query<'w, 's, Q, F>
{
}

Expand Down Expand Up @@ -1555,7 +1555,7 @@ impl<'w, 's, P: SystemParam> StaticSystemParam<'w, 's, P> {
pub struct StaticSystemParamState<S, P>(S, PhantomData<fn() -> P>);

// SAFETY: This doesn't add any more reads, and the delegated fetch confirms it
unsafe impl<'w, 's, P: SystemParam + ReadOnlySystemParam> ReadOnlySystemParam
unsafe impl<'w, 's, P: ReadOnlySystemParam + 'static> ReadOnlySystemParam
for StaticSystemParam<'w, 's, P>
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
assert_readonly::<Mutable>();
}

fn assert_readonly<P: SystemParam>()
fn assert_readonly<P>()
where
P: ReadOnlySystemParam,
{
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_render/src/extract_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ use std::ops::{Deref, DerefMut};
/// [Window]: bevy_window::Window
pub struct Extract<'w, 's, P>
where
P: SystemParam + ReadOnlySystemParam + 'static,
P: ReadOnlySystemParam + 'static,
{
item: SystemParamItem<'w, 's, P>,
}

impl<'w, 's, P> SystemParam for Extract<'w, 's, P>
where
P: SystemParam + ReadOnlySystemParam,
P: ReadOnlySystemParam,
{
type State = ExtractState<P>;
}
Expand All @@ -66,7 +66,7 @@ pub struct ExtractState<P: SystemParam + 'static> {
// which is initialized in init()
unsafe impl<P: SystemParam + 'static> SystemParamState for ExtractState<P>
where
P: SystemParam + ReadOnlySystemParam + 'static,
P: ReadOnlySystemParam + 'static,
{
type Item<'w, 's> = Extract<'w, 's, P>;

Expand Down