Skip to content

Commit

Permalink
Clean up marker generics for systems (#7789)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
JoJoJet committed Feb 23, 2023
1 parent ee4c8c5 commit 695d30b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
6 changes: 2 additions & 4 deletions crates/bevy_ecs/src/schedule/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -373,9 +373,7 @@ pub mod common_conditions {
/// #
/// # fn my_system() { unreachable!() }
/// ```
pub fn not<Marker>(
condition: impl Condition<Marker>,
) -> impl ReadOnlySystem<In = (), Out = bool> {
pub fn not<Marker>(condition: impl Condition<Marker>) -> impl Condition<()> {
condition.pipe(|In(val): In<bool>| !val)
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ecs/src/system/exclusive_function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -181,7 +181,7 @@ pub trait ExclusiveSystemParamFunction<Marker>: Send + Sync + 'static {
macro_rules! impl_exclusive_system_function {
($($param: ident),*) => {
#[allow(non_snake_case)]
impl<Out, Func: Send + Sync + 'static, $($param: ExclusiveSystemParam),*> ExclusiveSystemParamFunction<((), Out, $($param,)*)> for Func
impl<Out, Func: Send + Sync + 'static, $($param: ExclusiveSystemParam),*> ExclusiveSystemParamFunction<fn($($param,)*) -> Out> for Func
where
for <'a> &'a mut Func:
FnMut(&mut World, $($param),*) -> Out +
Expand Down Expand Up @@ -209,7 +209,7 @@ macro_rules! impl_exclusive_system_function {
}
}
#[allow(non_snake_case)]
impl<Input, Out, Func: Send + Sync + 'static, $($param: ExclusiveSystemParam),*> ExclusiveSystemParamFunction<(Input, Out, $($param,)* InputMarker)> for Func
impl<Input, Out, Func: Send + Sync + 'static, $($param: ExclusiveSystemParam),*> ExclusiveSystemParamFunction<fn(In<Input>, $($param,)*) -> Out> for Func
where
for <'a> &'a mut Func:
FnMut(In<Input>, &mut World, $($param),*) -> Out +
Expand Down
10 changes: 3 additions & 7 deletions crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,8 @@ pub trait IntoSystem<In, Out, Marker>: Sized {
fn into_system(this: Self) -> Self::System;
}

pub struct AlreadyWasSystem;

// Systems implicitly implement IntoSystem
impl<In, Out, Sys: System<In = In, Out = Out>> IntoSystem<In, Out, AlreadyWasSystem> for Sys {
impl<In, Out, Sys: System<In = In, Out = Out>> IntoSystem<In, Out, ()> for Sys {
type System = Sys;
fn into_system(this: Self) -> Sys {
this
Expand Down Expand Up @@ -362,8 +360,6 @@ impl<In, Out, Sys: System<In = In, Out = Out>> IntoSystem<In, Out, AlreadyWasSys
/// }
/// ```
pub struct In<In>(pub In);
#[doc(hidden)]
pub struct InputMarker;

/// The [`System`] counter part of an ordinary function.
///
Expand Down Expand Up @@ -611,7 +607,7 @@ pub trait SystemParamFunction<Marker>: Send + Sync + 'static {
macro_rules! impl_system_function {
($($param: ident),*) => {
#[allow(non_snake_case)]
impl<Out, Func: Send + Sync + 'static, $($param: SystemParam),*> SystemParamFunction<((), Out, $($param,)*)> for Func
impl<Out, Func: Send + Sync + 'static, $($param: SystemParam),*> SystemParamFunction<fn($($param,)*) -> Out> for Func
where
for <'a> &'a mut Func:
FnMut($($param),*) -> Out +
Expand All @@ -638,7 +634,7 @@ macro_rules! impl_system_function {
}

#[allow(non_snake_case)]
impl<Input, Out, Func: Send + Sync + 'static, $($param: SystemParam),*> SystemParamFunction<(Input, Out, $($param,)* InputMarker)> for Func
impl<Input, Out, Func: Send + Sync + 'static, $($param: SystemParam),*> SystemParamFunction<fn(In<Input>, $($param,)*) -> Out> for Func
where
for <'a> &'a mut Func:
FnMut(In<Input>, $($param),*) -> Out +
Expand Down

0 comments on commit 695d30b

Please sign in to comment.