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

Run criteria should not be allowed to mutate the world #2841

Closed
alice-i-cecile opened this issue Sep 18, 2021 · 3 comments
Closed

Run criteria should not be allowed to mutate the world #2841

alice-i-cecile opened this issue Sep 18, 2021 · 3 comments
Labels
A-ECS Entities, components, systems, and events C-Enhancement A new feature S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@alice-i-cecile
Copy link
Member

What problem does this solve or what need does it fill?

Run criteria are currently implemented using ordinary systems, and evaluated in order.

However, run criteria should not be allowed to mutate the world state:

  • this can cause surprising side effects, as the run criteria itself may change the world
  • this forces us to care about the order they are executed in
  • this reduces type safety, as users can accidentally place run criteria where they intend to use a system and so on

As far as I can tell, there are no valid use cases for run criteria mutating the world themselves.

What solution would you like?

Run criteria are no longer systems. Instead, they are system-like. Conceptually, they could be described as "pure systems", in analogy to pure functions.

Run criteria can read data from the world, but every run criteria parameter must satisfy ReadOnlyFetch.

By enforcing this constraint, we can skip out on expensive coordination machinery (and complex ordering and side effect concerns) when checking run criteria. All run criteria then be evaluated in parallel, completely ignoring order.

What alternative(s) have you considered?

Enforce this with code hygiene or a lint.

Make this a special case of systems. However, specialization is not "yet" part of Rust, and this approach will fail due to conflicting trait impls.

Additional context

This should probably be tackled as part of the initiative in #2801.

@alice-i-cecile alice-i-cecile added C-Enhancement A new feature A-ECS Entities, components, systems, and events S-Needs-Design This issue requires design work to think about how it would best be accomplished labels Sep 18, 2021
@TheRawMeatball
Copy link
Member

As far as I can tell, there are no valid use cases for run criteria mutating the world themselves.

States currently rely on this.

@alice-i-cecile
Copy link
Member Author

States currently rely on this.

Right, that shouldn't surprise me. So I suppose this gets tossed onto the pile of hard schedule-adjacent problems in #2801.

@maniwani
Copy link
Contributor

maniwani commented Feb 6, 2023

Resolved by #7267.

@maniwani maniwani closed this as completed Feb 6, 2023
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 C-Enhancement A new feature S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

No branches or pull requests

3 participants