-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Sync bound on Component and Resource #4680
Conversation
50fce3c
to
998b4bf
Compare
It's worth noting that at the time #2487 was written, It's actually more interesting and useful to do the same transformation for resources. That being said, if we can get this incrementally added I'm not too unhappy. |
@@ -13,7 +13,7 @@ use std::marker::PhantomData; | |||
use super::Resource; | |||
|
|||
/// A [`World`] mutation. | |||
pub trait Command: Send + Sync + 'static { | |||
pub trait Command: Send + 'static { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll also want to do the same transformation for Send
at some point.
Note that doing that requires we keep proper main thread management - it requires a lot of care.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the Send + Sync necessary when the target is wasm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually we'll want Web Worker-based multithreading, so it will still be required.
This is basically ready for review. I still need to figure out how to make the compile tests work. |
@@ -370,7 +370,7 @@ mod menu { | |||
|
|||
// This system updates the settings when a new value for a setting is selected, and marks | |||
// the button as the one currently selected | |||
fn setting_button<T: Component + PartialEq + Copy>( | |||
fn setting_button<T: Component + Sync + PartialEq + Copy>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an unfortunate bound to need to add in end-user code.
What happens if it's omitted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bound on &T
fails to compile. This honestly only comes up in generic code though.
Following @DJMcNab's suggestion, I've been thinking on how to make |
This PR would allow me to make a game similar to screeps but with lua using mlua crate. Hopefully this gets merged soon. |
@JohnTheCoolingFan can you link to the |
@@ -553,12 +578,12 @@ impl<T: Component> WorldQuery for &T { | |||
#[doc(hidden)] | |||
pub struct ReadState<T> { | |||
component_id: ComponentId, | |||
marker: PhantomData<T>, | |||
marker: PhantomData<fn() -> T>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This aligns with my mental model of how this should be modelled, but this is subtle enough that it deserves a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't really think it's needed. This is very much the standard way to express 'this represents something which can produce a T
'.
It's no more strange than the initial use of PhantomData
imo - maybe we should have a comment that we need to be able to 'reconstruct' the original T
, so store it here. But we don't need to comment specifically on it being fn()->T
@@ -292,6 +292,31 @@ use std::{cell::UnsafeCell, marker::PhantomData}; | |||
/// | |||
/// # bevy_ecs::system::assert_is_system(my_system); | |||
/// ``` | |||
/// | |||
/// ## Non-Sync Queries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docs are great; add a copy of this to Res
and NonSend
?
We should also try to deduplicate these docs with the include_str!
doc macro trick; these are subtle and critical enough that I really don't want that duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Core changes are good, and make sense to me.
I have some doc nits that should be addressed, and I think that doc deduplication is unusually important here.
Closing in favor of the revived #5879. |
Objective
Fixes #2487. Remove the
Sync
bound onComponent
andResource
to allowSend
-only components.Solution
Sync
bound fromComponent
andResource
.PhantomData<T>
inFetchState
andSystemParamState
to usePhantomData<fn() -> T>
to ensure they're Sync.Sync
bound on theWorldQuery
impl for &T.Sync
bound onRes<T>
andOption<Res<T>>
Sync
bound onQuery::get_component
,World::get
,EntityRef::get
, andEntityMut::get
.Changelog
Removed:
Sync
bound onComponent
andResource
.Migration Guide
Component
andResource
no longer requiresSync
. Any generic code usingComponent
as a bound,&T
as Query parameter, orRes<T>
might require an additionalSync
bound.