Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
maniwani committed Sep 24, 2022
1 parent fbfee24 commit addcfeb
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 124 deletions.
7 changes: 2 additions & 5 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,11 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
}

fn world_access_level() -> WorldAccessLevel {
let mut exclusive = false;
let mut shared = false;
#(
match #param_fetch::world_access_level() {
WorldAccessLevel::Exclusive => {
exclusive = true;
return WorldAccessLevel::Exclusive;
}
WorldAccessLevel::Shared => {
shared = true;
Expand All @@ -243,9 +242,7 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
}
)*

if exclusive {
WorldAccessLevel::Exclusive
} else if shared {
if shared {
WorldAccessLevel::Shared
} else {
WorldAccessLevel::None
Expand Down
8 changes: 3 additions & 5 deletions crates/bevy_ecs/src/schedule/ambiguity_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl SystemOrderAmbiguity {
stage: &SystemStage,
world: &World,
) -> Self {
use crate::schedule::graph_utils::GraphNode;
use SystemStageSegment::*;

// TODO: blocked on https://github.com/bevyengine/bevy/pull/4166
Expand Down Expand Up @@ -220,7 +219,7 @@ impl SystemStage {
/// Returns vector containing all pairs of indices of systems with ambiguous execution order,
/// along with specific components that have triggered the warning.
/// Systems must be topologically sorted beforehand.
fn find_ambiguities(systems: &[impl SystemContainer]) -> Vec<(usize, usize, Vec<ComponentId>)> {
fn find_ambiguities(systems: &[SystemContainer]) -> Vec<(usize, usize, Vec<ComponentId>)> {
let mut all_dependencies = Vec::<FixedBitSet>::with_capacity(systems.len());
let mut all_dependants = Vec::<FixedBitSet>::with_capacity(systems.len());
for (index, container) in systems.iter().enumerate() {
Expand Down Expand Up @@ -266,9 +265,8 @@ fn find_ambiguities(systems: &[impl SystemContainer]) -> Vec<(usize, usize, Vec<
let a_access = systems[index_a].component_access();
let b_access = systems[index_b].component_access();
if let (Some(a), Some(b)) = (a_access, b_access) {
let conflicts = a.get_conflicts(b);
if !conflicts.is_empty() {
ambiguities.push((index_a, index_b, conflicts));
if !a.is_compatible(b) {
ambiguities.push((index_a, index_b, a.get_conflicts(b)));
}
} else {
ambiguities.push((index_a, index_b, Vec::new()));
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/schedule/executor.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{schedule::FunctionSystemContainer, world::World};
use crate::{schedule::SystemContainer, world::World};
use downcast_rs::{impl_downcast, Downcast};

pub trait ParallelSystemExecutor: Downcast + Send + Sync {
/// Called by `SystemStage` whenever `systems` have been changed.
fn rebuild_cached_data(&mut self, systems: &[FunctionSystemContainer]);
fn rebuild_cached_data(&mut self, systems: &[SystemContainer]);

fn run_systems(&mut self, systems: &mut [FunctionSystemContainer], world: &mut World);
fn run_systems(&mut self, systems: &mut [SystemContainer], world: &mut World);
}

impl_downcast!(ParallelSystemExecutor);
Expand All @@ -14,9 +14,9 @@ impl_downcast!(ParallelSystemExecutor);
pub struct SingleThreadedExecutor;

impl ParallelSystemExecutor for SingleThreadedExecutor {
fn rebuild_cached_data(&mut self, _: &[FunctionSystemContainer]) {}
fn rebuild_cached_data(&mut self, _: &[SystemContainer]) {}

fn run_systems(&mut self, systems: &mut [FunctionSystemContainer], world: &mut World) {
fn run_systems(&mut self, systems: &mut [SystemContainer], world: &mut World) {
for system in systems {
if system.should_run() {
#[cfg(feature = "trace")]
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ecs/src/schedule/executor_parallel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
archetype::ArchetypeComponentId,
query::Access,
schedule::{FunctionSystemContainer, ParallelSystemExecutor},
schedule::{ParallelSystemExecutor, SystemContainer},
system::MaybeUnsafeCell,
world::World,
};
Expand Down Expand Up @@ -78,7 +78,7 @@ impl Default for ParallelExecutor {
}

impl ParallelSystemExecutor for ParallelExecutor {
fn rebuild_cached_data(&mut self, systems: &[FunctionSystemContainer]) {
fn rebuild_cached_data(&mut self, systems: &[SystemContainer]) {
self.system_metadata.clear();
self.queued.grow(systems.len());
self.running.grow(systems.len());
Expand Down Expand Up @@ -109,7 +109,7 @@ impl ParallelSystemExecutor for ParallelExecutor {
}
}

fn run_systems(&mut self, systems: &mut [FunctionSystemContainer], world: &mut World) {
fn run_systems(&mut self, systems: &mut [SystemContainer], world: &mut World) {
#[cfg(test)]
if self.events_sender.is_none() {
let (sender, receiver) = async_channel::unbounded::<SchedulingEvent>();
Expand Down Expand Up @@ -172,7 +172,7 @@ impl ParallelExecutor {
fn prepare_systems<'scope>(
&mut self,
scope: &mut Scope<'scope, ()>,
systems: &'scope mut [FunctionSystemContainer],
systems: &'scope mut [SystemContainer],
world: &'scope World,
) {
// These are used as a part of a unit test.
Expand Down
77 changes: 25 additions & 52 deletions crates/bevy_ecs/src/schedule/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use crate::{
prelude::IntoSystem,
schedule::{
graph_utils::{self, DependencyGraphError},
BoxedRunCriteria, DuplicateLabelStrategy, FunctionSystemContainer, GraphNode,
InsertionPoint, ParallelExecutor, ParallelSystemExecutor, RunCriteriaContainer,
RunCriteriaDescriptor, RunCriteriaDescriptorOrLabel, RunCriteriaInner, RunCriteriaLabelId,
ShouldRun, SingleThreadedExecutor, SystemContainer, SystemDescriptor, SystemLabelId,
SystemSet, SystemType,
BoxedRunCriteria, DuplicateLabelStrategy, GraphNode, InsertionPoint, ParallelExecutor,
ParallelSystemExecutor, RunCriteriaContainer, RunCriteriaDescriptor,
RunCriteriaDescriptorOrLabel, RunCriteriaInner, RunCriteriaLabelId, ShouldRun,
SingleThreadedExecutor, SystemContainer, SystemDescriptor, SystemLabelId, SystemSet,
SystemType,
},
world::{World, WorldId},
};
Expand Down Expand Up @@ -62,22 +62,22 @@ pub struct SystemStage {
/// Topologically sorted run criteria of systems.
run_criteria: Vec<RunCriteriaContainer>,
/// Topologically sorted exclusive systems that want to be run at the start of the stage.
pub(super) exclusive_at_start: Vec<FunctionSystemContainer>,
pub(super) exclusive_at_start: Vec<SystemContainer>,
/// Topologically sorted exclusive systems that want to be run after parallel systems but
/// before the application of their command buffers.
pub(super) exclusive_before_commands: Vec<FunctionSystemContainer>,
pub(super) exclusive_before_commands: Vec<SystemContainer>,
/// Topologically sorted exclusive systems that want to be run at the end of the stage.
pub(super) exclusive_at_end: Vec<FunctionSystemContainer>,
pub(super) exclusive_at_end: Vec<SystemContainer>,
/// Topologically sorted parallel systems.
pub(super) parallel: Vec<FunctionSystemContainer>,
pub(super) parallel: Vec<SystemContainer>,
/// Determines if the stage was modified and needs to rebuild its graphs and orders.
pub(super) systems_modified: bool,
/// Determines if the stage's executor was changed.
executor_modified: bool,
/// Newly inserted run criteria that will be initialized at the next opportunity.
uninitialized_run_criteria: Vec<(usize, DuplicateLabelStrategy)>,
/// Newly inserted systems that will be initialized at the next opportunity.
uninitialized_systems: Vec<(FunctionSystemContainer, SystemType)>,
uninitialized_systems: Vec<(SystemContainer, SystemType)>,
/// Saves the value of the World change_tick during the last tick check
last_tick_check: u32,
/// If true, buffers will be automatically applied at the end of the stage. If false, buffers must be manually applied.
Expand Down Expand Up @@ -155,7 +155,7 @@ impl SystemStage {
self.systems_modified = true;
let system_type = descriptor.system_type;
let criteria = descriptor.run_criteria.take();
let mut container = FunctionSystemContainer::from_descriptor(descriptor);
let mut container = SystemContainer::from_descriptor(descriptor);
match criteria {
Some(RunCriteriaDescriptorOrLabel::Label(label)) => {
container.run_criteria_label = Some(label);
Expand Down Expand Up @@ -189,29 +189,29 @@ impl SystemStage {
/// Topologically sorted parallel systems.
///
/// Note that systems won't be fully-formed until the stage has been run at least once.
pub fn parallel_systems(&self) -> &[impl SystemContainer] {
pub fn parallel_systems(&self) -> &[SystemContainer] {
&self.parallel
}

/// Topologically sorted exclusive systems that want to be run at the start of the stage.
///
/// Note that systems won't be fully-formed until the stage has been run at least once.
pub fn exclusive_at_start_systems(&self) -> &[impl SystemContainer] {
pub fn exclusive_at_start_systems(&self) -> &[SystemContainer] {
&self.exclusive_at_start
}

/// Topologically sorted exclusive systems that want to be run at the end of the stage.
///
/// Note that systems won't be fully-formed until the stage has been run at least once.
pub fn exclusive_at_end_systems(&self) -> &[impl SystemContainer] {
pub fn exclusive_at_end_systems(&self) -> &[SystemContainer] {
&self.exclusive_at_end
}

/// Topologically sorted exclusive systems that want to be run after parallel systems but
/// before the application of their command buffers.
///
/// Note that systems won't be fully-formed until the stage has been run at least once.
pub fn exclusive_before_commands_systems(&self) -> &[impl SystemContainer] {
pub fn exclusive_before_commands_systems(&self) -> &[SystemContainer] {
&self.exclusive_before_commands
}

Expand Down Expand Up @@ -515,8 +515,8 @@ impl SystemStage {
}
}

fn update_run_criteria_indices<T: SystemContainer>(
systems: &mut [T],
fn update_run_criteria_indices(
systems: &mut [SystemContainer],
order_inverted: &[(usize, &usize)],
) {
for system in systems {
Expand All @@ -542,7 +542,7 @@ impl SystemStage {
/// Sorts given system containers topologically, populates their resolved dependencies
/// and run criteria.
fn process_systems(
systems: &mut Vec<impl SystemContainer>,
systems: &mut Vec<SystemContainer>,
run_criteria_labels: &HashMap<RunCriteriaLabelId, usize>,
) -> Result<(), DependencyGraphError<HashSet<SystemLabelId>>> {
let mut graph = graph_utils::build_dependency_graph(systems);
Expand Down Expand Up @@ -638,7 +638,7 @@ impl Stage for SystemStage {
run_system_loop = false;

fn should_run(
container: &impl SystemContainer,
container: &SystemContainer,
run_criteria: &[RunCriteriaContainer],
default: ShouldRun,
) -> bool {
Expand Down Expand Up @@ -800,7 +800,7 @@ mod tests {
use crate::{
schedule::{
IntoSystemDescriptor, RunCriteria, RunCriteriaDescriptorCoercion, ShouldRun,
SingleThreadedExecutor, Stage, SystemLabel, SystemLabelId, SystemSet, SystemStage,
SingleThreadedExecutor, Stage, SystemLabel, SystemSet, SystemStage,
},
system::{In, Local, Query, ResMut},
world::World,
Expand Down Expand Up @@ -978,13 +978,7 @@ mod tests {
.with_system(make_exclusive(1).before(L234).after(L0))
.with_system(make_exclusive(0).label(L0))
.with_system(make_exclusive(4).label(L234).label(L4))
.with_system(
make_exclusive(3)

.label(L234)
.after(L2)
.before(L4),
);
.with_system(make_exclusive(3).label(L234).after(L2).before(L4));
stage.run(&mut world);
stage.set_executor(Box::new(SingleThreadedExecutor::default()));
stage.run(&mut world);
Expand All @@ -999,31 +993,11 @@ mod tests {
let mut world = World::new();
world.init_resource::<EntityCount>();
let mut stage = SystemStage::parallel()
.with_system(
make_exclusive(2)

.label(L2)
.after(L1)
.before(L3)
.before(L3),
)
.with_system(
make_exclusive(1)

.label(L1)
.after(L0)
.after(L0)
.before(L2),
)
.with_system(make_exclusive(2).label(L2).after(L1).before(L3).before(L3))
.with_system(make_exclusive(1).label(L1).after(L0).after(L0).before(L2))
.with_system(make_exclusive(0).label(L0).before(L1))
.with_system(make_exclusive(4).label(L4).after(L3))
.with_system(
make_exclusive(3)

.label(L3)
.after(L2)
.before(L4),
);
.with_system(make_exclusive(3).label(L3).after(L2).before(L4));
stage.run(&mut world);
stage.set_executor(Box::new(SingleThreadedExecutor::default()));
stage.run(&mut world);
Expand Down Expand Up @@ -1083,8 +1057,7 @@ mod tests {
fn exclusive_cycle_1() {
let mut world = World::new();
world.init_resource::<EntityCount>();
let mut stage = SystemStage::parallel()
.with_system(make_exclusive(0).label(L0).after(L0));
let mut stage = SystemStage::parallel().with_system(make_exclusive(0).label(L0).after(L0));
stage.run(&mut world);
}

Expand Down
Loading

0 comments on commit addcfeb

Please sign in to comment.