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] - Add report_sets option to ScheduleBuildSettings #7756

Closed
wants to merge 6 commits into from
Closed
50 changes: 48 additions & 2 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,21 @@ impl ScheduleGraph {
impl ScheduleGraph {
fn get_node_name(&self, id: &NodeId) -> String {
let mut name = match id {
NodeId::System(_) => self.systems[id.index()].get().unwrap().name().to_string(),
NodeId::System(_) => {
let name = self.systems[id.index()].get().unwrap().name().to_string();
if self.settings.report_sets {
let sets = self.names_of_sets_containing_node(id);
if sets.is_empty() {
name
} else if sets.len() == 1 {
format!("{name} (in set {})", sets[0])
} else {
format!("{name} (in sets {})", sets.join(", "))
}
} else {
name
}
}
NodeId::Set(_) => self.system_sets[id.index()].name(),
};
if self.settings.use_shortnames {
Expand Down Expand Up @@ -1453,6 +1467,27 @@ impl ScheduleGraph {

warn!("{}", string);
}

fn traverse_sets_containing_node(&self, id: NodeId, f: &mut impl FnMut(NodeId) -> bool) {
for (set_id, _, _) in self.hierarchy.graph.edges_directed(id, Direction::Incoming) {
if f(set_id) {
self.traverse_sets_containing_node(set_id, f);
}
}
}

fn names_of_sets_containing_node(&self, id: &NodeId) -> Vec<String> {
let mut sets = HashSet::new();
self.traverse_sets_containing_node(*id, &mut |set_id| {
!self.system_sets[set_id.index()].is_system_type() && sets.insert(set_id)
});
let mut sets: Vec<_> = sets
.into_iter()
.map(|set_id| self.get_node_name(&set_id))
.collect();
sets.sort();
sets
}
}

/// Category of errors encountered during schedule construction.
Expand Down Expand Up @@ -1525,13 +1560,23 @@ pub enum LogLevel {
pub struct ScheduleBuildSettings {
/// Determines whether the presence of ambiguities (systems with conflicting access but indeterminate order)
/// is only logged or also results in an [`Ambiguity`](ScheduleBuildError::Ambiguity) error.
///
/// Defaults to [`LogLevel::Ignore`].
pub ambiguity_detection: LogLevel,
/// Determines whether the presence of redundant edges in the hierarchy of system sets is only
/// logged or also results in a [`HierarchyRedundancy`](ScheduleBuildError::HierarchyRedundancy)
/// error.
///
/// Defaults to [`LogLevel::Warn`].
pub hierarchy_detection: LogLevel,
/// If set to true, node names will be shortened instead of the fully qualified type path.
///
/// Defaults to `true`.
pub use_shortnames: bool,
/// If set to true, report all system sets the conflicting systems are part of.
///
/// Defaults to `true`.
pub report_sets: bool,
}

impl Default for ScheduleBuildSettings {
Expand All @@ -1545,7 +1590,8 @@ impl ScheduleBuildSettings {
Self {
ambiguity_detection: LogLevel::Ignore,
hierarchy_detection: LogLevel::Warn,
use_shortnames: false,
use_shortnames: true,
report_sets: true,
}
}
}