Remove Sync bound on Component and Resource (adopted)#5879
Remove Sync bound on Component and Resource (adopted)#5879JohnTheCoolingFan wants to merge 21 commits intobevyengine:mainfrom
Conversation
|
Currently working on resolving merge conflicts |
|
Sounds good :) Let us know if you have any questions or need help. |
|
|
||
| /// A type that can run as a step of a [`Schedule`](super::Schedule). | ||
| pub trait Stage: Downcast + Send + Sync { | ||
| pub trait Stage: Downcast + Send { |
There was a problem hiding this comment.
Doesn't schedule.get_stage() depend on stages being Sync?
| pub fn get_resource_by_id(&self, component_id: ComponentId) -> Option<Ptr<'_>> { | ||
| let info = self.components.get_info(component_id)?; | ||
| if !info.is_send_and_sync() { | ||
| if !info.is_send() { |
There was a problem hiding this comment.
This should check for sync, right?
|
Currently can't figure out how to make |
| /// Non-`Sync` components are supported, but cannot be accessed as `&T`, | ||
| /// as the type cannot be safely read from multiple threads at the same | ||
| /// time. These components must be accessed via a `&mut T` to guarentee | ||
| /// that the system has exclusive access to the components. |
There was a problem hiding this comment.
this isnt going to work and imo is flawed anyway, why shouldn't you be able to use &T from multiple places in a system?
imo we should do one of:
- Add
NonSyncversions of&Tand&mut T, leaving the existing types requiringT: Sync - Remove
T: Syncbound from&Tand&mut Tworldqueries (this is a bad idea since now we're going to be registering almost eveyr component as!Sync) - Add a
NonSync<T>and use that as the readonly version of&mut T(this is a bad idea since its going to screw up theQuery::to_readonlyeffort by making the readonly version ofQuery<&mut T>not beQuery<&T>)
I am assuming here that the scheduler is smart enough to know not to schedule two systems with read only access of a !Sync component in parallel, if not that should be fixed
There was a problem hiding this comment.
Why not just add NonSyncRead<T> for the 'use &T from multiple places in a system' case?
Fundamentally, &mut T requiring T: Sync is entirely superfluous - the requirement that T is Sync would never be used.
There was a problem hiding this comment.
Oh I see, because we need to convert to readonly. That's annoying.
I don't suppose we can gate a readonly conversion existing on T being Sync? Is conversion to readonly really a fundamental part of the Query API?
There was a problem hiding this comment.
conversion to readonly doesnt require it. we could after all set the readonly version of &mut T to be NonSync<T>. It's just kinda silly to have the readonly version of &mut T not be &T.
Is conversion to readonly really a fundamental part of the Query API?
I think so? It's not quite there yet but I hope that in a bit of time we'll have much more flexibility around changing the Q/F generics and being able to downgrade a query to readonly is a part of that. Personally I value to_readonly working on everything a lot more than some extreme edge case of non sync components needing to use NonSyncMut<T> instead of &mut T
|
@JohnTheCoolingFan are you still working on this? I'd like to get |
|
No, I just resolved the merge conflicts in an attempt to bring some attention and possibly merge. I now realise that I do not have the knowledge and skills to further maintain this PR. |
|
I'll make a PR for this then 👍 |
Adoption of #4680
Objective
Fixes #2487. Remove the
Syncbound onComponentandResourceto allow Send-only components.Solution
Syncbound fromComponentandResource.PhantomData<T>inFetchStateandSystemParamStateto usePhantomData<fn() -> T>to ensure they'reSync.compile_fail_test.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.