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

Safety comments in MultiThreadedExecutor are incorrect #7833

Closed
JoJoJet opened this issue Feb 27, 2023 · 0 comments · Fixed by #8292
Closed

Safety comments in MultiThreadedExecutor are incorrect #7833

JoJoJet opened this issue Feb 27, 2023 · 0 comments · Fixed by #8292
Labels
A-ECS Entities, components, systems, and events P-Unsound A bug that results in undefined compiler behavior

Comments

@JoJoJet
Copy link
Member

JoJoJet commented Feb 27, 2023

Both places where System::run_unsafe is called in MultiThreadedExecutor still have placeholder safety comments. They simply state that the safety invariants are upheld, without making any attempt to explain how they are upheld.

// SAFETY: access is compatible

// SAFETY: caller ensures system access is compatible

@JoJoJet JoJoJet added A-ECS Entities, components, systems, and events P-Unsound A bug that results in undefined compiler behavior labels Feb 27, 2023
alice-i-cecile pushed a commit that referenced this issue Apr 17, 2023
# Objective

The implementation of `System::run_unsafe` for `FunctionSystem` requires
that the world is the same one used to initialize the system. However,
the `System` trait has no requirements that the world actually matches,
which makes this implementation unsound.

This was previously mentioned in
#7605 (comment)

Fixes part of #7833.

## Solution

Add the safety invariant that
`System::update_archetype_component_access` must be called prior to
`System::run_unsafe`. Since
`FunctionSystem::update_archetype_component_access` properly validates
the world, this ensures that `run_unsafe` is not called with a
mismatched world.

Most exclusive systems are not required to be run on the same world that
they are initialized with, so this is not a concern for them. Systems
formed by combining an exclusive system with a regular system *do*
require the world to match, however the validation is done inside of
`System::run` when needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events P-Unsound A bug that results in undefined compiler behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant