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

Exclusive systems accessing World in their signature cannot be chained. #5248

Closed
AlexOkafor opened this issue Jul 8, 2022 · 2 comments
Closed
Labels
A-ECS Entities, components, systems, and events C-Usability A simple quality-of-life change that makes Bevy easier to use

Comments

@AlexOkafor
Copy link
Contributor

Bevy version

https://github.com/bevyengine/bevy/tree/v0.7.0
83c6ffb

What you did

When trying to setup fallible systems, I had a case where one system needed exclusive access to the world, but could also error. Upon chaining it with an error handler I would get a compile error. Other exclusive systems that didn't refer to the world seemed to work. I'm new to rust so I couldn't exactly make sense of what the type errors was wanting from me. Below is a minimal repo case of the compile error:

// main.rs
use bevy::prelude::*;

struct DummyEvent;

fn exclusive_1(mut _writer: EventWriter<DummyEvent>) -> std::io::Result<()> {
    Ok(())
}

fn exclusive_2(_world: &mut World) -> std::io::Result<()> {
    Ok(())
}

fn error_handler(In(result): In<std::io::Result<()>>) {
    //noop
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_event::<DummyEvent>()
        .add_startup_system(exclusive_1.chain(error_handler).exclusive_system())
        // compile error when using a different signature system
        .add_startup_system(exclusive_2.chain(error_handler).exclusive_system())
        .run();
}

What went wrong

I was expecting systems that have the signature:
fn exclusive_2(_world: &mut World) -> std::io::Result<()> can be chained as exclusive systems, but the compiler suggests there are some trait bounds not being satisfied.

Additional information

Compiler error below:

error[E0599]: the method `chain` exists for fn item `for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}`, but its trait bounds were not satisfied
  --> src\main.rs:23:41
   |
23 |         .add_startup_system(exclusive_2.chain(error_handler).exclusive_system())
   |                                         ^^^^^ method cannot be called on `for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}` due to unsatisfied trait bounds
   |
   = note: `exclusive_2` is a function, perhaps you wish to call it
   = note: the following trait bounds were not satisfied:
           `for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: IntoSystem<(), _, _>`
           which is required by `for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: bevy::prelude::IntoChainSystem<_, _, _, _, _>`
           `&for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: IntoSystem<(), _, _>`
           which is required by `&for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: bevy::prelude::IntoChainSystem<_, _, _, _, _>`
           `&mut for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: IntoSystem<(), _, _>`
           which is required by `&mut for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: bevy::prelude::IntoChainSystem<_, _, _, _, _>`
           `for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: Iterator`
           which is required by `&mut for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: Iterator`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `chain-repo` due to previous error
@AlexOkafor AlexOkafor added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jul 8, 2022
@DJMcNab
Copy link
Member

DJMcNab commented Jul 8, 2022

This would be resolved by #4166

I think that exclusive_2.exclusive_system().chain(whatever) might work?

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A simple quality-of-life change that makes Bevy easier to use and removed C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jul 8, 2022
@AlexOkafor
Copy link
Contributor Author

Thanks for the heads up on that PR! Just tried what you suggested and unfortunately won't work as-is (0.7.0).

@bors bors bot closed this as completed in 38005b0 Jan 16, 2023
alradish pushed a commit to alradish/bevy that referenced this issue Jan 22, 2023
# Objective

Fix bevyengine#5248.

## Solution

Support `In<T>` parameters and allow returning arbitrary types in exclusive systems.

---

## Changelog

- Exclusive systems may now be used with system piping.

## Migration Guide

Exclusive systems (systems that access `&mut World`) now support system piping, so the `ExclusiveSystemParamFunction` trait now has generics for the `In`put and `Out`put types.

```rust
// Before
fn my_generic_system<T, Param>(system_function: T)
where T: ExclusiveSystemParamFunction<Param>
{ ... }

// After
fn my_generic_system<T, In, Out, Param>(system_function: T)
where T: ExclusiveSystemParamFunction<In, Out, Param>
{ ... }
```
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

Fix bevyengine#5248.

## Solution

Support `In<T>` parameters and allow returning arbitrary types in exclusive systems.

---

## Changelog

- Exclusive systems may now be used with system piping.

## Migration Guide

Exclusive systems (systems that access `&mut World`) now support system piping, so the `ExclusiveSystemParamFunction` trait now has generics for the `In`put and `Out`put types.

```rust
// Before
fn my_generic_system<T, Param>(system_function: T)
where T: ExclusiveSystemParamFunction<Param>
{ ... }

// After
fn my_generic_system<T, In, Out, Param>(system_function: T)
where T: ExclusiveSystemParamFunction<In, Out, Param>
{ ... }
```
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-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants