From 8258d5675d69169227e6102391f410aaa443c1a2 Mon Sep 17 00:00:00 2001 From: targrub Date: Sun, 9 Oct 2022 15:17:26 -0400 Subject: [PATCH 1/8] Implementations of Debug for App, System, Stage, Schedule, and related. --- crates/bevy_app/src/app.rs | 20 ++++++++++++++-- crates/bevy_ecs/src/archetype.rs | 11 +++++++-- crates/bevy_ecs/src/schedule/executor.rs | 9 ++++++- crates/bevy_ecs/src/schedule/mod.rs | 2 +- crates/bevy_ecs/src/schedule/run_criteria.rs | 24 +++++++++++++++++-- crates/bevy_ecs/src/schedule/stage.rs | 8 +++++++ .../bevy_ecs/src/schedule/system_container.rs | 7 ++++++ .../src/schedule/system_descriptor.rs | 1 + crates/bevy_ecs/src/system/system.rs | 19 +++++++++++++++ 9 files changed, 93 insertions(+), 8 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index e71cda2229307..79388fba23902 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -12,7 +12,7 @@ use bevy_ecs::{ world::World, }; use bevy_utils::{tracing::debug, HashMap}; -use std::fmt::Debug; +use core::fmt::Debug; #[cfg(feature = "trace")] use bevy_utils::tracing::info_span; @@ -25,7 +25,7 @@ bevy_utils::define_label!( /// The [`Resource`] that stores the [`App`]'s [`TypeRegistry`](bevy_reflect::TypeRegistry). #[cfg(feature = "bevy_reflect")] -#[derive(Resource, Clone, Deref, DerefMut, Default)] +#[derive(Debug, Resource, Clone, Deref, DerefMut, Default)] pub struct AppTypeRegistry(pub bevy_reflect::TypeRegistryArc); #[allow(clippy::needless_doctest_main)] @@ -70,12 +70,28 @@ pub struct App { sub_apps: HashMap, } +impl Debug for App { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "App {{sub_apps: ")?; + f.debug_map() + .entries(self.sub_apps.iter().map(|(k, v)| (k, v))) + .finish()?; + write!(f, "}}") + } +} + /// Each `SubApp` has its own [`Schedule`] and [`World`], enabling a separation of concerns. struct SubApp { app: App, runner: Box, } +impl Debug for SubApp { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "SubApp") + } +} + impl Default for App { fn default() -> Self { let mut app = App::empty(); diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index cf81b5b633a2e..358ae8099f96e 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -32,11 +32,13 @@ impl ArchetypeId { } } +#[derive(Debug)] pub(crate) enum ComponentStatus { Added, Mutated, } +#[derive(Debug)] pub struct AddBundle { pub archetype_id: ArchetypeId, pub(crate) bundle_status: Vec, @@ -56,7 +58,7 @@ pub struct AddBundle { /// yet. /// /// [`World`]: crate::world::World -#[derive(Default)] +#[derive(Debug, Default)] pub struct Edges { add_bundle: SparseArray, remove_bundle: SparseArray>, @@ -118,21 +120,25 @@ impl Edges { } } +#[derive(Debug)] struct TableInfo { id: TableId, entity_rows: Vec, } +#[derive(Debug)] pub(crate) struct ArchetypeSwapRemoveResult { pub(crate) swapped_entity: Option, pub(crate) table_row: usize, } +#[derive(Debug)] pub(crate) struct ArchetypeComponentInfo { pub(crate) storage_type: StorageType, pub(crate) archetype_component_id: ArchetypeComponentId, } +#[derive(Debug)] pub struct Archetype { id: ArchetypeId, entities: Vec, @@ -346,7 +352,7 @@ impl ArchetypeGeneration { } } -#[derive(Hash, PartialEq, Eq)] +#[derive(Debug, Hash, PartialEq, Eq)] pub struct ArchetypeIdentity { table_components: Box<[ComponentId]>, sparse_set_components: Box<[ComponentId]>, @@ -378,6 +384,7 @@ impl SparseSetIndex for ArchetypeComponentId { } } +#[derive(Debug)] pub struct Archetypes { pub(crate) archetypes: Vec, pub(crate) archetype_component_count: usize, diff --git a/crates/bevy_ecs/src/schedule/executor.rs b/crates/bevy_ecs/src/schedule/executor.rs index 4e649d47086f9..ef0cb45fb229d 100644 --- a/crates/bevy_ecs/src/schedule/executor.rs +++ b/crates/bevy_ecs/src/schedule/executor.rs @@ -1,4 +1,5 @@ use crate::{schedule::SystemContainer, world::World}; +use core::fmt::Debug; use downcast_rs::{impl_downcast, Downcast}; pub trait ParallelSystemExecutor: Downcast + Send + Sync { @@ -8,9 +9,15 @@ pub trait ParallelSystemExecutor: Downcast + Send + Sync { fn run_systems(&mut self, systems: &mut [SystemContainer], world: &mut World); } +impl Debug for dyn ParallelSystemExecutor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "dyn ParallelSystemExecutor") + } +} + impl_downcast!(ParallelSystemExecutor); -#[derive(Default)] +#[derive(Debug, Default)] pub struct SingleThreadedExecutor; impl ParallelSystemExecutor for SingleThreadedExecutor { diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index a6d41240e96f4..8f0e6edf2c906 100644 --- a/crates/bevy_ecs/src/schedule/mod.rs +++ b/crates/bevy_ecs/src/schedule/mod.rs @@ -37,7 +37,7 @@ use bevy_utils::HashMap; /// In this way, the properties of the child schedule can be set differently from the parent. /// For example, it can be set to run only once during app execution, while the parent schedule /// runs indefinitely. -#[derive(Default)] +#[derive(Debug, Default)] pub struct Schedule { stages: HashMap>, stage_order: Vec, diff --git a/crates/bevy_ecs/src/schedule/run_criteria.rs b/crates/bevy_ecs/src/schedule/run_criteria.rs index 575a63080d3fc..3a4da3351cfcd 100644 --- a/crates/bevy_ecs/src/schedule/run_criteria.rs +++ b/crates/bevy_ecs/src/schedule/run_criteria.rs @@ -1,8 +1,10 @@ use crate::{ + prelude::System, schedule::{GraphNode, RunCriteriaLabel, RunCriteriaLabelId}, system::{BoxedSystem, IntoSystem, Local}, world::World, }; +use core::fmt::Debug; use std::borrow::Cow; /// Determines whether a system should be executed or not, and how many times it should be ran each @@ -66,7 +68,19 @@ impl From for ShouldRun { } } -#[derive(Default)] +impl Debug for dyn System + 'static { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "System with In=(), Out=ShouldRun") + } +} + +impl Debug for dyn System + 'static { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "System with In=ShouldRun, Out=ShouldRun") + } +} + +#[derive(Debug, Default)] pub(crate) struct BoxedRunCriteria { criteria_system: Option>, initialized: bool, @@ -93,6 +107,7 @@ impl BoxedRunCriteria { } } +#[derive(Debug)] pub(crate) enum RunCriteriaInner { Single(BoxedSystem<(), ShouldRun>), Piped { @@ -101,6 +116,7 @@ pub(crate) enum RunCriteriaInner { }, } +#[derive(Debug)] pub(crate) struct RunCriteriaContainer { pub(crate) should_run: ShouldRun, pub(crate) inner: RunCriteriaInner, @@ -165,17 +181,19 @@ impl GraphNode for RunCriteriaContainer { } } +#[derive(Debug)] pub enum RunCriteriaDescriptorOrLabel { Descriptor(RunCriteriaDescriptor), Label(RunCriteriaLabelId), } -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub(crate) enum DuplicateLabelStrategy { Panic, Discard, } +#[derive(Debug)] pub struct RunCriteriaDescriptor { pub(crate) system: RunCriteriaSystem, pub(crate) label: Option, @@ -184,6 +202,7 @@ pub struct RunCriteriaDescriptor { pub(crate) after: Vec, } +#[derive(Debug)] pub(crate) enum RunCriteriaSystem { Single(BoxedSystem<(), ShouldRun>), Piped(BoxedSystem), @@ -326,6 +345,7 @@ where } } +#[derive(Debug)] pub struct RunCriteria { label: RunCriteriaLabelId, } diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index ff9479c715c37..86bf21407e1d4 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -14,6 +14,7 @@ use crate::{ }; use bevy_ecs_macros::Resource; use bevy_utils::{tracing::warn, HashMap, HashSet}; +use core::fmt::Debug; use downcast_rs::{impl_downcast, Downcast}; use super::IntoSystemDescriptor; @@ -25,6 +26,12 @@ pub trait Stage: Downcast + Send + Sync { fn run(&mut self, world: &mut World); } +impl Debug for dyn Stage { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Stage {:?}", self.as_any().downcast_ref::()) + } +} + impl_downcast!(Stage); /// When this resource is present in the `App`'s `Resources`, @@ -51,6 +58,7 @@ pub struct ReportExecutionOrderAmbiguities; /// Stores and executes systems. Execution order is not defined unless explicitly specified; /// see `SystemDescriptor` documentation. +#[derive(Debug)] pub struct SystemStage { /// The WorldId this stage was last run on. world_id: Option, diff --git a/crates/bevy_ecs/src/schedule/system_container.rs b/crates/bevy_ecs/src/schedule/system_container.rs index 721faa80f8ac8..8b9cc4d3ccd33 100644 --- a/crates/bevy_ecs/src/schedule/system_container.rs +++ b/crates/bevy_ecs/src/schedule/system_container.rs @@ -4,6 +4,7 @@ use crate::{ schedule::{GraphNode, RunCriteriaLabelId, SystemDescriptor, SystemLabelId}, system::System, }; +use core::fmt::Debug; use std::borrow::Cow; pub struct SystemContainer { @@ -79,6 +80,12 @@ impl SystemContainer { } } +impl Debug for SystemContainer { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "\n{{{:?}}}", &self.system()) + } +} + impl GraphNode for SystemContainer { type Label = SystemLabelId; diff --git a/crates/bevy_ecs/src/schedule/system_descriptor.rs b/crates/bevy_ecs/src/schedule/system_descriptor.rs index e673f12cc58ab..f61bb44071eeb 100644 --- a/crates/bevy_ecs/src/schedule/system_descriptor.rs +++ b/crates/bevy_ecs/src/schedule/system_descriptor.rs @@ -31,6 +31,7 @@ use crate::{ /// .with_system(do_the_other_thing.after(Something)) /// .with_system(do_something_else.at_end()); /// ``` +#[derive(Debug)] pub struct SystemDescriptor { pub(crate) system: BoxedSystem<(), ()>, pub(crate) exclusive_insertion_point: Option, diff --git a/crates/bevy_ecs/src/system/system.rs b/crates/bevy_ecs/src/system/system.rs index 354d4aa1b0dd7..2b84594cf9077 100644 --- a/crates/bevy_ecs/src/system/system.rs +++ b/crates/bevy_ecs/src/system/system.rs @@ -1,4 +1,5 @@ use bevy_utils::tracing::warn; +use core::fmt::Debug; use crate::{ archetype::ArchetypeComponentId, change_detection::MAX_CHANGE_AGE, component::ComponentId, @@ -95,3 +96,21 @@ pub(crate) fn check_system_change_tick( *last_change_tick = change_tick.wrapping_sub(MAX_CHANGE_AGE); } } + +impl Debug for dyn System { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{} {{{}}}", self.name(), { + if self.is_send() { + if self.is_exclusive() { + "is_send is_exclusive" + } else { + "is_send" + } + } else if self.is_exclusive() { + "is_exclusive" + } else { + "" + } + },) + } +} From 483d7c3fd0ebca0b954c5471f85caf9b239a3e14 Mon Sep 17 00:00:00 2001 From: targrub Date: Sun, 9 Oct 2022 17:46:53 -0400 Subject: [PATCH 2/8] Added Debug trait to Query, QueryState --- crates/bevy_ecs/src/query/state.rs | 6 ++++++ crates/bevy_ecs/src/system/query.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index 262e0bcd9fa0c..5e31119d46e99 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -35,6 +35,12 @@ pub struct QueryState { pub(crate) filter_state: F::State, } +impl std::fmt::Debug for QueryState { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "QueryState matched_table_ids: {} matched_archetype_ids: {}", self.matched_table_ids.len(), self.matched_archetype_ids.len()) + } +} + impl FromWorld for QueryState { fn from_world(world: &mut World) -> Self { world.query_filtered() diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index ce6cc2e470151..43542e0f114a7 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -280,6 +280,12 @@ pub struct Query<'world, 'state, Q: WorldQuery, F: ReadOnlyWorldQuery = ()> { pub(crate) change_tick: u32, } +impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> std::fmt::Debug for Query<'w, 's, Q, F> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Query {{ matched entities: {}, world: {:?}, state: {:?}, last_change_tick: {}, change_tick: {} }}", self.iter().count(), self.world, self.state, self.last_change_tick, self.change_tick) + } +} + impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> { /// Creates a new query. /// From 22feb57d51834694c656501510d3a6445b05058c Mon Sep 17 00:00:00 2001 From: targrub Date: Sun, 9 Oct 2022 18:08:58 -0400 Subject: [PATCH 3/8] Revert some changes to simplify the overall changes --- crates/bevy_app/src/app.rs | 6 +++--- crates/bevy_ecs/src/archetype.rs | 11 ++--------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 79388fba23902..1b20746072bad 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -12,7 +12,7 @@ use bevy_ecs::{ world::World, }; use bevy_utils::{tracing::debug, HashMap}; -use core::fmt::Debug; +use std::fmt::Debug; #[cfg(feature = "trace")] use bevy_utils::tracing::info_span; @@ -25,7 +25,7 @@ bevy_utils::define_label!( /// The [`Resource`] that stores the [`App`]'s [`TypeRegistry`](bevy_reflect::TypeRegistry). #[cfg(feature = "bevy_reflect")] -#[derive(Debug, Resource, Clone, Deref, DerefMut, Default)] +#[derive(Resource, Clone, Deref, DerefMut, Default)] pub struct AppTypeRegistry(pub bevy_reflect::TypeRegistryArc); #[allow(clippy::needless_doctest_main)] @@ -72,7 +72,7 @@ pub struct App { impl Debug for App { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "App {{sub_apps: ")?; + write!(f, "App {{ sub_apps: ")?; f.debug_map() .entries(self.sub_apps.iter().map(|(k, v)| (k, v))) .finish()?; diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index 358ae8099f96e..cf81b5b633a2e 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -32,13 +32,11 @@ impl ArchetypeId { } } -#[derive(Debug)] pub(crate) enum ComponentStatus { Added, Mutated, } -#[derive(Debug)] pub struct AddBundle { pub archetype_id: ArchetypeId, pub(crate) bundle_status: Vec, @@ -58,7 +56,7 @@ pub struct AddBundle { /// yet. /// /// [`World`]: crate::world::World -#[derive(Debug, Default)] +#[derive(Default)] pub struct Edges { add_bundle: SparseArray, remove_bundle: SparseArray>, @@ -120,25 +118,21 @@ impl Edges { } } -#[derive(Debug)] struct TableInfo { id: TableId, entity_rows: Vec, } -#[derive(Debug)] pub(crate) struct ArchetypeSwapRemoveResult { pub(crate) swapped_entity: Option, pub(crate) table_row: usize, } -#[derive(Debug)] pub(crate) struct ArchetypeComponentInfo { pub(crate) storage_type: StorageType, pub(crate) archetype_component_id: ArchetypeComponentId, } -#[derive(Debug)] pub struct Archetype { id: ArchetypeId, entities: Vec, @@ -352,7 +346,7 @@ impl ArchetypeGeneration { } } -#[derive(Debug, Hash, PartialEq, Eq)] +#[derive(Hash, PartialEq, Eq)] pub struct ArchetypeIdentity { table_components: Box<[ComponentId]>, sparse_set_components: Box<[ComponentId]>, @@ -384,7 +378,6 @@ impl SparseSetIndex for ArchetypeComponentId { } } -#[derive(Debug)] pub struct Archetypes { pub(crate) archetypes: Vec, pub(crate) archetype_component_count: usize, From 76adb7ca15e1b91c78e8cf92dee27dc68940bfce Mon Sep 17 00:00:00 2001 From: targrub Date: Sun, 9 Oct 2022 18:22:38 -0400 Subject: [PATCH 4/8] Formatting change. --- crates/bevy_ecs/src/query/state.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index 5e31119d46e99..80326b586ca46 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -37,7 +37,12 @@ pub struct QueryState { impl std::fmt::Debug for QueryState { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "QueryState matched_table_ids: {} matched_archetype_ids: {}", self.matched_table_ids.len(), self.matched_archetype_ids.len()) + write!( + f, + "QueryState matched_table_ids: {} matched_archetype_ids: {}", + self.matched_table_ids.len(), + self.matched_archetype_ids.len() + ) } } From ec35a1e688dc04a1882690ef4976baa64b5e7530 Mon Sep 17 00:00:00 2001 From: targrub Date: Sun, 9 Oct 2022 21:01:51 -0400 Subject: [PATCH 5/8] Debug adjustments. Added a copy of the Debug of App for SubApps. Removed newline in SystemContainer Debug. Added more Debug info for Systems with run criteria. --- crates/bevy_app/src/app.rs | 6 +- crates/bevy_ecs/src/schedule/run_criteria.rs | 58 +++++++++++++++---- .../bevy_ecs/src/schedule/system_container.rs | 2 +- crates/bevy_ecs/src/system/system.rs | 2 +- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 1b20746072bad..25c2271365544 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -88,7 +88,11 @@ struct SubApp { impl Debug for SubApp { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "SubApp") + write!(f, "SubApp {{ app: ")?; + f.debug_map() + .entries(self.app.sub_apps.iter().map(|(k, v)| (k, v))) + .finish()?; + write!(f, "}}") } } diff --git a/crates/bevy_ecs/src/schedule/run_criteria.rs b/crates/bevy_ecs/src/schedule/run_criteria.rs index 3a4da3351cfcd..8bfd84bf04c22 100644 --- a/crates/bevy_ecs/src/schedule/run_criteria.rs +++ b/crates/bevy_ecs/src/schedule/run_criteria.rs @@ -68,18 +68,6 @@ impl From for ShouldRun { } } -impl Debug for dyn System + 'static { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "System with In=(), Out=ShouldRun") - } -} - -impl Debug for dyn System + 'static { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "System with In=ShouldRun, Out=ShouldRun") - } -} - #[derive(Debug, Default)] pub(crate) struct BoxedRunCriteria { criteria_system: Option>, @@ -366,3 +354,49 @@ impl RunCriteria { } } } + +impl Debug for dyn System + 'static { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "System {} with In=(), Out=ShouldRun: {{{}}}", + self.name(), + { + if self.is_send() { + if self.is_exclusive() { + "is_send is_exclusive" + } else { + "is_send" + } + } else if self.is_exclusive() { + "is_exclusive" + } else { + "" + } + }, + ) + } +} + +impl Debug for dyn System + 'static { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "System {} with In=ShouldRun, Out=ShouldRun: {{{}}}", + self.name(), + { + if self.is_send() { + if self.is_exclusive() { + "is_send is_exclusive" + } else { + "is_send" + } + } else if self.is_exclusive() { + "is_exclusive" + } else { + "" + } + }, + ) + } +} diff --git a/crates/bevy_ecs/src/schedule/system_container.rs b/crates/bevy_ecs/src/schedule/system_container.rs index 8b9cc4d3ccd33..f2c6ad967b79e 100644 --- a/crates/bevy_ecs/src/schedule/system_container.rs +++ b/crates/bevy_ecs/src/schedule/system_container.rs @@ -82,7 +82,7 @@ impl SystemContainer { impl Debug for SystemContainer { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "\n{{{:?}}}", &self.system()) + write!(f, "{{{:?}}}", &self.system()) } } diff --git a/crates/bevy_ecs/src/system/system.rs b/crates/bevy_ecs/src/system/system.rs index 2b84594cf9077..43fcdb41dd3cb 100644 --- a/crates/bevy_ecs/src/system/system.rs +++ b/crates/bevy_ecs/src/system/system.rs @@ -99,7 +99,7 @@ pub(crate) fn check_system_change_tick( impl Debug for dyn System { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{} {{{}}}", self.name(), { + write!(f, "System {}: {{{}}}", self.name(), { if self.is_send() { if self.is_exclusive() { "is_send is_exclusive" From 96f7bcc3e43945d2b7638bc1288bf6ba174cc766 Mon Sep 17 00:00:00 2001 From: targrub Date: Sun, 9 Oct 2022 22:00:34 -0400 Subject: [PATCH 6/8] Custom Debug for SystemStage writing Systems on new lines if multiple. --- crates/bevy_ecs/src/schedule/stage.rs | 59 ++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index 86bf21407e1d4..cdea7079f98c5 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -58,7 +58,6 @@ pub struct ReportExecutionOrderAmbiguities; /// Stores and executes systems. Execution order is not defined unless explicitly specified; /// see `SystemDescriptor` documentation. -#[derive(Debug)] pub struct SystemStage { /// The WorldId this stage was last run on. world_id: Option, @@ -592,6 +591,64 @@ impl SystemStage { } Ok(labels) } + + pub fn vec_system_container_debug( + &self, + name: &str, + v: &Vec, + f: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + write!(f, "{}: ", name)?; + if v.len() > 1 { + writeln!(f, "[")?; + for sc in v.iter() { + writeln!(f, "{:?},", sc)?; + } + write!(f, "], ") + } else { + write!(f, "{:?}, ", v) + } + } +} + +impl std::fmt::Debug for SystemStage { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "SystemStage: {{ ")?; + write!( + f, + "world_id: {:?}, executor: {:?}, stage_run_criteria: {:?}, run_criteria: {:?}, ", + self.world_id, self.executor, self.stage_run_criteria, self.run_criteria + )?; + self.vec_system_container_debug("exclusive_at_start", &self.exclusive_at_start, f)?; + self.vec_system_container_debug( + "exclusive_before_commands", + &self.exclusive_before_commands, + f, + )?; + self.vec_system_container_debug("exclusive_at_end", &self.exclusive_at_end, f)?; + self.vec_system_container_debug("parallel", &self.parallel, f)?; + write!( + f, + "systems_modified: {:?}, uninitialized_run_criteria: {:?}, ", + self.systems_modified, self.uninitialized_run_criteria + )?; + write!( + f, + "uninitialized_at_start: {:?}, uninitialized_before_commands: {:?}, ", + self.uninitialized_at_start, self.uninitialized_before_commands + )?; + write!( + f, + "uninitialized_at_end: {:?}, uninitialized_parallel: {:?}, ", + self.uninitialized_at_end, self.uninitialized_parallel + )?; + write!( + f, + "last_tick_check: {:?}, apply_buffers: {:?}, ", + self.last_tick_check, self.apply_buffers + )?; + write!(f, "must_read_resource: {:?}}}", self.must_read_resource) + } } /// Sorts given system containers topologically, populates their resolved dependencies From b319293f3ded265b6c965c13c93d92fa3fb11477 Mon Sep 17 00:00:00 2001 From: targrub Date: Mon, 10 Oct 2022 08:16:59 -0400 Subject: [PATCH 7/8] Handle downcasting of dyn Stage properly. --- crates/bevy_ecs/src/schedule/stage.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/stage.rs b/crates/bevy_ecs/src/schedule/stage.rs index cdea7079f98c5..bb14e63e05057 100644 --- a/crates/bevy_ecs/src/schedule/stage.rs +++ b/crates/bevy_ecs/src/schedule/stage.rs @@ -17,7 +17,7 @@ use bevy_utils::{tracing::warn, HashMap, HashSet}; use core::fmt::Debug; use downcast_rs::{impl_downcast, Downcast}; -use super::IntoSystemDescriptor; +use super::{IntoSystemDescriptor, Schedule}; /// A type that can run as a step of a [`Schedule`](super::Schedule). pub trait Stage: Downcast + Send + Sync { @@ -28,7 +28,13 @@ pub trait Stage: Downcast + Send + Sync { impl Debug for dyn Stage { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Stage {:?}", self.as_any().downcast_ref::()) + if let Some(as_systemstage) = self.as_any().downcast_ref::() { + write!(f, "{:?}", as_systemstage) + } else if let Some(as_schedule) = self.as_any().downcast_ref::() { + write!(f, "{:?}", as_schedule) + } else { + write!(f, "Unknown dyn Stage") + } } } From 0aa4438b9202829c4e197c3c0996ec02c288ed33 Mon Sep 17 00:00:00 2001 From: targrub Date: Mon, 10 Oct 2022 16:33:52 -0400 Subject: [PATCH 8/8] Added Debug for new enum AmbiguityDetection. --- crates/bevy_ecs/src/schedule/system_descriptor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/schedule/system_descriptor.rs b/crates/bevy_ecs/src/schedule/system_descriptor.rs index 0e6b37f568ec5..8628069e9042a 100644 --- a/crates/bevy_ecs/src/schedule/system_descriptor.rs +++ b/crates/bevy_ecs/src/schedule/system_descriptor.rs @@ -4,7 +4,7 @@ use crate::{ }; /// Configures ambiguity detection for a single system. -#[derive(Default)] +#[derive(Debug, Default)] pub(crate) enum AmbiguityDetection { #[default] Check,