diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index fdd7db483beaa..1c2e9515aee60 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -400,7 +400,7 @@ impl App { self } - /// Inserts the [`!Send`](Send) resource into the app, overwriting any existing resource + /// Inserts the [`NonSendRes`] resource into the app, overwriting any existing resource /// of the same type. /// /// There is also an [`init_non_send_resource`](Self::init_non_send_resource) for @@ -424,7 +424,7 @@ impl App { self } - /// Inserts the [`!Send`](Send) resource into the app if there is no existing instance of `R`. + /// Inserts the [`NonSendRes`] resource into the app if there is no existing instance of `R`. /// /// `R` must implement [`FromWorld`]. /// If `R` implements [`Default`], [`FromWorld`] will be automatically implemented and diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index dc93ddf2c0bef..159f01ff43d18 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -58,7 +58,7 @@ impl Plugin for TaskPoolPlugin { _app.add_systems(Last, tick_global_task_pools); } } -/// A dummy type that is [`!Send`](Send), to force systems to run on the main thread. +/// A dummy type that is `!Send`, to force systems to run on the main thread. pub struct NonSendMarker(PhantomData<*mut ()>); /// A system used to check and advanced our task pools. @@ -66,7 +66,7 @@ pub struct NonSendMarker(PhantomData<*mut ()>); /// Calls [`tick_global_task_pools_on_main_thread`], /// and uses [`NonSendMarker`] to ensure that this system runs on the main thread #[cfg(not(target_arch = "wasm32"))] -fn tick_global_task_pools(_main_thread_marker: Option>) { +fn tick_global_task_pools(_main_thread_marker: Option>) { tick_global_task_pools_on_main_thread(); } diff --git a/crates/bevy_ecs/src/change_detection.rs b/crates/bevy_ecs/src/change_detection.rs index 03e8a40b55a02..2b8857dfa14f7 100644 --- a/crates/bevy_ecs/src/change_detection.rs +++ b/crates/bevy_ecs/src/change_detection.rs @@ -135,7 +135,7 @@ pub trait DetectChangesMut: DetectChanges { /// then consider applying a `map_unchanged` beforehand to allow changing only the relevant /// field and prevent unnecessary copying and cloning. /// See the docs of [`Mut::map_unchanged`], [`MutUntyped::map_unchanged`], - /// [`ResMut::map_unchanged`] or [`NonSendMut::map_unchanged`] for an example + /// [`ResMut::map_unchanged`] or [`NonSendResMut::map_unchanged`] for an example /// /// If you need the previous value, use [`replace_if_neq`](DetectChangesMut::replace_if_neq). /// @@ -191,7 +191,7 @@ pub trait DetectChangesMut: DetectChanges { /// then consider applying a [`map_unchanged`](Mut::map_unchanged) beforehand to allow /// changing only the relevant field and prevent unnecessary copying and cloning. /// See the docs of [`Mut::map_unchanged`], [`MutUntyped::map_unchanged`], - /// [`ResMut::map_unchanged`] or [`NonSendMut::map_unchanged`] for an example + /// [`ResMut::map_unchanged`] or [`NonSendResMut::map_unchanged`] for an example /// /// If you don't need the previous value, use [`set_if_neq`](DetectChangesMut::set_if_neq). /// @@ -615,21 +615,25 @@ impl<'w, T: Resource> From> for Mut<'w, T> { /// /// Panics when used as a `SystemParameter` if the resource does not exist. /// -/// Use `Option>` instead if the resource might not always exist. -pub struct NonSendMut<'w, T: ?Sized + 'static> { +/// Use `Option>` instead if the resource might not always exist. +pub struct NonSendResMut<'w, T: ?Sized + 'static> { pub(crate) value: &'w mut T, pub(crate) ticks: TicksMut<'w>, } -change_detection_impl!(NonSendMut<'w, T>, T,); -change_detection_mut_impl!(NonSendMut<'w, T>, T,); -impl_methods!(NonSendMut<'w, T>, T,); -impl_debug!(NonSendMut<'w, T>,); +/// See [`NonSendResMut`] +#[deprecated = "Use `NonSendResMut` instead"] +pub type NonSendMut<'w, T> = NonSendResMut<'w, T>; -impl<'w, T: 'static> From> for Mut<'w, T> { - /// Convert this `NonSendMut` into a `Mut`. This allows keeping the change-detection feature of `Mut` - /// while losing the specificity of `NonSendMut`. - fn from(other: NonSendMut<'w, T>) -> Mut<'w, T> { +change_detection_impl!(NonSendResMut<'w, T>, T,); +change_detection_mut_impl!(NonSendResMut<'w, T>, T,); +impl_methods!(NonSendResMut<'w, T>, T,); +impl_debug!(NonSendResMut<'w, T>,); + +impl<'w, T: 'static> From> for Mut<'w, T> { + /// Convert this `NonSendResMut` into a `Mut`. This allows keeping the change-detection feature of `Mut` + /// while losing the specificity of `NonSendResMut`. + fn from(other: NonSendResMut<'w, T>) -> Mut<'w, T> { Mut { value: other.value, ticks: other.ticks, @@ -1034,7 +1038,7 @@ mod tests { use crate::{ self as bevy_ecs, change_detection::{ - Mut, NonSendMut, Ref, ResMut, TicksMut, CHECK_TICK_THRESHOLD, MAX_CHANGE_AGE, + Mut, NonSendResMut, Ref, ResMut, TicksMut, CHECK_TICK_THRESHOLD, MAX_CHANGE_AGE, }, component::{Component, ComponentTicks, Tick}, system::{IntoSystem, Query, System}, @@ -1205,7 +1209,7 @@ mod tests { this_run: Tick::new(4), }; let mut res = R {}; - let non_send_mut = NonSendMut { + let non_send_mut = NonSendResMut { value: &mut res, ticks, }; diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index 28582d20dbc66..afd083996c11b 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -800,7 +800,7 @@ impl Components { } } - /// Initializes a [non-send resource](crate::system::NonSend) of type `T` with this instance. + /// Initializes a [non-send resource](crate::system::NonSendRes) of type `T` with this instance. /// If a resource of this type has already been initialized, this will return /// the ID of the pre-existing resource. #[inline] diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 307c7a94a16e5..5deecb1d88fcb 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -55,7 +55,7 @@ pub mod prelude { IntoSystemSetConfigs, Schedule, Schedules, SystemSet, }, system::{ - Commands, Deferred, In, IntoSystem, Local, NonSend, NonSendMut, ParallelCommands, + Commands, Deferred, In, IntoSystem, Local, NonSendRes, NonSendResMut, ParallelCommands, ParamSet, Query, ReadOnlySystem, Res, ResMut, Resource, System, SystemBuilder, SystemParamFunction, }, @@ -98,7 +98,7 @@ mod tests { #[allow(dead_code)] #[derive(Default)] - struct NonSendA(usize, PhantomData<*mut ()>); + struct NonSendResA(usize, PhantomData<*mut ()>); #[derive(Component, Clone, Debug)] struct DropCk(Arc); @@ -1430,11 +1430,11 @@ mod tests { #[test] #[should_panic( - expected = "Attempted to access or drop non-send resource bevy_ecs::tests::NonSendA from thread" + expected = "Attempted to access or drop non-send resource bevy_ecs::tests::NonSendResA from thread" )] fn non_send_resource_drop_from_different_thread() { let mut world = World::default(); - world.insert_non_send_resource(NonSendA::default()); + world.insert_non_send_resource(NonSendResA::default()); let thread = std::thread::spawn(move || { // Dropping the non-send resource on a different thread @@ -1450,7 +1450,7 @@ mod tests { #[test] fn non_send_resource_drop_from_same_thread() { let mut world = World::default(); - world.insert_non_send_resource(NonSendA::default()); + world.insert_non_send_resource(NonSendResA::default()); drop(world); } diff --git a/crates/bevy_ecs/src/schedule/config.rs b/crates/bevy_ecs/src/schedule/config.rs index ddf725260141b..5bde5578ceeff 100644 --- a/crates/bevy_ecs/src/schedule/config.rs +++ b/crates/bevy_ecs/src/schedule/config.rs @@ -14,7 +14,7 @@ fn new_condition(condition: impl Condition) -> BoxedCondition { let condition_system = IntoSystem::into_system(condition); assert!( condition_system.is_send(), - "Condition `{}` accesses `NonSend` resources. This is not currently supported.", + "Condition `{}` accesses `NonSendRes` resources. This is not currently supported.", condition_system.name() ); diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index 184bef250a6b5..d8b8d36e0e718 100644 --- a/crates/bevy_ecs/src/schedule/mod.rs +++ b/crates/bevy_ecs/src/schedule/mod.rs @@ -740,8 +740,8 @@ mod tests { fn empty_system() {} fn res_system(_res: Res) {} fn resmut_system(_res: ResMut) {} - fn nonsend_system(_ns: NonSend) {} - fn nonsendmut_system(_ns: NonSendMut) {} + fn nonsendres_system(_ns: NonSendRes) {} + fn nonsendresmut_system(_ns: NonSendResMut) {} fn read_component_system(_query: Query<&A>) {} fn write_component_system(_query: Query<&mut A>) {} fn with_filtered_component_system(_query: Query<&mut A, With>) {} @@ -763,7 +763,7 @@ mod tests { let mut schedule = Schedule::default(); schedule - // nonsendmut system deliberately conflicts with resmut system + // nonsendresmut system deliberately conflicts with resmut system .add_systems((resmut_system, write_component_system, event_writer_system)); let _ = schedule.initialize(&mut world); @@ -784,8 +784,8 @@ mod tests { empty_system, res_system, res_system, - nonsend_system, - nonsend_system, + nonsendres_system, + nonsendres_system, read_component_system, read_component_system, event_reader_system, @@ -838,7 +838,7 @@ mod tests { world.insert_resource(R); let mut schedule = Schedule::default(); - schedule.add_systems((nonsendmut_system, nonsend_system)); + schedule.add_systems((nonsendresmut_system, nonsendres_system)); let _ = schedule.initialize(&mut world); @@ -940,7 +940,7 @@ mod tests { schedule.add_systems(( resmut_system.ambiguous_with_all(), res_system, - nonsend_system, + nonsendres_system, )); let _ = schedule.initialize(&mut world); @@ -960,7 +960,7 @@ mod tests { schedule.add_systems(( resmut_system.ambiguous_with(IgnoreMe), res_system.in_set(IgnoreMe), - nonsend_system.in_set(IgnoreMe), + nonsendres_system.in_set(IgnoreMe), )); let _ = schedule.initialize(&mut world); diff --git a/crates/bevy_ecs/src/storage/mod.rs b/crates/bevy_ecs/src/storage/mod.rs index 72b1dced7daf8..ab788310026cd 100644 --- a/crates/bevy_ecs/src/storage/mod.rs +++ b/crates/bevy_ecs/src/storage/mod.rs @@ -38,6 +38,6 @@ pub struct Storages { pub tables: Tables, /// Backing storage for resources. pub resources: Resources, - /// Backing storage for `!Send` resources. + /// Backing storage for [`NonSendRes`] resources. pub non_send_resources: Resources, } diff --git a/crates/bevy_ecs/src/storage/resource.rs b/crates/bevy_ecs/src/storage/resource.rs index 83e533fe609c4..bbf12625bf907 100644 --- a/crates/bevy_ecs/src/storage/resource.rs +++ b/crates/bevy_ecs/src/storage/resource.rs @@ -44,7 +44,7 @@ impl ResourceData { /// The only row in the underlying `BlobVec`. const ROW: usize = 0; - /// Validates the access to `!Send` resources is only done on the thread they were created from. + /// Validates the access to [`NonSendRes`] resources is only done on the thread they were created from. /// /// # Panics /// If `SEND` is false, this will panic if called from a different thread than the one it was inserted from. diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index b41255194cdf0..efacbb2bbb76c 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -89,8 +89,8 @@ //! - [`Local`] //! - [`EventReader`](crate::event::EventReader) //! - [`EventWriter`](crate::event::EventWriter) -//! - [`NonSend`] and `Option` -//! - [`NonSendMut`] and `Option` +//! - [`NonSendRes`] and `Option` +//! - [`NonSendResMut`] and `Option` //! - [`RemovedComponents`](crate::removal_detection::RemovedComponents) //! - [`SystemName`] //! - [`SystemChangeTick`] @@ -359,8 +359,8 @@ mod tests { Schedule, }, system::{ - Commands, In, IntoSystem, Local, NonSend, NonSendMut, ParamSet, Query, Res, ResMut, - Resource, StaticSystemParam, System, SystemState, + Commands, In, IntoSystem, Local, NonSendRes, NonSendResMut, ParamSet, Query, Res, + ResMut, Resource, StaticSystemParam, System, SystemState, }, world::{FromWorld, World}, }; @@ -859,11 +859,11 @@ mod tests { world.insert_non_send_resource(NotSend1(std::rc::Rc::new(0))); fn sys( - op: Option>, - mut _op2: Option>, + op: Option>, + mut _op2: Option>, mut system_ran: ResMut, ) { - op.expect("NonSend should exist"); + op.expect("NonSendRes should exist"); *system_ran = SystemRan::Yes; } @@ -886,8 +886,8 @@ mod tests { world.insert_non_send_resource(NotSend2(std::rc::Rc::new(2))); fn sys( - _op: NonSend, - mut _op2: NonSendMut, + _op: NonSendRes, + mut _op2: NonSendResMut, mut system_ran: ResMut, ) { *system_ran = SystemRan::Yes; diff --git a/crates/bevy_ecs/src/system/system.rs b/crates/bevy_ecs/src/system/system.rs index a36900a353824..fe9bce4f9d9fe 100644 --- a/crates/bevy_ecs/src/system/system.rs +++ b/crates/bevy_ecs/src/system/system.rs @@ -359,7 +359,7 @@ mod tests { #[test] fn non_send_resources() { - fn non_send_count_down(mut ns: NonSendMut) { + fn non_send_count_down(mut ns: NonSendResMut) { ns.0 -= 1; } diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index aae8e4e2e26f3..9630657203448 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -1,4 +1,4 @@ -pub use crate::change_detection::{NonSendMut, Res, ResMut}; +pub use crate::change_detection::{NonSendResMut, Res, ResMut}; use crate::{ archetype::{Archetype, Archetypes}, bundle::Bundles, @@ -1065,27 +1065,31 @@ unsafe impl SystemParam for Deferred<'_, T> { /// /// Panics when used as a `SystemParameter` if the resource does not exist. /// -/// Use `Option>` instead if the resource might not always exist. -pub struct NonSend<'w, T: 'static> { +/// Use `Option>` instead if the resource might not always exist. +pub struct NonSendRes<'w, T: 'static> { pub(crate) value: &'w T, ticks: ComponentTicks, last_run: Tick, this_run: Tick, } +/// See [`NonSendRes`] +#[deprecated = "Use `NonSendRes` instead"] +pub type NonSend<'w, T> = NonSendRes<'w, T>; + // SAFETY: Only reads a single World non-send resource -unsafe impl<'w, T> ReadOnlySystemParam for NonSend<'w, T> {} +unsafe impl<'w, T> ReadOnlySystemParam for NonSendRes<'w, T> {} -impl<'w, T> Debug for NonSend<'w, T> +impl<'w, T> Debug for NonSendRes<'w, T> where T: Debug, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_tuple("NonSend").field(&self.value).finish() + f.debug_tuple("NonSendRes").field(&self.value).finish() } } -impl<'w, T: 'static> NonSend<'w, T> { +impl<'w, T: 'static> NonSendRes<'w, T> { /// Returns `true` if the resource was added after the system last ran. pub fn is_added(&self) -> bool { self.ticks.is_added(self.last_run, self.this_run) @@ -1097,15 +1101,15 @@ impl<'w, T: 'static> NonSend<'w, T> { } } -impl<'w, T> Deref for NonSend<'w, T> { +impl<'w, T> Deref for NonSendRes<'w, T> { type Target = T; fn deref(&self) -> &Self::Target { self.value } } -impl<'a, T> From> for NonSend<'a, T> { - fn from(nsm: NonSendMut<'a, T>) -> Self { +impl<'a, T> From> for NonSendRes<'a, T> { + fn from(nsm: NonSendResMut<'a, T>) -> Self { Self { value: nsm.value, ticks: ComponentTicks { @@ -1119,10 +1123,10 @@ impl<'a, T> From> for NonSend<'a, T> { } // SAFETY: NonSendComponentId and ArchetypeComponentId access is applied to SystemMeta. If this -// NonSend conflicts with any prior access, a panic will occur. -unsafe impl<'a, T: 'static> SystemParam for NonSend<'a, T> { +// `NonSendRes` conflicts with any prior access, a panic will occur. +unsafe impl<'a, T: 'static> SystemParam for NonSendRes<'a, T> { type State = ComponentId; - type Item<'w, 's> = NonSend<'w, T>; + type Item<'w, 's> = NonSendRes<'w, T>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { system_meta.set_non_send(); @@ -1133,7 +1137,7 @@ unsafe impl<'a, T: 'static> SystemParam for NonSend<'a, T> { let combined_access = system_meta.component_access_set.combined_access(); assert!( !combined_access.has_write(component_id), - "error[B0002]: NonSend<{}> in system {} conflicts with a previous mutable resource access ({0}). Consider removing the duplicate access. See: https://bevyengine.org/learn/errors/#b0002", + "error[B0002]: NonSendRes<{}> in system {} conflicts with a previous mutable resource access ({0}). Consider removing the duplicate access. See: https://bevyengine.org/learn/errors/#b0002", std::any::type_name::(), system_meta.name, ); @@ -1168,7 +1172,7 @@ unsafe impl<'a, T: 'static> SystemParam for NonSend<'a, T> { ) }); - NonSend { + NonSendRes { value: ptr.deref(), ticks: ticks.read(), last_run: system_meta.last_run, @@ -1178,15 +1182,15 @@ unsafe impl<'a, T: 'static> SystemParam for NonSend<'a, T> { } // SAFETY: Only reads a single World non-send resource -unsafe impl ReadOnlySystemParam for Option> {} +unsafe impl ReadOnlySystemParam for Option> {} -// SAFETY: this impl defers to `NonSend`, which initializes and validates the correct world access. -unsafe impl SystemParam for Option> { +// SAFETY: this impl defers to `NonSendRes`, which initializes and validates the correct world access. +unsafe impl SystemParam for Option> { type State = ComponentId; - type Item<'w, 's> = Option>; + type Item<'w, 's> = Option>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { - NonSend::::init_state(world, system_meta) + NonSendRes::::init_state(world, system_meta) } #[inline] @@ -1198,7 +1202,7 @@ unsafe impl SystemParam for Option> { ) -> Self::Item<'w, 's> { world .get_non_send_with_ticks(component_id) - .map(|(ptr, ticks)| NonSend { + .map(|(ptr, ticks)| NonSendRes { value: ptr.deref(), ticks: ticks.read(), last_run: system_meta.last_run, @@ -1207,11 +1211,11 @@ unsafe impl SystemParam for Option> { } } -// SAFETY: NonSendMut ComponentId and ArchetypeComponentId access is applied to SystemMeta. If this -// NonSendMut conflicts with any prior access, a panic will occur. -unsafe impl<'a, T: 'static> SystemParam for NonSendMut<'a, T> { +// SAFETY: NonSendResMut ComponentId and ArchetypeComponentId access is applied to SystemMeta. If this +// NonSendResMut conflicts with any prior access, a panic will occur. +unsafe impl<'a, T: 'static> SystemParam for NonSendResMut<'a, T> { type State = ComponentId; - type Item<'w, 's> = NonSendMut<'w, T>; + type Item<'w, 's> = NonSendResMut<'w, T>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { system_meta.set_non_send(); @@ -1222,11 +1226,11 @@ unsafe impl<'a, T: 'static> SystemParam for NonSendMut<'a, T> { let combined_access = system_meta.component_access_set.combined_access(); if combined_access.has_write(component_id) { panic!( - "error[B0002]: NonSendMut<{}> in system {} conflicts with a previous mutable resource access ({0}). Consider removing the duplicate access. See: https://bevyengine.org/learn/errors/#b0002", + "error[B0002]: NonSendResMut<{}> in system {} conflicts with a previous mutable resource access ({0}). Consider removing the duplicate access. See: https://bevyengine.org/learn/errors/#b0002", std::any::type_name::(), system_meta.name); } else if combined_access.has_read(component_id) { panic!( - "error[B0002]: NonSendMut<{}> in system {} conflicts with a previous immutable resource access ({0}). Consider removing the duplicate access. See: https://bevyengine.org/learn/errors/#b0002", + "error[B0002]: NonSendResMut<{}> in system {} conflicts with a previous immutable resource access ({0}). Consider removing the duplicate access. See: https://bevyengine.org/learn/errors/#b0002", std::any::type_name::(), system_meta.name); } system_meta @@ -1259,20 +1263,20 @@ unsafe impl<'a, T: 'static> SystemParam for NonSendMut<'a, T> { std::any::type_name::() ) }); - NonSendMut { + NonSendResMut { value: ptr.assert_unique().deref_mut(), ticks: TicksMut::from_tick_cells(ticks, system_meta.last_run, change_tick), } } } -// SAFETY: this impl defers to `NonSendMut`, which initializes and validates the correct world access. -unsafe impl<'a, T: 'static> SystemParam for Option> { +// SAFETY: this impl defers to `NonSendResMut`, which initializes and validates the correct world access. +unsafe impl<'a, T: 'static> SystemParam for Option> { type State = ComponentId; - type Item<'w, 's> = Option>; + type Item<'w, 's> = Option>; fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State { - NonSendMut::::init_state(world, system_meta) + NonSendResMut::::init_state(world, system_meta) } #[inline] @@ -1284,7 +1288,7 @@ unsafe impl<'a, T: 'static> SystemParam for Option> { ) -> Self::Item<'w, 's> { world .get_non_send_with_ticks(component_id) - .map(|(ptr, ticks)| NonSendMut { + .map(|(ptr, ticks)| NonSendResMut { value: ptr.assert_unique().deref_mut(), ticks: TicksMut::from_tick_cells(ticks, system_meta.last_run, change_tick), }) @@ -1833,7 +1837,7 @@ mod tests { // 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>, ())>) { + fn non_send_param_set(mut p: ParamSet<(NonSendRes<*mut u8>, ())>) { let _ = p.p0(); p.p1(); } @@ -1848,7 +1852,7 @@ mod tests { // 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>)>) { + fn non_send_param_set(mut p: ParamSet<((), NonSendResMut<*mut u8>)>) { p.p0(); let _ = p.p1(); } diff --git a/crates/bevy_ecs/src/world/deferred_world.rs b/crates/bevy_ecs/src/world/deferred_world.rs index 71f5a059aed20..2e7f902779171 100644 --- a/crates/bevy_ecs/src/world/deferred_world.rs +++ b/crates/bevy_ecs/src/world/deferred_world.rs @@ -242,7 +242,7 @@ impl<'w> DeferredWorld<'w> { unsafe { self.world.get_resource_mut_by_id(component_id) } } - /// Gets a `!Send` resource to the resource with the id [`ComponentId`] if it exists. + /// Gets a [`NonSendRes`] resource to the resource with the id [`ComponentId`] if it exists. /// The returned pointer may be used to modify the resource, as long as the mutable borrow /// of the [`World`] is still valid. /// diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index d509eaa349c65..1a2d7a1c32b50 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -1309,7 +1309,7 @@ impl World { }); } - /// Initializes a new non-send resource and returns the [`ComponentId`] created for it. + /// Initializes a new [`NonSendRes`] resource and returns the [`ComponentId`] created for it. /// /// If the resource already exists, nothing happens. /// @@ -1340,11 +1340,11 @@ impl World { component_id } - /// Inserts a new non-send resource with the given `value`. + /// Inserts a new [`NonSendRes`] resource with the given `value`. /// - /// `NonSend` resources cannot be sent across threads, + /// `NonSendRes` resources cannot be sent across threads, /// and do not need the `Send + Sync` bounds. - /// Systems with `NonSend` resources are always scheduled on the main thread. + /// Systems with `NonSendRes` resources are always scheduled on the main thread. /// /// # Panics /// If a value is already present, this function will panic if called @@ -1369,11 +1369,11 @@ impl World { unsafe { Some(ptr.read::()) } } - /// Removes a `!Send` resource from the world and returns it, if present. + /// Removes a [`NonSendRes`] resource from the world and returns it, if present. /// - /// `NonSend` resources cannot be sent across threads, + /// `NonSendRes` resources cannot be sent across threads, /// and do not need the `Send + Sync` bounds. - /// Systems with `NonSend` resources are always scheduled on the main thread. + /// Systems with `NonSendRes` resources are always scheduled on the main thread. /// /// Returns `None` if a value was not previously present. /// @@ -1402,9 +1402,9 @@ impl World { .unwrap_or(false) } - /// Returns `true` if a resource of type `R` exists. Otherwise returns `false`. + /// Returns `true` if a [`NonSendRes`] resource of type `R` exists. Otherwise returns `false`. #[inline] - pub fn contains_non_send(&self) -> bool { + pub fn contains_non_send_resource(&self) -> bool { self.components .get_resource_id(TypeId::of::()) .and_then(|component_id| self.storages.non_send_resources.get(component_id)) @@ -1412,6 +1412,13 @@ impl World { .unwrap_or(false) } + /// See [`World::contains_non_send_resource`]. + #[inline] + #[deprecated = "Use `contains_non_send_resource` instead"] + pub fn contains_non_send(&self) -> bool { + self.contains_non_send_resource::() + } + /// Returns `true` if a resource of type `R` exists and was added since the world's /// [`last_change_tick`](World::last_change_tick()). Otherwise, this returns `false`. /// @@ -1964,7 +1971,7 @@ impl World { } } - /// Inserts a new `!Send` resource with the given `value`. Will replace the value if it already + /// Inserts a new [`NonSendRes`] resource with the given `value`. Will replace the value if it already /// existed. /// /// **You should prefer to use the typed API [`World::insert_non_send_resource`] where possible and only @@ -2528,7 +2535,7 @@ impl World { }) } - /// Gets a `!Send` resource to the resource with the id [`ComponentId`] if it exists. + /// Gets a [`NonSendRes`] resource to the resource with the id [`ComponentId`] if it exists. /// The returned pointer must not be used to modify the resource, and must not be /// dereferenced after the immutable borrow of the [`World`] ends. /// @@ -2548,7 +2555,7 @@ impl World { } } - /// Gets a `!Send` resource to the resource with the id [`ComponentId`] if it exists. + /// Gets a [`NonSendRes`] resource to the resource with the id [`ComponentId`] if it exists. /// The returned pointer may be used to modify the resource, as long as the mutable borrow /// of the [`World`] is still valid. /// diff --git a/crates/bevy_ecs/src/world/unsafe_world_cell.rs b/crates/bevy_ecs/src/world/unsafe_world_cell.rs index 8de3d3af3e83a..818bbc87cfb32 100644 --- a/crates/bevy_ecs/src/world/unsafe_world_cell.rs +++ b/crates/bevy_ecs/src/world/unsafe_world_cell.rs @@ -382,7 +382,7 @@ impl<'w> UnsafeWorldCell<'w> { } } - /// Gets a `!Send` resource to the resource with the id [`ComponentId`] if it exists. + /// Gets a [`NonSendRes`] resource to the resource with the id [`ComponentId`] if it exists. /// The returned pointer must not be used to modify the resource, and must not be /// dereferenced after the immutable borrow of the [`World`] ends. /// @@ -483,7 +483,7 @@ impl<'w> UnsafeWorldCell<'w> { } } - /// Gets a `!Send` resource to the resource with the id [`ComponentId`] if it exists. + /// Gets a [`NonSendRes`] resource to the resource with the id [`ComponentId`] if it exists. /// The returned pointer may be used to modify the resource, as long as the mutable borrow /// of the [`World`] is still valid. /// diff --git a/crates/bevy_gilrs/src/gilrs_system.rs b/crates/bevy_gilrs/src/gilrs_system.rs index 331bccb0cad91..93171ee495af2 100644 --- a/crates/bevy_gilrs/src/gilrs_system.rs +++ b/crates/bevy_gilrs/src/gilrs_system.rs @@ -4,7 +4,7 @@ use crate::{ }; use bevy_ecs::event::EventWriter; #[cfg(target_arch = "wasm32")] -use bevy_ecs::system::NonSendMut; +use bevy_ecs::system::NonSendResMut; use bevy_ecs::system::{Res, ResMut}; use bevy_input::gamepad::{ GamepadAxisChangedEvent, GamepadButtonChangedEvent, GamepadConnection, GamepadConnectionEvent, @@ -16,7 +16,7 @@ use bevy_input::Axis; use gilrs::{ev::filter::axis_dpad_to_button, EventType, Filter}; pub fn gilrs_event_startup_system( - #[cfg(target_arch = "wasm32")] mut gilrs: NonSendMut, + #[cfg(target_arch = "wasm32")] mut gilrs: NonSendResMut, #[cfg(not(target_arch = "wasm32"))] mut gilrs: ResMut, mut events: EventWriter, ) { @@ -36,7 +36,7 @@ pub fn gilrs_event_startup_system( } pub fn gilrs_event_system( - #[cfg(target_arch = "wasm32")] mut gilrs: NonSendMut, + #[cfg(target_arch = "wasm32")] mut gilrs: NonSendResMut, #[cfg(not(target_arch = "wasm32"))] mut gilrs: ResMut, mut events: EventWriter, mut gamepad_buttons: ResMut>, diff --git a/crates/bevy_gilrs/src/rumble.rs b/crates/bevy_gilrs/src/rumble.rs index b59abef9a066f..ddd8514ac7847 100644 --- a/crates/bevy_gilrs/src/rumble.rs +++ b/crates/bevy_gilrs/src/rumble.rs @@ -2,7 +2,7 @@ use crate::Gilrs; use bevy_ecs::prelude::{EventReader, Res, ResMut, Resource}; #[cfg(target_arch = "wasm32")] -use bevy_ecs::system::NonSendMut; +use bevy_ecs::system::NonSendResMut; use bevy_input::gamepad::{GamepadRumbleIntensity, GamepadRumbleRequest}; use bevy_time::{Real, Time}; use bevy_utils::tracing::{debug, warn}; @@ -124,7 +124,7 @@ fn handle_rumble_request( } pub(crate) fn play_gilrs_rumble( time: Res>, - #[cfg(target_arch = "wasm32")] mut gilrs: NonSendMut, + #[cfg(target_arch = "wasm32")] mut gilrs: NonSendResMut, #[cfg(not(target_arch = "wasm32"))] mut gilrs: ResMut, mut requests: EventReader, mut running_rumbles: ResMut, diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index cf347586e6429..4df3b13add617 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -440,10 +440,10 @@ const DEFAULT_DESIRED_MAXIMUM_FRAME_LATENCY: u32 = 2; /// Creates window surfaces. pub fn create_surfaces( - // By accessing a NonSend resource, we tell the scheduler to put this system on the main thread, + // By accessing a `NonSendRes` resource, we tell the scheduler to put this system on the main thread, // which is necessary for some OS's #[cfg(any(target_os = "macos", target_os = "ios"))] _marker: Option< - NonSend, + NonSendRes, >, windows: Res, mut window_surfaces: ResMut, diff --git a/crates/bevy_winit/src/accessibility.rs b/crates/bevy_winit/src/accessibility.rs index e72c6c8cfe79c..648249e0d479c 100644 --- a/crates/bevy_winit/src/accessibility.rs +++ b/crates/bevy_winit/src/accessibility.rs @@ -19,7 +19,7 @@ use bevy_ecs::{ prelude::{DetectChanges, Entity, EventReader, EventWriter}, query::With, schedule::IntoSystemConfigs, - system::{NonSendMut, Query, Res, ResMut, Resource}, + system::{NonSendResMut, Query, Res, ResMut, Resource}, }; use bevy_hierarchy::{Children, Parent}; use bevy_window::{PrimaryWindow, Window, WindowClosed}; @@ -148,7 +148,7 @@ pub(crate) fn prepare_accessibility_for_window( } fn window_closed( - mut adapters: NonSendMut, + mut adapters: NonSendResMut, mut handlers: ResMut, mut events: EventReader, ) { @@ -178,7 +178,7 @@ fn should_update_accessibility_nodes( } fn update_accessibility_nodes( - mut adapters: NonSendMut, + mut adapters: NonSendResMut, focus: Res, primary_window: Query<(Entity, &Window), With>, nodes: Query<( diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 8be97fc8082cc..8e58b524a1e9f 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -146,7 +146,7 @@ pub struct WakeUp; /// /// The `EventLoopProxy` can be used to request a redraw from outside bevy. /// -/// Use `NonSend` to receive this resource. +/// Use `NonSendRes` to receive this resource. pub type EventLoopProxy = winit::event_loop::EventLoopProxy; trait AppSendEvent { @@ -173,8 +173,8 @@ pub type CreateWindowParams<'w, 's, F = ()> = ( F, >, EventWriter<'w, WindowCreated>, - NonSendMut<'w, WinitWindows>, - NonSendMut<'w, AccessKitAdapters>, + NonSendResMut<'w, WinitWindows>, + NonSendResMut<'w, AccessKitAdapters>, ResMut<'w, WinitActionRequestHandlers>, Res<'w, AccessibilityRequested>, ); diff --git a/crates/bevy_winit/src/state.rs b/crates/bevy_winit/src/state.rs index 0638a5cf857cc..b67cb271e9601 100644 --- a/crates/bevy_winit/src/state.rs +++ b/crates/bevy_winit/src/state.rs @@ -1,6 +1,6 @@ use approx::relative_eq; use bevy_app::{App, AppExit, PluginsState}; -use bevy_ecs::change_detection::{DetectChanges, NonSendMut, Res}; +use bevy_ecs::change_detection::{DetectChanges, Res}; use bevy_ecs::entity::Entity; use bevy_ecs::event::{EventWriter, ManualEventReader}; use bevy_ecs::prelude::*; @@ -75,9 +75,9 @@ struct WinitAppRunnerState { EventWriter<'static, WindowResized>, EventWriter<'static, WindowBackendScaleFactorChanged>, EventWriter<'static, WindowScaleFactorChanged>, - NonSend<'static, WinitWindows>, + NonSendRes<'static, WinitWindows>, Query<'static, 'static, (&'static mut Window, &'static mut CachedWindow)>, - NonSendMut<'static, AccessKitAdapters>, + NonSendResMut<'static, AccessKitAdapters>, )>, } @@ -89,9 +89,9 @@ impl WinitAppRunnerState { EventWriter, EventWriter, EventWriter, - NonSend, + NonSendRes, Query<(&mut Window, &mut CachedWindow)>, - NonSendMut, + NonSendResMut, )> = SystemState::new(app.world_mut()); Self { diff --git a/crates/bevy_winit/src/system.rs b/crates/bevy_winit/src/system.rs index 48b0a5ef6e40f..c3b3e0ec4873e 100644 --- a/crates/bevy_winit/src/system.rs +++ b/crates/bevy_winit/src/system.rs @@ -4,7 +4,7 @@ use bevy_ecs::{ prelude::{Changed, Component}, query::QueryFilter, removal_detection::RemovedComponents, - system::{Local, NonSendMut, Query, SystemParamItem}, + system::{Local, NonSendResMut, Query, SystemParamItem}, }; use bevy_utils::tracing::{error, info, warn}; use bevy_window::{ @@ -125,7 +125,7 @@ pub(crate) fn despawn_windows( window_entities: Query>, mut closing_events: EventWriter, mut closed_events: EventWriter, - mut winit_windows: NonSendMut, + mut winit_windows: NonSendResMut, mut windows_to_drop: Local>>, mut exit_events: EventReader, ) { @@ -177,7 +177,7 @@ pub struct CachedWindow { /// - [`Window::focused`] cannot be manually changed to `false` after the window is created. pub(crate) fn changed_windows( mut changed_windows: Query<(Entity, &mut Window, &mut CachedWindow), Changed>, - winit_windows: NonSendMut, + winit_windows: NonSendResMut, mut window_resized: EventWriter, ) { for (entity, mut window, mut cache) in &mut changed_windows { diff --git a/examples/app/log_layers_ecs.rs b/examples/app/log_layers_ecs.rs index 179a4715adf61..2c5a415f2bbfc 100644 --- a/examples/app/log_layers_ecs.rs +++ b/examples/app/log_layers_ecs.rs @@ -34,7 +34,7 @@ struct CapturedLogEvents(mpsc::Receiver); /// Transfers information from the `LogEvents` resource to [`Events`](LogEvent). fn transfer_log_events( - receiver: NonSend, + receiver: NonSendRes, mut log_events: EventWriter, ) { // Make sure to use `try_iter()` and not `iter()` to prevent blocking. diff --git a/examples/window/custom_user_event.rs b/examples/window/custom_user_event.rs index 6fe3c57d7a034..9474435767ac0 100644 --- a/examples/window/custom_user_event.rs +++ b/examples/window/custom_user_event.rs @@ -72,7 +72,7 @@ fn send_event(input: Res>) { } } -fn expose_event_loop_proxy(event_loop_proxy: NonSend>) { +fn expose_event_loop_proxy(event_loop_proxy: NonSendRes>) { EVENT_LOOP_PROXY.set((*event_loop_proxy).clone()).unwrap(); } diff --git a/examples/window/low_power.rs b/examples/window/low_power.rs index 795d064b352b6..5b52df8607b85 100644 --- a/examples/window/low_power.rs +++ b/examples/window/low_power.rs @@ -57,7 +57,7 @@ enum ExampleMode { fn update_winit( mode: Res, mut winit_config: ResMut, - event_loop_proxy: NonSend>, + event_loop_proxy: NonSendRes>, ) { use ExampleMode::*; *winit_config = match *mode {