Skip to content
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

Expose SystemMeta field accessors (#5497) #7119

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
42 changes: 42 additions & 0 deletions crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,36 @@ impl SystemMeta {
&self.name
}

/// Returns the system's component access set.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the system's component access set.
/// Fetches the system's component access set.

#[inline]
pub fn component_access_set(&self) -> &FilteredAccessSet<ComponentId> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should all be const, along with the other methods on this type.

&self.component_access_set
}

/// Returns a mutable reference to the system's component access set.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns a mutable reference to the system's component access set.
/// Fetches a mutable reference to the system's component access set.

///
/// # Safety
/// This allows unsafe modifications to the component access set that can violate Bevy's scheduling soundness.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't documenting the actual safety invariant. Editing the component access set needs to accurately reflect the actual mutable and immutable accesses the system (or parameter) fetches from the World.

#[inline]
pub unsafe fn component_access_set_mut(&mut self) -> &mut FilteredAccessSet<ComponentId> {
Copy link
Member

@james7132 james7132 Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pub(crate) on the fields should be removed and the bevy_ecs uses of the access sets should use these accessors. Won't block on this, can be done in a followup PR.

&mut self.component_access_set
}

/// Returns the system's archetype component access set.
#[inline]
pub fn archetype_component_access(&self) -> &Access<ArchetypeComponentId> {
&self.archetype_component_access
}

/// Returns a mutable reference to this system's archetype component access set.
///
/// # Safety
/// This allows unsafe modifications to the archetype component access set that can violate Bevy's scheduling soundness.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also must exactly reflect the safety invariants of using this.

#[inline]
pub unsafe fn archetype_component_access_mut(&mut self) -> &mut Access<ArchetypeComponentId> {
&mut self.archetype_component_access
}

/// Returns true if the system is [`Send`].
#[inline]
pub fn is_send(&self) -> bool {
Expand All @@ -56,6 +86,18 @@ impl SystemMeta {
pub fn set_non_send(&mut self) {
self.is_send = false;
}

/// Returns this system's last change tick.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs links.

#[inline]
pub fn last_change_tick(&self) -> u32 {
self.last_change_tick
}

/// Set this system's last change tick.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs links and warnings.

#[inline]
pub fn set_last_change_tick(&mut self, last_change_tick: u32) {
self.last_change_tick = last_change_tick;
}
}

// TODO: Actually use this in FunctionSystem. We should probably only do this once Systems are constructed using a World reference
Expand Down