From cbe8d7f595758e1f2dd4d4e71e2d3e29f39961da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 6 Sep 2022 13:36:27 +0200 Subject: [PATCH 1/2] Fix lf-lang/reactor-rs#17 Effect-dependencies were not being correctly registered for child port references. --- org.lflang/src/lib/rs/reactor-rs | 2 +- .../generator/rust/RustReactorEmitter.kt | 2 +- test/Rust/src/DependencyThroughChildPort.lf | 42 +++++++++++++++++++ test/Rust/src/README.md | 1 + 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/Rust/src/DependencyThroughChildPort.lf diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/src/lib/rs/reactor-rs index a2b9dae07b..fe8429f897 160000 --- a/org.lflang/src/lib/rs/reactor-rs +++ b/org.lflang/src/lib/rs/reactor-rs @@ -1 +1 @@ -Subproject commit a2b9dae07bb8568ee321cfe87226ef59151efad4 +Subproject commit fe8429f89768375dbb8f94ef826562c0af922abc diff --git a/org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt b/org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt index 37aaa94515..dd2156172b 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustReactorEmitter.kt @@ -283,7 +283,7 @@ ${" | "..declareChildConnections()} if (n.isShutdown) this += "__assembler.declare_triggers($rsRuntime::assembly::TriggerId::SHUTDOWN, ${n.invokerId})?;" this += n.uses.map { trigger -> "__assembler.declare_uses(${n.invokerId}, __self.${trigger.rustFieldName}.get_id())?;" } - this += n.effects.filterIsInstance().map { port -> + this += n.effects.filterIsInstance().map { port -> if (port.isMultiport) { "__assembler.effects_bank(${n.invokerId}, &__self.${port.rustFieldName})?;" } else { diff --git a/test/Rust/src/DependencyThroughChildPort.lf b/test/Rust/src/DependencyThroughChildPort.lf new file mode 100644 index 0000000000..5fc080a6ff --- /dev/null +++ b/test/Rust/src/DependencyThroughChildPort.lf @@ -0,0 +1,42 @@ +target Rust; +reactor Destination { + input x: u32; + input y: u32; + + state exec_count: u32; + + reaction(x, y) {= + let tag = ctx.get_tag(); + println!( + "Time since start: {}, microstep: {}", + tag.offset_from_t0.as_nanos(), + tag.microstep, + ); + + if tag == tag!(T0) { + assert!(ctx.is_present(x)); + assert_eq!(self.exec_count, 0); + } else { + assert_tag_is!(ctx, (T0, 1)); + assert!(ctx.is_present(y)); + assert_eq!(self.exec_count, 1); + } + self.exec_count += 1; + =} + + reaction(shutdown) {= + assert!(self.exec_count == 2, "reaction was not executed twice"); + println!("success"); + =} +} +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); + =} +} diff --git a/test/Rust/src/README.md b/test/Rust/src/README.md index d272323595..5d09ad52eb 100644 --- a/test/Rust/src/README.md +++ b/test/Rust/src/README.md @@ -21,6 +21,7 @@ This is not exhaustive. Ideally each of those bullet points would have a test ca - dependencies can be declared... - [x] all test files: on ports of this reactor - [x] `DependencyOnChildPort.lf`: on ports of a child reactor + - [x] `DependencyThroughChildPort.lf`: on ports of a child, triggers child reactions - [x] all test files: on an action - [x] trigger dependencies - [x] all test files: trigger dependencies trigger reactions From fcb929fbab5c664dceab3deae781100aa96f0c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 9 Sep 2022 11:16:52 +0200 Subject: [PATCH 2/2] Format --- test/Rust/src/DependencyThroughChildPort.lf | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/Rust/src/DependencyThroughChildPort.lf b/test/Rust/src/DependencyThroughChildPort.lf index 5fc080a6ff..0e708cf878 100644 --- a/test/Rust/src/DependencyThroughChildPort.lf +++ b/test/Rust/src/DependencyThroughChildPort.lf @@ -1,9 +1,10 @@ -target Rust; +target Rust + reactor Destination { - input x: u32; - input y: u32; + input x: u32 + input y: u32 - state exec_count: u32; + state exec_count: u32 reaction(x, y) {= let tag = ctx.get_tag(); @@ -29,14 +30,15 @@ reactor Destination { println!("success"); =} } + main reactor { - logical action repeat; - d = new Destination(); + 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); - =} + + reaction(repeat) -> d.y {= ctx.set(d__y, 1); =} }