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

In generated Rust code, logical actions in main reactors aren't mutable, making them not schedulable #1110

Closed
jhaye opened this issue Apr 22, 2022 · 3 comments
Labels
bug Something isn't working rust Related to the Rust target

Comments

@jhaye
Copy link
Collaborator

jhaye commented Apr 22, 2022

When implementing the code snippets for the website, I created this short program:

target Rust;
main reactor {
    state count:u32(1);
    logical action a;
    reaction(startup, a) {=
        let tag = ctx.get_tag();
        println!(
            "{}. Logical time is {}. Microstep is {}.",
            self.count,
            tag.duration_since_start().as_nanos(),
            tag.microstep(),
        );
        if self.count < 5 {
            self.count += 1;
            ctx.schedule(a, Asap);
        }
    =}
}

It doesn't compile:

error[E0308]: mismatched types
  --> src/reactors/microsteps.rs:32:26
   |
32 |             ctx.schedule(a, Asap);
   |                          ^ types differ in mutability
   |
   = note: expected mutable reference `&mut LogicalAction<_>`
                      found reference `&LogicalAction<()>`

This is not a problem outside of main reactors.

@jhaye jhaye added bug Something isn't working rust Related to the Rust target labels Apr 22, 2022
@jhaye
Copy link
Collaborator Author

jhaye commented Apr 22, 2022

But it does seem to work when other reactors are present?

For example, this

target Rust;
reactor Destination {
    input x:u32;
    input y:u32;
    reaction(x, y) {=
        let tag = ctx.get_tag();
        println!(
            "Time since start: {}, microstep: {}",
            tag.offset_from_t0.as_nanos(),
            tag.microstep,
        );
        if ctx.is_present(x) {
            println!("  x is present.");
        }
        if ctx.is_present(y) {
            println!("  y is present.");
        }
    =}
}
main reactor {
    logical action repeat;
    d = new Destination();
    reaction(startup) -> d.x, repeat {=
        ctx.set(d__x, 1);
        ctx.schedule(repeat, Asap);
    =}
    reaction(repeat) -> d.y {=
        ctx.set(d__y, 1);
    =}
}

does compile.

@cmnrd
Copy link
Collaborator

cmnrd commented Apr 22, 2022

In your first example, you have not declared a as an effect of the reaction. It is only declared as a trigger and hence it is not mutable to prevent accidental scheduling. In your other example repeat is declared as an effect of the reaction and hence it works.

@jhaye
Copy link
Collaborator Author

jhaye commented Apr 22, 2022

Ah, right, so that's a problem with the C implementation that I took as a blueprint.

@jhaye jhaye closed this as completed Apr 22, 2022
@lhstrh lhstrh changed the title Logical actions in main reactors aren't mutable, making them not schedulable In generated Rust code, logical actions in main reactors aren't mutable, making them not schedulable May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rust Related to the Rust target
Projects
None yet
Development

No branches or pull requests

2 participants