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:
		
							parent
							
								
									38e0a8010e
								
							
						
					
					
						commit
						0716922165
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user