-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Unify ExclusiveSystemParams with normal SystemParams #16622
base: main
Are you sure you want to change the base?
Conversation
How are you handling parameters like fn do_something(world: &mut World, archetypes: &Archetypes, query: Query<Entity>) {} would be UB, since the I think that's why #4166 had |
Added the controversial tag since there was a old pr with this approach, but we merged the current approach instead. You should add tests for the current SystemParams that conflict with &mut World, since that's now a safety concern. Maybe 2 tests each, one with &mut World first and one with &mut World second. |
system_meta.component_access_set.write_all(); | ||
let mut access = Access::default(); | ||
access.read_all(); | ||
if !system_meta |
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.
Does the existing code for DeferredWorld not check for conflicts? This change should probably pulled out if so as that's a safety concern.
|
||
let mut filtered_access = FilteredAccess::default(); | ||
|
||
filtered_access.read_all(); |
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 feel like we shouldn't set any filtered_access as &mut World doesn't filter.
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 feel like we shouldn't set any filtered_access as &mut World doesn't filter.
component_access_set
is the one that actually gets checked for conflicts by things like Res
and Query
, so you do want to populate it. FilteredAccess::default()
is unfiltered, so this is declaring read access with no filter. It could also be written FilteredAccess::matches_everything()
, which may be more clear.
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.
ah right, I misremembered what the filtered_access was for. This is fine then.
A fun thing this would enable is putting Another thing this would enable is adding |
761edc6
to
9a77c73
Compare
9a77c73
to
150266d
Compare
# Objective - Required by #16622 due to differing implementations of `System` by `FunctionSystem` and `ExclusiveFunctionSystem`. - Optimize the memory usage of instances of `apply_deferred` in system schedules. ## Solution By changing `apply_deferred` from being an ordinary system that ends up as an `ExclusiveFunctionSystem`, and instead into a ZST struct that implements `System` manually, we save ~320 bytes per instance of `apply_deferred` in any schedule. ## Testing - All current tests pass. --- ## Migration Guide - If you were previously calling the special `apply_deferred` system via `apply_deferred(world)`, don't.
Objective
Remove
ExclusiveSystemParam
andExclusiveFunctionSystem
in favor of justSystemParam
s, and define a system's exclusivity based on its parameters'SystemParam::is_exclusive
return value.Solution
Note: This PR relies on #16642 to be merged first.
ExclusiveSystemParam
,ExclusiveFunctionSystem
, andExclusiveSystemParamFunction
.&mut World
,&mut QueryState<D, F>
, and&mut SystemState<P>
now implementSystemParam
.&mut World
registers exclusive access, so it cannot be used alongside any parameter that accesses the world&mut QueryState
and&mut SystemState
don't hold access to the world, so can be used alongside itSystemParam
s:&mut QueryState
now will automatically update its archetypes viaSystemParam::new_archetype
&mut SystemState
will now have its deferred mutations automatically applied viaSystemParam::apply
DeferredWorld
'sinit_state
was updated to align with&World
and&mut World
TODO
&mut World
, but this PR in its current state allows it.DeferredWorld
, however. We should consider splitting "exclusivity" into "structural exclusivity" and "deferred exclusivity".&mut QueryState
and&mut SystemState
shouldn't do their things above automatically.bevy_lint
to tell users not to use two&mut World
s in a system or&mut World
+Query
/Res
/etcTesting
Most pre-existing tests are passing currently, will need to add some new ones before merging.
Showcase
Systems with
&mut World
no longer require it to be the first parameter (or second if using system input). It can now be placed anywhere in the function arguments:Migration Guide
TODO