Skip to content

Commit

Permalink
Some cleanups (bevyengine#2170)
Browse files Browse the repository at this point in the history
The first commit monomorphizes `add_system_inner` which I think was intended to be monomorphized anyway. The second commit moves the type argument of `GraphNode` to an associated type.
  • Loading branch information
bjorn3 authored and ostwilkens committed Jul 27, 2021
1 parent 0123050 commit 686b98a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
19 changes: 10 additions & 9 deletions crates/bevy_ecs/src/schedule/graph_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ pub enum DependencyGraphError<Labels> {
GraphCycles(Vec<(usize, Labels)>),
}

pub trait GraphNode<Label> {
pub trait GraphNode {
type Label;
fn name(&self) -> Cow<'static, str>;
fn labels(&self) -> &[Label];
fn before(&self) -> &[Label];
fn after(&self) -> &[Label];
fn labels(&self) -> &[Self::Label];
fn before(&self) -> &[Self::Label];
fn after(&self) -> &[Self::Label];
}

/// Constructs a dependency graph of given nodes.
pub fn build_dependency_graph<Node, Label>(
pub fn build_dependency_graph<Node>(
nodes: &[Node],
) -> HashMap<usize, HashMap<usize, HashSet<Label>>>
) -> HashMap<usize, HashMap<usize, HashSet<Node::Label>>>
where
Node: GraphNode<Label>,
Label: Debug + Clone + Eq + Hash,
Node: GraphNode,
Node::Label: Debug + Clone + Eq + Hash,
{
let mut labels = HashMap::<Label, FixedBitSet>::default();
let mut labels = HashMap::<Node::Label, FixedBitSet>::default();
for (label, index) in nodes.iter().enumerate().flat_map(|(index, container)| {
container
.labels()
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_ecs/src/schedule/run_criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ impl RunCriteriaContainer {
}
}

impl GraphNode<BoxedRunCriteriaLabel> for RunCriteriaContainer {
impl GraphNode for RunCriteriaContainer {
type Label = BoxedRunCriteriaLabel;

fn name(&self) -> Cow<'static, str> {
match &self.inner {
RunCriteriaInner::Single(system) => system.name(),
Expand Down
14 changes: 5 additions & 9 deletions crates/bevy_ecs/src/schedule/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,13 @@ impl SystemStage {
}

pub fn add_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut Self {
self.add_system_inner(system, None);
self.add_system_inner(system.into(), None);
self
}

fn add_system_inner(
&mut self,
system: impl Into<SystemDescriptor>,
default_run_criteria: Option<usize>,
) {
fn add_system_inner(&mut self, system: SystemDescriptor, default_run_criteria: Option<usize>) {
self.systems_modified = true;
match system.into() {
match system {
SystemDescriptor::Exclusive(mut descriptor) => {
let insertion_point = descriptor.insertion_point;
let criteria = descriptor.run_criteria.take();
Expand Down Expand Up @@ -416,9 +412,9 @@ impl SystemStage {
&& self.uninitialized_before_commands.is_empty()
&& self.uninitialized_at_end.is_empty()
);
fn unwrap_dependency_cycle_error<Output, Label, Labels: Debug>(
fn unwrap_dependency_cycle_error<Node: GraphNode, Output, Labels: Debug>(
result: Result<Output, DependencyGraphError<Labels>>,
nodes: &[impl GraphNode<Label>],
nodes: &[Node],
nodes_description: &'static str,
) -> Output {
match result {
Expand Down
10 changes: 7 additions & 3 deletions crates/bevy_ecs/src/schedule/system_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
use std::{borrow::Cow, ptr::NonNull};

/// System metadata like its name, labels, order requirements and component access.
pub trait SystemContainer: GraphNode<BoxedSystemLabel> {
pub trait SystemContainer: GraphNode<Label = BoxedSystemLabel> {
#[doc(hidden)]
fn dependencies(&self) -> &[usize];
#[doc(hidden)]
Expand Down Expand Up @@ -54,7 +54,9 @@ impl ExclusiveSystemContainer {
}
}

impl GraphNode<BoxedSystemLabel> for ExclusiveSystemContainer {
impl GraphNode for ExclusiveSystemContainer {
type Label = BoxedSystemLabel;

fn name(&self) -> Cow<'static, str> {
self.system.name()
}
Expand Down Expand Up @@ -163,7 +165,9 @@ impl ParallelSystemContainer {
}
}

impl GraphNode<BoxedSystemLabel> for ParallelSystemContainer {
impl GraphNode for ParallelSystemContainer {
type Label = BoxedSystemLabel;

fn name(&self) -> Cow<'static, str> {
self.system().name()
}
Expand Down

0 comments on commit 686b98a

Please sign in to comment.