Skip to content

Commit 1d65294

Browse files
committed
Some cleanups (#2170)
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.
1 parent b8c98a9 commit 1d65294

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

crates/bevy_ecs/src/schedule/graph_utils.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ pub enum DependencyGraphError<Labels> {
66
GraphCycles(Vec<(usize, Labels)>),
77
}
88

9-
pub trait GraphNode<Label> {
9+
pub trait GraphNode {
10+
type Label;
1011
fn name(&self) -> Cow<'static, str>;
11-
fn labels(&self) -> &[Label];
12-
fn before(&self) -> &[Label];
13-
fn after(&self) -> &[Label];
12+
fn labels(&self) -> &[Self::Label];
13+
fn before(&self) -> &[Self::Label];
14+
fn after(&self) -> &[Self::Label];
1415
}
1516

1617
/// Constructs a dependency graph of given nodes.
17-
pub fn build_dependency_graph<Node, Label>(
18+
pub fn build_dependency_graph<Node>(
1819
nodes: &[Node],
19-
) -> HashMap<usize, HashMap<usize, HashSet<Label>>>
20+
) -> HashMap<usize, HashMap<usize, HashSet<Node::Label>>>
2021
where
21-
Node: GraphNode<Label>,
22-
Label: Debug + Clone + Eq + Hash,
22+
Node: GraphNode,
23+
Node::Label: Debug + Clone + Eq + Hash,
2324
{
24-
let mut labels = HashMap::<Label, FixedBitSet>::default();
25+
let mut labels = HashMap::<Node::Label, FixedBitSet>::default();
2526
for (label, index) in nodes.iter().enumerate().flat_map(|(index, container)| {
2627
container
2728
.labels()

crates/bevy_ecs/src/schedule/run_criteria.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ impl RunCriteriaContainer {
124124
}
125125
}
126126

127-
impl GraphNode<BoxedRunCriteriaLabel> for RunCriteriaContainer {
127+
impl GraphNode for RunCriteriaContainer {
128+
type Label = BoxedRunCriteriaLabel;
129+
128130
fn name(&self) -> Cow<'static, str> {
129131
match &self.inner {
130132
RunCriteriaInner::Single(system) => system.name(),

crates/bevy_ecs/src/schedule/stage.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,13 @@ impl SystemStage {
137137
}
138138

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

144-
fn add_system_inner(
145-
&mut self,
146-
system: impl Into<SystemDescriptor>,
147-
default_run_criteria: Option<usize>,
148-
) {
144+
fn add_system_inner(&mut self, system: SystemDescriptor, default_run_criteria: Option<usize>) {
149145
self.systems_modified = true;
150-
match system.into() {
146+
match system {
151147
SystemDescriptor::Exclusive(mut descriptor) => {
152148
let insertion_point = descriptor.insertion_point;
153149
let criteria = descriptor.run_criteria.take();
@@ -416,9 +412,9 @@ impl SystemStage {
416412
&& self.uninitialized_before_commands.is_empty()
417413
&& self.uninitialized_at_end.is_empty()
418414
);
419-
fn unwrap_dependency_cycle_error<Output, Label, Labels: Debug>(
415+
fn unwrap_dependency_cycle_error<Node: GraphNode, Output, Labels: Debug>(
420416
result: Result<Output, DependencyGraphError<Labels>>,
421-
nodes: &[impl GraphNode<Label>],
417+
nodes: &[Node],
422418
nodes_description: &'static str,
423419
) -> Output {
424420
match result {

crates/bevy_ecs/src/schedule/system_container.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
use std::{borrow::Cow, ptr::NonNull};
1111

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

57-
impl GraphNode<BoxedSystemLabel> for ExclusiveSystemContainer {
57+
impl GraphNode for ExclusiveSystemContainer {
58+
type Label = BoxedSystemLabel;
59+
5860
fn name(&self) -> Cow<'static, str> {
5961
self.system.name()
6062
}
@@ -163,7 +165,9 @@ impl ParallelSystemContainer {
163165
}
164166
}
165167

166-
impl GraphNode<BoxedSystemLabel> for ParallelSystemContainer {
168+
impl GraphNode for ParallelSystemContainer {
169+
type Label = BoxedSystemLabel;
170+
167171
fn name(&self) -> Cow<'static, str> {
168172
self.system().name()
169173
}

0 commit comments

Comments
 (0)