bevy
bevy copied to clipboard
Remove `Sync` bound from `Local`
Objective
Currently, Local
has a Sync
bound. Theoretically this is unnecessary as a local can only ever be accessed from its own system, ensuring exclusive access on one thread. This PR removes this restriction.
Solution
- By removing the
Resource
bound fromLocal
and adding the newSyncCell
threading primative,Local
can have theSync
bound removed.
Changelog
Added
- Added
SyncCell
tobevy_utils
Changed
- Removed
Resource
bound fromLocal
-
Local
is now wrapped in aSyncCell
Migration Guide
- Any code relying on
Local<T>
havingT: Resource
will have to be changed, but this is unlikely.
bors try
try
Build succeeded:
I like the relaxation on the bounds for Locals, but I'm unsure about taking on SyncCell
when Exclusive
seems to be close-ish to being stabilized. Are there any clear use cases for this? If there are it'd probably be worth merging now.
The idea is to just swap SyncCell
for Exclusive
once it stabilizes. As this is probably going to be the only use of SyncCell
until that point, it shouldn't take more than a minute to put together a PR for.
users could also depend on it. see the issue on bevy_fundsp
that is in this feed.
In that case, we can typedef SyncCell
to Exclusive
and deprecate it, and remove it in the next major version. Or just deprecate it. Or just remove it- bevy users are still very much supposed to expect breaking changes, as long as we add to the migration guide for that version that SyncCell
is replaced by Exclusive
it should be fine. Either way I don't see it as worth waiting for something to stabilize "soon" unless we have a concrete date.
see the issue on bevy_fundsp that is in this feed.
btw, i don't need it anymore as #5819 is now merged.
also, if in the case that users would need it, i would prefer just removing it outright as bevy's api isn't really stabilized yet. I think bevy's development is fast enough to update SyncCell
usage to Exclusive
, and we don't have to wait for stabilization.
bors r+
Pull request successfully merged into main.
Build succeeded: