From 695d30bd54af2978dc99f214dda34b568348cf86 Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Thu, 23 Feb 2023 05:11:12 +0000 Subject: [PATCH] Clean up marker generics for systems (#7789) # Objective While we use `#[doc(hidden)]` to try and hide marker generics from the user, these types reveal themselves in compiler errors, adding visual noise and confusion. ## Solution Replace the `AlreadyWasSystem` marker generic with `()`, to reduce visual noise in error messages. This also makes it possible to return `impl Condition<()>` from combinators. For function systems, use their function signature as the marker type. This should drastically improve the legibility of some error messages. The `InputMarker` type has been removed, since it is unnecessary. --- crates/bevy_ecs/src/schedule/condition.rs | 6 ++---- .../bevy_ecs/src/system/exclusive_function_system.rs | 8 ++++---- crates/bevy_ecs/src/system/function_system.rs | 10 +++------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/condition.rs b/crates/bevy_ecs/src/schedule/condition.rs index 040d53d6ca0bb..96ca767bd442c 100644 --- a/crates/bevy_ecs/src/schedule/condition.rs +++ b/crates/bevy_ecs/src/schedule/condition.rs @@ -137,7 +137,7 @@ pub mod common_conditions { event::{Event, EventReader}, prelude::{Component, Query, With}, schedule::{State, States}, - system::{In, IntoPipeSystem, ReadOnlySystem, Res, Resource}, + system::{In, IntoPipeSystem, Res, Resource}, }; /// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true` @@ -373,9 +373,7 @@ pub mod common_conditions { /// # /// # fn my_system() { unreachable!() } /// ``` - pub fn not( - condition: impl Condition, - ) -> impl ReadOnlySystem { + pub fn not(condition: impl Condition) -> impl Condition<()> { condition.pipe(|In(val): In| !val) } } diff --git a/crates/bevy_ecs/src/system/exclusive_function_system.rs b/crates/bevy_ecs/src/system/exclusive_function_system.rs index 4ba4a15418655..1fde9619e2436 100644 --- a/crates/bevy_ecs/src/system/exclusive_function_system.rs +++ b/crates/bevy_ecs/src/system/exclusive_function_system.rs @@ -4,8 +4,8 @@ use crate::{ component::ComponentId, query::Access, system::{ - check_system_change_tick, ExclusiveSystemParam, ExclusiveSystemParamItem, In, InputMarker, - IntoSystem, System, SystemMeta, + check_system_change_tick, ExclusiveSystemParam, ExclusiveSystemParamItem, In, IntoSystem, + System, SystemMeta, }, world::{World, WorldId}, }; @@ -181,7 +181,7 @@ pub trait ExclusiveSystemParamFunction: Send + Sync + 'static { macro_rules! impl_exclusive_system_function { ($($param: ident),*) => { #[allow(non_snake_case)] - impl ExclusiveSystemParamFunction<((), Out, $($param,)*)> for Func + impl ExclusiveSystemParamFunction Out> for Func where for <'a> &'a mut Func: FnMut(&mut World, $($param),*) -> Out + @@ -209,7 +209,7 @@ macro_rules! impl_exclusive_system_function { } } #[allow(non_snake_case)] - impl ExclusiveSystemParamFunction<(Input, Out, $($param,)* InputMarker)> for Func + impl ExclusiveSystemParamFunction, $($param,)*) -> Out> for Func where for <'a> &'a mut Func: FnMut(In, &mut World, $($param),*) -> Out + diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index aa87b75a29282..fe6701df605c2 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -325,10 +325,8 @@ pub trait IntoSystem: Sized { fn into_system(this: Self) -> Self::System; } -pub struct AlreadyWasSystem; - // Systems implicitly implement IntoSystem -impl> IntoSystem for Sys { +impl> IntoSystem for Sys { type System = Sys; fn into_system(this: Self) -> Sys { this @@ -362,8 +360,6 @@ impl> IntoSystem(pub In); -#[doc(hidden)] -pub struct InputMarker; /// The [`System`] counter part of an ordinary function. /// @@ -611,7 +607,7 @@ pub trait SystemParamFunction: Send + Sync + 'static { macro_rules! impl_system_function { ($($param: ident),*) => { #[allow(non_snake_case)] - impl SystemParamFunction<((), Out, $($param,)*)> for Func + impl SystemParamFunction Out> for Func where for <'a> &'a mut Func: FnMut($($param),*) -> Out + @@ -638,7 +634,7 @@ macro_rules! impl_system_function { } #[allow(non_snake_case)] - impl SystemParamFunction<(Input, Out, $($param,)* InputMarker)> for Func + impl SystemParamFunction, $($param,)*) -> Out> for Func where for <'a> &'a mut Func: FnMut(In, $($param),*) -> Out +