Remove Sync bound on Component and Resource#4680
Remove Sync bound on Component and Resource#4680james7132 wants to merge 17 commits intobevyengine:mainfrom
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. |
|
|
||
| /// A [`World`] mutation. | ||
| pub trait Command: Send + Sync + 'static { | ||
| pub trait Command: Send + 'static { |
There was a problem hiding this comment.
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.
Is the Send + Sync necessary when the target is wasm?
There was a problem hiding this comment.
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. |
| // 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.
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.
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 |
| pub struct ReadState<T> { | ||
| component_id: ComponentId, | ||
| marker: PhantomData<T>, | ||
| marker: PhantomData<fn() -> T>, |
There was a problem hiding this comment.
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.
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
| /// # bevy_ecs::system::assert_is_system(my_system); | ||
| /// ``` | ||
| /// | ||
| /// ## Non-Sync Queries |
There was a problem hiding this comment.
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.
alice-i-cecile
left a comment
There was a problem hiding this comment.
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
Syncbound onComponentandResourceto allowSend-only components.Solution
Syncbound fromComponentandResource.PhantomData<T>inFetchStateandSystemParamStateto usePhantomData<fn() -> T>to ensure they're Sync.Syncbound on theWorldQueryimpl for &T.Syncbound onRes<T>andOption<Res<T>>Syncbound onQuery::get_component,World::get,EntityRef::get, andEntityMut::get.Changelog
Removed:
Syncbound onComponentandResource.Migration Guide
ComponentandResourceno longer requiresSync. Any generic code usingComponentas a bound,&Tas Query parameter, orRes<T>might require an additionalSyncbound.