From 7bf80dd5984dc48b1b232400ceddfc024456170f Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 13:23:07 +0200 Subject: [PATCH 01/20] documentation for variadics --- crates/bevy_ecs/src/lib.rs | 3 ++ crates/bevy_ecs/src/system/builder.rs | 13 ++++++- .../src/system/exclusive_function_system.rs | 2 +- crates/bevy_ecs/src/system/function_system.rs | 22 +++++++++-- crates/bevy_ecs/src/system/observer_system.rs | 37 +++++++++++++++++++ crates/bevy_reflect/src/func/info.rs | 12 +++++- crates/bevy_reflect/src/func/reflect_fn.rs | 12 +++++- .../bevy_reflect/src/func/reflect_fn_mut.rs | 12 +++++- crates/bevy_reflect/src/tuple.rs | 24 ++++++++++-- 9 files changed, 121 insertions(+), 16 deletions(-) diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 69dfea19f5bda..5b0ea69cb88be 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -9,6 +9,9 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] +// `rustdoc_internals` is needed for `#[doc(fake_variadics)]` +#![allow(internal_features)] +#![cfg_attr(any(docsrs, docsrs_dep), feature(rustdoc_internals))] #[cfg(target_pointer_width = "16")] compile_error!("bevy_ecs cannot safely compile for a 16-bit platform."); diff --git a/crates/bevy_ecs/src/system/builder.rs b/crates/bevy_ecs/src/system/builder.rs index 279cc41381af5..27956eb1e27d6 100644 --- a/crates/bevy_ecs/src/system/builder.rs +++ b/crates/bevy_ecs/src/system/builder.rs @@ -233,7 +233,8 @@ unsafe impl> SystemParamBuilder> pub struct ParamSetBuilder(pub T); macro_rules! impl_param_set_builder_tuple { - ($(($param: ident, $builder: ident, $meta: ident)),*) => { + ($(#[$meta2:meta])* $(($param: ident, $builder: ident, $meta: ident)),*) => { + $(#[$meta2])* // SAFETY: implementors of each `SystemParamBuilder` in the tuple have validated their impls unsafe impl<'w, 's, $($param: SystemParam,)* $($builder: SystemParamBuilder<$param>,)*> SystemParamBuilder> for ParamSetBuilder<($($builder,)*)> { #[allow(non_snake_case)] @@ -267,7 +268,15 @@ macro_rules! impl_param_set_builder_tuple { }; } -all_tuples!(impl_param_set_builder_tuple, 1, 8, P, B, meta); +all_tuples!( + #[doc(fake_variadic)] + impl_param_set_builder_tuple, + 1, + 8, + P, + B, + meta +); // SAFETY: Relevant parameter ComponentId and ArchetypeComponentId access is applied to SystemMeta. If any ParamState conflicts // with any prior access, a panic will occur. diff --git a/crates/bevy_ecs/src/system/exclusive_function_system.rs b/crates/bevy_ecs/src/system/exclusive_function_system.rs index 3075f3c55772e..636a8ad928135 100644 --- a/crates/bevy_ecs/src/system/exclusive_function_system.rs +++ b/crates/bevy_ecs/src/system/exclusive_function_system.rs @@ -219,7 +219,7 @@ pub struct HasExclusiveSystemInput; macro_rules! impl_exclusive_system_function { ($($param: ident),*) => { #[allow(non_snake_case)] - impl ExclusiveSystemParamFunction Out> for Func + impl ExclusiveSystemParamFunction Out> for Func where Func: Send + Sync + 'static, for <'a> &'a mut Func: diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index 0614d7339ca4b..2b5653827011f 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -218,7 +218,8 @@ pub struct SystemState { // So, generate a function for each arity with an explicit `FnMut` constraint to enable higher-order lifetimes, // along with a regular `SystemParamFunction` constraint to allow the system to be built. macro_rules! impl_build_system { - ($($param: ident),*) => { + ($(#[$meta:meta])* $($param: ident),*) => { + $(#[$meta])* impl<$($param: SystemParam),*> SystemState<($($param,)*)> { /// Create a [`FunctionSystem`] from a [`SystemState`]. /// This method signature allows type inference of closure parameters for a system with no input. @@ -256,7 +257,13 @@ macro_rules! impl_build_system { } } -all_tuples!(impl_build_system, 0, 16, P); +all_tuples!( + #[doc(fake_variadic)] + impl_build_system, + 0, + 16, + P +); impl SystemState { /// Creates a new [`SystemState`] with default state. @@ -809,7 +816,8 @@ pub trait SystemParamFunction: Send + Sync + 'static { pub struct HasSystemInput; macro_rules! impl_system_function { - ($($param: ident),*) => { + ($(#[$meta:meta])* $($param: ident),*) => { + $(#[$meta])* #[allow(non_snake_case)] impl SystemParamFunction Out> for Func where @@ -871,7 +879,13 @@ macro_rules! impl_system_function { // Note that we rely on the highest impl to be <= the highest order of the tuple impls // of `SystemParam` created. -all_tuples!(impl_system_function, 0, 16, F); +all_tuples!( + #[doc(fake_variadic)] + impl_system_function, + 0, + 16, + F +); #[cfg(test)] mod tests { diff --git a/crates/bevy_ecs/src/system/observer_system.rs b/crates/bevy_ecs/src/system/observer_system.rs index 55173ccf4f22a..044c0e5901df9 100644 --- a/crates/bevy_ecs/src/system/observer_system.rs +++ b/crates/bevy_ecs/src/system/observer_system.rs @@ -51,6 +51,43 @@ where } } +macro_rules! impl_system_function { + ($($param: ident),*) => { + #[allow(non_snake_case)] + impl SystemParamFunction, $($param,)*)> for Func + where + for <'a> &'a mut Func: + FnMut(Trigger, $($param),*) -> Out + + FnMut(Trigger, $(SystemParamItem<$param>),*) -> Out, Out: 'static + { + type In = Trigger<'static, E, B>; + type Out = Out; + type Param = ($($param,)*); + #[inline] + fn run(&mut self, input: Trigger<'static, E, B>, param_value: SystemParamItem< ($($param,)*)>) -> Out { + #[allow(clippy::too_many_arguments)] + fn call_inner( + mut f: impl FnMut(Trigger<'static, E, B>, $($param,)*) -> Out, + input: Trigger<'static, E, B>, + $($param: $param,)* + ) -> Out{ + f(input, $($param,)*) + } + let ($($param,)*) = param_value; + call_inner(self, input, $($param),*) + } + } + } +} + +all_tuples!( + #[doc(fake_variadic)] + impl_system_function, + 0, + 16, + F +); + #[cfg(test)] mod tests { use crate::{ diff --git a/crates/bevy_reflect/src/func/info.rs b/crates/bevy_reflect/src/func/info.rs index 39accdf52dceb..0a9d6084124e0 100644 --- a/crates/bevy_reflect/src/func/info.rs +++ b/crates/bevy_reflect/src/func/info.rs @@ -231,8 +231,9 @@ pub trait TypedFunction { /// - `FnMut(&mut Receiver, arg0, arg1, ..., argN) -> &mut R` /// - `FnMut(&mut Receiver, arg0, arg1, ..., argN) -> &R` macro_rules! impl_typed_function { - ($(($Arg:ident, $arg:ident)),*) => { + ($(#[$meta:meta])* $(($Arg:ident, $arg:ident)),*) => { // === (...) -> ReturnType === // + $(#[$meta])* impl<$($Arg,)* ReturnType, Function> TypedFunction [ReturnType]> for Function where $($Arg: TypePath + GetOwnership,)* @@ -332,7 +333,14 @@ macro_rules! impl_typed_function { }; } -all_tuples!(impl_typed_function, 0, 15, Arg, arg); +all_tuples!( + #[doc(fake_variadic)] + impl_typed_function, + 0, + 15, + Arg, + arg +); /// Helper function for creating [`FunctionInfo`] with the proper name value. /// diff --git a/crates/bevy_reflect/src/func/reflect_fn.rs b/crates/bevy_reflect/src/func/reflect_fn.rs index 6e29fd4e075eb..f66a7ce709700 100644 --- a/crates/bevy_reflect/src/func/reflect_fn.rs +++ b/crates/bevy_reflect/src/func/reflect_fn.rs @@ -76,8 +76,9 @@ pub trait ReflectFn<'env, Marker>: ReflectFnMut<'env, Marker> { /// - `Fn(&mut Receiver, arg0, arg1, ..., argN) -> &mut R` /// - `Fn(&mut Receiver, arg0, arg1, ..., argN) -> &R` macro_rules! impl_reflect_fn { - ($(($Arg:ident, $arg:ident)),*) => { + ($(#[$meta:meta])* $(($Arg:ident, $arg:ident)),*) => { // === (...) -> ReturnType === // + $(#[$meta])* impl<'env, $($Arg,)* ReturnType, Function> ReflectFn<'env, fn($($Arg),*) -> [ReturnType]> for Function where $($Arg: FromArg,)* @@ -197,4 +198,11 @@ macro_rules! impl_reflect_fn { }; } -all_tuples!(impl_reflect_fn, 0, 15, Arg, arg); +all_tuples!( + #[doc(fake_variadic)] + impl_reflect_fn, + 0, + 15, + Arg, + arg +); diff --git a/crates/bevy_reflect/src/func/reflect_fn_mut.rs b/crates/bevy_reflect/src/func/reflect_fn_mut.rs index be73aca79b6bb..008e52f334a64 100644 --- a/crates/bevy_reflect/src/func/reflect_fn_mut.rs +++ b/crates/bevy_reflect/src/func/reflect_fn_mut.rs @@ -82,8 +82,9 @@ pub trait ReflectFnMut<'env, Marker> { /// - `FnMut(&mut Receiver, arg0, arg1, ..., argN) -> &mut R` /// - `FnMut(&mut Receiver, arg0, arg1, ..., argN) -> &R` macro_rules! impl_reflect_fn_mut { - ($(($Arg:ident, $arg:ident)),*) => { + ($(#[$meta:meta])* $(($Arg:ident, $arg:ident)),*) => { // === (...) -> ReturnType === // + $(#[$meta])* impl<'env, $($Arg,)* ReturnType, Function> ReflectFnMut<'env, fn($($Arg),*) -> [ReturnType]> for Function where $($Arg: FromArg,)* @@ -203,4 +204,11 @@ macro_rules! impl_reflect_fn_mut { }; } -all_tuples!(impl_reflect_fn_mut, 0, 15, Arg, arg); +all_tuples!( + #[doc(fake_variadic)] + impl_reflect_fn_mut, + 0, + 15, + Arg, + arg +); diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index 6ec53efa514e4..20df0362fae1e 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -737,7 +737,13 @@ const _: () = { }; } - all_tuples!(impl_get_ownership_tuple, 0, 12, P); + all_tuples!( + #[doc(fake_variadic)] + impl_get_ownership_tuple, + 0, + 12, + P + ); macro_rules! impl_from_arg_tuple { ($($name: ident),*) => { @@ -745,7 +751,13 @@ const _: () = { }; } - all_tuples!(impl_from_arg_tuple, 0, 12, P); + all_tuples!( + #[doc(fake_variadic)] + impl_from_arg_tuple, + 0, + 12, + P + ); macro_rules! impl_into_return_tuple { ($($name: ident),+) => { @@ -754,7 +766,13 @@ const _: () = { } // The unit type (i.e. `()`) is special-cased, so we skip implementing it here. - all_tuples!(impl_into_return_tuple, 1, 12, P); + all_tuples!( + #[doc(fake_variadic)] + impl_into_return_tuple, + 1, + 12, + P + ); }; #[cfg(test)] From 2ca4e15050ef7a9cda97bf29640f640260f319fa Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 13:28:55 +0200 Subject: [PATCH 02/20] fix error --- crates/bevy_reflect/src/lib.rs | 2 +- crates/bevy_reflect/src/tuple.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/bevy_reflect/src/lib.rs b/crates/bevy_reflect/src/lib.rs index 021971a33a68c..f575c345ea425 100644 --- a/crates/bevy_reflect/src/lib.rs +++ b/crates/bevy_reflect/src/lib.rs @@ -520,7 +520,7 @@ //! [the language feature for dyn upcasting coercion]: https://github.com/rust-lang/rust/issues/65991 //! [derive macro]: derive@crate::Reflect //! [`'static` lifetime]: https://doc.rust-lang.org/rust-by-example/scope/lifetime/static_lifetime.html#trait-bound -//! [`Function`]: func::Function +//! [`Function`]: crate::func::Function //! [derive macro documentation]: derive@crate::Reflect //! [deriving `Reflect`]: derive@crate::Reflect //! [type data]: TypeData diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index 20df0362fae1e..e824c323907cf 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -732,7 +732,8 @@ all_tuples!( #[cfg(feature = "functions")] const _: () = { macro_rules! impl_get_ownership_tuple { - ($($name: ident),*) => { + ($(#[$meta:meta])* $($name: ident),*) => { + $(#[$meta])* $crate::func::args::impl_get_ownership!(($($name,)*); <$($name),*>); }; } @@ -746,7 +747,8 @@ const _: () = { ); macro_rules! impl_from_arg_tuple { - ($($name: ident),*) => { + ($(#[$meta:meta])* $($name: ident),*) => { + $(#[$meta])* $crate::func::args::impl_from_arg!(($($name,)*); <$($name: FromReflect + MaybeTyped + TypePath + GetTypeRegistration),*>); }; } @@ -760,7 +762,8 @@ const _: () = { ); macro_rules! impl_into_return_tuple { - ($($name: ident),+) => { + ($(#[$meta:meta])* $($name: ident),+) => { + $(#[$meta])* $crate::func::impl_into_return!(($($name,)*); <$($name: FromReflect + MaybeTyped + TypePath + GetTypeRegistration),*>); }; } From 6be5d4b26f85d613872bf92af58e3d5d7027e3cd Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 13:35:27 +0200 Subject: [PATCH 03/20] fix error --- crates/bevy_ecs/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 5b0ea69cb88be..69dfea19f5bda 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -9,9 +9,6 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -// `rustdoc_internals` is needed for `#[doc(fake_variadics)]` -#![allow(internal_features)] -#![cfg_attr(any(docsrs, docsrs_dep), feature(rustdoc_internals))] #[cfg(target_pointer_width = "16")] compile_error!("bevy_ecs cannot safely compile for a 16-bit platform."); From b86eba7b506d143e5805d5dc8d70e4e7f457bd78 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 19:24:50 +0200 Subject: [PATCH 04/20] wip --- crates/bevy_app/src/plugin.rs | 12 +++++++++-- crates/bevy_ecs/src/query/fetch.rs | 12 +++++++++-- crates/bevy_reflect/src/tuple.rs | 34 ++++++++++++++++++------------ 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/crates/bevy_app/src/plugin.rs b/crates/bevy_app/src/plugin.rs index 0659c6a311884..c264264695c63 100644 --- a/crates/bevy_app/src/plugin.rs +++ b/crates/bevy_app/src/plugin.rs @@ -162,7 +162,8 @@ mod sealed { } macro_rules! impl_plugins_tuples { - ($(($param: ident, $plugins: ident)),*) => { + ($(#[$meta:meta])* $(($param: ident, $plugins: ident)),*) => { + $(#[$meta])* impl<$($param, $plugins),*> Plugins<(PluginsTupleMarker, $($param,)*)> for ($($plugins,)*) where $($plugins: Plugins<$param>),* @@ -179,5 +180,12 @@ mod sealed { } } - all_tuples!(impl_plugins_tuples, 0, 15, P, S); + all_tuples!( + #[doc(fake_variadic)] + impl_plugins_tuples, + 0, + 15, + P, + S + ); } diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index e2140a36912ff..8cb0a0b96d8ec 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -2025,7 +2025,7 @@ macro_rules! impl_tuple_query_data { } macro_rules! impl_anytuple_fetch { - ($(($name: ident, $state: ident)),*) => { + ($(#[$meta:meta])* $(($name: ident, $state: ident)),*) => { #[allow(non_snake_case)] #[allow(clippy::unused_unit)] @@ -2034,6 +2034,7 @@ macro_rules! impl_anytuple_fetch { /// This is sound because `update_component_access` and `update_archetype_component_access` adds accesses according to the implementations of all the subqueries. /// `update_component_access` replaces the filters with a disjunction where every element is a conjunction of the previous filters and the filters of one of the subqueries. /// This is sound because `matches_component_set` returns a disjunction of the results of the subqueries' implementations. + $(#[$meta])* unsafe impl<$($name: WorldQuery),*> WorldQuery for AnyOf<($($name,)*)> { type Fetch<'w> = ($(($name::Fetch<'w>, bool),)*); type Item<'w> = ($(Option<$name::Item<'w>>,)*); @@ -2168,7 +2169,14 @@ all_tuples!( F, S ); -all_tuples!(impl_anytuple_fetch, 0, 15, F, S); +all_tuples!( + #[doc(fake_variadic)] + impl_anytuple_fetch, + 0, + 15, + F, + S +); /// [`WorldQuery`] used to nullify queries by turning `Query` into `Query>` /// diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index e824c323907cf..1994ad06b9c77 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -469,7 +469,8 @@ pub fn tuple_debug(dyn_tuple: &dyn Tuple, f: &mut Formatter<'_>) -> core::fmt::R } macro_rules! impl_reflect_tuple { - {$($index:tt : $name:tt),*} => { + {$(#[$meta:meta])* $($index:tt : $name:tt),*} => { + $(#[$meta])* impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Tuple for ($($name,)*) { #[inline] fn field(&self, index: usize) -> Option<&dyn PartialReflect> { @@ -521,6 +522,7 @@ macro_rules! impl_reflect_tuple { } } + $(#[$meta])* impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> PartialReflect for ($($name,)*) { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { Some(::type_info()) @@ -584,6 +586,7 @@ macro_rules! impl_reflect_tuple { } } + $(#[$meta])* impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Reflect for ($($name,)*) { fn into_any(self: Box) -> Box { self @@ -615,6 +618,7 @@ macro_rules! impl_reflect_tuple { } } + $(#[$meta])* impl <$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Typed for ($($name,)*) { fn type_info() -> &'static TypeInfo { static CELL: $crate::utility::GenericTypeInfoCell = $crate::utility::GenericTypeInfoCell::new(); @@ -628,6 +632,7 @@ macro_rules! impl_reflect_tuple { } } + $(#[$meta])* impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> GetTypeRegistration for ($($name,)*) { fn get_type_registration() -> TypeRegistration { TypeRegistration::of::<($($name,)*)>() @@ -638,6 +643,7 @@ macro_rules! impl_reflect_tuple { } } + $(#[$meta])* impl<$($name: FromReflect + MaybeTyped + TypePath + GetTypeRegistration),*> FromReflect for ($($name,)*) { fn from_reflect(reflect: &dyn PartialReflect) -> Option { @@ -655,19 +661,19 @@ macro_rules! impl_reflect_tuple { } } -impl_reflect_tuple! {} -impl_reflect_tuple! {0: A} -impl_reflect_tuple! {0: A, 1: B} -impl_reflect_tuple! {0: A, 1: B, 2: C} -impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D} -impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E} -impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F} -impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G} -impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H} -impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I} -impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J} -impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K} -impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K, 11: L} +impl_reflect_tuple! {#[doc(fake_variadic)]} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K} +impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K, 11: L} macro_rules! impl_type_path_tuple { ($(#[$meta:meta])*) => { From 194db24896b160ddccaca9839b581f88804b4df7 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 19:25:52 +0200 Subject: [PATCH 05/20] undo --- crates/bevy_reflect/src/func/info.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/bevy_reflect/src/func/info.rs b/crates/bevy_reflect/src/func/info.rs index 0a9d6084124e0..404053ee0c7fc 100644 --- a/crates/bevy_reflect/src/func/info.rs +++ b/crates/bevy_reflect/src/func/info.rs @@ -231,9 +231,8 @@ pub trait TypedFunction { /// - `FnMut(&mut Receiver, arg0, arg1, ..., argN) -> &mut R` /// - `FnMut(&mut Receiver, arg0, arg1, ..., argN) -> &R` macro_rules! impl_typed_function { - ($(#[$meta:meta])* $(($Arg:ident, $arg:ident)),*) => { + ($(($Arg:ident, $arg:ident)),*) => { // === (...) -> ReturnType === // - $(#[$meta])* impl<$($Arg,)* ReturnType, Function> TypedFunction [ReturnType]> for Function where $($Arg: TypePath + GetOwnership,)* @@ -334,7 +333,6 @@ macro_rules! impl_typed_function { } all_tuples!( - #[doc(fake_variadic)] impl_typed_function, 0, 15, From 737cd0894f7686230cdcf5c5f43e23065db3c5e2 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 19:26:11 +0200 Subject: [PATCH 06/20] fmt --- crates/bevy_reflect/src/func/info.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/crates/bevy_reflect/src/func/info.rs b/crates/bevy_reflect/src/func/info.rs index 404053ee0c7fc..39accdf52dceb 100644 --- a/crates/bevy_reflect/src/func/info.rs +++ b/crates/bevy_reflect/src/func/info.rs @@ -332,13 +332,7 @@ macro_rules! impl_typed_function { }; } -all_tuples!( - impl_typed_function, - 0, - 15, - Arg, - arg -); +all_tuples!(impl_typed_function, 0, 15, Arg, arg); /// Helper function for creating [`FunctionInfo`] with the proper name value. /// From 3da56be4902b1805df29c5d3fed3cb08aeb4295b Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 21:09:24 +0200 Subject: [PATCH 07/20] temp --- crates/bevy_reflect/src/tuple.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index 1994ad06b9c77..a32190dfc307e 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -469,7 +469,7 @@ pub fn tuple_debug(dyn_tuple: &dyn Tuple, f: &mut Formatter<'_>) -> core::fmt::R } macro_rules! impl_reflect_tuple { - {$(#[$meta:meta])* $($index:tt : $name:tt),*} => { + {$(#[$meta:meta]) $($index:tt : $name:tt),*} => { $(#[$meta])* impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Tuple for ($($name,)*) { #[inline] From 1cc17aa0f743443eefdd6e82c09d5f39c88e0c3b Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 21:30:15 +0200 Subject: [PATCH 08/20] wip --- crates/bevy_reflect/src/tuple.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index a32190dfc307e..cbd4d5af25d1c 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -469,7 +469,7 @@ pub fn tuple_debug(dyn_tuple: &dyn Tuple, f: &mut Formatter<'_>) -> core::fmt::R } macro_rules! impl_reflect_tuple { - {$(#[$meta:meta]) $($index:tt : $name:tt),*} => { + {$(#[$meta:meta])+ $($index:tt : $name:tt),*} => { $(#[$meta])* impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Tuple for ($($name,)*) { #[inline] From f011ed94bf6813789f5b3896acfce56cdffe34dd Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 23:04:05 +0200 Subject: [PATCH 09/20] cleanup --- crates/bevy_reflect/src/tuple.rs | 34 +++++++++++++------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index cbd4d5af25d1c..02be82faa18ab 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -469,8 +469,7 @@ pub fn tuple_debug(dyn_tuple: &dyn Tuple, f: &mut Formatter<'_>) -> core::fmt::R } macro_rules! impl_reflect_tuple { - {$(#[$meta:meta])+ $($index:tt : $name:tt),*} => { - $(#[$meta])* + {$($index:tt : $name:tt),*} => { impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Tuple for ($($name,)*) { #[inline] fn field(&self, index: usize) -> Option<&dyn PartialReflect> { @@ -522,7 +521,6 @@ macro_rules! impl_reflect_tuple { } } - $(#[$meta])* impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> PartialReflect for ($($name,)*) { fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { Some(::type_info()) @@ -586,7 +584,6 @@ macro_rules! impl_reflect_tuple { } } - $(#[$meta])* impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Reflect for ($($name,)*) { fn into_any(self: Box) -> Box { self @@ -618,7 +615,6 @@ macro_rules! impl_reflect_tuple { } } - $(#[$meta])* impl <$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> Typed for ($($name,)*) { fn type_info() -> &'static TypeInfo { static CELL: $crate::utility::GenericTypeInfoCell = $crate::utility::GenericTypeInfoCell::new(); @@ -632,7 +628,6 @@ macro_rules! impl_reflect_tuple { } } - $(#[$meta])* impl<$($name: Reflect + MaybeTyped + TypePath + GetTypeRegistration),*> GetTypeRegistration for ($($name,)*) { fn get_type_registration() -> TypeRegistration { TypeRegistration::of::<($($name,)*)>() @@ -643,7 +638,6 @@ macro_rules! impl_reflect_tuple { } } - $(#[$meta])* impl<$($name: FromReflect + MaybeTyped + TypePath + GetTypeRegistration),*> FromReflect for ($($name,)*) { fn from_reflect(reflect: &dyn PartialReflect) -> Option { @@ -661,19 +655,19 @@ macro_rules! impl_reflect_tuple { } } -impl_reflect_tuple! {#[doc(fake_variadic)]} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K} -impl_reflect_tuple! {#[doc(fake_variadic)] 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K, 11: L} +impl_reflect_tuple! {} +impl_reflect_tuple! { 0: A} +impl_reflect_tuple! { 0: A, 1: B} +impl_reflect_tuple! { 0: A, 1: B, 2: C} +impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D} +impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E} +impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F} +impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G} +impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H} +impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I} +impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J} +impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K} +impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K, 11: L} macro_rules! impl_type_path_tuple { ($(#[$meta:meta])*) => { From 1e6fb99a09ba4e7e839b7d1dd8981be42e219ef2 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Mon, 23 Sep 2024 23:12:57 +0200 Subject: [PATCH 10/20] fix --- crates/bevy_ecs/src/query/fetch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 8cb0a0b96d8ec..b8f54203111ba 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -2029,12 +2029,12 @@ macro_rules! impl_anytuple_fetch { #[allow(non_snake_case)] #[allow(clippy::unused_unit)] + $(#[$meta])* /// SAFETY: /// `fetch` accesses are a subset of the subqueries' accesses /// This is sound because `update_component_access` and `update_archetype_component_access` adds accesses according to the implementations of all the subqueries. /// `update_component_access` replaces the filters with a disjunction where every element is a conjunction of the previous filters and the filters of one of the subqueries. /// This is sound because `matches_component_set` returns a disjunction of the results of the subqueries' implementations. - $(#[$meta])* unsafe impl<$($name: WorldQuery),*> WorldQuery for AnyOf<($($name,)*)> { type Fetch<'w> = ($(($name::Fetch<'w>, bool),)*); type Item<'w> = ($(Option<$name::Item<'w>>,)*); From 4405f16b09196d2981bc405b140d76abb928bd31 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Wed, 25 Sep 2024 10:21:51 +0200 Subject: [PATCH 11/20] add unused meta --- crates/bevy_ecs/src/system/exclusive_function_system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/system/exclusive_function_system.rs b/crates/bevy_ecs/src/system/exclusive_function_system.rs index 636a8ad928135..3075f3c55772e 100644 --- a/crates/bevy_ecs/src/system/exclusive_function_system.rs +++ b/crates/bevy_ecs/src/system/exclusive_function_system.rs @@ -219,7 +219,7 @@ pub struct HasExclusiveSystemInput; macro_rules! impl_exclusive_system_function { ($($param: ident),*) => { #[allow(non_snake_case)] - impl ExclusiveSystemParamFunction Out> for Func + impl ExclusiveSystemParamFunction Out> for Func where Func: Send + Sync + 'static, for <'a> &'a mut Func: From 819bcf1683a6ca83278b43bfd6b421e196d03691 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Wed, 25 Sep 2024 15:05:36 +0200 Subject: [PATCH 12/20] doc errors --- crates/bevy_app/src/lib.rs | 3 +++ crates/bevy_ecs/src/query/fetch.rs | 24 ++++--------------- crates/bevy_ecs/src/system/builder.rs | 13 ++-------- crates/bevy_ecs/src/system/function_system.rs | 22 ++++------------- 4 files changed, 13 insertions(+), 49 deletions(-) diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index 830772803bec0..bcbd0afd9bc58 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -1,4 +1,7 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] +// `rustdoc_internals` is needed for `#[doc(fake_variadics)]` +#![allow(internal_features)] +#![cfg_attr(any(docsrs, docsrs_dep), feature(doc_auto_cfg, rustdoc_internals))] #![forbid(unsafe_code)] #![doc( html_logo_url = "https://bevyengine.org/assets/icon.png", diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index b8f54203111ba..c9ca4adf0194e 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -2008,11 +2008,10 @@ unsafe impl ReadOnlyQueryData for Has {} pub struct AnyOf(PhantomData); macro_rules! impl_tuple_query_data { - ($(#[$meta:meta])* $(($name: ident, $state: ident)),*) => { + ($(($name: ident, $state: ident)),*) => { #[allow(non_snake_case)] #[allow(clippy::unused_unit)] - $(#[$meta])* // SAFETY: defers to soundness `$name: WorldQuery` impl unsafe impl<$($name: QueryData),*> QueryData for ($($name,)*) { type ReadOnly = ($($name::ReadOnly,)*); @@ -2025,11 +2024,10 @@ macro_rules! impl_tuple_query_data { } macro_rules! impl_anytuple_fetch { - ($(#[$meta:meta])* $(($name: ident, $state: ident)),*) => { + ($(($name: ident, $state: ident)),*) => { #[allow(non_snake_case)] #[allow(clippy::unused_unit)] - $(#[$meta])* /// SAFETY: /// `fetch` accesses are a subset of the subqueries' accesses /// This is sound because `update_component_access` and `update_archetype_component_access` adds accesses according to the implementations of all the subqueries. @@ -2161,22 +2159,8 @@ macro_rules! impl_anytuple_fetch { }; } -all_tuples!( - #[doc(fake_variadic)] - impl_tuple_query_data, - 0, - 15, - F, - S -); -all_tuples!( - #[doc(fake_variadic)] - impl_anytuple_fetch, - 0, - 15, - F, - S -); +all_tuples!(impl_tuple_query_data, 0, 15, F, S); +all_tuples!(impl_anytuple_fetch, 0, 15, F, S); /// [`WorldQuery`] used to nullify queries by turning `Query` into `Query>` /// diff --git a/crates/bevy_ecs/src/system/builder.rs b/crates/bevy_ecs/src/system/builder.rs index 27956eb1e27d6..21f1756ce8852 100644 --- a/crates/bevy_ecs/src/system/builder.rs +++ b/crates/bevy_ecs/src/system/builder.rs @@ -233,8 +233,7 @@ unsafe impl> SystemParamBuilder> pub struct ParamSetBuilder(pub T); macro_rules! impl_param_set_builder_tuple { - ($(#[$meta2:meta])* $(($param: ident, $builder: ident, $meta: ident)),*) => { - $(#[$meta2])* + ($(($param: ident, $builder: ident, $meta: ident)),*) => { // SAFETY: implementors of each `SystemParamBuilder` in the tuple have validated their impls unsafe impl<'w, 's, $($param: SystemParam,)* $($builder: SystemParamBuilder<$param>,)*> SystemParamBuilder> for ParamSetBuilder<($($builder,)*)> { #[allow(non_snake_case)] @@ -268,15 +267,7 @@ macro_rules! impl_param_set_builder_tuple { }; } -all_tuples!( - #[doc(fake_variadic)] - impl_param_set_builder_tuple, - 1, - 8, - P, - B, - meta -); +all_tuples!(impl_param_set_builder_tuple, 1, 8, P, B, meta); // SAFETY: Relevant parameter ComponentId and ArchetypeComponentId access is applied to SystemMeta. If any ParamState conflicts // with any prior access, a panic will occur. diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index 2b5653827011f..0614d7339ca4b 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -218,8 +218,7 @@ pub struct SystemState { // So, generate a function for each arity with an explicit `FnMut` constraint to enable higher-order lifetimes, // along with a regular `SystemParamFunction` constraint to allow the system to be built. macro_rules! impl_build_system { - ($(#[$meta:meta])* $($param: ident),*) => { - $(#[$meta])* + ($($param: ident),*) => { impl<$($param: SystemParam),*> SystemState<($($param,)*)> { /// Create a [`FunctionSystem`] from a [`SystemState`]. /// This method signature allows type inference of closure parameters for a system with no input. @@ -257,13 +256,7 @@ macro_rules! impl_build_system { } } -all_tuples!( - #[doc(fake_variadic)] - impl_build_system, - 0, - 16, - P -); +all_tuples!(impl_build_system, 0, 16, P); impl SystemState { /// Creates a new [`SystemState`] with default state. @@ -816,8 +809,7 @@ pub trait SystemParamFunction: Send + Sync + 'static { pub struct HasSystemInput; macro_rules! impl_system_function { - ($(#[$meta:meta])* $($param: ident),*) => { - $(#[$meta])* + ($($param: ident),*) => { #[allow(non_snake_case)] impl SystemParamFunction Out> for Func where @@ -879,13 +871,7 @@ macro_rules! impl_system_function { // Note that we rely on the highest impl to be <= the highest order of the tuple impls // of `SystemParam` created. -all_tuples!( - #[doc(fake_variadic)] - impl_system_function, - 0, - 16, - F -); +all_tuples!(impl_system_function, 0, 16, F); #[cfg(test)] mod tests { From d9a3b03fe505183a775ab72bcdbfc8bbc3afdceb Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Wed, 25 Sep 2024 15:21:54 +0200 Subject: [PATCH 13/20] fix feature decl --- crates/bevy_app/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index bcbd0afd9bc58..aac1cfddff875 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -1,4 +1,3 @@ -#![cfg_attr(docsrs, feature(doc_auto_cfg))] // `rustdoc_internals` is needed for `#[doc(fake_variadics)]` #![allow(internal_features)] #![cfg_attr(any(docsrs, docsrs_dep), feature(doc_auto_cfg, rustdoc_internals))] From d16b04c0bf84ff1c2639bdcf3848a0599e577056 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Wed, 25 Sep 2024 18:06:16 +0200 Subject: [PATCH 14/20] feedback --- crates/bevy_ecs/src/query/fetch.rs | 19 ++++++++++++++++--- crates/bevy_reflect/src/func/reflect_fn.rs | 12 ++---------- .../bevy_reflect/src/func/reflect_fn_mut.rs | 12 ++---------- crates/bevy_reflect/src/tuple.rs | 1 + 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index c9ca4adf0194e..15382058b63ed 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -2024,10 +2024,11 @@ macro_rules! impl_tuple_query_data { } macro_rules! impl_anytuple_fetch { - ($(($name: ident, $state: ident)),*) => { + ($(#[$meta:meta])* $(($name: ident, $state: ident)),*) => { #[allow(non_snake_case)] #[allow(clippy::unused_unit)] + $(#[$meta])* /// SAFETY: /// `fetch` accesses are a subset of the subqueries' accesses /// This is sound because `update_component_access` and `update_archetype_component_access` adds accesses according to the implementations of all the subqueries. @@ -2159,8 +2160,20 @@ macro_rules! impl_anytuple_fetch { }; } -all_tuples!(impl_tuple_query_data, 0, 15, F, S); -all_tuples!(impl_anytuple_fetch, 0, 15, F, S); +all_tuples!( + impl_tuple_query_data, + 0, + 15, + F, + S +); +all_tuples!( + impl_anytuple_fetch, + 0, + 15, + F, + S +); /// [`WorldQuery`] used to nullify queries by turning `Query` into `Query>` /// diff --git a/crates/bevy_reflect/src/func/reflect_fn.rs b/crates/bevy_reflect/src/func/reflect_fn.rs index f66a7ce709700..6e29fd4e075eb 100644 --- a/crates/bevy_reflect/src/func/reflect_fn.rs +++ b/crates/bevy_reflect/src/func/reflect_fn.rs @@ -76,9 +76,8 @@ pub trait ReflectFn<'env, Marker>: ReflectFnMut<'env, Marker> { /// - `Fn(&mut Receiver, arg0, arg1, ..., argN) -> &mut R` /// - `Fn(&mut Receiver, arg0, arg1, ..., argN) -> &R` macro_rules! impl_reflect_fn { - ($(#[$meta:meta])* $(($Arg:ident, $arg:ident)),*) => { + ($(($Arg:ident, $arg:ident)),*) => { // === (...) -> ReturnType === // - $(#[$meta])* impl<'env, $($Arg,)* ReturnType, Function> ReflectFn<'env, fn($($Arg),*) -> [ReturnType]> for Function where $($Arg: FromArg,)* @@ -198,11 +197,4 @@ macro_rules! impl_reflect_fn { }; } -all_tuples!( - #[doc(fake_variadic)] - impl_reflect_fn, - 0, - 15, - Arg, - arg -); +all_tuples!(impl_reflect_fn, 0, 15, Arg, arg); diff --git a/crates/bevy_reflect/src/func/reflect_fn_mut.rs b/crates/bevy_reflect/src/func/reflect_fn_mut.rs index 008e52f334a64..be73aca79b6bb 100644 --- a/crates/bevy_reflect/src/func/reflect_fn_mut.rs +++ b/crates/bevy_reflect/src/func/reflect_fn_mut.rs @@ -82,9 +82,8 @@ pub trait ReflectFnMut<'env, Marker> { /// - `FnMut(&mut Receiver, arg0, arg1, ..., argN) -> &mut R` /// - `FnMut(&mut Receiver, arg0, arg1, ..., argN) -> &R` macro_rules! impl_reflect_fn_mut { - ($(#[$meta:meta])* $(($Arg:ident, $arg:ident)),*) => { + ($(($Arg:ident, $arg:ident)),*) => { // === (...) -> ReturnType === // - $(#[$meta])* impl<'env, $($Arg,)* ReturnType, Function> ReflectFnMut<'env, fn($($Arg),*) -> [ReturnType]> for Function where $($Arg: FromArg,)* @@ -204,11 +203,4 @@ macro_rules! impl_reflect_fn_mut { }; } -all_tuples!( - #[doc(fake_variadic)] - impl_reflect_fn_mut, - 0, - 15, - Arg, - arg -); +all_tuples!(impl_reflect_fn_mut, 0, 15, Arg, arg); diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index 02be82faa18ab..caf59fd518870 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -671,6 +671,7 @@ impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J macro_rules! impl_type_path_tuple { ($(#[$meta:meta])*) => { + $(#[$meta])* impl TypePath for () { fn type_path() -> &'static str { "()" From 5d4351d76d542c0872753efc56db60ab22371a7a Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Wed, 25 Sep 2024 18:37:34 +0200 Subject: [PATCH 15/20] fmt --- crates/bevy_ecs/src/query/fetch.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 15382058b63ed..da8ea9fe122b9 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -2160,20 +2160,8 @@ macro_rules! impl_anytuple_fetch { }; } -all_tuples!( - impl_tuple_query_data, - 0, - 15, - F, - S -); -all_tuples!( - impl_anytuple_fetch, - 0, - 15, - F, - S -); +all_tuples!(impl_tuple_query_data, 0, 15, F, S); +all_tuples!(impl_anytuple_fetch, 0, 15, F, S); /// [`WorldQuery`] used to nullify queries by turning `Query` into `Query>` /// From 6292b91dc2b48c689b8ad41d35c372a1aaf95734 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Fri, 27 Sep 2024 14:35:23 +0200 Subject: [PATCH 16/20] feedback --- crates/bevy_ecs/src/query/fetch.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index da8ea9fe122b9..725252a9184bb 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -2008,10 +2008,10 @@ unsafe impl ReadOnlyQueryData for Has {} pub struct AnyOf(PhantomData); macro_rules! impl_tuple_query_data { - ($(($name: ident, $state: ident)),*) => { - + ($(#[$meta:meta])* $(($name: ident, $state: ident)),*) => { #[allow(non_snake_case)] #[allow(clippy::unused_unit)] + $(#[$meta])* // SAFETY: defers to soundness `$name: WorldQuery` impl unsafe impl<$($name: QueryData),*> QueryData for ($($name,)*) { type ReadOnly = ($($name::ReadOnly,)*); @@ -2024,11 +2024,10 @@ macro_rules! impl_tuple_query_data { } macro_rules! impl_anytuple_fetch { - ($(#[$meta:meta])* $(($name: ident, $state: ident)),*) => { + ($(($name: ident, $state: ident)),*) => { #[allow(non_snake_case)] #[allow(clippy::unused_unit)] - $(#[$meta])* /// SAFETY: /// `fetch` accesses are a subset of the subqueries' accesses /// This is sound because `update_component_access` and `update_archetype_component_access` adds accesses according to the implementations of all the subqueries. From 06a681a9ba2b952d182fec3c55ada991ee40e8d7 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Fri, 27 Sep 2024 14:36:45 +0200 Subject: [PATCH 17/20] feedback and fixes --- crates/bevy_ecs/src/bundle.rs | 1 + crates/bevy_ecs/src/query/fetch.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index bbe114a2fee87..5eeb01c8699cc 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -280,6 +280,7 @@ macro_rules! tuple_impl { } } + $(#[$meta])* impl<$($name: Bundle),*> DynamicBundle for ($($name,)*) { #[allow(unused_variables, unused_mut)] #[inline(always)] diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 725252a9184bb..76c2274a6fbb1 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -2017,6 +2017,7 @@ macro_rules! impl_tuple_query_data { type ReadOnly = ($($name::ReadOnly,)*); } + $(#[$meta])* /// SAFETY: each item in the tuple is read only unsafe impl<$($name: ReadOnlyQueryData),*> ReadOnlyQueryData for ($($name,)*) {} From 26bc84d2dcd7fe686fcb7e8f9558686b3ead340a Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Sun, 29 Sep 2024 03:56:55 +0200 Subject: [PATCH 18/20] undo accidental changes --- crates/bevy_ecs/src/query/fetch.rs | 9 ++++++++- crates/bevy_ecs/src/system/builder.rs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 24fb22291fb58..17d92fc97930a 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -2165,7 +2165,14 @@ macro_rules! impl_anytuple_fetch { }; } -all_tuples!(impl_tuple_query_data, 0, 15, F, S); +all_tuples!( + #[doc(fake_variadic)] + impl_tuple_query_data, + 0, + 15, + F, + S +); all_tuples!(impl_anytuple_fetch, 0, 15, F, S); /// [`WorldQuery`] used to nullify queries by turning `Query` into `Query>` diff --git a/crates/bevy_ecs/src/system/builder.rs b/crates/bevy_ecs/src/system/builder.rs index 21f1756ce8852..279cc41381af5 100644 --- a/crates/bevy_ecs/src/system/builder.rs +++ b/crates/bevy_ecs/src/system/builder.rs @@ -233,7 +233,7 @@ unsafe impl> SystemParamBuilder> pub struct ParamSetBuilder(pub T); macro_rules! impl_param_set_builder_tuple { - ($(($param: ident, $builder: ident, $meta: ident)),*) => { + ($(($param: ident, $builder: ident, $meta: ident)),*) => { // SAFETY: implementors of each `SystemParamBuilder` in the tuple have validated their impls unsafe impl<'w, 's, $($param: SystemParam,)* $($builder: SystemParamBuilder<$param>,)*> SystemParamBuilder> for ParamSetBuilder<($($builder,)*)> { #[allow(non_snake_case)] From 80e5379e911191cfc69fa07a88930c12863c3c19 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Sun, 29 Sep 2024 03:58:54 +0200 Subject: [PATCH 19/20] undo strange change --- crates/bevy_ecs/src/system/observer_system.rs | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/crates/bevy_ecs/src/system/observer_system.rs b/crates/bevy_ecs/src/system/observer_system.rs index 044c0e5901df9..55173ccf4f22a 100644 --- a/crates/bevy_ecs/src/system/observer_system.rs +++ b/crates/bevy_ecs/src/system/observer_system.rs @@ -51,43 +51,6 @@ where } } -macro_rules! impl_system_function { - ($($param: ident),*) => { - #[allow(non_snake_case)] - impl SystemParamFunction, $($param,)*)> for Func - where - for <'a> &'a mut Func: - FnMut(Trigger, $($param),*) -> Out + - FnMut(Trigger, $(SystemParamItem<$param>),*) -> Out, Out: 'static - { - type In = Trigger<'static, E, B>; - type Out = Out; - type Param = ($($param,)*); - #[inline] - fn run(&mut self, input: Trigger<'static, E, B>, param_value: SystemParamItem< ($($param,)*)>) -> Out { - #[allow(clippy::too_many_arguments)] - fn call_inner( - mut f: impl FnMut(Trigger<'static, E, B>, $($param,)*) -> Out, - input: Trigger<'static, E, B>, - $($param: $param,)* - ) -> Out{ - f(input, $($param,)*) - } - let ($($param,)*) = param_value; - call_inner(self, input, $($param),*) - } - } - } -} - -all_tuples!( - #[doc(fake_variadic)] - impl_system_function, - 0, - 16, - F -); - #[cfg(test)] mod tests { use crate::{ From 0e3999dcfb69a6faa02322e70a29510425fbe971 Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Sun, 29 Sep 2024 04:00:08 +0200 Subject: [PATCH 20/20] undo accidental change --- crates/bevy_reflect/src/tuple.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/bevy_reflect/src/tuple.rs b/crates/bevy_reflect/src/tuple.rs index caf59fd518870..af0e8c9348170 100644 --- a/crates/bevy_reflect/src/tuple.rs +++ b/crates/bevy_reflect/src/tuple.rs @@ -656,18 +656,18 @@ macro_rules! impl_reflect_tuple { } impl_reflect_tuple! {} -impl_reflect_tuple! { 0: A} -impl_reflect_tuple! { 0: A, 1: B} -impl_reflect_tuple! { 0: A, 1: B, 2: C} -impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D} -impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E} -impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F} -impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G} -impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H} -impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I} -impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J} -impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K} -impl_reflect_tuple! { 0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K, 11: L} +impl_reflect_tuple! {0: A} +impl_reflect_tuple! {0: A, 1: B} +impl_reflect_tuple! {0: A, 1: B, 2: C} +impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D} +impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E} +impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F} +impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G} +impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H} +impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I} +impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J} +impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K} +impl_reflect_tuple! {0: A, 1: B, 2: C, 3: D, 4: E, 5: F, 6: G, 7: H, 8: I, 9: J, 10: K, 11: L} macro_rules! impl_type_path_tuple { ($(#[$meta:meta])*) => {