Skip to content

Commit

Permalink
Fix SystemTypeSet::system_type being out of sync with `System::type…
Browse files Browse the repository at this point in the history
…_id` (#12030)

## Objective

Always have `some_system.into_system().type_id() ==
some_system.into_system_set().system_type().unwrap()`.

System sets have a `fn system_type() -> Option<TypeId>` that is
implemented by `SystemTypeSet` to returning the TypeId of the system's
function type. This was implemented in
#7715 and is used in
`bevy_mod_debugdump` to handle `.after(function)` constraints.

Back then, `System::type_id` always also returned the type id of the
function item, not of `FunctionSystem<M, F>`.

#11728 changes the behaviour of
`System::type_id` so that it returns the id of the
`FunctionSystem`/`ExclusiveFunctionSystem` wrapper, but it did not
change `SystemTypeSet::system_type`, so doing the lookup breaks in
`bevy_mod_debugdump`.

## Solution

Change `IntoSystemSet` for functions to return a
`SystemTypeSet<FunctionSystem>` /
`SystemTypeSet<ExclusiveFunctionSystem>` instead of `SystemTypeSet<F>`.
  • Loading branch information
jakobhellermann authored and mockersf committed Feb 27, 2024
1 parent 48d93b8 commit 4022385
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions crates/bevy_ecs/src/schedule/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use bevy_utils::intern::Interned;
pub use bevy_utils::label::DynEq;

use crate::system::{
ExclusiveSystemParamFunction, IsExclusiveFunctionSystem, IsFunctionSystem, SystemParamFunction,
ExclusiveFunctionSystem, ExclusiveSystemParamFunction, FunctionSystem,
IsExclusiveFunctionSystem, IsFunctionSystem, SystemParamFunction,
};

define_label!(
Expand Down Expand Up @@ -167,26 +168,28 @@ impl<S: SystemSet> IntoSystemSet<()> for S {
// systems
impl<Marker, F> IntoSystemSet<(IsFunctionSystem, Marker)> for F
where
Marker: 'static,
F: SystemParamFunction<Marker>,
{
type Set = SystemTypeSet<Self>;
type Set = SystemTypeSet<FunctionSystem<Marker, F>>;

#[inline]
fn into_system_set(self) -> Self::Set {
SystemTypeSet::new()
SystemTypeSet::<FunctionSystem<Marker, F>>::new()
}
}

// exclusive systems
impl<Marker, F> IntoSystemSet<(IsExclusiveFunctionSystem, Marker)> for F
where
Marker: 'static,
F: ExclusiveSystemParamFunction<Marker>,
{
type Set = SystemTypeSet<Self>;
type Set = SystemTypeSet<ExclusiveFunctionSystem<Marker, F>>;

#[inline]
fn into_system_set(self) -> Self::Set {
SystemTypeSet::new()
SystemTypeSet::<ExclusiveFunctionSystem<Marker, F>>::new()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/exclusive_function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ where
}

fn default_system_sets(&self) -> Vec<InternedSystemSet> {
let set = crate::schedule::SystemTypeSet::<F>::new();
let set = crate::schedule::SystemTypeSet::<Self>::new();
vec![set.intern()]
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ where
}

fn default_system_sets(&self) -> Vec<InternedSystemSet> {
let set = crate::schedule::SystemTypeSet::<F>::new();
let set = crate::schedule::SystemTypeSet::<Self>::new();
vec![set.intern()]
}

Expand Down

0 comments on commit 4022385

Please sign in to comment.