ParamSets containing non-send parameters should also be non-send (#10211)

# Objective

Fix #10207

## Solution

Mark a `ParamSet`'s `SystemMeta` as non-send if any of its component
parameters are non-send.
This commit is contained in:
Joseph 2023-10-21 11:07:52 -07:00 committed by GitHub
parent 38e0a8010e
commit 0716922165
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View file

@ -201,6 +201,10 @@ pub fn impl_param_set(_input: TokenStream) -> TokenStream {
#param::init_state(world, &mut #meta);
let #param = #param::init_state(world, &mut system_meta.clone());
)*
// Make the ParamSet non-send if any of its parameters are non-send.
if false #(|| !#meta.is_send())* {
system_meta.set_non_send();
}
#(
system_meta
.component_access_set

View file

@ -1739,4 +1739,34 @@ mod tests {
schedule.add_systems(non_sync_system);
schedule.run(&mut world);
}
// Regression test for https://github.com/bevyengine/bevy/issues/10207.
#[test]
fn param_set_non_send_first() {
fn non_send_param_set(mut p: ParamSet<(NonSend<*mut u8>, ())>) {
let _ = p.p0();
p.p1();
}
let mut world = World::new();
world.insert_non_send_resource(std::ptr::null_mut::<u8>());
let mut schedule = crate::schedule::Schedule::default();
schedule.add_systems((non_send_param_set, non_send_param_set, non_send_param_set));
schedule.run(&mut world);
}
// Regression test for https://github.com/bevyengine/bevy/issues/10207.
#[test]
fn param_set_non_send_second() {
fn non_send_param_set(mut p: ParamSet<((), NonSendMut<*mut u8>)>) {
p.p0();
let _ = p.p1();
}
let mut world = World::new();
world.insert_non_send_resource(std::ptr::null_mut::<u8>());
let mut schedule = crate::schedule::Schedule::default();
schedule.add_systems((non_send_param_set, non_send_param_set, non_send_param_set));
schedule.run(&mut world);
}
}